一个RGB 快速resize 的实例

参考其它得到的,做了修改放在这里备用。

 

void RGB_scanline_resample_nearest (unsigned char * dest, unsigned char * src, int n, int *accumulator, int increment) { int acc = *accumulator; int i; int j; int x; for (i = 0; i < n; i++) { j = acc >> 16; x = acc & 0xffff; dest[i * 3 + 0] = (x < 32768) ? src[j * 3 + 0] : src[j * 3 + 3]; dest[i * 3 + 1] = (x < 32768) ? src[j * 3 + 1] : src[j * 3 + 4]; dest[i * 3 + 2] = (x < 32768) ? src[j * 3 + 2] : src[j * 3 + 5]; acc += increment; } *accumulator = acc; } void RGB_image_scale_nearest (unsigned char * dest, int dest_width, int dest_height, unsigned char * src, int src_width, int src_height) { int acc; int y_increment; int x_increment; int i; int j; int x; int xacc; int src_stride = src_width*3; int dest_stride = dest_width*3; if (dest_height == 1) y_increment = 0; else y_increment = ((src_height - 1) << 16) / (dest_height - 1); if (dest_width == 1) x_increment = 0; else x_increment = ((src_width - 1) << 16) / (dest_width - 1); acc = 0; for (i = 0; i < dest_height; i++) { j = acc >> 16; x = acc & 0xffff; xacc = 0; RGB_scanline_resample_nearest(dest + i * dest_stride, src + j * src_stride, dest_width, &xacc, x_increment); acc += y_increment; } }

你可能感兴趣的:(一个RGB 快速resize 的实例)