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

StackOverflow https://stackoverflow.com/questions/3702939

Question

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

Was it helpful?

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.

OTHER TIPS

I'm not sure that jpeglib has public functions for that. They support lossless transformations in the jtransform_execute_transformation, but only have rotate90/280/2780, flip, crop, and transpose.

You'll have to read the source of that function to find out how it gets the blocks. A quick look shows it using

srcinfo->mem->access_virt_barray

Which is a ptr-to-function, where srcinfo is a j_decompress_ptr. It gets a JBLOCKARRAY from that.

I would try to read do_flip_v which should be an easy transformation to understand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top