FFmpeg
colorspace.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdio.h>
22 #include <string.h> /* for memset() */
23 #include <stdlib.h>
24 #include <inttypes.h>
25 
26 #include "libavutil/mem.h"
27 
28 #include "libswscale/swscale.h"
29 #include "libswscale/rgb2rgb.h"
30 
31 #define SIZE 1000
32 #define srcByte 0x55
33 #define dstByte 0xBB
34 
35 #define FUNC(s, d, n) { s, d, #n, n }
36 
37 int main(int argc, char **argv)
38 {
39  int i, funcNum;
40  uint8_t *srcBuffer = av_malloc(SIZE);
41  uint8_t *dstBuffer = av_malloc(SIZE);
42  int failedNum = 0;
43  int passedNum = 0;
44 
45  if (!srcBuffer || !dstBuffer)
46  return -1;
47 
48  av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
50 
51  for (funcNum = 0; ; funcNum++) {
52  struct func_info_s {
53  int src_bpp;
54  int dst_bpp;
55  const char *name;
56  void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
57  } func_info[] = {
58  FUNC(2, 2, rgb12to15),
59  FUNC(2, 2, rgb15to16),
60  FUNC(2, 3, rgb15to24),
61  FUNC(2, 4, rgb15to32),
62  FUNC(2, 3, rgb16to24),
63  FUNC(2, 4, rgb16to32),
64  FUNC(3, 2, rgb24to15),
65  FUNC(3, 2, rgb24to16),
66  FUNC(3, 4, rgb24to32),
67  FUNC(4, 2, rgb32to15),
68  FUNC(4, 2, rgb32to16),
69  FUNC(4, 3, rgb32to24),
70  FUNC(2, 2, rgb16to15),
71  FUNC(2, 2, rgb12tobgr12),
72  FUNC(2, 2, rgb15tobgr15),
73  FUNC(2, 2, rgb15tobgr16),
74  FUNC(2, 3, rgb15tobgr24),
75  FUNC(2, 4, rgb15tobgr32),
76  FUNC(2, 2, rgb16tobgr15),
77  FUNC(2, 2, rgb16tobgr16),
78  FUNC(2, 3, rgb16tobgr24),
79  FUNC(2, 4, rgb16tobgr32),
80  FUNC(3, 2, rgb24tobgr15),
81  FUNC(3, 2, rgb24tobgr16),
82  FUNC(3, 3, rgb24tobgr24),
83  FUNC(3, 4, rgb24tobgr32),
84  FUNC(4, 2, rgb32tobgr15),
85  FUNC(4, 2, rgb32tobgr16),
86  FUNC(4, 3, rgb32tobgr24),
87  FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
89  FUNC(6, 6, rgb48tobgr48_bswap),
90  FUNC(8, 6, rgb64to48_nobswap),
91  FUNC(8, 6, rgb64to48_bswap),
93  FUNC(8, 6, rgb64tobgr48_bswap),
94  FUNC(0, 0, NULL)
95  };
96  int width;
97  int failed = 0;
98  int srcBpp = 0;
99  int dstBpp = 0;
100 
101  if (!func_info[funcNum].func)
102  break;
103 
104  av_log(NULL, AV_LOG_INFO, ".");
105  memset(srcBuffer, srcByte, SIZE);
106 
107  for (width = 63; width > 0; width--) {
108  int dstOffset;
109  for (dstOffset = 128; dstOffset < 196; dstOffset += 4) {
110  int srcOffset;
111  memset(dstBuffer, dstByte, SIZE);
112 
113  for (srcOffset = 128; srcOffset < 196; srcOffset += 4) {
114  uint8_t *src = srcBuffer + srcOffset;
115  uint8_t *dst = dstBuffer + dstOffset;
116  const char *name = NULL;
117 
118  // don't fill the screen with shit ...
119  if (failed)
120  break;
121 
122  srcBpp = func_info[funcNum].src_bpp;
123  dstBpp = func_info[funcNum].dst_bpp;
124  name = func_info[funcNum].name;
125 
126  func_info[funcNum].func(src, dst, width * srcBpp);
127 
128  if (!srcBpp)
129  break;
130 
131  for (i = 0; i < SIZE; i++) {
132  if (srcBuffer[i] != srcByte) {
134  "src damaged at %d w:%d src:%d dst:%d %s\n",
135  i, width, srcOffset, dstOffset, name);
136  failed = 1;
137  break;
138  }
139  }
140  for (i = 0; i < dstOffset; i++) {
141  if (dstBuffer[i] != dstByte) {
143  "dst damaged at %d w:%d src:%d dst:%d %s\n",
144  i, width, srcOffset, dstOffset, name);
145  failed = 1;
146  break;
147  }
148  }
149  for (i = dstOffset + width * dstBpp; i < SIZE; i++) {
150  if (dstBuffer[i] != dstByte) {
152  "dst damaged at %d w:%d src:%d dst:%d %s\n",
153  i, width, srcOffset, dstOffset, name);
154  failed = 1;
155  break;
156  }
157  }
158  }
159  }
160  }
161  if (failed)
162  failedNum++;
163  else if (srcBpp)
164  passedNum++;
165  }
166 
168  "\n%d converters passed, %d converters randomly overwrote memory\n",
169  passedNum, failedNum);
170  return failedNum;
171 }
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:67
rgb12tobgr12
void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:314
rgb32tobgr24
void(* rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:35
rgb15to24
void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:279
name
const char * name
Definition: avisynth_c.h:867
rgb16tobgr32
void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:182
rgb48tobgr48_nobswap
void rgb48tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
rgb32tobgr16
void(* rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:36
rgb24tobgr16
void(* rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:40
rgb15to32
void(* rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:52
rgb32to16
void(* rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:45
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
dstByte
#define dstByte
Definition: colorspace.c:33
rgb16tobgr16
void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:237
src
#define src
Definition: vp8dsp.c:254
rgb16tobgr24
void(* rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:42
width
#define width
rgb15tobgr24
void(* rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:43
shuffle_bytes_2103
void(* shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:55
rgb32tobgr15
void(* rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:37
rgb16to24
void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:223
rgb12to15
void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:204
NULL
#define NULL
Definition: coverity.c:32
rgb16to15
void(* rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:50
ff_sws_rgb2rgb_init
av_cold void ff_sws_rgb2rgb_init(void)
Definition: rgb2rgb.c:137
srcByte
#define srcByte
Definition: colorspace.c:32
rgb15tobgr16
void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:293
rgb64tobgr48_bswap
void rgb64tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
rgb24tobgr32
void(* rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:38
rgb64to48_nobswap
void rgb64to48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
SIZE
#define SIZE
Definition: colorspace.c:31
rgb64tobgr48_nobswap
void rgb64tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
rgb32to24
void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:144
rgb15tobgr15
void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:303
rgb24to16
void(* rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:47
main
int main(int argc, char **argv)
Definition: colorspace.c:37
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
rgb24to15
void(* rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:48
rgb32to15
void(* rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:46
uint8_t
uint8_t
Definition: audio_convert.c:194
rgb48tobgr48_bswap
void rgb48tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
rgb16to32
void(* rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:49
rgb24to32
void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:162
FUNC
#define FUNC(s, d, n)
Definition: colorspace.c:35
rgb24tobgr15
void(* rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:41
rgb15tobgr32
void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:257
rgb15to16
void(* rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:51
rgb24tobgr24
void(* rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:39
rgb64to48_bswap
void rgb64to48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
mem.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
rgb2rgb.h
swscale.h
rgb16tobgr15
void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:247