📄 display.c
字号:
} else if ( bpp==24 ) { dither_frame=ditherframeRGB; dither_even =dithertopRGB; dither_odd =ditherbotRGB; init_ditherRGB(); } else error("unsuported dither type"); bpp/=8; if(!(dithered_image = (unsigned char *)malloc(bpp*coded_picture_width* coded_picture_height))) error("malloc failed"); if(!(dithered_image2 = (unsigned char *)malloc(bpp*coded_picture_width* coded_picture_height))) error("malloc failed"); for (i=-8; i<256+8; i++) { v = i>>4; if (v<1) v = 1; else if (v>14) v = 14; ytab[i+8] = v<<4; } for (i=0; i<128+16; i++) { v = (i-40)>>4; if (v<0) v = 0; else if (v>3) v = 3; utab[i] = v<<2; vtab[i] = v; } for (i=0; i<256; i++) pixel[i]=i;}//////////////////////////////////////////////////////////////////////////////// RGB dithering routines//////////////////////////////////////////////////////////////////////////////#define BITS 8#define ONE ((int) 1)#define CONST_SCALE (ONE << BITS)#define ROUND_FACTOR (ONE << (BITS-1))#define UP(x) (((int)(x)) << BITS)#define DOWN(x) (((x) + ROUND_FACTOR) >> BITS)#define FIX(x) ((int) ((x)*CONST_SCALE + 0.5))#define CLAMP(ll,x,ul) ( ((x)<(ll)) ?(ll):( ((x)>(ul)) ?(ul):(x)))static int Cr_r_tab[256];static int Cb_g_tab[256];static int Cr_g_tab[256];static int Cb_b_tab[256];static int Cy_tab [256];//// initialize tables used in YCbCr -> RGB conversion//static void init_ditherRGB(){ int CR, CB, i; for (i=0; i<256; i++) { CB = CR = i - 128; Cr_r_tab[i] = FIX(1.40200) * CR; Cb_g_tab[i] = -FIX(0.34414) * CB; Cr_g_tab[i] = -FIX(0.71414) * CR; Cb_b_tab[i] = FIX(1.77200) * CB; Cy_tab [i] = FIX(255.0/219.0) * i; }}static void ditherframeRGB(src)unsigned char *src[];{ unsigned char *lum=src[0]; unsigned char *cb =src[1]; unsigned char *cr =src[2]; int cols=coded_picture_width; int rows=coded_picture_height; int L, CR, CB; unsigned char *lum2, *r1, *r2; int x, y; int cr_r; int cr_g; int cb_g; int cb_b;#ifdef _WIN32 r1 = dithered_image + (rows - 1) * cols * 3; r2 = r1 - cols * 3;#else r1 = dithered_image; r2 = r1 + cols * 3;#endif lum2 = lum + cols; for (y=0; y<rows; y+=2) { for (x=0; x<cols; x+=2) { int R, G, B; CR = *cr++; CB = *cb++; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; L = *lum++; L = Cy_tab[L]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r1++ = CLAMP(0,B,UP(255)) >> BITS; *r1++ = CLAMP(0,G,UP(255)) >> BITS; *r1++ = CLAMP(0,R,UP(255)) >> BITS; L = *lum++; L = Cy_tab[L]; if (chroma_format==CHROMA444) { CR = *cr; CB = *cb; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; } R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r1++ = CLAMP(0,B,UP(255)) >> BITS; *r1++ = CLAMP(0,G,UP(255)) >> BITS; *r1++ = CLAMP(0,R,UP(255)) >> BITS; /* * Now, do second row. */ if (chroma_format!=CHROMA420) { CR = cr[chrom_width-1]; CB = cb[chrom_width-1]; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; } L = *lum2++; L = Cy_tab[L]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r2++ = CLAMP(0,B,UP(255)) >> BITS; *r2++ = CLAMP(0,G,UP(255)) >> BITS; *r2++ = CLAMP(0,R,UP(255)) >> BITS; L = *lum2++; L = Cy_tab[L]; if (chroma_format==CHROMA444) { CR = cr[chrom_width]; CB = cb[chrom_width]; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; cr++; cb++; } R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r2++ = CLAMP(0,B,UP(255)) >> BITS; *r2++ = CLAMP(0,G,UP(255)) >> BITS; *r2++ = CLAMP(0,R,UP(255)) >> BITS; } lum += cols; lum2 += cols; if (chroma_format!=CHROMA420) { cr += chrom_width; cb += chrom_width; }#ifdef _WIN32 r1 -= 9 * cols; r2 -= 9 * cols;#else r1 += 3 * cols; r2 += 3 * cols;#endif }}static void dithertopRGB(src,dst)unsigned char *src[];unsigned char *dst;{ unsigned char *lum=src[0]; unsigned char *cb =src[1]; unsigned char *cr =src[2]; int cols=coded_picture_width; int rows=coded_picture_height; int L, CR, CB; unsigned char *lum2, *r1, *r2; int x, y; int cr_r; int cr_g; int cb_g; int cb_b; int chrom_offset[3]; if (chroma_format==CHROMA420) chrom_offset[0] = -chrom_width; else chrom_offset[0] = chrom_width; chrom_offset[2] = chrom_width;#ifdef _WIN32 r1 = dst + (rows - 1) * cols * 3; r2 = r1 - cols * 3;#else r1 = dst; r2 = r1 + cols * 3;#endif lum2 = lum + 2*cols; for (y=0; y<rows; y+=2) { for (x=0; x<cols; x+=2) { int R, G, B, Y; CR = *cr++; CB = *cb++; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; Y = *lum++; L = Cy_tab[Y]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r1++ = CLAMP(0,B,UP(255)) >> BITS; *r1++ = CLAMP(0,G,UP(255)) >> BITS; *r1++ = CLAMP(0,R,UP(255)) >> BITS; L = (Y + *lum2++)>>1; L = Cy_tab[L]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r2++ = CLAMP(0,B,UP(255)) >> BITS; *r2++ = CLAMP(0,G,UP(255)) >> BITS; *r2++ = CLAMP(0,R,UP(255)) >> BITS; Y = *lum++; L = Cy_tab[Y]; if (chroma_format==CHROMA444) { CR = *cr++; CB = *cb++; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; } R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r1++ = CLAMP(0,B,UP(255)) >> BITS; *r1++ = CLAMP(0,G,UP(255)) >> BITS; *r1++ = CLAMP(0,R,UP(255)) >> BITS; L = (Y + *lum2++)>>1; L = Cy_tab[L]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r2++ = CLAMP(0,B,UP(255)) >> BITS; *r2++ = CLAMP(0,G,UP(255)) >> BITS; *r2++ = CLAMP(0,R,UP(255)) >> BITS; } lum += cols; if (y!=(rows-2)) lum2 += cols; else lum2 -= cols; cb += chrom_offset[y & 2]; cr += chrom_offset[y & 2];#ifdef _WIN32 r1 -= 9 * cols; r2 -= 9 * cols;#else r1 += 3 * cols; r2 += 3 * cols;#endif }}static void ditherbotRGB(src,dst)unsigned char *src[];unsigned char *dst;{ unsigned char *lum=src[0]; unsigned char *cb =src[1] + chrom_width; unsigned char *cr =src[2] + chrom_width; int cols=coded_picture_width; int rows=coded_picture_height; int L, CR, CB; unsigned char *lum2, *r1, *r2; int x, y; int cr_r; int cr_g; int cb_g; int cb_b; int chrom_offset[3]; if (chroma_format==CHROMA420) chrom_offset[0] = -chrom_width; else chrom_offset[0] = chrom_width; chrom_offset[2] = chrom_width;#ifdef _WIN32 r1 = dst + (rows - 1) * cols * 3; r2 = r1 - cols * 3;#else r1 = dst; r2 = r1 + cols * 3;#endif lum +=cols; lum2 =lum; for (y=0; y<rows; y+=2) { for (x=0; x<cols; x+=2) { int R, G, B, Y; CR = *cr++; CB = *cb++; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; Y = *lum++; L = Cy_tab[Y]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r1++ = CLAMP(0,B,UP(255)) >> BITS; *r1++ = CLAMP(0,G,UP(255)) >> BITS; *r1++ = CLAMP(0,R,UP(255)) >> BITS; L = (Y + *lum2++)>>1; L = Cy_tab[L]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r2++ = CLAMP(0,B,UP(255)) >> BITS; *r2++ = CLAMP(0,G,UP(255)) >> BITS; *r2++ = CLAMP(0,R,UP(255)) >> BITS; Y = *lum++; L = Cy_tab[Y]; if (chroma_format==CHROMA444) { CR = *cr++; CB = *cb++; cr_r = Cr_r_tab[CR]; cr_g = Cr_g_tab[CR]; cb_g = Cb_g_tab[CB]; cb_b = Cb_b_tab[CB]; } R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r1++ = CLAMP(0,B,UP(255)) >> BITS; *r1++ = CLAMP(0,G,UP(255)) >> BITS; *r1++ = CLAMP(0,R,UP(255)) >> BITS; L = (Y + *lum2++)>>1; L = Cy_tab[L]; R = L + cr_r; G = L + cr_g + cb_g; B = L + cb_b; *r2++ = CLAMP(0,B,UP(255)) >> BITS; *r2++ = CLAMP(0,G,UP(255)) >> BITS; *r2++ = CLAMP(0,R,UP(255)) >> BITS; } lum += cols; if (y!=0) lum2 += cols; else lum2 -= cols; cb += chrom_offset[y & 2]; cr += chrom_offset[y & 2];#ifdef _WIN32 r1 -= 9 * cols; r2 -= 9 * cols;#else r1 += 3 * cols; r2 += 3 * cols;#endif }}//// portable display function//void display_second_field(){ display_image(dithered_image2);}#endif // DISPLAY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -