Blender  V2.93
avi_endian.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #include "AVI_avi.h"
32 #include "avi_endian.h"
33 #include "avi_intern.h"
34 
35 #ifdef __BIG_ENDIAN__
36 # include "MEM_guardedalloc.h"
37 #endif
38 
39 #ifdef __BIG_ENDIAN__
40 
41 /* copied from BLI_endian_switch_inline.h */
42 static void invert(int *val)
43 {
44  int tval = *val;
45  *val = ((tval >> 24)) | ((tval << 8) & 0x00ff0000) | ((tval >> 8) & 0x0000ff00) | ((tval << 24));
46 }
47 
48 static void sinvert(short int *val)
49 {
50  short tval = *val;
51  *val = (tval >> 8) | (tval << 8);
52 }
53 
54 static void Ichunk(AviChunk *chunk)
55 {
56  invert(&chunk->fcc);
57  invert(&chunk->size);
58 }
59 #endif
60 
61 #ifdef __BIG_ENDIAN__
62 static void Ilist(AviList *list)
63 {
64  invert(&list->fcc);
65  invert(&list->size);
66  invert(&list->ids);
67 }
68 
69 static void Imainh(AviMainHeader *mainh)
70 {
71  invert(&mainh->fcc);
72  invert(&mainh->size);
73  invert(&mainh->MicroSecPerFrame);
74  invert(&mainh->MaxBytesPerSec);
75  invert(&mainh->PaddingGranularity);
76  invert(&mainh->Flags);
77  invert(&mainh->TotalFrames);
78  invert(&mainh->InitialFrames);
79  invert(&mainh->Streams);
80  invert(&mainh->SuggestedBufferSize);
81  invert(&mainh->Width);
82  invert(&mainh->Height);
83  invert(&mainh->Reserved[0]);
84  invert(&mainh->Reserved[1]);
85  invert(&mainh->Reserved[2]);
86  invert(&mainh->Reserved[3]);
87 }
88 
89 static void Istreamh(AviStreamHeader *streamh)
90 {
91  invert(&streamh->fcc);
92  invert(&streamh->size);
93  invert(&streamh->Type);
94  invert(&streamh->Handler);
95  invert(&streamh->Flags);
96  sinvert(&streamh->Priority);
97  sinvert(&streamh->Language);
98  invert(&streamh->InitialFrames);
99  invert(&streamh->Scale);
100  invert(&streamh->Rate);
101  invert(&streamh->Start);
102  invert(&streamh->Length);
103  invert(&streamh->SuggestedBufferSize);
104  invert(&streamh->Quality);
105  invert(&streamh->SampleSize);
106  sinvert(&streamh->left);
107  sinvert(&streamh->right);
108  sinvert(&streamh->top);
109  sinvert(&streamh->bottom);
110 }
111 
112 static void Ibitmaph(AviBitmapInfoHeader *bitmaph)
113 {
114  invert(&bitmaph->fcc);
115  invert(&bitmaph->size);
116  invert(&bitmaph->Size);
117  invert(&bitmaph->Width);
118  invert(&bitmaph->Height);
119  sinvert(&bitmaph->Planes);
120  sinvert(&bitmaph->BitCount);
121  invert(&bitmaph->Compression);
122  invert(&bitmaph->SizeImage);
123  invert(&bitmaph->XPelsPerMeter);
124  invert(&bitmaph->YPelsPerMeter);
125  invert(&bitmaph->ClrUsed);
126  invert(&bitmaph->ClrImportant);
127 }
128 
129 static void Imjpegu(AviMJPEGUnknown *mjpgu)
130 {
131  invert(&mjpgu->a);
132  invert(&mjpgu->b);
133  invert(&mjpgu->c);
134  invert(&mjpgu->d);
135  invert(&mjpgu->e);
136  invert(&mjpgu->f);
137  invert(&mjpgu->g);
138 }
139 
140 static void Iindexe(AviIndexEntry *indexe)
141 {
142  invert(&indexe->ChunkId);
143  invert(&indexe->Flags);
144  invert(&indexe->Offset);
145  invert(&indexe->Size);
146 }
147 #endif /* __BIG_ENDIAN__ */
148 
149 void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type)
150 {
151 #ifdef __BIG_ENDIAN__
152  void *data;
153 
154  data = MEM_mallocN(size, "avi endian");
155 
156  memcpy(data, datain, size);
157 
158  switch (type) {
159  case AVI_RAW:
160  fwrite(data, block, size, fp);
161  break;
162  case AVI_CHUNK:
163  Ichunk((AviChunk *)data);
164  fwrite(data, block, size, fp);
165  break;
166  case AVI_LIST:
167  Ilist((AviList *)data);
168  fwrite(data, block, size, fp);
169  break;
170  case AVI_MAINH:
171  Imainh((AviMainHeader *)data);
172  fwrite(data, block, size, fp);
173  break;
174  case AVI_STREAMH:
175  Istreamh((AviStreamHeader *)data);
176  fwrite(data, block, size, fp);
177  break;
178  case AVI_BITMAPH:
179  Ibitmaph((AviBitmapInfoHeader *)data);
180  if (size == sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) {
181  Imjpegu((AviMJPEGUnknown *)((char *)data + sizeof(AviBitmapInfoHeader)));
182  }
183  fwrite(data, block, size, fp);
184  break;
185  case AVI_MJPEGU:
186  Imjpegu((AviMJPEGUnknown *)data);
187  fwrite(data, block, size, fp);
188  break;
189  case AVI_INDEXE:
190  Iindexe((AviIndexEntry *)data);
191  fwrite(data, block, size, fp);
192  break;
193  default:
194  break;
195  }
196 
197  MEM_freeN(data);
198 #else /* __BIG_ENDIAN__ */
199  (void)movie; /* unused */
200  (void)type; /* unused */
201  fwrite(datain, block, size, fp);
202 #endif /* __BIG_ENDIAN__ */
203 }
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type)
Definition: avi_endian.c:149
#define AVI_RAW
Definition: avi_endian.h:28
#define AVI_LIST
Definition: avi_endian.h:30
#define AVI_STREAMH
Definition: avi_endian.h:32
#define AVI_INDEXE
Definition: avi_endian.h:34
#define AVI_MAINH
Definition: avi_endian.h:31
#define AVI_MJPEGU
Definition: avi_endian.h:35
#define AVI_CHUNK
Definition: avi_endian.h:29
#define AVI_BITMAPH
Definition: avi_endian.h:33
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
int size
Definition: AVI_avi.h:49
int fcc
Definition: AVI_avi.h:48
int ids
Definition: AVI_avi.h:55
int size
Definition: AVI_avi.h:54
int fcc
Definition: AVI_avi.h:53
int Reserved[4]
Definition: AVI_avi.h:84
int MicroSecPerFrame
Definition: AVI_avi.h:61
int MaxBytesPerSec
Definition: AVI_avi.h:62
int InitialFrames
Definition: AVI_avi.h:79
int SuggestedBufferSize
Definition: AVI_avi.h:81
int TotalFrames
Definition: AVI_avi.h:78
int PaddingGranularity
Definition: AVI_avi.h:63
int SuggestedBufferSize
Definition: AVI_avi.h:108
short Priority
Definition: AVI_avi.h:101
short Language
Definition: AVI_avi.h:102
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19