?? encoder.c
字號:
}
}
for (j = (16 - cols) >> 1; j > 0; j--)
{
*CB_Ptr++ = *(CB_Ptr - 1);
*CR_Ptr++ = *(CR_Ptr - 1);
}
Y3_Ptr += 8;
Y4_Ptr += 8;
Y3Ptr += 8;
Y4Ptr += 8;
input_ptr += incr;
}
if (rows <= 8)
{
for (i = 8 - rows; i > 0; i--)
{
for (j = 8; j > 0; j--)
{
*Y1_Ptr++ = *(Y1_Ptr - 8);
*Y2_Ptr++ = *(Y2_Ptr - 8);
}
}
for (i = 8; i > 0; i--)
{
Y1_Ptr -= 8;
Y2_Ptr -= 8;
for (j = 8; j > 0; j--)
{
*Y3_Ptr++ = *Y1_Ptr++;
*Y4_Ptr++ = *Y2_Ptr++;
}
}
}
else
{
for (i = (16 - rows); i > 0; i--)
{
for (j = 8; j > 0; j--)
{
*Y3_Ptr++ = *(Y3_Ptr - 8);
*Y4_Ptr++ = *(Y4_Ptr - 8);
}
}
}
for (i = ((16 - rows) >> 1); i > 0; i--)
{
for (j = 8; j > 0; j--)
{
*CB_Ptr++ = *(CB_Ptr - 8);
*CR_Ptr++ = *(CR_Ptr - 8);
}
}
}
static void
read_422_format (JPEG_ENCODER_STRUCTURE * jpeg_encoder_structure,
UINT8 * input_ptr)
{
INT32 i, j;
UINT16 Y1_cols, Y2_cols;
INT16 * Y1_Ptr = Y1;
INT16 * Y2_Ptr = Y2;
INT16 * CB_Ptr = CB;
INT16 * CR_Ptr = CR;
UINT16 rows = jpeg_encoder_structure->rows;
UINT16 cols = jpeg_encoder_structure->cols;
UINT16 incr = jpeg_encoder_structure->incr;
if (cols <= 8)
{
Y1_cols = cols;
Y2_cols = 0;
}
else
{
Y1_cols = 8;
Y2_cols = (UINT16) (cols - 8);
}
for (i = rows; i > 0; i--)
{
for (j = Y1_cols >> 1; j > 0; j--)
{
*Y1_Ptr++ = *input_ptr++ - 128;
*CB_Ptr++ = *input_ptr++ - 128;
*Y1_Ptr++ = *input_ptr++ - 128;
*CR_Ptr++ = *input_ptr++ - 128;
}
for (j = Y2_cols >> 1; j > 0; j--)
{
*Y2_Ptr++ = *input_ptr++ - 128;
*CB_Ptr++ = *input_ptr++ - 128;
*Y2_Ptr++ = *input_ptr++ - 128;
*CR_Ptr++ = *input_ptr++ - 128;
}
if (cols <= 8)
{
for (j = 8 - Y1_cols; j > 0; j--)
*Y1_Ptr++ = *(Y1_Ptr - 1);
for (j = 8 - Y2_cols; j > 0; j--)
*Y2_Ptr++ = *(Y1_Ptr - 1);
}
else
{
for (j = 8 - Y2_cols; j > 0; j--)
*Y2_Ptr++ = *(Y2_Ptr - 1);
}
for (j = (16 - cols) >> 1; j > 0; j--)
{
*CB_Ptr++ = *(CB_Ptr - 1);
*CR_Ptr++ = *(CR_Ptr - 1);
}
input_ptr += incr;
}
for (i = 8 - rows; i > 0; i--)
{
for (j = 8; j > 0; j--)
{
*Y1_Ptr++ = *(Y1_Ptr - 8);
*Y2_Ptr++ = *(Y2_Ptr - 8);
*CB_Ptr++ = *(CB_Ptr - 8);
*CR_Ptr++ = *(CR_Ptr - 8);
}
}
}
static void
read_444_format (JPEG_ENCODER_STRUCTURE * jpeg_encoder_structure,
UINT8 * input_ptr)
{
INT32 i, j;
INT16 * Y1_Ptr = Y1;
INT16 * CB_Ptr = CB;
INT16 * CR_Ptr = CR;
UINT16 rows = jpeg_encoder_structure->rows;
UINT16 cols = jpeg_encoder_structure->cols;
UINT16 incr = jpeg_encoder_structure->incr;
for (i = rows; i > 0; i--)
{
for (j = cols; j > 0; j--)
{
*Y1_Ptr++ = *input_ptr++ - 128;
*CB_Ptr++ = *input_ptr++ - 128;
*CR_Ptr++ = *input_ptr++ - 128;
}
for (j = 8 - cols; j > 0; j--)
{
*Y1_Ptr++ = *(Y1_Ptr - 1);
*CB_Ptr++ = *(CB_Ptr - 1);
*CR_Ptr++ = *(CR_Ptr - 1);
}
input_ptr += incr;
}
for (i = 8 - rows; i > 0; i--)
{
for (j = 8; j > 0; j--)
{
*Y1_Ptr++ = *(Y1_Ptr - 8);
*CB_Ptr++ = *(CB_Ptr - 8);
*CR_Ptr++ = *(CR_Ptr - 8);
}
}
}
#define CLIP(color) (unsigned char)(((color)>0xFF)?0xff:(((color)<0)?0:(color)))
/* translate RGB24 to YUV444 in input */
static void
RGB_2_444 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, size;
UINT8 R, G, B;
INT32 Y, Cb, Cr;
size = image_width * image_height;
for (i = size; i > 0; i--)
{
B = input_ptr[0];
G = input_ptr[1];
R = input_ptr[2];
//input_ptr -= 3;
Y = CLIP ((77 * R + 150 * G + 29 * B) >> 8);
Cb = CLIP (((-43 * R - 85 * G + 128 * B) >> 8) + 128);
Cr = CLIP (((128 * R - 107 * G - 21 * B) >> 8) + 128);
*input_ptr++ = (UINT8) Y;
*input_ptr++ = (UINT8) Cb;
*input_ptr++ = (UINT8) Cr;
}
}
/* translate RGB24 to YUV422 in input */
static void
RGB_2_422 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, size;
UINT8 R, G, B, R1, G1, B1;
INT32 Y, Yp, Cb, Cr;
UINT8 * inbuf = input_ptr;
size = image_width * image_height;
for (i = size; i > 0; i--)
{
B = inbuf[0];
G = inbuf[1];
R = inbuf[2];
B1 = inbuf[3];
G1 = inbuf[4];
R1 = inbuf[5];
inbuf += 6;
Y = CLIP ((77 * R + 150 * G + 29 * B) >> 8);
Yp = CLIP ((77 * R1 + 150 * G1 + 29 * B1) >> 8);
Cb = CLIP (((-43 * R - 85 * G + 128 * B) >> 8) + 128);
Cr = CLIP (((128 * R - 107 * G - 21 * B) >> 8) + 128);
*input_ptr++ = (UINT8) Y;
*input_ptr++ = (UINT8) Cb;
*input_ptr++ = (UINT8) Yp;
*input_ptr++ = (UINT8) Cr;
}
}
/* translate RGB24 to YUV420 in input */
static void
RGB_2_420 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, j, size;
UINT8 R, G, B, R1, G1, B1, Rd, Gd, Bd, Rd1, Gd1, Bd1;
INT32 Y, Yd, Y11, Yd1, Cb, Cr;
UINT8 * inbuf = input_ptr;
UINT8 * inbuf1 = input_ptr + (image_width * 3);
size = image_width * image_height >> 2;
for (i = size, j = 0; i > 0; i--)
{
B = inbuf[0];
G = inbuf[1];
R = inbuf[2];
B1 = inbuf[3];
G1 = inbuf[4];
R1 = inbuf[5];
Bd = inbuf1[0];
Gd = inbuf1[1];
Rd = inbuf1[2];
Bd1 = inbuf1[3];
Gd1 = inbuf1[4];
Rd1 = inbuf1[5];
inbuf += 6;
inbuf1 += 6;
j++;
if (j >= image_width / 2)
{
j = 0;
inbuf += (image_width * 3);
inbuf1 += (image_width * 3);
}
Y = CLIP ((77 * R + 150 * G + 29 * B) >> 8);
Y11 = CLIP ((77 * R1 + 150 * G1 + 29 * B1) >> 8);
Yd = CLIP ((77 * Rd + 150 * Gd + 29 * Bd) >> 8);
Yd1 = CLIP ((77 * Rd1 + 150 * Gd1 + 29 * Bd1) >> 8);
Cb = CLIP (((-43 * R - 85 * G + 128 * B) >> 8) + 128);
Cr = CLIP (((128 * R - 107 * G - 21 * B) >> 8) + 128);
*input_ptr++ = (UINT8) Y;
*input_ptr++ = (UINT8) Y11;
*input_ptr++ = (UINT8) Yd;
*input_ptr++ = (UINT8) Yd1;
*input_ptr++ = (UINT8) Cb;
*input_ptr++ = (UINT8) Cr;
}
}
/* translate RGB32 to YUV420 in input */
static void
RGB32_2_420 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, j, size;
UINT8 R, G, B, R1, G1, B1, Rd, Gd, Bd, Rd1, Gd1, Bd1;
INT32 Y, Yd, Y11, Yd1, Cb, Cr;
UINT8 * inbuf = input_ptr;
UINT8 * inbuf1 = input_ptr + (image_width * 4);
size = image_width * image_height >> 2;
for (i = size, j = 0; i > 0; i--)
{
B = inbuf[0];
G = inbuf[1];
R = inbuf[2];
B1 = inbuf[4];
G1 = inbuf[5];
R1 = inbuf[6];
Bd = inbuf1[0];
Gd = inbuf1[1];
Rd = inbuf1[2];
Bd1 = inbuf1[4];
Gd1 = inbuf1[5];
Rd1 = inbuf1[6];
inbuf += 8;
inbuf1 += 8;
j++;
if (j >= image_width / 2)
{
j = 0;
inbuf += (image_width * 4);
inbuf1 += (image_width * 4);
}
Y = CLIP ((77 * R + 150 * G + 29 * B) >> 8);
Y11 = CLIP ((77 * R1 + 150 * G1 + 29 * B1) >> 8);
Yd = CLIP ((77 * Rd + 150 * Gd + 29 * Bd) >> 8);
Yd1 = CLIP ((77 * Rd1 + 150 * Gd1 + 29 * Bd1) >> 8);
Cb = CLIP (((-43 * R - 85 * G + 128 * B) >> 8) + 128);
Cr = CLIP (((128 * R - 107 * G - 21 * B) >> 8) + 128);
*input_ptr++ = (UINT8) Y;
*input_ptr++ = (UINT8) Y11;
*input_ptr++ = (UINT8) Yd;
*input_ptr++ = (UINT8) Yd1;
*input_ptr++ = (UINT8) Cb;
*input_ptr++ = (UINT8) Cr;
}
}
/* translate RGB565 to YUV420 in input */
static void
RGB565_2_420 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, j, size;
UINT8 R, G, B, R1, G1, B1, Rd, Gd, Bd, Rd1, Gd1, Bd1;
INT32 Y, Yd, Y11, Yd1, Cb, Cr;
Myrgb16 * inbuf = (Myrgb16 *) input_ptr;
Myrgb16 * inbuf1 = inbuf + (image_width);
size = image_width * image_height >> 2;
for (i = size, j = 0; i > 0; i--)
{
/*
B = inbuf[0] & 0xf8;
G = ((inbuf[0] & 0x07) << 5) | ((inbuf[1] & 0xe0) >> 3);
R = (inbuf[1] & 0x1f) << 3;
B1 = inbuf[2] & 0xf8;
G1 = ((inbuf[2] & 0x07) << 5) | ((inbuf[3] & 0xe0) >> 3);
R1 = (inbuf[3] & 0x1f) << 3;
Bd = inbuf1[0] & 0xf8;
Gd = ((inbuf1[0] & 0x07) << 5) | ((inbuf1[1] & 0xe0) >> 3);
Rd = (inbuf1[1] & 0x1f) << 3;
Bd1 = inbuf1[2] & 0xf8;
Gd1 = ((inbuf1[2] & 0x07) << 5) | ((inbuf1[3] & 0xe0) >> 3);
Rd1 = (inbuf1[3] & 0x1f) << 3;
*/
B = inbuf[0].blue << 3;
G = inbuf[0].green << 2;
R = inbuf[0].red << 3;
B1 = inbuf[1].blue << 3;
G1 = inbuf[1].green << 2;
R1 = inbuf[1].red << 3;
Bd = inbuf1[0].blue << 3;
Gd = inbuf1[0].green << 2;
Rd = inbuf1[0].red << 3;
Bd1 = inbuf1[1].blue << 3;
Gd1 = inbuf[1].green << 2;
Rd1 = inbuf[1].red << 3;
inbuf += 2;
inbuf1 += 2;
j++;
if (j >= image_width / 2)
{
j = 0;
inbuf += (image_width);
inbuf1 += (image_width);
}
Y = CLIP ((77 * R + 150 * G + 29 * B) >> 8);
Y11 = CLIP ((77 * R1 + 150 * G1 + 29 * B1) >> 8);
Yd = CLIP ((77 * Rd + 150 * Gd + 29 * Bd) >> 8);
Yd1 = CLIP ((77 * Rd1 + 150 * Gd1 + 29 * Bd1) >> 8);
Cb = CLIP (((-43 * R - 85 * G + 128 * B) >> 8) + 128);
Cr = CLIP (((128 * R - 107 * G - 21 * B) >> 8) + 128);
*input_ptr++ = (UINT8) Y;
*input_ptr++ = (UINT8) Y11;
*input_ptr++ = (UINT8) Yd;
*input_ptr++ = (UINT8) Yd1;
*input_ptr++ = (UINT8) Cb;
*input_ptr++ = (UINT8) Cr;
}
}
static void
RGB_2_400 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, size;
UINT8 R, G, B;
INT32 Y;
UINT8 * inbuf = input_ptr;
size = image_width * image_height;
for (i = size; i > 0; i--)
{
B = inbuf[0];
G = inbuf[1];
R = inbuf[2];
inbuf += 3;
Y = CLIP ((77 * R + 150 * G + 29 * B) >> 8);
*input_ptr++ = (UINT8) Y;
}
}
/* translate YUV444P to YUV444 in input */
static void
YUV_2_444 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, size;
UINT8 * Ytmp = NULL;
UINT8 * Cbtmp = NULL;
UINT8 * Crtmp = NULL;
UINT8 * Buff = NULL;
Buff =
(UINT8 *) realloc ((UINT8 *) Buff,
(size_t) (image_width * image_height * 3));
if (Buff)
{
memcpy (Buff, input_ptr, image_width * image_height * 3);
Ytmp = Buff;
Cbtmp = Buff + image_width * image_height;
Crtmp = Buff + (image_width * image_height << 1);
size = image_width * image_height;
for (i = size; i > 0; i--)
{
*input_ptr++ = (UINT8) * Ytmp++;
*input_ptr++ = (UINT8) * Cbtmp++;
*input_ptr++ = (UINT8) * Crtmp++;
}
free (Buff);
Buff = NULL;
}
}
/* translate YUV422P to YUV422 in input */
static void
YUV_2_422 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 i, size;
UINT8 * inbuf = input_ptr;
UINT8 * Ytmp = NULL;
UINT8 * Cbtmp = NULL;
UINT8 * Crtmp = NULL;
UINT8 * Buff = NULL;
Buff =
(UINT8 *) realloc ((UINT8 *) Buff,
(size_t) (image_width * image_height * 2));
if (Buff)
{
memcpy (Buff, input_ptr, image_width * image_height * 2);
Ytmp = Buff;
Cbtmp = Buff + image_width * image_height;
Crtmp = Cbtmp + (image_width * image_height >> 1);
size = image_width * image_height;
for (i = size; i > 0; i--)
{
*input_ptr++ = (UINT8) * Ytmp++;
*input_ptr++ = (UINT8) * Cbtmp++;
*input_ptr++ = (UINT8) * Ytmp++;
*input_ptr++ = (UINT8) * Crtmp++;
}
free (Buff);
Buff = NULL;
}
}
/* translate YUV420P to YUV420 in input */
static void
YUV_2_420 (UINT8 * input_ptr, UINT8 * output_ptr, UINT32 image_width,
UINT32 image_height)
{
UINT32 x, y, size;
UINT8 * inbuf = input_ptr;
UINT8 * Ytmp = NULL;
UINT8 * Y2tmp = NULL;
UINT8 * Cbtmp = NULL;
UINT8 * Crtmp = NULL;
UINT8 * Buff = NULL;
Buff =
(UINT8 *) realloc ((UINT8 *) Buff,
(size_t) ((image_width * image_height * 3) >> 1));
if (Buff)
{
memcpy (Buff, input_ptr, (image_width * image_height * 3) >> 1);
Ytmp = Buff;
Y2tmp = Buff + image_width;
Cbtmp = Buff + image_width * image_height;
Crtmp = Cbtmp + (image_width * image_height >> 2);
size = image_width * image_height >> 2;
for (y = 0; y < image_height; y += 2)
{
for (x = 0; x < image_width; x += 2)
{
*input_ptr++ = (UINT8) * Ytmp++;
*input_ptr++ = (UINT8) * Ytmp++;
*input_ptr++ = (UINT8) * Y2tmp++;
*input_ptr++ = (UINT8) * Y2tmp++;
*input_ptr++ = (UINT8) * Cbtmp++;
*input_ptr++ = (UINT8) * Crtmp++;
}
Ytmp += image_width;
Y2tmp += image_width;
}
free (Buff);
Buff = NULL;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -