Danny
Danny

Reputation: 1

BitMiracle decoding YCbCr data output from ReadScanLine TIFF issue

I'm using BitMiracle to extract individual pages from multi page TIFF files and save them to disk as single page files. The process generally works fine - I'm using ReadRGBAImage to read the full file into an int buffer. However, for some images the images are too large to read the full image into a buffer due to system restrictions, so I tried to rewrite the code to use a line by line method using ReadScanLine with each line having a length returned by ScanlineSize. This works correctly for RGB Tiffs, but if the TIFF is YCbCr subsampled, then I can't seem to convert the buffer returned by ReadScanLine to the correct RGB values. I've tried several variants of the equations found online but nothing seems to return the correct colour values. The image itself is correct - you can tell that if the colours were correct then the output would be correct. For example, the background may be pink but you can still tell it's the same image. The YCbCr output seems to be in 2 lots of 2 bytes containing the Y Cb Cr values and a 127 which I assume is padding. These values need to be interpreted to regenerate the RBG values for 2 pixels. ScanlineSize returns 2 x image width bytes when the image is YCbCr sub-sampled, whereas it returns 3 x image width bytes where the image is just RGB (as expected). So I have a couple of questions - why does the array returned when using ReadScanLine differ in definition from that returned when using ReadRGBAImage ? Is there a way of getting ReadScanLine to return RGB instead of YCbCr ? If not - what is the correct way of converting values returned by ReadScanLine from a YCbCr 4:2:2 image to RGB ? Let me know if you need samples data or images etc. Thanks.

I've tried lots of variants of YCbCr -> RGB conversion equations found online. Most either give a grey output, or a pink background, or have the colours swapped.

Upvotes: 0

Views: 27

Answers (0)

Related Questions