سؤال

I have a question regarding jpeg encoding algorithm. I have 3 input plane data of an image: Y, Cb, Cr. And I want to encode it to a JPEG image. My question is is it possible to pass first 1/3 of these Y, Cb, Cr plane data to a jpeg encoder, get first 1/3 of a JPEG image back. Continue with then second 1/3 and get the 66% of JPEG image back and finally feed the rest of the 1/3 and get the full JPEG back?

Thank you.

هل كانت مفيدة؟

المحلول 2

It is not clear what you are trying to do? Are you trying to encode each component separately?

That can be done, depending upon your software. JPEG is oblivious to what is being compressed. It can't tell a Y, from a CB, from a B. The question is whether your software will allow it.

Each color is encoded as a separate scan. If you parse a compressed JPEG file, it is is simple to separate the scans for each color component.

The way you could probably do it is try to fake the encoder into compressing each component separately as a grayscale image.

If you are trying to do 1/3 of an image at a time, you'd have to break the image up yourself.

You might also want to look at progressive JPEG.

نصائح أخرى

JPEG does not require you to specify the height of the image in the "header". Indeed it allows you to specify the height to be zero in the "header" if you at the end tag on a DNL marker. DNL stands for Define-Number-of-Lines. This was a feature added to the standard to support things like JPEG compressing the output of a handheld scanner. So, using this format you can create a valid JPEG file consisting of the first 1/3. To add the second 1/3. First remove the old DNL marker, add the new entropy data and then tag on the DNL marker with the updated number of lines. Fairly simple if your software supports it.

The simplest would be to use restart markers such that there is such a marker after 1/3 of the images. Otherwise you will have to keep a little information from each 1/3 to the next.

What you're asking to do is technically feasible, but there are certain conditions that would need to be met. Typical JPEG encoders treat the operation as "atomic", meaning that you can't ask it produce a valid JPEG file and than call it again later with more data to add to the original file. Here's what is needed:

1) Your image divisions would each need to be a multiple of MCU size in the vertical direction (e.g. divisible by 8 or 16 depending on the color subsampling mode).

2) You will need to have restart markers which reset at each of your image boundaries. This will allow the output of each section to end on a byte boundary.

3) You will need to use a JPEG encoder that you have a lot of control over. It needs to use the same Huffman tables every time (fixed tables, not dynamically generated).

The main idea is that you will need to create a normal JPEG file for the first section, then merge it with the new sections by re-using the header and adjusting the image height, then appending the new compressed data part to the end of the old.

I say with certainty that this can be accomplished because I've written my own JPEG codec from scratch and I know that my code is capable of accomplishing this.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top