]> git.nihav.org Git - nihav.git/commitdiff
cinepakenc: try to calculate the number of strips automatically if requested
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 20 May 2023 15:07:13 +0000 (17:07 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 20 May 2023 15:07:13 +0000 (17:07 +0200)
nihav-commonfmt/src/codecs/cinepakenc.rs

index f4ac9b24fd375c52b4f5717fcb4aac1fbd3e2e42..8273de0197a8755914560af7ce6464189f315c7e 100644 (file)
@@ -1000,6 +1000,12 @@ impl NAEncoder for CinepakEncoder {
     fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> {
         let buf = frm.get_buffer();
         if let Some(ref vbuf) = buf.get_vbuf() {
+            if self.nstrips == 0 {
+                let (w, h) = vbuf.get_dimensions(0);
+                self.nstrips = ((((w * h) >> 4) + 1200) / 2400).max(1).min(3);
+                let strip_h = ((h + self.nstrips - 1) / self.nstrips + 3) & !3;
+                self.nstrips = (h + strip_h - 1) / strip_h;
+            }
             let cur_strips = self.v1_cb.len();
             if cur_strips != self.nstrips {
                 self.frmcount = 0;