Blender  V2.93
avi_rgb.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 
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include "MEM_guardedalloc.h"
30 
31 #include "AVI_avi.h"
32 #include "avi_rgb.h"
33 
34 #include "IMB_imbuf.h"
35 
36 #include "BLI_utildefines.h"
37 
38 /* implementation */
39 
41  int stream,
42  unsigned char *buffer,
43  const size_t *size)
44 {
45  unsigned char *buf;
47  short bits = 32;
48 
49  (void)size; /* unused */
50 
51  bi = (AviBitmapInfoHeader *)movie->streams[stream].sf;
52  if (bi) {
53  bits = bi->BitCount;
54  }
55 
56  if (bits == 16) {
57  unsigned short *pxl;
58  unsigned char *to;
59 #ifdef __BIG_ENDIAN__
60  unsigned char *pxla;
61 #endif
62 
63  buf = imb_alloc_pixels(
64  movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "fromavirgbbuf");
65 
66  if (buf) {
67  size_t y = movie->header->Height;
68  to = buf;
69 
70  while (y--) {
71  pxl = (unsigned short *)(buffer + y * movie->header->Width * 2);
72 
73 #ifdef __BIG_ENDIAN__
74  pxla = (unsigned char *)pxl;
75 #endif
76 
77  size_t x = movie->header->Width;
78  while (x--) {
79 #ifdef __BIG_ENDIAN__
80  int i = pxla[0];
81  pxla[0] = pxla[1];
82  pxla[1] = i;
83 
84  pxla += 2;
85 #endif
86 
87  *(to++) = ((*pxl >> 10) & 0x1f) * 8;
88  *(to++) = ((*pxl >> 5) & 0x1f) * 8;
89  *(to++) = (*pxl & 0x1f) * 8;
90  pxl++;
91  }
92  }
93  }
94 
96 
97  return buf;
98  }
99 
100  buf = imb_alloc_pixels(
101  movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "fromavirgbbuf");
102 
103  if (buf) {
104  size_t rowstride = movie->header->Width * 3;
105  BLI_assert(bits != 16);
106  if (movie->header->Width % 2) {
107  rowstride++;
108  }
109 
110  for (size_t y = 0; y < movie->header->Height; y++) {
111  memcpy(&buf[y * movie->header->Width * 3],
112  &buffer[((movie->header->Height - 1) - y) * rowstride],
113  movie->header->Width * 3);
114  }
115 
116  for (size_t y = 0; y < (size_t)movie->header->Height * (size_t)movie->header->Width * 3;
117  y += 3) {
118  int i = buf[y];
119  buf[y] = buf[y + 2];
120  buf[y + 2] = i;
121  }
122  }
123 
124  MEM_freeN(buffer);
125 
126  return buf;
127 }
128 
129 void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
130 {
131  unsigned char *buf;
132 
133  (void)stream; /* unused */
134 
135  size_t rowstride = movie->header->Width * 3;
136  /* AVI files has uncompressed lines 4-byte aligned */
137  rowstride = (rowstride + 3) & ~3;
138 
139  *size = movie->header->Height * rowstride;
140  buf = MEM_mallocN(*size, "toavirgbbuf");
141 
142  for (size_t y = 0; y < movie->header->Height; y++) {
143  memcpy(&buf[y * rowstride],
144  &buffer[((movie->header->Height - 1) - y) * movie->header->Width * 3],
145  movie->header->Width * 3);
146  }
147 
148  for (size_t y = 0; y < movie->header->Height; y++) {
149  for (size_t x = 0; x < movie->header->Width * 3; x += 3) {
150  int i = buf[y * rowstride + x];
151  buf[y * rowstride + x] = buf[y * rowstride + x + 2];
152  buf[y * rowstride + x + 2] = i;
153  }
154  }
155 
156  MEM_freeN(buffer);
157 
158  return buf;
159 }
#define BLI_assert(a)
Definition: BLI_assert.h:58
_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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void * imb_alloc_pixels(unsigned int x, unsigned int y, unsigned int channels, size_t typesize, const char *name)
Definition: allocimbuf.c:373
Read Guarded memory(de)allocation.
void * avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
Definition: avi_rgb.c:129
void * avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, const size_t *size)
Definition: avi_rgb.c:40
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
AviMainHeader * header
Definition: AVI_avi.h:187
AviStreamRec * streams
Definition: AVI_avi.h:188
void * sf
Definition: AVI_avi.h:173