Blender  V2.59
rgb32.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rgb32.c 35249 2011-02-27 20:43:42Z jesterking $
00003  *
00004  * This is external code. Converts between rgb32 and avi.
00005  *
00006  * ***** BEGIN GPL LICENSE BLOCK *****
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00023  * All rights reserved.
00024  *
00025  * The Original Code is: all of this file.
00026  *
00027  * Contributor(s): none yet.
00028  *
00029  * ***** END GPL LICENSE BLOCK *****
00030  *
00031  */
00032 
00038 #include "AVI_avi.h"
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include "MEM_guardedalloc.h"
00042 #include "rgb32.h"
00043 
00044 void *avi_converter_from_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size) {
00045         int y, x, rowstridea, rowstrideb;
00046         unsigned char *buf;
00047 
00048         (void)stream; /* unused */
00049 
00050         buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromrgb32buf");
00051         *size = movie->header->Height * movie->header->Width * 3;
00052 
00053         rowstridea = movie->header->Width*3;
00054         rowstrideb = movie->header->Width*4;
00055 
00056         for (y=0; y < movie->header->Height; y++) {
00057                 for (x=0; x < movie->header->Width; x++) {
00058                         buf[y*rowstridea + x*3 + 0] = buffer[y*rowstrideb + x*4 + 3];
00059                         buf[y*rowstridea + x*3 + 1] = buffer[y*rowstrideb + x*4 + 2];
00060                         buf[y*rowstridea + x*3 + 2] = buffer[y*rowstrideb + x*4 + 1];
00061                 }
00062         }
00063 
00064         MEM_freeN (buffer);
00065 
00066         return buf;
00067 }
00068 
00069 void *avi_converter_to_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size) {
00070         int i;
00071         unsigned char *buf;
00072         unsigned char *to, *from;
00073 
00074         (void)stream; /* unused */
00075 
00076         buf= MEM_mallocN (movie->header->Height * movie->header->Width * 4, "torgb32buf");
00077         *size= movie->header->Height * movie->header->Width * 4;
00078 
00079         memset(buf, 255, *size);
00080 
00081         to= buf; from= buffer;
00082         i=movie->header->Height*movie->header->Width;
00083         
00084         while(i--) {
00085                 memcpy(to, from, 3);
00086                 to+=4; from+=3;
00087         }
00088 
00089         MEM_freeN (buffer);
00090 
00091         return buf;
00092 }