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
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* implementation */
|
|
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
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
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
buf = imb_alloc_pixels(movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "fromavirgbbuf");
|
|
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
|
size_t y = movie->header->Height;
|
|
|
|
|
to = buf;
|
|
|
|
|
|
|
|
|
|
while (y--) {
|
|
|
|
|
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__
|
2018-01-14 14:19:57 +01:00
|
|
|
pxla = (unsigned char *)pxl;
|
2011-09-19 08:11:30 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
size_t x = movie->header->Width;
|
|
|
|
|
while (x--) {
|
2011-09-19 08:11:30 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2018-01-14 14:19:57 +01:00
|
|
|
int i = pxla[0];
|
|
|
|
|
pxla[0] = pxla[1];
|
|
|
|
|
pxla[1] = i;
|
|
|
|
|
|
|
|
|
|
pxla += 2;
|
2011-09-19 08:11:30 +00:00
|
|
|
#endif
|
2018-01-14 14:19:57 +01:00
|
|
|
|
|
|
|
|
*(to++) = ((*pxl >> 10) & 0x1f) * 8;
|
|
|
|
|
*(to++) = ((*pxl >> 5) & 0x1f) * 8;
|
|
|
|
|
*(to++) = (*pxl & 0x1f) * 8;
|
|
|
|
|
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 {
|
2018-01-14 14:19:57 +01:00
|
|
|
buf = imb_alloc_pixels(movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "fromavirgbbuf");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
if (buf) {
|
|
|
|
|
size_t rowstride = movie->header->Width * 3;
|
|
|
|
|
if ((bits != 16) && (movie->header->Width % 2)) rowstride++;
|
|
|
|
|
|
|
|
|
|
for (size_t 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t y = 0; y < (size_t)movie->header->Height * (size_t)movie->header->Width * 3; y += 3) {
|
|
|
|
|
int i = buf[y];
|
|
|
|
|
buf[y] = buf[y + 2];
|
|
|
|
|
buf[y + 2] = i;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2018-01-14 14:19:57 +01:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
MEM_freeN(buffer);
|
2018-01-14 14:19:57 +01:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
unsigned char *buf;
|
|
|
|
|
|
2010-10-17 06:38:56 +00:00
|
|
|
(void)stream; /* unused */
|
|
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
size_t rowstride = movie->header->Width * 3;
|
2014-10-06 16:35:11 +02:00
|
|
|
/* AVI files has uncompressed lines 4-byte aligned */
|
|
|
|
|
rowstride = (rowstride + 3) & ~3;
|
|
|
|
|
|
|
|
|
|
*size = movie->header->Height * rowstride;
|
|
|
|
|
buf = MEM_mallocN(*size, "toavirgbbuf");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < movie->header->Height; y++) {
|
2012-05-07 18:30:04 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-01-14 14:19:57 +01:00
|
|
|
for (size_t y = 0; y < movie->header->Height; y++) {
|
|
|
|
|
for (size_t x = 0; x < movie->header->Width * 3; x += 3) {
|
|
|
|
|
int i = buf[y * rowstride + x];
|
2012-05-07 18:30:04 +00:00
|
|
|
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;
|
|
|
|
|
}
|