images.cc

Go to the documentation of this file.
00001 /*
00002  * This file is part of openSDK.
00003  *
00004  * Copyright (C) 2007 openSDK team
00005  *
00006  * openSDK is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; version 2.
00009  *
00010  * openSDK is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with openSDK; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  *     $Id: images.cc,v 1.8 2007/04/22 09:26:13 nuno-lopes Exp $
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 }

Generated on Sun Dec 2 23:04:28 2007 for openSDK by  doxygen 1.3.9.1