2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-07 06:27:31 +00:00
|
|
|
/** \file blender/avi/intern/avi_rgb.c
|
2011-02-27 20:43:42 +00:00
|
|
|
* \ingroup avi
|
2012-04-30 14:24:11 +00:00
|
|
|
*
|
|
|
|
|
* This is external code. Converts rgb-type avi-s.
|
2011-02-27 20:43:42 +00:00
|
|
|
*/
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2012-10-07 06:27:31 +00:00
|
|
|
|
|
|
|
|
#include "AVI_avi.h"
|
|
|
|
|
#include "avi_rgb.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
/* implementation */
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2012-04-29 15:47:02 +00:00
|
|
|
int x, y, i, rowstride;
|
2002-10-12 11:37:38 +00:00
|
|
|
unsigned char *buf;
|
|
|
|
|
AviBitmapInfoHeader *bi;
|
2012-05-07 18:30:04 +00:00
|
|
|
short bits = 32;
|
2010-10-17 06:38:56 +00:00
|
|
|
|
|
|
|
|
(void)size; /* unused */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
bi = (AviBitmapInfoHeader *) movie->streams[stream].sf;
|
|
|
|
|
if (bi) bits = bi->BitCount;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
if (bits == 16) {
|
2002-10-12 11:37:38 +00:00
|
|
|
unsigned short *pxl;
|
|
|
|
|
unsigned char *to;
|
2011-09-19 08:11:30 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2002-10-12 11:37:38 +00:00
|
|
|
unsigned char *pxla;
|
2012-05-19 13:55:54 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
y = movie->header->Height;
|
|
|
|
|
to = buf;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
while (y--) {
|
2012-05-07 18:30:04 +00:00
|
|
|
pxl = (unsigned short *) (buffer + y * movie->header->Width * 2);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-09-19 08:11:30 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2012-05-07 18:30:04 +00:00
|
|
|
pxla = (unsigned char *)pxl;
|
2011-09-19 08:11:30 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
x = movie->header->Width;
|
2002-10-12 11:37:38 +00:00
|
|
|
while (x--) {
|
2011-09-19 08:11:30 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2012-05-07 18:30:04 +00:00
|
|
|
i = pxla[0];
|
|
|
|
|
pxla[0] = pxla[1];
|
|
|
|
|
pxla[1] = i;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
pxla += 2;
|
2011-09-19 08:11:30 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
*(to++) = ((*pxl >> 10) & 0x1f) * 8;
|
|
|
|
|
*(to++) = ((*pxl >> 5) & 0x1f) * 8;
|
|
|
|
|
*(to++) = (*pxl & 0x1f) * 8;
|
2012-10-21 05:46:41 +00:00
|
|
|
pxl++;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
MEM_freeN(buffer);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
return buf;
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-07 18:30:04 +00:00
|
|
|
buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
rowstride = movie->header->Width * 3;
|
2012-11-18 02:41:55 +00:00
|
|
|
if ((bits != 16) && (movie->header->Width % 2)) rowstride++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
for (y = 0; y < movie->header->Height; y++) {
|
|
|
|
|
memcpy(&buf[y * movie->header->Width * 3], &buffer[((movie->header->Height - 1) - y) * rowstride], movie->header->Width * 3);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
for (y = 0; y < movie->header->Height * movie->header->Width * 3; y += 3) {
|
2002-10-12 11:37:38 +00:00
|
|
|
i = buf[y];
|
2012-05-07 18:30:04 +00:00
|
|
|
buf[y] = buf[y + 2];
|
|
|
|
|
buf[y + 2] = i;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
MEM_freeN(buffer);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
int y, x, i, rowstride;
|
|
|
|
|
unsigned char *buf;
|
|
|
|
|
|
2010-10-17 06:38:56 +00:00
|
|
|
(void)stream; /* unused */
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
*size = movie->header->Height * movie->header->Width * 3;
|
|
|
|
|
if (movie->header->Width % 2) *size += movie->header->Height;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
buf = MEM_mallocN(*size, "toavirgbbuf");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
rowstride = movie->header->Width * 3;
|
|
|
|
|
if (movie->header->Width % 2) rowstride++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
for (y = 0; y < movie->header->Height; y++) {
|
|
|
|
|
memcpy(&buf[y * rowstride], &buffer[((movie->header->Height - 1) - y) * movie->header->Width * 3], movie->header->Width * 3);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
for (y = 0; y < movie->header->Height; y++) {
|
|
|
|
|
for (x = 0; x < movie->header->Width * 3; x += 3) {
|
|
|
|
|
i = buf[y * rowstride + x];
|
|
|
|
|
buf[y * rowstride + x] = buf[y * rowstride + x + 2];
|
|
|
|
|
buf[y * rowstride + x + 2] = i;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
MEM_freeN(buffer);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|