开发者

Should CbCr values for LibJPEG be signed or unsigned

I have a a SoC camera module which outputs YCbCr data in the following ranges: Y (0 -> 255) Cb and Cr (-127 -> 127)

Now my question is, does libjpeg accept these signed values or should I change the signed values so they are in the range 0 -> 255?

I am using the libjpeg 'bolt-on' jpeg compressor provided by ATMEL as part of the SAM3s-EK. The code for the bolt-on part for the ijg_compress_raw_no_padding function is shown below... as far as I can see this takes my nice neat array of YCbCr data and manipulates into a form that libjpeg likes ;-)

    static void _init_sarray_imcu_row(JSAMPIMAGE *image,JSAMPLE *src,uint32_t y_pos,uint32_t width,uint32_t rows)
{
    JSAMPLE *r0;
    JSAMPLE *r1;
    JSAMPARRAY ay = (*image)[0];
    JSAMPARRAY au = (*image)[1];
    JSAMPARRAY av = (*image)[2];
    JSAMPROW ry0,ru,rv,ry1;    

    int i,j;
    for( i = 0; i < rows/2 ;i++)
    {
        r0 = & src[ (i * 2 + y_pos) * width * 2];
        r1 = & src[ (i * 2 + y_pos + 1) * width * 2];

        ry0 = ay[i*2];
        ry1 = ay[i*2+1];

        ru = au[i];
        rv = av[i];

        for(j = 0; j < width /2; j++)
        {
            ry0[j * 2] = r0[j*4];
        开发者_开发问答    ry1[j * 2] = r1[j*4];
            ry0[j * 2 + 1] = r0[j*4+2];
            ry1[j * 2 +1] = r1[j*4+2];

            ru[j] = (r0[ j * 4 + 1] + r1[j*4+1])/2;
            rv[j] = (r0[ j * 4 + 3] + r1[j*4+3])/2;

        }


    }
}

I am also not entirely sure of the order the values should be in within the raw data array that I send the this function ie; YCbCrY or YCbYCr etc etc, but this I can play with as it becomes obvious when the output image is viewed.

As it is I am getting an image where some colours appear to be mixed up , Red & blue seem to be swapped and the same with yellow and green.

So I repeat my initial question just in case it was lost in there:

Does this function only accept values in the region 0->255 or does it accept the data as is from the camera with Y (0->255) and Cb & Cr (-127->127)?

And if anybody can advise on the order the array should be packed that would also help.

Many thanks deBoogle


According to Wikipedia JFIF is using 0-255. It looks like you have to add 128 to your Cb and Cr colour differences.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜