]> git.nihav.org Git - nihav.git/commitdiff
avimux: write smaller palettes if actual palette bits are lower
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 25 Apr 2026 16:22:45 +0000 (18:22 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 25 Apr 2026 16:22:45 +0000 (18:22 +0200)
nihav-commonfmt/src/muxers/avi.rs

index 1116b71ef5a0e16d20a42d5f502659b067bd0dbf..c91f2b51be0ef0089ef854548b9de0f7b4b397fd 100644 (file)
@@ -296,10 +296,11 @@ impl<'a> MuxCore<'a> for AVIMuxer<'a> {
                     self.bw.write_u32le(0)?; // x dpi
                     self.bw.write_u32le(0)?; // y dpi
                     if vinfo.format.palette {
-                        self.bw.write_u32le(256)?; // total colors
+                        let nclrs = 1 << vinfo.bits.min(8);
+                        self.bw.write_u32le(nclrs)?; // total colors
                         self.bw.write_u32le(0)?; // important colors
                         self.pal_pos[strno] = self.bw.tell() as u32;
-                        for _ in 0..256 {
+                        for _ in 0..(nclrs as usize) {
                             self.bw.write_u32le(0)?;
                         }
                     } else {
@@ -450,7 +451,10 @@ impl<'a> MuxCore<'a> for AVIMuxer<'a> {
                 if let NASideData::Palette(_, ref pal) = sdata {
                     let cur_pos = self.bw.tell();
                     self.bw.seek(SeekFrom::Start(u64::from(self.pal_pos[str_num])))?;
-                    for quad in pal.chunks(4) {
+
+                    let vinfo = stream.get_info().get_properties().get_video_info().unwrap();
+                    let nclrs = 1 << vinfo.bits.min(8);
+                    for quad in pal.chunks(4).take(nclrs) {
                         self.bw.write_byte(quad[2])?;
                         self.bw.write_byte(quad[1])?;
                         self.bw.write_byte(quad[0])?;