jpeg_write_coefficients() public method

Compression initialization for writing raw-coefficient data. Useful for lossless transcoding.
Before calling this, all parameters and a data destination must be set up. Call jpeg_finish_compress to actually write the data.
public jpeg_write_coefficients ( jvirt_array coef_arrays ) : void
coef_arrays jvirt_array The virtual arrays need not be filled or even realized at the time /// jpeg_write_coefficients is called; indeed, the virtual arrays typically will be realized /// during this routine and filled afterwards. ///
return void
Ejemplo n.º 1
0
 public static string IncImageDCT(string fullPath)
 {
     string suffix = "testDCT";
     var img = new Bitmap(fullPath);
     var width = img.Width;
     var height = img.Height;
     int hd = height / 8;
     int wd = width / 8;
     img.Dispose();
     BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
     System.IO.FileStream oFileStreamImage = new System.IO.FileStream(fullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
     oJpegDecompress.jpeg_stdio_src(oFileStreamImage);
     oJpegDecompress.jpeg_read_header(true);
     BitMiracle.LibJpeg.Classic.jvirt_array<BitMiracle.LibJpeg.Classic.JBLOCK>[] JBlock = oJpegDecompress.jpeg_read_coefficients();
     var block = JBlock[0].Access(0, hd); // accessing the element
     for (int i = 0; i < hd; i++)
     {
         for (int j = 0; j < wd; j++)
         {
             short t = block[i][j].data[0];
             if ((t >= 0 && t % 2 == 1) || (t < 0 && t % 2 == 0))
             {
                 t--;
             }
             else if ((t >= 0 && t % 2 == 0) || (t < 0 && t % 2 == 1))
             {
                 t++;
             }
             block[i][j].data[0] = t;
         }
     }
     oJpegDecompress.jpeg_finish_decompress();
     oFileStreamImage.Close();
     ////
     string filenameNew = MyHelper.AppendFileName(fullPath, suffix);
     System.IO.FileStream objFileStreamMegaMap = System.IO.File.Create(filenameNew);
     BitMiracle.LibJpeg.Classic.jpeg_compress_struct oJpegCompress = new BitMiracle.LibJpeg.Classic.jpeg_compress_struct();
     oJpegCompress.jpeg_stdio_dest(objFileStreamMegaMap);
     oJpegDecompress.jpeg_copy_critical_parameters(oJpegCompress);
     oJpegCompress.Image_height = height;
     oJpegCompress.Image_width = width;
     oJpegCompress.jpeg_write_coefficients(JBlock);
     oJpegCompress.jpeg_finish_compress();
     objFileStreamMegaMap.Close();
     oJpegDecompress.jpeg_abort_decompress();
     return filenameNew;
 }