2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17 * All rights reserved.
20 /** \file \ingroup avi
22 * This is external code. Converts between rgb32 and avi.
28 #include "MEM_guardedalloc.h"
30 #include "IMB_imbuf.h"
33 #include "avi_rgb32.h"
35 void *avi_converter_from_rgb32(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
39 (void)stream; /* unused */
41 *size = (size_t)movie->header->Height * (size_t)movie->header->Width * 3;
42 buf = imb_alloc_pixels(movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "fromrgb32buf");
47 size_t rowstridea = movie->header->Width * 3;
48 size_t rowstrideb = movie->header->Width * 4;
50 for (size_t y = 0; y < movie->header->Height; y++) {
51 for (size_t x = 0; x < movie->header->Width; x++) {
52 buf[y * rowstridea + x * 3 + 0] = buffer[y * rowstrideb + x * 4 + 3];
53 buf[y * rowstridea + x * 3 + 1] = buffer[y * rowstrideb + x * 4 + 2];
54 buf[y * rowstridea + x * 3 + 2] = buffer[y * rowstrideb + x * 4 + 1];
63 void *avi_converter_to_rgb32(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
66 unsigned char *to, *from;
68 (void)stream; /* unused */
70 *size = (size_t)movie->header->Height * (size_t)movie->header->Width * 4;
71 buf = imb_alloc_pixels(movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "torgb32buf");
76 memset(buf, 255, *size);
78 to = buf; from = buffer;
79 size_t i = (size_t)movie->header->Height * (size_t)movie->header->Width;