2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
2011-02-23 18:03:40 +00:00
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup avi
|
2012-04-30 14:24:11 +00:00
|
|
|
*
|
|
|
|
|
* This is external code. Streams bytes to output depending on the
|
|
|
|
|
* endianness of the system.
|
2011-02-27 20:43:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2012-10-07 06:27:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "AVI_avi.h"
|
2012-10-07 06:27:31 +00:00
|
|
|
#include "avi_endian.h"
|
2006-01-25 16:47:20 +00:00
|
|
|
#include "avi_intern.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-01-26 10:59:31 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-09-19 08:02:17 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2012-10-07 06:06:28 +00:00
|
|
|
|
|
|
|
|
/* copied from BLI_endian_switch_inline.h */
|
2012-12-21 03:02:36 +00:00
|
|
|
static void invert(int *val)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-10-07 06:06:28 +00:00
|
|
|
int tval = *val;
|
|
|
|
|
*val = ((tval >> 24)) |
|
|
|
|
|
((tval << 8) & 0x00ff0000) |
|
|
|
|
|
((tval >> 8) & 0x0000ff00) |
|
|
|
|
|
((tval << 24));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-07 06:06:28 +00:00
|
|
|
static void sinvert(short int *val)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-10-07 06:06:28 +00:00
|
|
|
short tval = *val;
|
|
|
|
|
*val = (tval >> 8) |
|
|
|
|
|
(tval << 8);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
static void Ichunk(AviChunk *chunk)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-05-07 18:30:04 +00:00
|
|
|
invert(&chunk->fcc);
|
|
|
|
|
invert(&chunk->size);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-02-03 18:50:03 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-09-19 08:02:17 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2012-05-07 18:30:04 +00:00
|
|
|
static void Ilist(AviList *list)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-05-07 18:30:04 +00:00
|
|
|
invert(&list->fcc);
|
|
|
|
|
invert(&list->size);
|
|
|
|
|
invert(&list->ids);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
static void Imainh(AviMainHeader *mainh)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-05-07 18:30:04 +00:00
|
|
|
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]);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
static void Istreamh(AviStreamHeader *streamh)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-05-07 18:30:04 +00:00
|
|
|
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);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
static void Ibitmaph(AviBitmapInfoHeader *bitmaph)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-05-07 18:30:04 +00:00
|
|
|
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);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
static void Imjpegu(AviMJPEGUnknown *mjpgu)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-05-07 18:30:04 +00:00
|
|
|
invert(&mjpgu->a);
|
|
|
|
|
invert(&mjpgu->b);
|
|
|
|
|
invert(&mjpgu->c);
|
|
|
|
|
invert(&mjpgu->d);
|
|
|
|
|
invert(&mjpgu->e);
|
|
|
|
|
invert(&mjpgu->f);
|
|
|
|
|
invert(&mjpgu->g);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
static void Iindexe(AviIndexEntry *indexe)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-05-07 18:30:04 +00:00
|
|
|
invert(&indexe->ChunkId);
|
|
|
|
|
invert(&indexe->Flags);
|
|
|
|
|
invert(&indexe->Offset);
|
|
|
|
|
invert(&indexe->Size);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-09-19 08:02:17 +00:00
|
|
|
#endif /* __BIG_ENDIAN__ */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2011-09-19 08:02:17 +00:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2002-10-12 11:37:38 +00:00
|
|
|
void *data;
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
data = MEM_mallocN(size, "avi endian");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
memcpy(data, datain, size);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
switch (type) {
|
2012-05-07 18:30:04 +00:00
|
|
|
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;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 18:30:04 +00:00
|
|
|
MEM_freeN(data);
|
2011-09-19 08:02:17 +00:00
|
|
|
#else /* __BIG_ENDIAN__ */
|
2010-10-16 14:32:17 +00:00
|
|
|
(void)movie; /* unused */
|
|
|
|
|
(void)type; /* unused */
|
2012-05-07 18:30:04 +00:00
|
|
|
fwrite(datain, block, size, fp);
|
2011-09-19 08:02:17 +00:00
|
|
|
#endif /* __BIG_ENDIAN__ */
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|