00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <cstdlib>
00023 #include "images.h"
00024
00025
00027 void RGB_to_YCbCr(const byte *img, size_t width, size_t height, byte *Y, byte *Cb, byte *Cr)
00028 {
00029 for (int i=height-1; i >= 0; --i) {
00030 for (size_t j=0; j < width; ++j) {
00031
00032 float B = float(*img++);
00033 float G = float(*img++);
00034 float R = float(*img++);
00035
00036 size_t idx = i*width + j;
00037
00038 Y[idx] = 16 + char(( 65.738*R + 129.057*G + 25.064*B) * 0.00390625);
00039 Cb[idx] = 128 + char((-37.945*R - 74.494*G + 112.439*B) * 0.00390625);
00040 Cr[idx] = 128 + char((112.439*R - 94.154*G - 18.285*B) * 0.00390625);
00041 }
00042 }
00043 }
00044
00045
00047 void shrink_frame(size_t width,
00048 size_t height,
00049 unsigned int factor,
00050 const byte *inY,
00051 const byte *inCb,
00052 const byte *inCr,
00053 byte *outY,
00054 byte *outCb,
00055 byte *outCr )
00056 {
00057 size_t i, j, x;
00058
00059 for (i = x = 0; i < height; i+=factor) {
00060 for (j = 0; j < width; j+=factor, x++) {
00061 outY[x] = inY[i*width+j];
00062 outCb[x] = inCb[i*width+j];
00063 outCr[x] = inCr[i*width+j];
00064 }
00065 }
00066 }