This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/avi/intern/avi_rgb.c

150 lines
3.6 KiB
C
Raw Normal View History

/*
* ***** 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
* 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.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +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"
#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)
{
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;
(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;
#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
#ifdef __BIG_ENDIAN__
2012-05-07 18:30:04 +00:00
pxla = (unsigned char *)pxl;
#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--) {
#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;
#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;
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;
}
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)
{
2002-10-12 11:37:38 +00:00
int y, x, i, rowstride;
unsigned char *buf;
(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;
}