Blender  V3.3
avi_endian.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #include "AVI_avi.h"
16 #include "avi_endian.h"
17 #include "avi_intern.h"
18 
19 #ifdef __BIG_ENDIAN__
20 # include "MEM_guardedalloc.h"
21 #endif
22 
23 #ifdef __BIG_ENDIAN__
24 
25 /* copied from BLI_endian_switch_inline.h */
26 static void invert(int *val)
27 {
28  int tval = *val;
29  *val = (tval >> 24) | ((tval << 8) & 0x00ff0000) | ((tval >> 8) & 0x0000ff00) | (tval << 24);
30 }
31 
32 static void sinvert(short int *val)
33 {
34  short tval = *val;
35  *val = (tval >> 8) | (tval << 8);
36 }
37 
38 static void Ichunk(AviChunk *chunk)
39 {
40  invert(&chunk->fcc);
41  invert(&chunk->size);
42 }
43 #endif
44 
45 #ifdef __BIG_ENDIAN__
46 static void Ilist(AviList *list)
47 {
48  invert(&list->fcc);
49  invert(&list->size);
50  invert(&list->ids);
51 }
52 
53 static void Imainh(AviMainHeader *mainh)
54 {
55  invert(&mainh->fcc);
56  invert(&mainh->size);
57  invert(&mainh->MicroSecPerFrame);
58  invert(&mainh->MaxBytesPerSec);
59  invert(&mainh->PaddingGranularity);
60  invert(&mainh->Flags);
61  invert(&mainh->TotalFrames);
62  invert(&mainh->InitialFrames);
63  invert(&mainh->Streams);
64  invert(&mainh->SuggestedBufferSize);
65  invert(&mainh->Width);
66  invert(&mainh->Height);
67  invert(&mainh->Reserved[0]);
68  invert(&mainh->Reserved[1]);
69  invert(&mainh->Reserved[2]);
70  invert(&mainh->Reserved[3]);
71 }
72 
73 static void Istreamh(AviStreamHeader *streamh)
74 {
75  invert(&streamh->fcc);
76  invert(&streamh->size);
77  invert(&streamh->Type);
78  invert(&streamh->Handler);
79  invert(&streamh->Flags);
80  sinvert(&streamh->Priority);
81  sinvert(&streamh->Language);
82  invert(&streamh->InitialFrames);
83  invert(&streamh->Scale);
84  invert(&streamh->Rate);
85  invert(&streamh->Start);
86  invert(&streamh->Length);
87  invert(&streamh->SuggestedBufferSize);
88  invert(&streamh->Quality);
89  invert(&streamh->SampleSize);
90  sinvert(&streamh->left);
91  sinvert(&streamh->right);
92  sinvert(&streamh->top);
93  sinvert(&streamh->bottom);
94 }
95 
96 static void Ibitmaph(AviBitmapInfoHeader *bitmaph)
97 {
98  invert(&bitmaph->fcc);
99  invert(&bitmaph->size);
100  invert(&bitmaph->Size);
101  invert(&bitmaph->Width);
102  invert(&bitmaph->Height);
103  sinvert(&bitmaph->Planes);
104  sinvert(&bitmaph->BitCount);
105  invert(&bitmaph->Compression);
106  invert(&bitmaph->SizeImage);
107  invert(&bitmaph->XPelsPerMeter);
108  invert(&bitmaph->YPelsPerMeter);
109  invert(&bitmaph->ClrUsed);
110  invert(&bitmaph->ClrImportant);
111 }
112 
113 static void Imjpegu(AviMJPEGUnknown *mjpgu)
114 {
115  invert(&mjpgu->a);
116  invert(&mjpgu->b);
117  invert(&mjpgu->c);
118  invert(&mjpgu->d);
119  invert(&mjpgu->e);
120  invert(&mjpgu->f);
121  invert(&mjpgu->g);
122 }
123 
124 static void Iindexe(AviIndexEntry *indexe)
125 {
126  invert(&indexe->ChunkId);
127  invert(&indexe->Flags);
128  invert(&indexe->Offset);
129  invert(&indexe->Size);
130 }
131 #endif /* __BIG_ENDIAN__ */
132 
133 void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int type)
134 {
135 #ifdef __BIG_ENDIAN__
136  void *data;
137 
138  data = MEM_mallocN(size, "avi endian");
139 
140  memcpy(data, datain, size);
141 
142  switch (type) {
143  case AVI_RAW:
144  fwrite(data, block, size, fp);
145  break;
146  case AVI_CHUNK:
147  Ichunk((AviChunk *)data);
148  fwrite(data, block, size, fp);
149  break;
150  case AVI_LIST:
151  Ilist((AviList *)data);
152  fwrite(data, block, size, fp);
153  break;
154  case AVI_MAINH:
155  Imainh((AviMainHeader *)data);
156  fwrite(data, block, size, fp);
157  break;
158  case AVI_STREAMH:
159  Istreamh((AviStreamHeader *)data);
160  fwrite(data, block, size, fp);
161  break;
162  case AVI_BITMAPH:
163  Ibitmaph((AviBitmapInfoHeader *)data);
164  if (size == sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) {
165  Imjpegu((AviMJPEGUnknown *)((char *)data + sizeof(AviBitmapInfoHeader)));
166  }
167  fwrite(data, block, size, fp);
168  break;
169  case AVI_MJPEGU:
170  Imjpegu((AviMJPEGUnknown *)data);
171  fwrite(data, block, size, fp);
172  break;
173  case AVI_INDEXE:
174  Iindexe((AviIndexEntry *)data);
175  fwrite(data, block, size, fp);
176  break;
177  default:
178  break;
179  }
180 
181  MEM_freeN(data);
182 #else /* __BIG_ENDIAN__ */
183  (void)movie; /* unused */
184  (void)type; /* unused */
185  fwrite(datain, block, size, fp);
186 #endif /* __BIG_ENDIAN__ */
187 }
_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:133
#define AVI_RAW
Definition: avi_endian.h:12
#define AVI_LIST
Definition: avi_endian.h:14
#define AVI_STREAMH
Definition: avi_endian.h:16
#define AVI_INDEXE
Definition: avi_endian.h:18
#define AVI_MAINH
Definition: avi_endian.h:15
#define AVI_MJPEGU
Definition: avi_endian.h:19
#define AVI_CHUNK
Definition: avi_endian.h:13
#define AVI_BITMAPH
Definition: avi_endian.h:17
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SyclQueue void void size_t num_bytes void
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: invert.h:8
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
int size
Definition: AVI_avi.h:33
int fcc
Definition: AVI_avi.h:32
int ids
Definition: AVI_avi.h:39
int size
Definition: AVI_avi.h:38
int fcc
Definition: AVI_avi.h:37
int Reserved[4]
Definition: AVI_avi.h:68
int MicroSecPerFrame
Definition: AVI_avi.h:45
int MaxBytesPerSec
Definition: AVI_avi.h:46
int InitialFrames
Definition: AVI_avi.h:63
int SuggestedBufferSize
Definition: AVI_avi.h:65
int TotalFrames
Definition: AVI_avi.h:62
int PaddingGranularity
Definition: AVI_avi.h:47
int SuggestedBufferSize
Definition: AVI_avi.h:92
int InitialFrames
Definition: AVI_avi.h:87
short Priority
Definition: AVI_avi.h:85
short Language
Definition: AVI_avi.h:86
short bottom
Definition: AVI_avi.h:98