Blender  V3.3
avi_rgb.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 
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #include "MEM_guardedalloc.h"
14 
15 #include "AVI_avi.h"
16 #include "avi_rgb.h"
17 
18 #include "IMB_imbuf.h"
19 
20 #include "BLI_utildefines.h"
21 
22 /* implementation */
23 
25  int stream,
26  unsigned char *buffer,
27  const size_t *size)
28 {
29  unsigned char *buf;
31  short bits = 32;
32 
33  (void)size; /* unused */
34 
35  bi = (AviBitmapInfoHeader *)movie->streams[stream].sf;
36  if (bi) {
37  bits = bi->BitCount;
38  }
39 
40  if (bits == 16) {
41  unsigned short *pxl;
42  unsigned char *to;
43 #ifdef __BIG_ENDIAN__
44  unsigned char *pxla;
45 #endif
46 
47  buf = imb_alloc_pixels(
48  movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "fromavirgbbuf");
49 
50  if (buf) {
51  size_t y = movie->header->Height;
52  to = buf;
53 
54  while (y--) {
55  pxl = (unsigned short *)(buffer + y * movie->header->Width * 2);
56 
57 #ifdef __BIG_ENDIAN__
58  pxla = (unsigned char *)pxl;
59 #endif
60 
61  size_t x = movie->header->Width;
62  while (x--) {
63 #ifdef __BIG_ENDIAN__
64  int i = pxla[0];
65  pxla[0] = pxla[1];
66  pxla[1] = i;
67 
68  pxla += 2;
69 #endif
70 
71  *(to++) = ((*pxl >> 10) & 0x1f) * 8;
72  *(to++) = ((*pxl >> 5) & 0x1f) * 8;
73  *(to++) = (*pxl & 0x1f) * 8;
74  pxl++;
75  }
76  }
77  }
78 
80 
81  return buf;
82  }
83 
84  buf = imb_alloc_pixels(
85  movie->header->Height, movie->header->Width, 3, sizeof(unsigned char), "fromavirgbbuf");
86 
87  if (buf) {
88  size_t rowstride = movie->header->Width * 3;
89  BLI_assert(bits != 16);
90  if (movie->header->Width % 2) {
91  rowstride++;
92  }
93 
94  for (size_t y = 0; y < movie->header->Height; y++) {
95  memcpy(&buf[y * movie->header->Width * 3],
96  &buffer[((movie->header->Height - 1) - y) * rowstride],
97  movie->header->Width * 3);
98  }
99 
100  for (size_t y = 0; y < (size_t)movie->header->Height * (size_t)movie->header->Width * 3;
101  y += 3) {
102  int i = buf[y];
103  buf[y] = buf[y + 2];
104  buf[y + 2] = i;
105  }
106  }
107 
108  MEM_freeN(buffer);
109 
110  return buf;
111 }
112 
113 void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
114 {
115  unsigned char *buf;
116 
117  (void)stream; /* unused */
118 
119  size_t rowstride = movie->header->Width * 3;
120  /* AVI files has uncompressed lines 4-byte aligned */
121  rowstride = (rowstride + 3) & ~3;
122 
123  *size = movie->header->Height * rowstride;
124  buf = MEM_mallocN(*size, "toavirgbbuf");
125 
126  for (size_t y = 0; y < movie->header->Height; y++) {
127  memcpy(&buf[y * rowstride],
128  &buffer[((movie->header->Height - 1) - y) * movie->header->Width * 3],
129  movie->header->Width * 3);
130  }
131 
132  for (size_t y = 0; y < movie->header->Height; y++) {
133  for (size_t x = 0; x < movie->header->Width * 3; x += 3) {
134  int i = buf[y * rowstride + x];
135  buf[y * rowstride + x] = buf[y * rowstride + x + 2];
136  buf[y * rowstride + x + 2] = i;
137  }
138  }
139 
140  MEM_freeN(buffer);
141 
142  return buf;
143 }
#define BLI_assert(a)
Definition: BLI_assert.h:46
_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:354
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:113
void * avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, const size_t *size)
Definition: avi_rgb.c:24
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SyclQueue void void size_t num_bytes void
ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
AviMainHeader * header
Definition: AVI_avi.h:171
AviStreamRec * streams
Definition: AVI_avi.h:172
void * sf
Definition: AVI_avi.h:157