0

I need to get DCT-coefficients array after quantization for further changing bits (steganography). My question is: Lets say, i have jpeg image in picturebox or whatever. How can i acess to dct coef. of this image using C# and library like LibJpeg.Net? Need a code pls. Can't find anything complete and simple on whole web. Also, can't see any tutorial on LibJpeg.Net.

After this steps:

    BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
     System.IO.FileStream oFileStreamImage = new System.IO.FileStream(strImagePath, 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();

what should i do now, to edit dct coeff? Use .Access()? How do i use this? Any examples?

Following:

short[] block = JBlock[c].Access(x, y);

gives an error like that: "Cannot implicitly convert type 'BitMiracle.LibJpeg.Classic.JBLOCK[][]' to 'short[]'"

Also, while using something similar, it gives an error about converting "BitMiracle.LibJpeg.Classic.JBLOCK[][]" to type "System.IConvertible".

Or maybe someone knows another easy way for my problem?

Errorfreak
  • 79
  • 2
  • 9
  • 3
    This site is geared toward help debugging code you have already written, not to provide the code for you. Try to figure something out yourself and then post what you have written if you are having trouble getting it to work. – Kmeixner Feb 10 '15 at 19:16
  • I'm asking in case if somebody has something working already, and able to share. I can't figure anything by myself if i don't have examples, tutorials, and other useful things, that actually will teach. – Errorfreak Feb 10 '15 at 20:53
  • `varrJBlockOrg` from [this post](http://stackoverflow.com/a/3736863/2243104) seems to be relevant to you. – Reti43 Feb 15 '15 at 14:37
  • I saw this code, i used it, but still, questions about viewing dct arrays and manipulating coefficients are open. Maybe i just can't understand what is going on with all this amount of cycles and in places like that: `varrJBlockNew[i].Access(iY + iTileY * iComponentHeigthInBlocks, 1)[0][iX + iTileX * iComponentWidthInBlocks] = varrJBlockOrg[i].Access(iY, 1)[0][iX];`, and can not implement this for my needs. – Errorfreak Feb 15 '15 at 15:58

2 Answers2

2

All right, i figured out something. At least, its answering my main question.

private void button1_Click(object sender, EventArgs e)
        {
            string path = @"D:\067.jpg";
            var img = new Bitmap(path);
            var jo = img.Width; 
            var joj = img.Height;
            BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
            System.IO.FileStream oFileStreamImage = new System.IO.FileStream(path, 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 ll = JBlock[0].Access(0, 1); // accessing the element
            var oo = 5; // its gonna be new value for coefficient
            for (int i = 0; i < 64; i++) // some cycle
            {
                ll[0][i][0] = Convert.ToInt16(oo); // changes
            }
            oJpegDecompress.jpeg_finish_decompress(); 
            oFileStreamImage.Close();
            /////
            System.IO.FileStream objFileStreamMegaMap = System.IO.File.Create(@"D:\068.jpg");
            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 = joj;
            oJpegCompress.Image_width = jo;
            oJpegCompress.jpeg_write_coefficients(JBlock);          
            oJpegCompress.jpeg_finish_compress();
            objFileStreamMegaMap.Close();
            oJpegDecompress.jpeg_abort_decompress();
            oFileStreamImage.Close();
        }

Little bit sloppy, but still, just the test... Used some code from here

Like that, as you can see in your console, every 0th element under 0->m_buffer->0->i in the output image will be equal to 5

All hail to me.

Community
  • 1
  • 1
Errorfreak
  • 79
  • 2
  • 9
-1

I've done this while writing a JPEG library to verify its correctness. You just have to get the source code to LIBJPEG; identify where it does the functions you are interested int (somewhat difficult because the code is convoluted); set a breakpoint or return there.

user3344003
  • 20,574
  • 3
  • 26
  • 62