📄 yuv2rgb.cpp
字号:
int edge_pixels = c_this->dest_width % 8; for ( int i = 0; i < (edge_pixels-1); i+=2 ) { RGB32(0); DST1(0); pu += 1; pv += 1; py_1 += 2; dst_1 += 2; } if (c_this->dest_width % 1) { RGB32(0); _DST(0,1,0); } dy += c_this->step_dy; _dst += c_this->rgb_stride; while (--dst_height > 0 && dy < 32768) { memcpy(_dst, (uint8_t*)_dst-c_this->rgb_stride, c_this->dest_width*4); dy += c_this->step_dy; _dst += c_this->rgb_stride; } if (dst_height <= 0) break; do { dy -= 32768; _py += c_this->y_stride; scale_line (_py, c_this->y_buffer, c_this->dest_width, c_this->step_dx); if (height & 1 || !c_this->uv_stretch_y ) { _pu += c_this->uv_stride; _pv += c_this->uv_stride; scale_line (_pu, c_this->u_buffer, c_this->dest_width >> 1, c_this->step_dx); scale_line (_pv, c_this->v_buffer, c_this->dest_width >> 1, c_this->step_dx); } height++; } while( dy>=32768); } } else { height = c_this->source_height >> 1; do { dst_1 = (uint32_t*)_dst; dst_2 = (uint32_t*)( (uint8_t *)_dst + c_this->rgb_stride ); py_1 = _py; py_2 = _py + c_this->y_stride; pu = _pu; pv = _pv; width = c_this->source_width >> 3; do { RGB32(0); DST1(0); DST2(0); RGB32(1); DST2(1); DST1(1); RGB32(2); DST1(2); DST2(2); RGB32(3); DST2(3); DST1(3); pu += 4; pv += 4; py_1 += 8; py_2 += 8; dst_1 += 8; dst_2 += 8; } while (--width); int edge_pixels = c_this->source_width % 8; for ( int i = 0; i < (edge_pixels-1); i+=2 ) { RGB32(0) DST1(0) DST2(0) pu += 1; pv += 1; py_1 += 2; py_2 += 2; dst_1 += 2; dst_2 += 2; } if (c_this->source_width % 1) { RGB32(0); _DST(0,1,0); } _dst += 2 * c_this->rgb_stride; _py += 2 * c_this->y_stride; _pu += c_this->uv_stride; _pv += c_this->uv_stride; } while (--height); }}/* This is exactly the same code as yuv2rgb_c_32 except for the types of *//* r, g, b, dst_1, dst_2 */static void yuv2rgb_c_16 (yuv2rgb_t *c_this, uint8_t * _dst, uint8_t * _py, uint8_t * _pu, uint8_t * _pv){ int U, V, Y; uint8_t * py_1, * py_2, * pu, * pv; uint16_t * r, * g, * b; uint16_t * dst_1, * dst_2; int width, height, dst_height; int dy; if (c_this->do_scale) { scale_line_func_t scale_line = c_this->scale_line; scale_line (_pu, c_this->u_buffer, c_this->dest_width >> c_this->uv_stretch_x, c_this->step_dx); scale_line (_pv, c_this->v_buffer, c_this->dest_width >> c_this->uv_stretch_x, c_this->step_dx); scale_line (_py, c_this->y_buffer, c_this->dest_width, c_this->step_dx); dy = 0; dst_height = c_this->dest_height; for (height = 0;; ) { dst_1 = (uint16_t*)_dst; py_1 = c_this->y_buffer; pu = c_this->u_buffer; pv = c_this->v_buffer; width = c_this->dest_width >> 3; do { RGB16(0); DST1(0); RGB16(1); DST1(1); RGB16(2); DST1(2); RGB16(3); DST1(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; } while (--width); int edge_pixels = c_this->dest_width % 8; for ( int i = 0; i < (edge_pixels-1); i+=2 ) { RGB16(0); DST1(0); pu += 1; pv += 1; py_1 += 2; dst_1 += 2; } if (c_this->dest_width % 1) { RGB16(0); _DST(0,1,0); } dy += c_this->step_dy; _dst += c_this->rgb_stride; while (--dst_height > 0 && dy < 32768) { memcpy (_dst, (uint8_t*)_dst-c_this->rgb_stride, c_this->dest_width*2); dy += c_this->step_dy; _dst += c_this->rgb_stride; } if (dst_height <= 0) break; do { dy -= 32768; _py += c_this->y_stride; scale_line (_py, c_this->y_buffer, c_this->dest_width, c_this->step_dx); if (height & 1 || !c_this->uv_stretch_y ) { _pu += c_this->uv_stride; _pv += c_this->uv_stride; scale_line (_pu, c_this->u_buffer, c_this->dest_width >> 1, c_this->step_dx); scale_line (_pv, c_this->v_buffer, c_this->dest_width >> 1, c_this->step_dx); } height++; } while( dy>=32768); } } else { height = c_this->source_height >> 1; do { dst_1 = (uint16_t*)_dst; dst_2 = (uint16_t*)( (uint8_t *)_dst + c_this->rgb_stride ); py_1 = _py; py_2 = _py + c_this->y_stride; pu = _pu; pv = _pv; width = c_this->source_width >> 3; do { RGB16(0); DST1(0); DST2(0); RGB16(1); DST2(1); DST1(1); RGB16(2); DST1(2); DST2(2); RGB16(3); DST2(3); DST1(3); pu += 4; pv += 4; py_1 += 8; py_2 += 8; dst_1 += 8; dst_2 += 8; } while (--width); int edge_pixels = c_this->source_width % 8; for ( int i = 0; i < (edge_pixels-1); i+=2 ) { RGB16(0); DST1(0); DST2(0); pu += 1; pv += 1; py_1 += 2; py_2 += 2; dst_1 += 2; dst_2 += 2; } if (c_this->source_width % 1) { RGB16(0); _DST(0,1,0); } _dst += 2 * c_this->rgb_stride; _py += 2 * c_this->y_stride; _pu += c_this->uv_stride; _pv += c_this->uv_stride; } while (--height); }}static int div_round (int dividend, int divisor){ if (dividend > 0) return (dividend + (divisor>>1)) / divisor; else return -((-dividend + (divisor>>1)) / divisor);}/*#include <linux/config.h>#ifdef CONFIG_ARM#include "yuv2rgb_arm.c"#endif*/yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped, int gamma){ yuv2rgb_factory_t *c_this; c_this = (yuv2rgb_factory_t *) malloc (sizeof (yuv2rgb_factory_t)); c_this->mode = mode; c_this->swapped = swapped; c_this->matrix_coefficients = 6; int i; uint8_t table_Y[1024]; uint32_t * table_32 = 0; uint16_t * table_16 = 0; //uint8_t * table_8 = 0; int entry_size = 0; void *table_r = 0, *table_g = 0, *table_b = 0; int shift_r = 0, shift_g = 0, shift_b = 0; int crv = Inverse_Table_6_9[c_this->matrix_coefficients][0]; int cbu = Inverse_Table_6_9[c_this->matrix_coefficients][1]; int cgu = -Inverse_Table_6_9[c_this->matrix_coefficients][2]; int cgv = -Inverse_Table_6_9[c_this->matrix_coefficients][3]; for (i = 0; i < 1024; i++) { int j; j = (76309 * (i - 384 - 16) + 32768) >> 16; j = (j < 0) ? 0 : ((j > 255) ? 255 : j); table_Y[i] = j; } switch (mode) { case MODE_32_RGB: case MODE_32_BGR: table_32 = (uint32_t*)malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); entry_size = sizeof (uint32_t); table_r = table_32 + 197; table_b = table_32 + 197 + 685; table_g = table_32 + 197 + 2*682; if (swapped) { switch (mode) { case MODE_32_RGB: shift_r = 8; shift_g = 16; shift_b = 24; break; case MODE_32_BGR: shift_r = 24; shift_g = 16; shift_b = 8; break; } } else { switch (mode) { case MODE_32_RGB: shift_r = 16; shift_g = 8; shift_b = 0; break; case MODE_32_BGR: shift_r = 0; shift_g = 8; shift_b = 16; break; } } for (i = -197; i < 256+197; i++) ((uint32_t *) table_r)[i] = table_Y[i+384] << shift_r; for (i = -132; i < 256+132; i++) ((uint32_t *) table_g)[i] = table_Y[i+384] << shift_g; for (i = -232; i < 256+232; i++) ((uint32_t *) table_b)[i] = table_Y[i+384] << shift_b; break; case MODE_15_BGR: case MODE_16_BGR: case MODE_15_RGB: case MODE_16_RGB: table_16 = (uint16_t*)malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); entry_size = sizeof (uint16_t); table_r = table_16 + 197; table_b = table_16 + 197 + 685; table_g = table_16 + 197 + 2*682; if (swapped) { switch (mode) { case MODE_15_BGR: shift_r = 8; shift_g = 5; shift_b = 2; break; case MODE_16_BGR: shift_r = 8; shift_g = 5; shift_b = 3; break; case MODE_15_RGB: shift_r = 2; shift_g = 5; shift_b = 8; break; case MODE_16_RGB: shift_r = 3; shift_g = 5; shift_b = 8; break; } } else { switch (mode) { case MODE_15_BGR: shift_r = 0; shift_g = 5; shift_b = 10; break; case MODE_16_BGR: shift_r = 0; shift_g = 5; shift_b = 11; break; case MODE_15_RGB: shift_r = 10; shift_g = 5; shift_b = 0; break; case MODE_16_RGB: shift_r = 11; shift_g = 5; shift_b = 0; break; } } for (i = -197; i < 256+197; i++) ((uint16_t *)table_r)[i] = (table_Y[i+384] >> 3) << shift_r; for (i = -132; i < 256+132; i++) { int j = table_Y[i+384] >> (((mode==MODE_16_RGB) || (mode==MODE_16_BGR)) ? 2 : 3); if (swapped) ((uint16_t *)table_g)[i] = (j&7) << 13 | (j>>3); else ((uint16_t *)table_g)[i] = j << 5; } for (i = -232; i < 256+232; i++) ((uint16_t *)table_b)[i] = (table_Y[i+384] >> 3) << shift_b; break; default: fprintf (stderr, "mode %d not supported by yuv2rgb\n", mode); // No tr abort(); } for (i = 0; i < 256; i++) { c_this->table_rV[i] = (((uint8_t *) table_r) + entry_size * div_round (crv * (i-128), 76309)); c_this->table_gU[i] = (((uint8_t *) table_g) + entry_size * div_round (cgu * (i-128), 76309)); c_this->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309); c_this->table_bU[i] = (((uint8_t *)table_b) + entry_size * div_round (cbu * (i-128), 76309)); } c_this->gamma = 0; c_this->entry_size = entry_size; // yuv2rgb_set_gamma for (int i = 0; i < 256; i++) { uint8_t *rV_table = (uint8_t *)c_this->table_rV; uint8_t *gU_table = (uint8_t *)c_this->table_gU; uint8_t *bU_table = (uint8_t *)c_this->table_bU; rV_table[i] += c_this->entry_size*(gamma - c_this->gamma); gU_table[i] += c_this->entry_size*(gamma - c_this->gamma); bU_table[i] += c_this->entry_size*(gamma - c_this->gamma); } c_this->gamma = gamma; /* * auto-probe for the best yuv2rgb function */ c_this->yuv2rgb_fun = NULL;/* #ifdef CONFIG_ARM yuv2rgb_init_arm ( c_this ); if(c_this->yuv2rgb_fun != NULL) printf("yuv2rgb: using arm4l assembler for colorspace transform\n" ); #endif*/ if (c_this->yuv2rgb_fun == NULL) { printf ("yuv2rgb: using unaccelerated colorspace conversion\n"); if ( mode == MODE_32_RGB || mode == MODE_32_BGR) c_this->yuv2rgb_fun = yuv2rgb_c_32; else c_this->yuv2rgb_fun = yuv2rgb_c_16; } yuv2rgb_t *converter = c_this->converter = (yuv2rgb_t *) malloc (sizeof (yuv2rgb_t)); converter->y_chunk = converter->y_buffer = 0; converter->u_chunk = converter->u_buffer = 0; converter->v_chunk = converter->v_buffer = 0; converter->table_rV = c_this->table_rV; converter->table_gU = c_this->table_gU; converter->table_gV = c_this->table_gV; converter->table_bU = c_this->table_bU; converter->yuv2rgb_fun = c_this->yuv2rgb_fun; converter->configure = yuv2rgb_configure; return c_this;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -