Blender V2.61 - r43446
|
00001 /* 00002 * 00003 * This is external code. Converts rgb-type avi-s. 00004 * 00005 * ***** BEGIN GPL LICENSE BLOCK ***** 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation; either version 2 00010 * of the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software Foundation, 00019 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 * 00021 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00022 * All rights reserved. 00023 * 00024 * The Original Code is: all of this file. 00025 * 00026 * Contributor(s): none yet. 00027 * 00028 * ***** END GPL LICENSE BLOCK ***** 00029 * 00030 */ 00031 00037 #include "AVI_avi.h" 00038 #include <stdlib.h> 00039 #include <string.h> 00040 00041 #include "MEM_guardedalloc.h" 00042 #include "avirgb.h" 00043 00044 /* implementation */ 00045 00046 void *avi_converter_from_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size) 00047 { 00048 int x, y,i, rowstride; 00049 unsigned char *buf; 00050 AviBitmapInfoHeader *bi; 00051 short bits= 32; 00052 00053 (void)size; /* unused */ 00054 00055 bi= (AviBitmapInfoHeader *) movie->streams[stream].sf; 00056 if (bi) bits= bi->BitCount; 00057 00058 if (bits==16) { 00059 unsigned short *pxl; 00060 unsigned char *to; 00061 #ifdef __BIG_ENDIAN__ 00062 unsigned char *pxla; 00063 #endif 00064 00065 buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); 00066 00067 y= movie->header->Height; 00068 to= buf; 00069 00070 while (y--) { 00071 pxl= (unsigned short *) (buffer + y * movie->header->Width * 2); 00072 00073 #ifdef __BIG_ENDIAN__ 00074 pxla= (unsigned char *)pxl; 00075 #endif 00076 00077 x= movie->header->Width; 00078 while (x--) { 00079 #ifdef __BIG_ENDIAN__ 00080 i= pxla[0]; 00081 pxla[0]= pxla[1]; 00082 pxla[1]= i; 00083 00084 pxla+=2; 00085 #endif 00086 00087 *(to++)= ((*pxl>>10)&0x1f)*8; 00088 *(to++)= ((*pxl>>5)&0x1f)*8; 00089 *(to++)= (*pxl&0x1f)*8; 00090 pxl++; 00091 } 00092 } 00093 00094 MEM_freeN (buffer); 00095 00096 return buf; 00097 } else { 00098 buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); 00099 00100 rowstride = movie->header->Width*3; 00101 if (bits!=16) if (movie->header->Width%2) rowstride++; 00102 00103 for (y=0; y < movie->header->Height; y++) { 00104 memcpy (&buf[y*movie->header->Width*3], &buffer[((movie->header->Height-1)-y)*rowstride], movie->header->Width*3); 00105 } 00106 00107 for (y=0; y < movie->header->Height*movie->header->Width*3; y+=3) { 00108 i = buf[y]; 00109 buf[y] = buf[y+2]; 00110 buf[y+2] = i; 00111 } 00112 00113 MEM_freeN (buffer); 00114 00115 return buf; 00116 } 00117 } 00118 00119 void *avi_converter_to_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size) 00120 { 00121 int y, x, i, rowstride; 00122 unsigned char *buf; 00123 00124 (void)stream; /* unused */ 00125 00126 *size= movie->header->Height * movie->header->Width * 3; 00127 if (movie->header->Width%2) *size+= movie->header->Height; 00128 00129 buf = MEM_mallocN (*size,"toavirgbbuf"); 00130 00131 rowstride = movie->header->Width*3; 00132 if (movie->header->Width%2) rowstride++; 00133 00134 for (y=0; y < movie->header->Height; y++) { 00135 memcpy (&buf[y*rowstride], &buffer[((movie->header->Height-1)-y)*movie->header->Width*3], movie->header->Width*3); 00136 } 00137 00138 for (y=0; y < movie->header->Height; y++) { 00139 for (x=0; x < movie->header->Width*3; x+=3) { 00140 i = buf[y*rowstride+x]; 00141 buf[y*rowstride+x] = buf[y*rowstride+x+2]; 00142 buf[y*rowstride+x+2] = i; 00143 } 00144 } 00145 00146 MEM_freeN (buffer); 00147 00148 return buf; 00149 }