📄 qc-formats.c
字号:
unsigned char *cur_bay; unsigned int sum = 0; int column_cnt; int row_cnt; /* Skip 1/4 of left, right, top, and bottom pixels (use only center pixels) */ columns /= 2; rows /= 2; bay += rows/4*2*bay_line + columns/4*2; columns /= stepsize*2; rows /= stepsize*2; row_cnt = rows; do { column_cnt = columns; cur_bay = bay; do { sum += cur_bay[0] + cur_bay[1] + cur_bay[bay_line]; /* R + G + B */ cur_bay += 2*stepsize; } while (--column_cnt > 0); bay += 2*stepsize*bay_line; } while (--row_cnt > 0); sum /= 3 * columns * rows; return sum;}/* }}} */#if COMPRESS/* {{{ [fold] qc_imag_rgb24_midvalue(char *rgb, int rgb_line, int columns, int rows) *//* Compute and return the average pixel intensity from the RGB/BGR24 data. * The result can be used for automatic software exposure/gain control. * rgb = points to the RGB image data * rgb_line = bytes between the beginnings of two consecutive rows * columns, rows = RGB image size */static unsigned char qc_imag_rgb24_midvalue(unsigned char *rgb, int rgb_line, unsigned int columns, unsigned int rows){ static const unsigned int stepsize = 8; /* Larger = faster and less accurate */ unsigned char *cur_rgb; unsigned int sum = 0; int column_cnt; int row_cnt; /* Skip 1/4 of left, right, top, and bottom pixels (use only center pixels) */ columns /= 2; rows /= 2; rgb += rows/2*rgb_line + columns/2*3; columns /= stepsize; rows /= stepsize; row_cnt = rows; do { column_cnt = columns; cur_rgb = rgb; do { sum += cur_rgb[0] + cur_rgb[1] + cur_rgb[2]; /* R + G + B */ cur_rgb += 3*stepsize; } while (--column_cnt > 0); rgb += stepsize*rgb_line; } while (--row_cnt > 0); sum /= 3 * columns * rows; return sum;}/* }}} */#endif/* {{{ [fold] qc_imag_userlut(unsigned char (*userlut)[QC_LUT_SIZE], unsigned char (*lut)[QC_LUT_SIZE]) *//* Apply user-defined lookup-table to the given preinitialized lut */static inline void qc_imag_userlut(unsigned char (*userlut)[QC_LUT_SIZE], unsigned char (*lut)[QC_LUT_SIZE]){ unsigned int i,p; for (i=0; i<256; i++) { p = (*lut)[QC_LUT_RED + i]; p = (*userlut)[QC_LUT_RED + p]; (*lut)[QC_LUT_RED + i] = p; } for (i=0; i<256; i++) { p = (*lut)[QC_LUT_GREEN + i]; p = (*userlut)[QC_LUT_GREEN + p]; (*lut)[QC_LUT_GREEN + i] = p; } for (i=0; i<256; i++) { p = (*lut)[QC_LUT_BLUE + i]; p = (*userlut)[QC_LUT_BLUE + p]; (*lut)[QC_LUT_BLUE + i] = p; }}/* }}} *//* {{{ [fold] qc_imag_bayer_equalize(char *bay, int bay_line, int columns, int rows, char (*lut)[]) *//* Compute and fill a lookup table which will equalize the image. * bay = points to the bayer image data (upper left pixel is green) * bay_line = bytes between the beginnings of two consecutive rows * columns, rows = bayer image size (both must be even) * lut = lookup table to be filled, 3*256 char array */static void qc_imag_bayer_equalize(unsigned char *bay, int bay_line, unsigned int columns, unsigned int rows, unsigned char (*lut)[QC_LUT_SIZE]){ static const unsigned int stepsize = 4; /* Larger = faster and less accurate */ unsigned short red_cnt[256], green_cnt[256], blue_cnt[256]; /* FIXME: how much we can use stack? */ unsigned int red_sum, green_sum, blue_sum; unsigned int red_tot, green_tot, blue_tot; unsigned char *cur_bay; int i, column_cnt, row_cnt; memset(red_cnt, 0, sizeof(red_cnt)); memset(green_cnt, 0, sizeof(green_cnt)); memset(blue_cnt, 0, sizeof(blue_cnt)); columns /= 2*stepsize; rows /= 2*stepsize; /* Compute histogram */ row_cnt = rows; do { column_cnt = columns; cur_bay = bay; do { green_cnt[cur_bay[0]]++; red_cnt [cur_bay[1]]++; blue_cnt [cur_bay[bay_line]]++; green_cnt[cur_bay[bay_line+1]]++; cur_bay += 2*stepsize; } while (--column_cnt > 0); bay += 2*stepsize*bay_line; } while (--row_cnt > 0); /* Compute lookup table based on the histogram */ red_tot = columns * rows; /* Total number of pixels of each primary color */ green_tot = red_tot * 2; blue_tot = red_tot; red_sum = 0; green_sum = 0; blue_sum = 0; for (i=0; i<256; i++) { (*lut)[QC_LUT_RED + i] = 255 * red_sum / red_tot; (*lut)[QC_LUT_GREEN + i] = 255 * green_sum / green_tot; (*lut)[QC_LUT_BLUE + i] = 255 * blue_sum / blue_tot; red_sum += red_cnt[i]; green_sum += green_cnt[i]; blue_sum += blue_cnt[i]; }}/* }}} *//* {{{ [fold] qc_imag_bayer_lut(char *bay, int bay_line, int columns, int rows, char (*lut)[]) *//* Transform pixel values in a bayer image with a given lookup table. * bay = points to the bayer image data (upper left pixel is green) * bay_line = bytes between the beginnings of two consecutive rows * columns, rows = bayer image size (both must be even) * lut = lookup table to be used, 3*256 char array */static void qc_imag_bayer_lut(unsigned char *bay, int bay_line, unsigned int columns, unsigned int rows, unsigned char (*lut)[QC_LUT_SIZE]){ unsigned char *cur_bay; unsigned int total_columns; total_columns = columns / 2; /* Number of 2x2 bayer blocks */ rows /= 2; do { columns = total_columns; cur_bay = bay; do { cur_bay[0] = (*lut)[QC_LUT_GREEN + cur_bay[0]]; cur_bay[1] = (*lut)[QC_LUT_RED + cur_bay[1]]; cur_bay += 2; } while (--columns); bay += bay_line; columns = total_columns; cur_bay = bay; do { cur_bay[0] = (*lut)[QC_LUT_BLUE + cur_bay[0]]; cur_bay[1] = (*lut)[QC_LUT_GREEN + cur_bay[1]]; cur_bay += 2; } while (--columns); bay += bay_line; } while (--rows);}/* }}} *//* {{{ [fold] qc_imag_writergb(void *addr, int bpp, unsigned char r, unsigned char g, unsigned char b) *//* Write RGB pixel value to the given address. * addr = memory address, to which the pixel is written * bpp = number of bytes in the pixel (should be 3 or 4) * r, g, b = pixel component values to be written (red, green, blue) * Looks horribly slow but the compiler should be able to inline optimize it. */static inline void qc_imag_writergb(void *addr, int bpp, unsigned char r, unsigned char g, unsigned char b){ if (DEFAULT_BGR) { /* Blue is first (in the lowest memory address */ if (bpp==4) {#if defined(__LITTLE_ENDIAN) *(unsigned int *)addr = (unsigned int)r << 16 | (unsigned int)g << 8 | (unsigned int)b;#elif defined(__BIG_ENDIAN) *(unsigned int *)addr = (unsigned int)r << 8 | (unsigned int)g << 16 | (unsigned int)b << 24;#else unsigned char *addr2 = (unsigned char *)addr; addr2[0] = b; addr2[1] = g; addr2[2] = r; addr2[3] = 0;#endif } else { unsigned char *addr2 = (unsigned char *)addr; addr2[0] = b; addr2[1] = g; addr2[2] = r; } } else { /* Red is first (in the lowest memory address */ if (bpp==4) {#if defined(__LITTLE_ENDIAN) *(unsigned int *)addr = (unsigned int)b << 16 | (unsigned int)g << 8 | (unsigned int)r;#elif defined(__BIG_ENDIAN) *(unsigned int *)addr = (unsigned int)b << 8 | (unsigned int)g << 16 | (unsigned int)r << 24;#else unsigned char *addr2 = (unsigned char *)addr; addr2[0] = r; addr2[1] = g; addr2[2] = b; addr2[3] = 0;#endif } else { unsigned char *addr2 = (unsigned char *)addr; addr2[0] = r; addr2[1] = g; addr2[2] = b; } }}/* }}} *//* * Raw image data for Bayer-RGB-matrix: * G R for even rows * B G for odd rows */#if 0/* {{{ [fold] qc_imag_bay2rgb_noip(char *bay, int bay_line, char *rgb, int rgb_line, int columns, rows, bpp) *//* Convert bayer image to RGB image without using interpolation. * bay = points to the bayer image data (upper left pixel is green) * bay_line = bytes between the beginnings of two consecutive rows * rgb = points to the rgb image data that is written * rgb_line = bytes between the beginnings of two consecutive rows * columns, rows = bayer image size (both must be even) * bpp = number of bytes in each pixel in the RGB image (should be 3 or 4) *//* Execution time: 2391747-2653574 clock cycles for CIF image (Pentium II) *//* Do NOT use this routine: cottnoip is faster with better image quality */static inline void qc_imag_bay2rgb_noip(unsigned char *bay, int bay_line, unsigned char *rgb, int rgb_line, int columns, int rows, int bpp){ unsigned char *cur_bay, *cur_rgb; int bay_line2, rgb_line2; int total_columns; /* Process 2 lines and rows per each iteration */ total_columns = columns >> 1; rows >>= 1; bay_line2 = 2*bay_line; rgb_line2 = 2*rgb_line; do { cur_bay = bay; cur_rgb = rgb; columns = total_columns; do { qc_imag_writergb(cur_rgb+0, bpp, cur_bay[1], cur_bay[0], cur_bay[bay_line]); qc_imag_writergb(cur_rgb+bpp, bpp, cur_bay[1], cur_bay[0], cur_bay[bay_line]); qc_imag_writergb(cur_rgb+rgb_line, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]); qc_imag_writergb(cur_rgb+rgb_line+bpp, bpp, cur_bay[1], cur_bay[bay_line+1], cur_bay[bay_line]); cur_bay += 2; cur_rgb += 2*bpp; } while (--columns); bay += bay_line2; rgb += rgb_line2; } while (--rows);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -