Exemple #1
0
        static void Strategy()
        {
            JpegCompressor      compressor   = new JpegCompressor();
            BlackAndWhiteFilter filter       = new BlackAndWhiteFilter();
            ImageStorage        imageStorage = new ImageStorage(compressor, filter);

            imageStorage.Store("Video File");
        }
 public static byte[] EncodeJpeg(ReadOnlySpan <byte> pixelData,
                                 JpegPixelFormat pixelFormat,
                                 int width,
                                 int height,
                                 int quality,
                                 int pitch)
 {
     using var compressor = new JpegCompressor();
     return(compressor.Compress(
                pixelData,
                width,
                pitch,
                height,
                pixelFormat,
                quality
                ));
 }
Exemple #3
0
        /*
        * Interface routines.  This layer of routines exists
        * primarily to limit side-effects from LibJpeg.Net exceptions.
        * Also, normal/error returns are converted into return
        * values per LibTiff.Net practice.
        */
        private bool TIFFjpeg_create_compress()
        {
            /* initialize JPEG error handling */
            try
            {
                m_compression = new JpegCompressor();
                m_common = m_compression;
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Exemple #4
0
        public override bool Init()
        {
            Debug.Assert(m_scheme == Compression.JPEG);

            /*
            * Merge codec-specific tag information and override parent get/set
            * field methods.
            */
            m_tif.MergeFieldInfo(jpegFieldInfo, jpegFieldInfo.Length);

            /*
             * Allocate state block so tag methods have storage to record values.
             */
            m_compression = null;
            m_decompression = null;
            m_photometric = 0;
            m_h_sampling = 0;
            m_v_sampling = 0;
            m_bytesperline = 0;
            m_scancount = 0;
            m_samplesperclump = 0;
            m_recvtime = 0;

            m_parentTagMethods = m_tif.m_tagmethods;
            m_tif.m_tagmethods = m_tagMethods;

            /* Default values for codec-specific fields */
            m_jpegtables = null;
            m_jpegtables_length = 0;
            m_jpegquality = 75; /* Default IJG quality */
            m_jpegcolormode = JpegColorMode.RGB;
            m_jpegtablesmode = JpegTablesMode.Quant | JpegTablesMode.Huff;

            m_recvparams = 0;
            m_subaddress = null;
            m_faxdcs = null;

            m_ycbcrsampling_fetched = false;

            m_rawDecode = false;
            m_rawEncode = false;
            m_tif.m_flags |= TiffFlags.NoBitRev; // no bit reversal, please

            m_cinfo_initialized = false;

            /*
             ** Create a JPEGTables field if no directory has yet been created. 
             ** We do this just to ensure that sufficient space is reserved for
             ** the JPEGTables field.  It will be properly created the right
             ** size later. 
             */
            if (m_tif.m_diroff == 0)
            {
                const int SIZE_OF_JPEGTABLES = 2000;

                // The following line assumes incorrectly that all JPEG-in-TIFF
                // files will have a JpegTables tag generated and causes
                // null-filled JpegTables tags to be written when the JPEG data
                // is placed with WriteRawStrip. The field bit should be 
                // set, anyway, later when actual JpegTables header is
                // generated, so removing it here hopefully is harmless.
                //
                //       m_tif.setFieldBit(FIELD_JPEGTABLES);
                //

                m_jpegtables_length = SIZE_OF_JPEGTABLES;
                m_jpegtables = new byte[m_jpegtables_length];
            }

            /*
             * Mark the YCBCRSAMPLES as present even if it is not
             * see: JPEGFixupTestSubsampling().
             */
            m_tif.setFieldBit(FieldBit.YCbCrSubsampling);
            return true;
        }