]> git.nihav.org Git - nihav.git/commitdiff
factor out commonly used greyscale pixel formaton
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 13 May 2026 16:48:51 +0000 (18:48 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 13 May 2026 16:48:51 +0000 (18:48 +0200)
nihav-commonfmt/src/codecs/cinepak.rs
nihav-commonfmt/src/codecs/cinepakenc.rs
nihav-commonfmt/src/codecs/gifenc.rs
nihav-core/src/formats.rs
nihav-hlblocks/src/imgseqdec.rs
nihav-indeo/src/demuxers/dvi.rs

index eeef065e422f16f5115eaebabb116d1ab34da226..7b150f566f01d949cbcfe289ee1a0f2710fa94d1 100644 (file)
@@ -304,15 +304,7 @@ impl NADecoder for CinepakDecoder {
                 validate!(is_intra);
                 let fmt = match mode {
                         DecodeMode::YUV     => YUV420_FORMAT,
-                        DecodeMode::Gray    => NAPixelFormaton {
-                                model: ColourModel::YUV(YUVSubmodel::YUVJ),
-                                components: 1,
-                                comp_info: [Some(NAPixelChromaton{h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 0, next_elem: 1}), None, None, None, None],
-                                elem_size: 1,
-                                be: true,
-                                alpha: false,
-                                palette: false,
-                            },
+                        DecodeMode::Gray    => GREY_FORMAT,
                         DecodeMode::Palette => PAL8_FORMAT,
                         _ => unreachable!(),
                     };
index e8c624a39910c598ae1039e9840b0edc86c12676..b61b8a0e08d66d9ec9c53769c0548f356d7d08b0 100644 (file)
@@ -144,16 +144,6 @@ impl RNG {
     }
 }
 
-const GRAY_FORMAT: NAPixelFormaton = NAPixelFormaton {
-        model: ColourModel::YUV(YUVSubmodel::YUVJ),
-        components: 1,
-        comp_info: [Some(NAPixelChromaton{h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 0, next_elem: 1}), None, None, None, None],
-        elem_size: 1,
-        be: true,
-        alpha: false,
-        palette: false,
-    };
-
 struct MaskWriter {
     masks:  Vec<u32>,
     mask:   u32,
@@ -1159,7 +1149,7 @@ impl NAEncoder for CinepakEncoder {
             },
             NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
             NACodecTypeInfo::Video(vinfo) => {
-                let pix_fmt = if vinfo.format == GRAY_FORMAT { GRAY_FORMAT } else { YUV420_FORMAT };
+                let pix_fmt = if vinfo.format == GREY_FORMAT { GREY_FORMAT } else { YUV420_FORMAT };
                 let outinfo = NAVideoInfo::new((vinfo.width + 3) & !3, (vinfo.height + 3) & !3, false, pix_fmt);
                 let mut ofmt = *encinfo;
                 ofmt.format = NACodecTypeInfo::Video(outinfo);
@@ -1173,7 +1163,7 @@ impl NAEncoder for CinepakEncoder {
             NACodecTypeInfo::None => Err(EncoderError::FormatError),
             NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
             NACodecTypeInfo::Video(vinfo) => {
-                if vinfo.format != YUV420_FORMAT && vinfo.format != GRAY_FORMAT {
+                if vinfo.format != YUV420_FORMAT && vinfo.format != GREY_FORMAT {
                     return Err(EncoderError::FormatError);
                 }
                 if ((vinfo.width | vinfo.height) & 3) != 0 {
index 94084eb6692dd9cd7f1d2c4a4185719826504836..4ed90c9f12ac969a0368d90fea003bf889f6b569 100644 (file)
@@ -2,16 +2,6 @@ use nihav_core::codecs::*;
 use nihav_core::io::byteio::*;
 use nihav_core::io::bitwriter::*;
 
-const GRAY_FORMAT: NAPixelFormaton = NAPixelFormaton {
-        model: ColourModel::YUV(YUVSubmodel::YUVJ),
-        components: 1,
-        comp_info: [Some(NAPixelChromaton{h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 0, next_elem: 1}), None, None, None, None],
-        elem_size: 1,
-        be: true,
-        alpha: false,
-        palette: false,
-    };
-
 #[derive(Clone,Copy,Default,PartialEq)]
 enum CompressionLevel {
     None,
@@ -271,7 +261,7 @@ impl NAEncoder for GIFEncoder {
             },
             NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
             NACodecTypeInfo::Video(vinfo) => {
-                let format = if vinfo.format == GRAY_FORMAT { GRAY_FORMAT } else { PAL8_FORMAT };
+                let format = if vinfo.format == GREY_FORMAT { GREY_FORMAT } else { PAL8_FORMAT };
                 let outinfo = NAVideoInfo::new(vinfo.width, vinfo.height, false, format);
                 let mut ofmt = *encinfo;
                 ofmt.format = NACodecTypeInfo::Video(outinfo);
@@ -288,12 +278,12 @@ impl NAEncoder for GIFEncoder {
                 if vinfo.width > 65535 || vinfo.height > 65535 {
                     return Err(EncoderError::FormatError);
                 }
-                if vinfo.format != PAL8_FORMAT && vinfo.format != GRAY_FORMAT {
+                if vinfo.format != PAL8_FORMAT && vinfo.format != GREY_FORMAT {
                     return Err(EncoderError::FormatError);
                 }
                 self.width  = vinfo.width;
                 self.height = vinfo.height;
-                self.grayscale = vinfo.format == GRAY_FORMAT;
+                self.grayscale = vinfo.format == GREY_FORMAT;
 
                 let edata = self.tr_idx.map(|val| vec![val]);
 
index c1ba215b84ee29f69443cea7bedd4fd55327677b..370314e44fb178669a0a9fb3853f84c228f21807 100644 (file)
@@ -552,6 +552,13 @@ pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColourModel::R
                                             None, None],
                                         elem_size: 3, be: false, alpha: false, palette: true };
 
+/// Pre-defined format for 8-bit greyscale.
+pub const GREY_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColourModel::YUV(YUVSubmodel::YUVJ), components: 1,
+                                        comp_info: [
+                                            chromaton!(0, 0, false, 8, 0, 0, 1),
+                                            None, None, None, None],
+                                        elem_size: 1, be: true, alpha: false, palette: false };
+
 /// Predefined format for RGB555 packed video.
 pub const RGB555_FORMAT: NAPixelFormaton = NAPixelFormaton::make_rgb16_fmt(5, 5, 5, true, false);
 
index 814ec38eaf827fb3c0e44f388f3de3165bba5ab9..633f345ef861a6876b107792f66683390e45336b 100644 (file)
@@ -208,15 +208,8 @@ fn read_pnm_header(file: &mut BufReader<File>, pgmyuv: bool) -> DemuxerResult<NA
     let mut vinfo = NAVideoInfo::new(w, h, false, RGB24_FORMAT);
     match magic[1] {
         b'5' | b'2' if !pgmyuv => {
-            vinfo.format = NAPixelFormaton {
-                    model: ColourModel::YUV(YUVSubmodel::YUVJ),
-                    components: 1,
-                    comp_info: [Some(NAPixelChromaton{h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 0, next_elem: 1}), None, None, None, None],
-                    elem_size: 1,
-                    be: true,
-                    alpha: false,
-                    palette: false,
-                };
+            // todo: modify format for different bit-depths
+            vinfo.format = GREY_FORMAT;
             vinfo.bits = bits;
         },
         b'5' | b'2' => {
index 5244185d238856d015a6ca86bfcfbc9a8c84cf22..36da559d23b3f3b7171eb71793142aea5e7510bc 100644 (file)
@@ -1,16 +1,6 @@
 use std::collections::VecDeque;
 use nihav_core::demuxers::*;
 
-const GRAY_FORMAT: NAPixelFormaton = NAPixelFormaton {
-    model: ColourModel::YUV(YUVSubmodel::YUVJ),
-    components: 1,
-    comp_info: [Some(NAPixelChromaton{h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 0, next_elem: 1}), None, None, None, None],
-    elem_size: 1,
-    be: true,
-    alpha: false,
-    palette: false,
-};
-
 struct DVIDemuxer<'a> {
     src:            &'a mut dyn ByteIO,
     data_end:       u64,
@@ -182,7 +172,7 @@ impl<'a> DemuxCore<'a> for DVIDemuxer<'a> {
                         };
 
                     let fmt = match hdr_subtype {
-                            1 | 11 | 12 => GRAY_FORMAT, // Y/U/V component only
+                            1 | 11 | 12 => GREY_FORMAT, // Y/U/V component only
                             _ => YUV410_FORMAT,
                         };