Search code examples
c#imagejpegminimum-coded-unit

how to read/write a raw jpeg MCU block from an image ? [.net preffered] [maybe using a 3rd party iamge library]


i want to read the raw image data of a jpeg so i can manipulate it without loosing any quality when doing so.
i took a look at the LibJpeg.Net library http://bitmiracle.com/libjpeg .
but there is a lot of code and couldnt find anything about reading/writing raw blocks.
mainly i want to implement lossless editing of a jpeg image and was wondering how to do it?
http://en.wikipedia.org/wiki/Jpeg#Lossless_editing
thanks

Update:

basically what i want to do is to access the jpeg block data as some kind of array so i can read the data.
and then i want to create a new jpeg and access some kind of block data array that i can fill with rows from other images.
the tasks seems easy but the problem is that the documentation of libJpeg.net is not that clear.
i have reached this state of code now.

var cinfo = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
cinfo.jpeg_stdio_src(new System.IO.FileStream(@"C:\File.jpg", System.IO.FileMode.Open));
cinfo.jpeg_read_header(true);
cinfo.jpeg_start_decompress();

but that is it , i dont know where to find that array of MCU blocks or if i am even reading the right structure


Solution

  • Maybe BitMiracle.LibJpeg.Classic.jpeg_decompress_struct.jpeg_read_raw_data() will do what you need.

    You may also want to review JpegCodec implementation in LibTiff.Net. That codec uses LibJpeg.Net for various purposes. Reading of uncompressed jpeg data is among of them.

    Disclaimer: I am one of the maintainers of the library.