From 89a415a49d0e96bd6bf63b5e6e9d5bfe2f87bc49 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 7 Oct 2012 06:27:31 +0000 Subject: rename avi files (endian.h is common linux include). --- source/blender/avi/AVI_avi.h | 2 +- source/blender/avi/CMakeLists.txt | 20 +- source/blender/avi/intern/avi.c | 3 +- source/blender/avi/intern/avi_codecs.c | 148 ++++++++++ source/blender/avi/intern/avi_endian.c | 217 ++++++++++++++ source/blender/avi/intern/avi_endian.h | 48 ++++ source/blender/avi/intern/avi_mjpeg.c | 490 ++++++++++++++++++++++++++++++++ source/blender/avi/intern/avi_mjpeg.h | 38 +++ source/blender/avi/intern/avi_options.c | 133 +++++++++ source/blender/avi/intern/avi_rgb.c | 149 ++++++++++ source/blender/avi/intern/avi_rgb.h | 38 +++ source/blender/avi/intern/avi_rgb32.c | 93 ++++++ source/blender/avi/intern/avi_rgb32.h | 38 +++ source/blender/avi/intern/avirgb.c | 149 ---------- source/blender/avi/intern/avirgb.h | 35 --- source/blender/avi/intern/codecs.c | 148 ---------- source/blender/avi/intern/endian.c | 216 -------------- source/blender/avi/intern/endian.h | 52 ---- source/blender/avi/intern/mjpeg.c | 488 ------------------------------- source/blender/avi/intern/mjpeg.h | 35 --- source/blender/avi/intern/options.c | 133 --------- source/blender/avi/intern/rgb32.c | 92 ------ source/blender/avi/intern/rgb32.h | 35 --- 23 files changed, 1404 insertions(+), 1396 deletions(-) create mode 100644 source/blender/avi/intern/avi_codecs.c create mode 100644 source/blender/avi/intern/avi_endian.c create mode 100644 source/blender/avi/intern/avi_endian.h create mode 100644 source/blender/avi/intern/avi_mjpeg.c create mode 100644 source/blender/avi/intern/avi_mjpeg.h create mode 100644 source/blender/avi/intern/avi_options.c create mode 100644 source/blender/avi/intern/avi_rgb.c create mode 100644 source/blender/avi/intern/avi_rgb.h create mode 100644 source/blender/avi/intern/avi_rgb32.c create mode 100644 source/blender/avi/intern/avi_rgb32.h delete mode 100644 source/blender/avi/intern/avirgb.c delete mode 100644 source/blender/avi/intern/avirgb.h delete mode 100644 source/blender/avi/intern/codecs.c delete mode 100644 source/blender/avi/intern/endian.c delete mode 100644 source/blender/avi/intern/endian.h delete mode 100644 source/blender/avi/intern/mjpeg.c delete mode 100644 source/blender/avi/intern/mjpeg.h delete mode 100644 source/blender/avi/intern/options.c delete mode 100644 source/blender/avi/intern/rgb32.c delete mode 100644 source/blender/avi/intern/rgb32.h (limited to 'source/blender/avi') diff --git a/source/blender/avi/AVI_avi.h b/source/blender/avi/AVI_avi.h index bdfdbc117ed..4dc52970119 100644 --- a/source/blender/avi/AVI_avi.h +++ b/source/blender/avi/AVI_avi.h @@ -178,7 +178,7 @@ typedef struct _AviStreamRec { } AviStreamRec; typedef struct _AviMovie { - FILE *fp; + FILE *fp; int type; #define AVI_MOVIE_READ 0 diff --git a/source/blender/avi/CMakeLists.txt b/source/blender/avi/CMakeLists.txt index 79422dff917..292206d8cb9 100644 --- a/source/blender/avi/CMakeLists.txt +++ b/source/blender/avi/CMakeLists.txt @@ -35,19 +35,19 @@ set(INC_SYS set(SRC intern/avi.c - intern/avirgb.c - intern/codecs.c - intern/endian.c - intern/mjpeg.c - intern/options.c - intern/rgb32.c + intern/avi_rgb.c + intern/avi_codecs.c + intern/avi_endian.c + intern/avi_mjpeg.c + intern/avi_options.c + intern/avi_rgb32.c AVI_avi.h intern/avi_intern.h - intern/avirgb.h - intern/endian.h - intern/mjpeg.h - intern/rgb32.h + intern/avi_rgb.h + intern/avi_endian.h + intern/avi_mjpeg.h + intern/avi_rgb32.h ) blender_add_lib(bf_avi "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/avi/intern/avi.c b/source/blender/avi/intern/avi.c index 2845b2f95c9..15d8702a5ec 100644 --- a/source/blender/avi/intern/avi.c +++ b/source/blender/avi/intern/avi.c @@ -32,7 +32,6 @@ * This is external code. */ - #include #include #include @@ -49,7 +48,7 @@ #include "AVI_avi.h" #include "avi_intern.h" -#include "endian.h" +#include "avi_endian.h" static int AVI_DEBUG = 0; static char DEBUG_FCC[4]; diff --git a/source/blender/avi/intern/avi_codecs.c b/source/blender/avi/intern/avi_codecs.c new file mode 100644 index 00000000000..e43826064a6 --- /dev/null +++ b/source/blender/avi/intern/avi_codecs.c @@ -0,0 +1,148 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + */ + +/** \file blender/avi/intern/avi_codecs.c + * \ingroup avi + * + * This is external code. Identify and convert different avi-files. + */ + + +#include "AVI_avi.h" +#include "avi_intern.h" + +#include "avi_rgb.h" +#include "avi_mjpeg.h" +#include "avi_rgb32.h" + +void *avi_format_convert(AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, int *size) +{ + if (from == to) + return buffer; + + if (from != AVI_FORMAT_RGB24 && + to != AVI_FORMAT_RGB24) + { + return avi_format_convert(movie, stream, + avi_format_convert(movie, stream, buffer, from, AVI_FORMAT_RGB24, size), + AVI_FORMAT_RGB24, to, size); + } + + switch (to) { + case AVI_FORMAT_RGB24: + switch (from) { + case AVI_FORMAT_AVI_RGB: + buffer = avi_converter_from_avi_rgb(movie, stream, buffer, size); + break; + case AVI_FORMAT_MJPEG: + buffer = avi_converter_from_mjpeg(movie, stream, buffer, size); + break; + case AVI_FORMAT_RGB32: + buffer = avi_converter_from_rgb32(movie, stream, buffer, size); + break; + default: + break; + } + break; + case AVI_FORMAT_AVI_RGB: + buffer = avi_converter_to_avi_rgb(movie, stream, buffer, size); + break; + case AVI_FORMAT_MJPEG: + buffer = avi_converter_to_mjpeg(movie, stream, buffer, size); + break; + case AVI_FORMAT_RGB32: + buffer = avi_converter_to_rgb32(movie, stream, buffer, size); + break; + default: + break; + } + + return buffer; +} + +int avi_get_data_id(AviFormat format, int stream) +{ + char fcc[5]; + + if (avi_get_format_type(format) == FCC("vids")) + sprintf(fcc, "%2.2ddc", stream); + else if (avi_get_format_type(format) == FCC("auds")) + sprintf(fcc, "%2.2ddc", stream); + else + return 0; + + return FCC(fcc); +} + +int avi_get_format_type(AviFormat format) +{ + switch (format) { + case AVI_FORMAT_RGB24: + case AVI_FORMAT_RGB32: + case AVI_FORMAT_AVI_RGB: + case AVI_FORMAT_MJPEG: + return FCC("vids"); + break; + default: + return 0; + break; + } +} + +int avi_get_format_fcc(AviFormat format) +{ + switch (format) { + case AVI_FORMAT_RGB24: + case AVI_FORMAT_RGB32: + case AVI_FORMAT_AVI_RGB: + return FCC("DIB "); + break; + case AVI_FORMAT_MJPEG: + return FCC("MJPG"); + break; + default: + return 0; + break; + } +} + +int avi_get_format_compression(AviFormat format) +{ + switch (format) { + case AVI_FORMAT_RGB24: + case AVI_FORMAT_RGB32: + case AVI_FORMAT_AVI_RGB: + return 0; + break; + case AVI_FORMAT_MJPEG: + return FCC("MJPG"); + break; + default: + return 0; + break; + } +} diff --git a/source/blender/avi/intern/avi_endian.c b/source/blender/avi/intern/avi_endian.c new file mode 100644 index 00000000000..70add8bd90f --- /dev/null +++ b/source/blender/avi/intern/avi_endian.c @@ -0,0 +1,217 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + * + */ + +/** \file blender/avi/intern/avi_endian.c + * \ingroup avi + * + * This is external code. Streams bytes to output depending on the + * endianness of the system. + */ + + +#include +#include +#include + +#include "AVI_avi.h" +#include "avi_endian.h" +#include "avi_intern.h" + +#ifdef __BIG_ENDIAN__ +#include "MEM_guardedalloc.h" +#endif + +#ifdef __BIG_ENDIAN__ + +/* copied from BLI_endian_switch_inline.h */ +static void invert(int *num) +{ + int tval = *val; + *val = ((tval >> 24)) | + ((tval << 8) & 0x00ff0000) | + ((tval >> 8) & 0x0000ff00) | + ((tval << 24)); +} + +static void sinvert(short int *val) +{ + short tval = *val; + *val = (tval >> 8) | + (tval << 8); +} + +static void Ichunk(AviChunk *chunk) +{ + invert(&chunk->fcc); + invert(&chunk->size); +} +#endif + +#ifdef __BIG_ENDIAN__ +static void Ilist(AviList *list) +{ + invert(&list->fcc); + invert(&list->size); + invert(&list->ids); +} + +static void Imainh(AviMainHeader *mainh) +{ + invert(&mainh->fcc); + invert(&mainh->size); + invert(&mainh->MicroSecPerFrame); + invert(&mainh->MaxBytesPerSec); + invert(&mainh->PaddingGranularity); + invert(&mainh->Flags); + invert(&mainh->TotalFrames); + invert(&mainh->InitialFrames); + invert(&mainh->Streams); + invert(&mainh->SuggestedBufferSize); + invert(&mainh->Width); + invert(&mainh->Height); + invert(&mainh->Reserved[0]); + invert(&mainh->Reserved[1]); + invert(&mainh->Reserved[2]); + invert(&mainh->Reserved[3]); +} + +static void Istreamh(AviStreamHeader *streamh) +{ + invert(&streamh->fcc); + invert(&streamh->size); + invert(&streamh->Type); + invert(&streamh->Handler); + invert(&streamh->Flags); + sinvert(&streamh->Priority); + sinvert(&streamh->Language); + invert(&streamh->InitialFrames); + invert(&streamh->Scale); + invert(&streamh->Rate); + invert(&streamh->Start); + invert(&streamh->Length); + invert(&streamh->SuggestedBufferSize); + invert(&streamh->Quality); + invert(&streamh->SampleSize); + sinvert(&streamh->left); + sinvert(&streamh->right); + sinvert(&streamh->top); + sinvert(&streamh->bottom); +} + +static void Ibitmaph(AviBitmapInfoHeader *bitmaph) +{ + invert(&bitmaph->fcc); + invert(&bitmaph->size); + invert(&bitmaph->Size); + invert(&bitmaph->Width); + invert(&bitmaph->Height); + sinvert(&bitmaph->Planes); + sinvert(&bitmaph->BitCount); + invert(&bitmaph->Compression); + invert(&bitmaph->SizeImage); + invert(&bitmaph->XPelsPerMeter); + invert(&bitmaph->YPelsPerMeter); + invert(&bitmaph->ClrUsed); + invert(&bitmaph->ClrImportant); +} + +static void Imjpegu(AviMJPEGUnknown *mjpgu) +{ + invert(&mjpgu->a); + invert(&mjpgu->b); + invert(&mjpgu->c); + invert(&mjpgu->d); + invert(&mjpgu->e); + invert(&mjpgu->f); + invert(&mjpgu->g); +} + +static void Iindexe(AviIndexEntry *indexe) +{ + invert(&indexe->ChunkId); + invert(&indexe->Flags); + invert(&indexe->Offset); + invert(&indexe->Size); +} +#endif /* __BIG_ENDIAN__ */ + +void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type) +{ +#ifdef __BIG_ENDIAN__ + void *data; + + data = MEM_mallocN(size, "avi endian"); + + memcpy(data, datain, size); + + switch (type) { + case AVI_RAW: + fwrite(data, block, size, fp); + break; + case AVI_CHUNK: + Ichunk((AviChunk *) data); + fwrite(data, block, size, fp); + break; + case AVI_LIST: + Ilist((AviList *) data); + fwrite(data, block, size, fp); + break; + case AVI_MAINH: + Imainh((AviMainHeader *) data); + fwrite(data, block, size, fp); + break; + case AVI_STREAMH: + Istreamh((AviStreamHeader *) data); + fwrite(data, block, size, fp); + break; + case AVI_BITMAPH: + Ibitmaph((AviBitmapInfoHeader *) data); + if (size == sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) { + Imjpegu((AviMJPEGUnknown *)((char *)data + sizeof(AviBitmapInfoHeader))); + } + fwrite(data, block, size, fp); + break; + case AVI_MJPEGU: + Imjpegu((AviMJPEGUnknown *) data); + fwrite(data, block, size, fp); + break; + case AVI_INDEXE: + Iindexe((AviIndexEntry *) data); + fwrite(data, block, size, fp); + break; + default: + break; + } + + MEM_freeN(data); +#else /* __BIG_ENDIAN__ */ + (void)movie; /* unused */ + (void)type; /* unused */ + fwrite(datain, block, size, fp); +#endif /* __BIG_ENDIAN__ */ +} diff --git a/source/blender/avi/intern/avi_endian.h b/source/blender/avi/intern/avi_endian.h new file mode 100644 index 00000000000..8cea283a553 --- /dev/null +++ b/source/blender/avi/intern/avi_endian.h @@ -0,0 +1,48 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + */ + +/** \file blender/avi/intern/avi_endian.h + * \ingroup avi + * + * This is external code. + */ + +#ifndef __AVI_ENDIAN_H__ +#define __AVI_ENDIAN_H__ + +#define AVI_RAW 0 +#define AVI_CHUNK 1 +#define AVI_LIST 2 +#define AVI_MAINH 3 +#define AVI_STREAMH 4 +#define AVI_BITMAPH 5 +#define AVI_INDEXE 6 +#define AVI_MJPEGU 7 + +void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type); + +#endif /* __AVI_ENDIAN_H__ */ diff --git a/source/blender/avi/intern/avi_mjpeg.c b/source/blender/avi/intern/avi_mjpeg.c new file mode 100644 index 00000000000..b98e03d6a19 --- /dev/null +++ b/source/blender/avi/intern/avi_mjpeg.c @@ -0,0 +1,490 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + * + */ + +/** \file blender/avi/intern/avi_mjpeg.c + * \ingroup avi + * + * This is external code. Converts between avi and mpeg/jpeg. + */ + +#include +#include + +#include "AVI_avi.h" + +#include "MEM_guardedalloc.h" + +#include "jpeglib.h" +#include "jerror.h" + +#include "avi_mjpeg.h" + +#define PADUP(num, amt) ((num + (amt - 1)) & ~(amt - 1)) + +static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize); +static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize); + +static int numbytes; + +static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) +{ + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo); + + memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); + memcpy((*htblptr)->huffval, val, sizeof((*htblptr)->huffval)); + + /* Initialize sent_table FALSE so table will be written to JPEG file. */ + (*htblptr)->sent_table = FALSE; +} + +/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ +/* IMPORTANT: these are only valid for 8-bit data precision! */ + +static void std_huff_tables(j_decompress_ptr dinfo) +{ + static const UINT8 bits_dc_luminance[17] = + { /* 0-base */ + 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 + }; + static const UINT8 val_dc_luminance[] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }; + + static const UINT8 bits_dc_chrominance[17] = + { /* 0-base */ + 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 + }; + static const UINT8 val_dc_chrominance[] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }; + + static const UINT8 bits_ac_luminance[17] = + { /* 0-base */ + 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d + }; + static const UINT8 val_ac_luminance[] = + { + 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, + 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, + 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, + 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, + 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, + 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, + 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, + 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa + }; + static const UINT8 bits_ac_chrominance[17] = + { /* 0-base */ + 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 + }; + static const UINT8 val_ac_chrominance[] = + { + 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, + 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, + 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, + 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, + 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, + 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, + 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, + 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, + 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, + 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa + }; + + add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[0], + bits_dc_luminance, val_dc_luminance); + add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[0], + bits_ac_luminance, val_ac_luminance); + add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[1], + bits_dc_chrominance, val_dc_chrominance); + add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[1], + bits_ac_chrominance, val_ac_chrominance); +} + +static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsigned int width, unsigned int height, int bufsize) +{ + int rowstride; + unsigned int y; + struct jpeg_decompress_struct dinfo; + struct jpeg_error_mgr jerr; + + (void)width; /* unused */ + + numbytes = 0; + + dinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&dinfo); + jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize); + jpeg_read_header(&dinfo, TRUE); + if (dinfo.dc_huff_tbl_ptrs[0] == NULL) { + std_huff_tables(&dinfo); + } + dinfo.out_color_space = JCS_RGB; + dinfo.dct_method = JDCT_IFAST; + + jpeg_start_decompress(&dinfo); + + rowstride = dinfo.output_width * dinfo.output_components; + for (y = 0; y < dinfo.output_height; y++) { + jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1); + outBuffer += rowstride; + } + jpeg_finish_decompress(&dinfo); + + if (dinfo.output_height >= height) return 0; + + inBuffer += numbytes; + jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize - numbytes); + + numbytes = 0; + jpeg_read_header(&dinfo, TRUE); + if (dinfo.dc_huff_tbl_ptrs[0] == NULL) { + std_huff_tables(&dinfo); + } + + jpeg_start_decompress(&dinfo); + rowstride = dinfo.output_width * dinfo.output_components; + for (y = 0; y < dinfo.output_height; y++) { + jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1); + outBuffer += rowstride; + } + jpeg_finish_decompress(&dinfo); + jpeg_destroy_decompress(&dinfo); + + return 1; +} + +static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char *inBuffer, int width, int height, int bufsize) +{ + int i, rowstride; + unsigned int y; + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + unsigned char marker[60]; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + jpegmemdestmgr_build(&cinfo, outbuffer, bufsize); + + cinfo.image_width = width; + cinfo.image_height = height; + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + + jpeg_set_defaults(&cinfo); + jpeg_set_colorspace(&cinfo, JCS_YCbCr); + + jpeg_set_quality(&cinfo, quality, TRUE); + + cinfo.dc_huff_tbl_ptrs[0]->sent_table = TRUE; + cinfo.dc_huff_tbl_ptrs[1]->sent_table = TRUE; + cinfo.ac_huff_tbl_ptrs[0]->sent_table = TRUE; + cinfo.ac_huff_tbl_ptrs[1]->sent_table = TRUE; + + cinfo.comp_info[0].component_id = 0; + cinfo.comp_info[0].v_samp_factor = 1; + cinfo.comp_info[1].component_id = 1; + cinfo.comp_info[2].component_id = 2; + + cinfo.write_JFIF_header = FALSE; + + jpeg_start_compress(&cinfo, FALSE); + + i = 0; + marker[i++] = 'A'; + marker[i++] = 'V'; + marker[i++] = 'I'; + marker[i++] = '1'; + marker[i++] = 0; + while (i < 60) + marker[i++] = 32; + + jpeg_write_marker(&cinfo, JPEG_APP0, marker, 60); + + i = 0; + while (i < 60) + marker[i++] = 0; + + jpeg_write_marker(&cinfo, JPEG_COM, marker, 60); + + rowstride = cinfo.image_width * cinfo.input_components; + for (y = 0; y < cinfo.image_height; y++) { + jpeg_write_scanlines(&cinfo, (JSAMPARRAY) &inBuffer, 1); + inBuffer += rowstride; + } + jpeg_finish_compress(&cinfo); + jpeg_destroy_compress(&cinfo); +} + +static void interlace(unsigned char *to, unsigned char *from, int width, int height) +{ + int i, rowstride = width * 3; + + for (i = 0; i < height; i++) { + if (i & 1) + memcpy(&to[i * rowstride], &from[(i / 2 + height / 2) * rowstride], rowstride); + else + memcpy(&to[i * rowstride], &from[(i / 2) * rowstride], rowstride); + } +} + +static void deinterlace(int odd, unsigned char *to, unsigned char *from, int width, int height) +{ + int i, rowstride = width * 3; + + for (i = 0; i < height; i++) { + if ((i & 1) == odd) + memcpy(&to[(i / 2 + height / 2) * rowstride], &from[i * rowstride], rowstride); + else + memcpy(&to[(i / 2) * rowstride], &from[i * rowstride], rowstride); + } +} + +static int check_and_decode_jpeg(unsigned char *inbuf, unsigned char *outbuf, int width, int height, int bufsize) +{ + /* JPEG's are always multiples of 16, extra is cropped out AVI's */ + if ((width & 0xF) || (height & 0xF)) { + int i, rrowstride, jrowstride; + int jwidth = PADUP(width, 16); + int jheight = PADUP(height, 16); + unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_decode_jpeg"); + int ret = Decode_JPEG(inbuf, tmpbuf, jwidth, jheight, bufsize); + + /* crop the tmpbuf into the real buffer */ + rrowstride = width * 3; + jrowstride = jwidth * 3; + for (i = 0; i < height; i++) + memcpy(&outbuf[i * rrowstride], &tmpbuf[i * jrowstride], rrowstride); + MEM_freeN(tmpbuf); + + return ret; + } + else { + return Decode_JPEG(inbuf, outbuf, width, height, bufsize); + } +} + +static void check_and_compress_jpeg(int quality, unsigned char *outbuf, unsigned char *inbuf, int width, int height, int bufsize) +{ + /* JPEG's are always multiples of 16, extra is ignored in AVI's */ + if ((width & 0xF) || (height & 0xF)) { + int i, rrowstride, jrowstride; + int jwidth = PADUP(width, 16); + int jheight = PADUP(height, 16); + unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_compress_jpeg"); + + /* resize the realbuf into the tmpbuf */ + rrowstride = width * 3; + jrowstride = jwidth * 3; + for (i = 0; i < jheight; i++) { + if (i < height) + memcpy(&tmpbuf[i * jrowstride], &inbuf[i * rrowstride], rrowstride); + else + memset(&tmpbuf[i * jrowstride], 0, rrowstride); + memset(&tmpbuf[i * jrowstride + rrowstride], 0, jrowstride - rrowstride); + } + + Compress_JPEG(quality, outbuf, tmpbuf, jwidth, jheight, bufsize); + + MEM_freeN(tmpbuf); + } + else { + Compress_JPEG(quality, outbuf, inbuf, width, height, bufsize); + } +} + +void *avi_converter_from_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size) +{ + int deint; + unsigned char *buf; + + (void)stream; /* unused */ + + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 1"); + + deint = check_and_decode_jpeg(buffer, buf, movie->header->Width, movie->header->Height, *size); + + MEM_freeN(buffer); + + if (deint) { + buffer = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 2"); + interlace(buffer, buf, movie->header->Width, movie->header->Height); + MEM_freeN(buf); + + buf = buffer; + } + + return buf; +} + +void *avi_converter_to_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size) +{ + unsigned char *buf; + int bufsize = *size; + + numbytes = 0; + *size = 0; + + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 1"); + if (!movie->interlace) { + check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer, movie->header->Width, movie->header->Height, bufsize); + } + else { + deinterlace(movie->odd_fields, buf, buffer, movie->header->Width, movie->header->Height); + MEM_freeN(buffer); + + buffer = buf; + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 2"); + + check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer, movie->header->Width, movie->header->Height / 2, bufsize / 2); + *size += numbytes; + numbytes = 0; + check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf + *size, buffer + (movie->header->Height / 2) * movie->header->Width * 3, movie->header->Width, movie->header->Height / 2, bufsize / 2); + } + *size += numbytes; + + MEM_freeN(buffer); + return buf; +} + + +/* Compression from memory */ + +static void jpegmemdestmgr_init_destination(j_compress_ptr cinfo) +{ + (void)cinfo; /* unused */ +} + +static boolean jpegmemdestmgr_empty_output_buffer(j_compress_ptr cinfo) +{ + (void)cinfo; /* unused */ + return TRUE; +} + +static void jpegmemdestmgr_term_destination(j_compress_ptr cinfo) +{ + numbytes -= cinfo->dest->free_in_buffer; + + MEM_freeN(cinfo->dest); +} + +static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize) +{ + cinfo->dest = MEM_mallocN(sizeof(*(cinfo->dest)), "avi.jpegmemdestmgr_build"); + + cinfo->dest->init_destination = jpegmemdestmgr_init_destination; + cinfo->dest->empty_output_buffer = jpegmemdestmgr_empty_output_buffer; + cinfo->dest->term_destination = jpegmemdestmgr_term_destination; + + cinfo->dest->next_output_byte = buffer; + cinfo->dest->free_in_buffer = bufsize; + + numbytes = bufsize; +} + +/* Decompression from memory */ + +static void jpegmemsrcmgr_init_source(j_decompress_ptr dinfo) +{ + (void)dinfo; +} + +static boolean jpegmemsrcmgr_fill_input_buffer(j_decompress_ptr dinfo) +{ + unsigned char *buf = (unsigned char *) dinfo->src->next_input_byte - 2; + + /* if we get called, must have run out of data */ + WARNMS(dinfo, JWRN_JPEG_EOF); + + buf[0] = (JOCTET) 0xFF; + buf[1] = (JOCTET) JPEG_EOI; + + dinfo->src->next_input_byte = buf; + dinfo->src->bytes_in_buffer = 2; + + return TRUE; +} + +static void jpegmemsrcmgr_skip_input_data(j_decompress_ptr dinfo, long skipcnt) +{ + if (dinfo->src->bytes_in_buffer < skipcnt) + skipcnt = dinfo->src->bytes_in_buffer; + + dinfo->src->next_input_byte += skipcnt; + dinfo->src->bytes_in_buffer -= skipcnt; +} + +static void jpegmemsrcmgr_term_source(j_decompress_ptr dinfo) +{ + numbytes -= dinfo->src->bytes_in_buffer; + + MEM_freeN(dinfo->src); +} + +static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize) +{ + dinfo->src = MEM_mallocN(sizeof(*(dinfo->src)), "avi.jpegmemsrcmgr_build"); + + dinfo->src->init_source = jpegmemsrcmgr_init_source; + dinfo->src->fill_input_buffer = jpegmemsrcmgr_fill_input_buffer; + dinfo->src->skip_input_data = jpegmemsrcmgr_skip_input_data; + dinfo->src->resync_to_restart = jpeg_resync_to_restart; + dinfo->src->term_source = jpegmemsrcmgr_term_source; + + dinfo->src->bytes_in_buffer = bufsize; + dinfo->src->next_input_byte = buffer; + + numbytes = bufsize; +} diff --git a/source/blender/avi/intern/avi_mjpeg.h b/source/blender/avi/intern/avi_mjpeg.h new file mode 100644 index 00000000000..6ae0e56ffa4 --- /dev/null +++ b/source/blender/avi/intern/avi_mjpeg.h @@ -0,0 +1,38 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + */ + +/** \file blender/avi/intern/avi_mjpeg.h + * \ingroup avi + */ + +#ifndef __AVI_MJPEG_H__ +#define __AVI_MJPEG_H__ + +void *avi_converter_from_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size); +void *avi_converter_to_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size); + +#endif /* __AVI_MJPEG_H__ */ diff --git a/source/blender/avi/intern/avi_options.c b/source/blender/avi/intern/avi_options.c new file mode 100644 index 00000000000..f7759a1099f --- /dev/null +++ b/source/blender/avi/intern/avi_options.c @@ -0,0 +1,133 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + * + */ + +/** \file blender/avi/intern/avi_options.c + * \ingroup avi + * + * This is external code. Sets some compression related options + * (width, height quality, framerate). + */ + +#include "AVI_avi.h" +#include "avi_intern.h" +#include "avi_endian.h" + +#ifdef WIN32 +# include "BLI_winstuff.h" +#endif + +/* avi_set_compress_options gets its own file... now don't WE feel important? */ + +AviError AVI_set_compress_option(AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data) +{ + int i; + int useconds; + + (void)stream; /* unused */ + + if (movie->header->TotalFrames != 0) /* Can't change params after we have already started writing frames */ + return AVI_ERROR_OPTION; + + switch (option_type) { + case AVI_OPTION_TYPE_MAIN: + switch (option) { + case AVI_OPTION_WIDTH: + movie->header->Width = *((int *) opt_data); + movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3; + + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data); + movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; + movie->streams[i].sh.right = *((int *) opt_data); + ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } + + break; + + case AVI_OPTION_HEIGHT: + movie->header->Height = *((int *) opt_data); + movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3; + + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data); + movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; + movie->streams[i].sh.bottom = *((int *) opt_data); + ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } + + break; + + case AVI_OPTION_QUALITY: + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + movie->streams[i].sh.Quality = (*((int *) opt_data)) * 100; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } + break; + + case AVI_OPTION_FRAMERATE: + useconds = (int)(1000000 / (*((double *) opt_data))); + if (useconds) + movie->header->MicroSecPerFrame = useconds; + + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } + + } + + fseek(movie->fp, movie->offset_table[0], SEEK_SET); + awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); + + break; + case AVI_OPTION_TYPE_STRH: + break; + case AVI_OPTION_TYPE_STRF: + break; + default: + return AVI_ERROR_OPTION; + break; + } + + return AVI_ERROR_NONE; +} + diff --git a/source/blender/avi/intern/avi_rgb.c b/source/blender/avi/intern/avi_rgb.c new file mode 100644 index 00000000000..61587e15e61 --- /dev/null +++ b/source/blender/avi/intern/avi_rgb.c @@ -0,0 +1,149 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + * + */ + +/** \file blender/avi/intern/avi_rgb.c + * \ingroup avi + * + * This is external code. Converts rgb-type avi-s. + */ + +#include +#include + +#include "MEM_guardedalloc.h" + +#include "AVI_avi.h" +#include "avi_rgb.h" + +/* implementation */ + +void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size) +{ + int x, y, i, rowstride; + unsigned char *buf; + AviBitmapInfoHeader *bi; + short bits = 32; + + (void)size; /* unused */ + + bi = (AviBitmapInfoHeader *) movie->streams[stream].sf; + if (bi) bits = bi->BitCount; + + if (bits == 16) { + unsigned short *pxl; + unsigned char *to; +#ifdef __BIG_ENDIAN__ + unsigned char *pxla; +#endif + + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); + + y = movie->header->Height; + to = buf; + + while (y--) { + pxl = (unsigned short *) (buffer + y * movie->header->Width * 2); + +#ifdef __BIG_ENDIAN__ + pxla = (unsigned char *)pxl; +#endif + + x = movie->header->Width; + while (x--) { +#ifdef __BIG_ENDIAN__ + i = pxla[0]; + pxla[0] = pxla[1]; + pxla[1] = i; + + pxla += 2; +#endif + + *(to++) = ((*pxl >> 10) & 0x1f) * 8; + *(to++) = ((*pxl >> 5) & 0x1f) * 8; + *(to++) = (*pxl & 0x1f) * 8; + pxl++; + } + } + + MEM_freeN(buffer); + + return buf; + } + else { + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); + + rowstride = movie->header->Width * 3; + if (bits != 16) if (movie->header->Width % 2) rowstride++; + + 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); + } + + for (y = 0; y < movie->header->Height * movie->header->Width * 3; y += 3) { + i = buf[y]; + buf[y] = buf[y + 2]; + buf[y + 2] = i; + } + + MEM_freeN(buffer); + + return buf; + } +} + +void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size) +{ + int y, x, i, rowstride; + unsigned char *buf; + + (void)stream; /* unused */ + + *size = movie->header->Height * movie->header->Width * 3; + if (movie->header->Width % 2) *size += movie->header->Height; + + buf = MEM_mallocN(*size, "toavirgbbuf"); + + rowstride = movie->header->Width * 3; + if (movie->header->Width % 2) rowstride++; + + 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); + } + + 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; + } + } + + MEM_freeN(buffer); + + return buf; +} diff --git a/source/blender/avi/intern/avi_rgb.h b/source/blender/avi/intern/avi_rgb.h new file mode 100644 index 00000000000..773166e9fab --- /dev/null +++ b/source/blender/avi/intern/avi_rgb.h @@ -0,0 +1,38 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + */ + +/** \file blender/avi/intern/avi_rgb.h + * \ingroup avi + */ + +#ifndef __AVI_RGB_H__ +#define __AVI_RGB_H__ + +void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size); +void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size); + +#endif /* __AVI_RGB_H__ */ diff --git a/source/blender/avi/intern/avi_rgb32.c b/source/blender/avi/intern/avi_rgb32.c new file mode 100644 index 00000000000..5c7a4889d97 --- /dev/null +++ b/source/blender/avi/intern/avi_rgb32.c @@ -0,0 +1,93 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + * + */ + +/** \file blender/avi/intern/avi_rgb32.c + * \ingroup avi + * + * This is external code. Converts between rgb32 and avi. + */ + +#include +#include + +#include "MEM_guardedalloc.h" + +#include "AVI_avi.h" +#include "avi_rgb32.h" + +void *avi_converter_from_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size) +{ + int y, x, rowstridea, rowstrideb; + unsigned char *buf; + + (void)stream; /* unused */ + + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromrgb32buf"); + *size = movie->header->Height * movie->header->Width * 3; + + rowstridea = movie->header->Width * 3; + rowstrideb = movie->header->Width * 4; + + for (y = 0; y < movie->header->Height; y++) { + for (x = 0; x < movie->header->Width; x++) { + buf[y * rowstridea + x * 3 + 0] = buffer[y * rowstrideb + x * 4 + 3]; + buf[y * rowstridea + x * 3 + 1] = buffer[y * rowstrideb + x * 4 + 2]; + buf[y * rowstridea + x * 3 + 2] = buffer[y * rowstrideb + x * 4 + 1]; + } + } + + MEM_freeN(buffer); + + return buf; +} + +void *avi_converter_to_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size) +{ + int i; + unsigned char *buf; + unsigned char *to, *from; + + (void)stream; /* unused */ + + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 4, "torgb32buf"); + *size = movie->header->Height * movie->header->Width * 4; + + memset(buf, 255, *size); + + to = buf; from = buffer; + i = movie->header->Height * movie->header->Width; + + while (i--) { + memcpy(to, from, 3); + to += 4; from += 3; + } + + MEM_freeN(buffer); + + return buf; +} diff --git a/source/blender/avi/intern/avi_rgb32.h b/source/blender/avi/intern/avi_rgb32.h new file mode 100644 index 00000000000..523f9e795fd --- /dev/null +++ b/source/blender/avi/intern/avi_rgb32.h @@ -0,0 +1,38 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * 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, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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 ***** + */ + +/** \file blender/avi/intern/avi_rgb32.h + * \ingroup avi + */ + +#ifndef __AVI_RGB32_H__ +#define __AVI_RGB32_H__ + +void *avi_converter_from_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size); +void *avi_converter_to_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size); + +#endif /* __AVI_RGB32_H__ */ diff --git a/source/blender/avi/intern/avirgb.c b/source/blender/avi/intern/avirgb.c deleted file mode 100644 index 7a95972845a..00000000000 --- a/source/blender/avi/intern/avirgb.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - * - */ - -/** \file blender/avi/intern/avirgb.c - * \ingroup avi - * - * This is external code. Converts rgb-type avi-s. - */ - - -#include "AVI_avi.h" -#include -#include - -#include "MEM_guardedalloc.h" -#include "avirgb.h" - -/* implementation */ - -void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size) -{ - int x, y, i, rowstride; - unsigned char *buf; - AviBitmapInfoHeader *bi; - short bits = 32; - - (void)size; /* unused */ - - bi = (AviBitmapInfoHeader *) movie->streams[stream].sf; - if (bi) bits = bi->BitCount; - - if (bits == 16) { - unsigned short *pxl; - unsigned char *to; -#ifdef __BIG_ENDIAN__ - unsigned char *pxla; -#endif - - buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); - - y = movie->header->Height; - to = buf; - - while (y--) { - pxl = (unsigned short *) (buffer + y * movie->header->Width * 2); - -#ifdef __BIG_ENDIAN__ - pxla = (unsigned char *)pxl; -#endif - - x = movie->header->Width; - while (x--) { -#ifdef __BIG_ENDIAN__ - i = pxla[0]; - pxla[0] = pxla[1]; - pxla[1] = i; - - pxla += 2; -#endif - - *(to++) = ((*pxl >> 10) & 0x1f) * 8; - *(to++) = ((*pxl >> 5) & 0x1f) * 8; - *(to++) = (*pxl & 0x1f) * 8; - pxl++; - } - } - - MEM_freeN(buffer); - - return buf; - } - else { - buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); - - rowstride = movie->header->Width * 3; - if (bits != 16) if (movie->header->Width % 2) rowstride++; - - 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); - } - - for (y = 0; y < movie->header->Height * movie->header->Width * 3; y += 3) { - i = buf[y]; - buf[y] = buf[y + 2]; - buf[y + 2] = i; - } - - MEM_freeN(buffer); - - return buf; - } -} - -void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size) -{ - int y, x, i, rowstride; - unsigned char *buf; - - (void)stream; /* unused */ - - *size = movie->header->Height * movie->header->Width * 3; - if (movie->header->Width % 2) *size += movie->header->Height; - - buf = MEM_mallocN(*size, "toavirgbbuf"); - - rowstride = movie->header->Width * 3; - if (movie->header->Width % 2) rowstride++; - - 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); - } - - 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; - } - } - - MEM_freeN(buffer); - - return buf; -} diff --git a/source/blender/avi/intern/avirgb.h b/source/blender/avi/intern/avirgb.h deleted file mode 100644 index 20211d6ab2d..00000000000 --- a/source/blender/avi/intern/avirgb.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - */ - -/** \file blender/avi/intern/avirgb.h - * \ingroup avi - */ - - -void *avi_converter_from_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size); -void *avi_converter_to_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size); - diff --git a/source/blender/avi/intern/codecs.c b/source/blender/avi/intern/codecs.c deleted file mode 100644 index 01e228d570e..00000000000 --- a/source/blender/avi/intern/codecs.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - */ - -/** \file blender/avi/intern/codecs.c - * \ingroup avi - * - * This is external code. Identify and convert different avi-files. - */ - - -#include "AVI_avi.h" -#include "avi_intern.h" - -#include "avirgb.h" -#include "mjpeg.h" -#include "rgb32.h" - -void *avi_format_convert(AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, int *size) -{ - if (from == to) - return buffer; - - if (from != AVI_FORMAT_RGB24 && - to != AVI_FORMAT_RGB24) - { - return avi_format_convert(movie, stream, - avi_format_convert(movie, stream, buffer, from, AVI_FORMAT_RGB24, size), - AVI_FORMAT_RGB24, to, size); - } - - switch (to) { - case AVI_FORMAT_RGB24: - switch (from) { - case AVI_FORMAT_AVI_RGB: - buffer = avi_converter_from_avi_rgb(movie, stream, buffer, size); - break; - case AVI_FORMAT_MJPEG: - buffer = avi_converter_from_mjpeg(movie, stream, buffer, size); - break; - case AVI_FORMAT_RGB32: - buffer = avi_converter_from_rgb32(movie, stream, buffer, size); - break; - default: - break; - } - break; - case AVI_FORMAT_AVI_RGB: - buffer = avi_converter_to_avi_rgb(movie, stream, buffer, size); - break; - case AVI_FORMAT_MJPEG: - buffer = avi_converter_to_mjpeg(movie, stream, buffer, size); - break; - case AVI_FORMAT_RGB32: - buffer = avi_converter_to_rgb32(movie, stream, buffer, size); - break; - default: - break; - } - - return buffer; -} - -int avi_get_data_id(AviFormat format, int stream) -{ - char fcc[5]; - - if (avi_get_format_type(format) == FCC("vids")) - sprintf(fcc, "%2.2ddc", stream); - else if (avi_get_format_type(format) == FCC("auds")) - sprintf(fcc, "%2.2ddc", stream); - else - return 0; - - return FCC(fcc); -} - -int avi_get_format_type(AviFormat format) -{ - switch (format) { - case AVI_FORMAT_RGB24: - case AVI_FORMAT_RGB32: - case AVI_FORMAT_AVI_RGB: - case AVI_FORMAT_MJPEG: - return FCC("vids"); - break; - default: - return 0; - break; - } -} - -int avi_get_format_fcc(AviFormat format) -{ - switch (format) { - case AVI_FORMAT_RGB24: - case AVI_FORMAT_RGB32: - case AVI_FORMAT_AVI_RGB: - return FCC("DIB "); - break; - case AVI_FORMAT_MJPEG: - return FCC("MJPG"); - break; - default: - return 0; - break; - } -} - -int avi_get_format_compression(AviFormat format) -{ - switch (format) { - case AVI_FORMAT_RGB24: - case AVI_FORMAT_RGB32: - case AVI_FORMAT_AVI_RGB: - return 0; - break; - case AVI_FORMAT_MJPEG: - return FCC("MJPG"); - break; - default: - return 0; - break; - } -} diff --git a/source/blender/avi/intern/endian.c b/source/blender/avi/intern/endian.c deleted file mode 100644 index 8e5ed80f5a0..00000000000 --- a/source/blender/avi/intern/endian.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - * - */ - -/** \file blender/avi/intern/endian.c - * \ingroup avi - * - * This is external code. Streams bytes to output depending on the - * endianness of the system. - */ - - -#include -#include -#include -#include "AVI_avi.h" -#include "endian.h" -#include "avi_intern.h" - -#ifdef __BIG_ENDIAN__ -#include "MEM_guardedalloc.h" -#endif - -#ifdef __BIG_ENDIAN__ - -/* copied from BLI_endian_switch_inline.h */ -static void invert(int *num) -{ - int tval = *val; - *val = ((tval >> 24)) | - ((tval << 8) & 0x00ff0000) | - ((tval >> 8) & 0x0000ff00) | - ((tval << 24)); -} - -static void sinvert(short int *val) -{ - short tval = *val; - *val = (tval >> 8) | - (tval << 8); -} - -static void Ichunk(AviChunk *chunk) -{ - invert(&chunk->fcc); - invert(&chunk->size); -} -#endif - -#ifdef __BIG_ENDIAN__ -static void Ilist(AviList *list) -{ - invert(&list->fcc); - invert(&list->size); - invert(&list->ids); -} - -static void Imainh(AviMainHeader *mainh) -{ - invert(&mainh->fcc); - invert(&mainh->size); - invert(&mainh->MicroSecPerFrame); - invert(&mainh->MaxBytesPerSec); - invert(&mainh->PaddingGranularity); - invert(&mainh->Flags); - invert(&mainh->TotalFrames); - invert(&mainh->InitialFrames); - invert(&mainh->Streams); - invert(&mainh->SuggestedBufferSize); - invert(&mainh->Width); - invert(&mainh->Height); - invert(&mainh->Reserved[0]); - invert(&mainh->Reserved[1]); - invert(&mainh->Reserved[2]); - invert(&mainh->Reserved[3]); -} - -static void Istreamh(AviStreamHeader *streamh) -{ - invert(&streamh->fcc); - invert(&streamh->size); - invert(&streamh->Type); - invert(&streamh->Handler); - invert(&streamh->Flags); - sinvert(&streamh->Priority); - sinvert(&streamh->Language); - invert(&streamh->InitialFrames); - invert(&streamh->Scale); - invert(&streamh->Rate); - invert(&streamh->Start); - invert(&streamh->Length); - invert(&streamh->SuggestedBufferSize); - invert(&streamh->Quality); - invert(&streamh->SampleSize); - sinvert(&streamh->left); - sinvert(&streamh->right); - sinvert(&streamh->top); - sinvert(&streamh->bottom); -} - -static void Ibitmaph(AviBitmapInfoHeader *bitmaph) -{ - invert(&bitmaph->fcc); - invert(&bitmaph->size); - invert(&bitmaph->Size); - invert(&bitmaph->Width); - invert(&bitmaph->Height); - sinvert(&bitmaph->Planes); - sinvert(&bitmaph->BitCount); - invert(&bitmaph->Compression); - invert(&bitmaph->SizeImage); - invert(&bitmaph->XPelsPerMeter); - invert(&bitmaph->YPelsPerMeter); - invert(&bitmaph->ClrUsed); - invert(&bitmaph->ClrImportant); -} - -static void Imjpegu(AviMJPEGUnknown *mjpgu) -{ - invert(&mjpgu->a); - invert(&mjpgu->b); - invert(&mjpgu->c); - invert(&mjpgu->d); - invert(&mjpgu->e); - invert(&mjpgu->f); - invert(&mjpgu->g); -} - -static void Iindexe(AviIndexEntry *indexe) -{ - invert(&indexe->ChunkId); - invert(&indexe->Flags); - invert(&indexe->Offset); - invert(&indexe->Size); -} -#endif /* __BIG_ENDIAN__ */ - -void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type) -{ -#ifdef __BIG_ENDIAN__ - void *data; - - data = MEM_mallocN(size, "avi endian"); - - memcpy(data, datain, size); - - switch (type) { - case AVI_RAW: - fwrite(data, block, size, fp); - break; - case AVI_CHUNK: - Ichunk((AviChunk *) data); - fwrite(data, block, size, fp); - break; - case AVI_LIST: - Ilist((AviList *) data); - fwrite(data, block, size, fp); - break; - case AVI_MAINH: - Imainh((AviMainHeader *) data); - fwrite(data, block, size, fp); - break; - case AVI_STREAMH: - Istreamh((AviStreamHeader *) data); - fwrite(data, block, size, fp); - break; - case AVI_BITMAPH: - Ibitmaph((AviBitmapInfoHeader *) data); - if (size == sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) { - Imjpegu((AviMJPEGUnknown *)((char *)data + sizeof(AviBitmapInfoHeader))); - } - fwrite(data, block, size, fp); - break; - case AVI_MJPEGU: - Imjpegu((AviMJPEGUnknown *) data); - fwrite(data, block, size, fp); - break; - case AVI_INDEXE: - Iindexe((AviIndexEntry *) data); - fwrite(data, block, size, fp); - break; - default: - break; - } - - MEM_freeN(data); -#else /* __BIG_ENDIAN__ */ - (void)movie; /* unused */ - (void)type; /* unused */ - fwrite(datain, block, size, fp); -#endif /* __BIG_ENDIAN__ */ -} diff --git a/source/blender/avi/intern/endian.h b/source/blender/avi/intern/endian.h deleted file mode 100644 index 7ef49cb1699..00000000000 --- a/source/blender/avi/intern/endian.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - */ - -/** \file blender/avi/intern/endian.h - * \ingroup avi - * - * This is external code. - */ - -#ifndef __ENDIAN_H__ -#define __ENDIAN_H__ - -#include -#include "AVI_avi.h" - -#define AVI_RAW 0 -#define AVI_CHUNK 1 -#define AVI_LIST 2 -#define AVI_MAINH 3 -#define AVI_STREAMH 4 -#define AVI_BITMAPH 5 -#define AVI_INDEXE 6 -#define AVI_MJPEGU 7 - -void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type); - -#endif - diff --git a/source/blender/avi/intern/mjpeg.c b/source/blender/avi/intern/mjpeg.c deleted file mode 100644 index a700284bf68..00000000000 --- a/source/blender/avi/intern/mjpeg.c +++ /dev/null @@ -1,488 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - * - */ - -/** \file blender/avi/intern/mjpeg.c - * \ingroup avi - * - * This is external code. Converts between avi and mpeg/jpeg. - */ - - -#include "AVI_avi.h" -#include -#include -#include "jpeglib.h" -#include "jerror.h" -#include "MEM_guardedalloc.h" - -#include "mjpeg.h" - -#define PADUP(num, amt) ((num + (amt - 1)) & ~(amt - 1)) - -static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize); -static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize); - -static int numbytes; - -static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) -{ - if (*htblptr == NULL) - *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo); - - memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); - memcpy((*htblptr)->huffval, val, sizeof((*htblptr)->huffval)); - - /* Initialize sent_table FALSE so table will be written to JPEG file. */ - (*htblptr)->sent_table = FALSE; -} - -/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ -/* IMPORTANT: these are only valid for 8-bit data precision! */ - -static void std_huff_tables(j_decompress_ptr dinfo) -{ - static const UINT8 bits_dc_luminance[17] = - { /* 0-base */ - 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 - }; - static const UINT8 val_dc_luminance[] = - { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 - }; - - static const UINT8 bits_dc_chrominance[17] = - { /* 0-base */ - 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 - }; - static const UINT8 val_dc_chrominance[] = - { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 - }; - - static const UINT8 bits_ac_luminance[17] = - { /* 0-base */ - 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d - }; - static const UINT8 val_ac_luminance[] = - { - 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, - 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, - 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, - 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, - 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, - 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, - 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, - 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, - 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, - 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa - }; - static const UINT8 bits_ac_chrominance[17] = - { /* 0-base */ - 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 - }; - static const UINT8 val_ac_chrominance[] = - { - 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, - 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, - 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, - 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, - 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, - 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, - 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, - 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, - 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, - 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, - 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, - 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, - 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, - 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, - 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, - 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa - }; - - add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[0], - bits_dc_luminance, val_dc_luminance); - add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[0], - bits_ac_luminance, val_ac_luminance); - add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[1], - bits_dc_chrominance, val_dc_chrominance); - add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[1], - bits_ac_chrominance, val_ac_chrominance); -} - -static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsigned int width, unsigned int height, int bufsize) -{ - int rowstride; - unsigned int y; - struct jpeg_decompress_struct dinfo; - struct jpeg_error_mgr jerr; - - (void)width; /* unused */ - - numbytes = 0; - - dinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&dinfo); - jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize); - jpeg_read_header(&dinfo, TRUE); - if (dinfo.dc_huff_tbl_ptrs[0] == NULL) { - std_huff_tables(&dinfo); - } - dinfo.out_color_space = JCS_RGB; - dinfo.dct_method = JDCT_IFAST; - - jpeg_start_decompress(&dinfo); - - rowstride = dinfo.output_width * dinfo.output_components; - for (y = 0; y < dinfo.output_height; y++) { - jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1); - outBuffer += rowstride; - } - jpeg_finish_decompress(&dinfo); - - if (dinfo.output_height >= height) return 0; - - inBuffer += numbytes; - jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize - numbytes); - - numbytes = 0; - jpeg_read_header(&dinfo, TRUE); - if (dinfo.dc_huff_tbl_ptrs[0] == NULL) { - std_huff_tables(&dinfo); - } - - jpeg_start_decompress(&dinfo); - rowstride = dinfo.output_width * dinfo.output_components; - for (y = 0; y < dinfo.output_height; y++) { - jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1); - outBuffer += rowstride; - } - jpeg_finish_decompress(&dinfo); - jpeg_destroy_decompress(&dinfo); - - return 1; -} - -static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char *inBuffer, int width, int height, int bufsize) -{ - int i, rowstride; - unsigned int y; - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; - unsigned char marker[60]; - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_compress(&cinfo); - jpegmemdestmgr_build(&cinfo, outbuffer, bufsize); - - cinfo.image_width = width; - cinfo.image_height = height; - cinfo.input_components = 3; - cinfo.in_color_space = JCS_RGB; - - jpeg_set_defaults(&cinfo); - jpeg_set_colorspace(&cinfo, JCS_YCbCr); - - jpeg_set_quality(&cinfo, quality, TRUE); - - cinfo.dc_huff_tbl_ptrs[0]->sent_table = TRUE; - cinfo.dc_huff_tbl_ptrs[1]->sent_table = TRUE; - cinfo.ac_huff_tbl_ptrs[0]->sent_table = TRUE; - cinfo.ac_huff_tbl_ptrs[1]->sent_table = TRUE; - - cinfo.comp_info[0].component_id = 0; - cinfo.comp_info[0].v_samp_factor = 1; - cinfo.comp_info[1].component_id = 1; - cinfo.comp_info[2].component_id = 2; - - cinfo.write_JFIF_header = FALSE; - - jpeg_start_compress(&cinfo, FALSE); - - i = 0; - marker[i++] = 'A'; - marker[i++] = 'V'; - marker[i++] = 'I'; - marker[i++] = '1'; - marker[i++] = 0; - while (i < 60) - marker[i++] = 32; - - jpeg_write_marker(&cinfo, JPEG_APP0, marker, 60); - - i = 0; - while (i < 60) - marker[i++] = 0; - - jpeg_write_marker(&cinfo, JPEG_COM, marker, 60); - - rowstride = cinfo.image_width * cinfo.input_components; - for (y = 0; y < cinfo.image_height; y++) { - jpeg_write_scanlines(&cinfo, (JSAMPARRAY) &inBuffer, 1); - inBuffer += rowstride; - } - jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); -} - -static void interlace(unsigned char *to, unsigned char *from, int width, int height) -{ - int i, rowstride = width * 3; - - for (i = 0; i < height; i++) { - if (i & 1) - memcpy(&to[i * rowstride], &from[(i / 2 + height / 2) * rowstride], rowstride); - else - memcpy(&to[i * rowstride], &from[(i / 2) * rowstride], rowstride); - } -} - -static void deinterlace(int odd, unsigned char *to, unsigned char *from, int width, int height) -{ - int i, rowstride = width * 3; - - for (i = 0; i < height; i++) { - if ((i & 1) == odd) - memcpy(&to[(i / 2 + height / 2) * rowstride], &from[i * rowstride], rowstride); - else - memcpy(&to[(i / 2) * rowstride], &from[i * rowstride], rowstride); - } -} - -static int check_and_decode_jpeg(unsigned char *inbuf, unsigned char *outbuf, int width, int height, int bufsize) -{ - /* JPEG's are always multiples of 16, extra is cropped out AVI's */ - if ((width & 0xF) || (height & 0xF)) { - int i, rrowstride, jrowstride; - int jwidth = PADUP(width, 16); - int jheight = PADUP(height, 16); - unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_decode_jpeg"); - int ret = Decode_JPEG(inbuf, tmpbuf, jwidth, jheight, bufsize); - - /* crop the tmpbuf into the real buffer */ - rrowstride = width * 3; - jrowstride = jwidth * 3; - for (i = 0; i < height; i++) - memcpy(&outbuf[i * rrowstride], &tmpbuf[i * jrowstride], rrowstride); - MEM_freeN(tmpbuf); - - return ret; - } - else { - return Decode_JPEG(inbuf, outbuf, width, height, bufsize); - } -} - -static void check_and_compress_jpeg(int quality, unsigned char *outbuf, unsigned char *inbuf, int width, int height, int bufsize) -{ - /* JPEG's are always multiples of 16, extra is ignored in AVI's */ - if ((width & 0xF) || (height & 0xF)) { - int i, rrowstride, jrowstride; - int jwidth = PADUP(width, 16); - int jheight = PADUP(height, 16); - unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_compress_jpeg"); - - /* resize the realbuf into the tmpbuf */ - rrowstride = width * 3; - jrowstride = jwidth * 3; - for (i = 0; i < jheight; i++) { - if (i < height) - memcpy(&tmpbuf[i * jrowstride], &inbuf[i * rrowstride], rrowstride); - else - memset(&tmpbuf[i * jrowstride], 0, rrowstride); - memset(&tmpbuf[i * jrowstride + rrowstride], 0, jrowstride - rrowstride); - } - - Compress_JPEG(quality, outbuf, tmpbuf, jwidth, jheight, bufsize); - - MEM_freeN(tmpbuf); - } - else { - Compress_JPEG(quality, outbuf, inbuf, width, height, bufsize); - } -} - -void *avi_converter_from_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size) -{ - int deint; - unsigned char *buf; - - (void)stream; /* unused */ - - buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 1"); - - deint = check_and_decode_jpeg(buffer, buf, movie->header->Width, movie->header->Height, *size); - - MEM_freeN(buffer); - - if (deint) { - buffer = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 2"); - interlace(buffer, buf, movie->header->Width, movie->header->Height); - MEM_freeN(buf); - - buf = buffer; - } - - return buf; -} - -void *avi_converter_to_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size) -{ - unsigned char *buf; - int bufsize = *size; - - numbytes = 0; - *size = 0; - - buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 1"); - if (!movie->interlace) { - check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer, movie->header->Width, movie->header->Height, bufsize); - } - else { - deinterlace(movie->odd_fields, buf, buffer, movie->header->Width, movie->header->Height); - MEM_freeN(buffer); - - buffer = buf; - buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 2"); - - check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer, movie->header->Width, movie->header->Height / 2, bufsize / 2); - *size += numbytes; - numbytes = 0; - check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf + *size, buffer + (movie->header->Height / 2) * movie->header->Width * 3, movie->header->Width, movie->header->Height / 2, bufsize / 2); - } - *size += numbytes; - - MEM_freeN(buffer); - return buf; -} - - -/* Compression from memory */ - -static void jpegmemdestmgr_init_destination(j_compress_ptr cinfo) -{ - (void)cinfo; /* unused */ -} - -static boolean jpegmemdestmgr_empty_output_buffer(j_compress_ptr cinfo) -{ - (void)cinfo; /* unused */ - return TRUE; -} - -static void jpegmemdestmgr_term_destination(j_compress_ptr cinfo) -{ - numbytes -= cinfo->dest->free_in_buffer; - - MEM_freeN(cinfo->dest); -} - -static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize) -{ - cinfo->dest = MEM_mallocN(sizeof(*(cinfo->dest)), "avi.jpegmemdestmgr_build"); - - cinfo->dest->init_destination = jpegmemdestmgr_init_destination; - cinfo->dest->empty_output_buffer = jpegmemdestmgr_empty_output_buffer; - cinfo->dest->term_destination = jpegmemdestmgr_term_destination; - - cinfo->dest->next_output_byte = buffer; - cinfo->dest->free_in_buffer = bufsize; - - numbytes = bufsize; -} - -/* Decompression from memory */ - -static void jpegmemsrcmgr_init_source(j_decompress_ptr dinfo) -{ - (void)dinfo; -} - -static boolean jpegmemsrcmgr_fill_input_buffer(j_decompress_ptr dinfo) -{ - unsigned char *buf = (unsigned char *) dinfo->src->next_input_byte - 2; - - /* if we get called, must have run out of data */ - WARNMS(dinfo, JWRN_JPEG_EOF); - - buf[0] = (JOCTET) 0xFF; - buf[1] = (JOCTET) JPEG_EOI; - - dinfo->src->next_input_byte = buf; - dinfo->src->bytes_in_buffer = 2; - - return TRUE; -} - -static void jpegmemsrcmgr_skip_input_data(j_decompress_ptr dinfo, long skipcnt) -{ - if (dinfo->src->bytes_in_buffer < skipcnt) - skipcnt = dinfo->src->bytes_in_buffer; - - dinfo->src->next_input_byte += skipcnt; - dinfo->src->bytes_in_buffer -= skipcnt; -} - -static void jpegmemsrcmgr_term_source(j_decompress_ptr dinfo) -{ - numbytes -= dinfo->src->bytes_in_buffer; - - MEM_freeN(dinfo->src); -} - -static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize) -{ - dinfo->src = MEM_mallocN(sizeof(*(dinfo->src)), "avi.jpegmemsrcmgr_build"); - - dinfo->src->init_source = jpegmemsrcmgr_init_source; - dinfo->src->fill_input_buffer = jpegmemsrcmgr_fill_input_buffer; - dinfo->src->skip_input_data = jpegmemsrcmgr_skip_input_data; - dinfo->src->resync_to_restart = jpeg_resync_to_restart; - dinfo->src->term_source = jpegmemsrcmgr_term_source; - - dinfo->src->bytes_in_buffer = bufsize; - dinfo->src->next_input_byte = buffer; - - numbytes = bufsize; -} diff --git a/source/blender/avi/intern/mjpeg.h b/source/blender/avi/intern/mjpeg.h deleted file mode 100644 index 75649891f2b..00000000000 --- a/source/blender/avi/intern/mjpeg.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - */ - -/** \file blender/avi/intern/mjpeg.h - * \ingroup avi - */ - - -void *avi_converter_from_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size); -void *avi_converter_to_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size); - diff --git a/source/blender/avi/intern/options.c b/source/blender/avi/intern/options.c deleted file mode 100644 index 7de91318ecf..00000000000 --- a/source/blender/avi/intern/options.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - * - */ - -/** \file blender/avi/intern/options.c - * \ingroup avi - * - * This is external code. Sets some compression related options - * (width, height quality, framerate). - */ - -#include "AVI_avi.h" -#include "avi_intern.h" -#include "endian.h" - -#ifdef WIN32 -# include "BLI_winstuff.h" -#endif - -/* avi_set_compress_options gets its own file... now don't WE feel important? */ - -AviError AVI_set_compress_option(AviMovie *movie, int option_type, int stream, AviOption option, void *opt_data) -{ - int i; - int useconds; - - (void)stream; /* unused */ - - if (movie->header->TotalFrames != 0) /* Can't change params after we have already started writing frames */ - return AVI_ERROR_OPTION; - - switch (option_type) { - case AVI_OPTION_TYPE_MAIN: - switch (option) { - case AVI_OPTION_WIDTH: - movie->header->Width = *((int *) opt_data); - movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3; - - for (i = 0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data); - movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; - movie->streams[i].sh.right = *((int *) opt_data); - ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; - fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); - awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } - } - - break; - - case AVI_OPTION_HEIGHT: - movie->header->Height = *((int *) opt_data); - movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3; - - for (i = 0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data); - movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; - movie->streams[i].sh.bottom = *((int *) opt_data); - ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; - fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); - awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } - } - - break; - - case AVI_OPTION_QUALITY: - for (i = 0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - movie->streams[i].sh.Quality = (*((int *) opt_data)) * 100; - fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); - awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } - } - break; - - case AVI_OPTION_FRAMERATE: - useconds = (int)(1000000 / (*((double *) opt_data))); - if (useconds) - movie->header->MicroSecPerFrame = useconds; - - for (i = 0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame; - fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); - awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } - } - - } - - fseek(movie->fp, movie->offset_table[0], SEEK_SET); - awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); - - break; - case AVI_OPTION_TYPE_STRH: - break; - case AVI_OPTION_TYPE_STRF: - break; - default: - return AVI_ERROR_OPTION; - break; - } - - return AVI_ERROR_NONE; -} - diff --git a/source/blender/avi/intern/rgb32.c b/source/blender/avi/intern/rgb32.c deleted file mode 100644 index 84630f09fe5..00000000000 --- a/source/blender/avi/intern/rgb32.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - * - */ - -/** \file blender/avi/intern/rgb32.c - * \ingroup avi - * - * This is external code. Converts between rgb32 and avi. - */ - - -#include "AVI_avi.h" -#include -#include -#include "MEM_guardedalloc.h" -#include "rgb32.h" - -void *avi_converter_from_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size) -{ - int y, x, rowstridea, rowstrideb; - unsigned char *buf; - - (void)stream; /* unused */ - - buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromrgb32buf"); - *size = movie->header->Height * movie->header->Width * 3; - - rowstridea = movie->header->Width * 3; - rowstrideb = movie->header->Width * 4; - - for (y = 0; y < movie->header->Height; y++) { - for (x = 0; x < movie->header->Width; x++) { - buf[y * rowstridea + x * 3 + 0] = buffer[y * rowstrideb + x * 4 + 3]; - buf[y * rowstridea + x * 3 + 1] = buffer[y * rowstrideb + x * 4 + 2]; - buf[y * rowstridea + x * 3 + 2] = buffer[y * rowstrideb + x * 4 + 1]; - } - } - - MEM_freeN(buffer); - - return buf; -} - -void *avi_converter_to_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size) -{ - int i; - unsigned char *buf; - unsigned char *to, *from; - - (void)stream; /* unused */ - - buf = MEM_mallocN(movie->header->Height * movie->header->Width * 4, "torgb32buf"); - *size = movie->header->Height * movie->header->Width * 4; - - memset(buf, 255, *size); - - to = buf; from = buffer; - i = movie->header->Height * movie->header->Width; - - while (i--) { - memcpy(to, from, 3); - to += 4; from += 3; - } - - MEM_freeN(buffer); - - return buf; -} diff --git a/source/blender/avi/intern/rgb32.h b/source/blender/avi/intern/rgb32.h deleted file mode 100644 index 55f9771a4df..00000000000 --- a/source/blender/avi/intern/rgb32.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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. - * - * 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, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * 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 ***** - */ - -/** \file blender/avi/intern/rgb32.h - * \ingroup avi - */ - - -void *avi_converter_from_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size); -void *avi_converter_to_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size); - -- cgit v1.2.3