]> git.sesse.net Git - ffmpeg/blob - libswscale/colorspace-test.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libswscale / colorspace-test.c
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 <unistd.h>
24 #include <stdlib.h>
25 #include <inttypes.h>
26
27 #include "swscale.h"
28 #include "rgb2rgb.h"
29
30 #define SIZE 1000
31 #define srcByte 0x55
32 #define dstByte 0xBB
33
34 #define FUNC(s,d,n) {s,d,#n,n}
35
36 int main(int argc, char **argv)
37 {
38     int i, funcNum;
39     uint8_t *srcBuffer = av_malloc(SIZE);
40     uint8_t *dstBuffer = av_malloc(SIZE);
41     int failedNum=0;
42     int passedNum=0;
43
44     if (!srcBuffer || !dstBuffer)
45         return -1;
46
47     av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
48     sws_rgb2rgb_init();
49
50     for(funcNum=0; ; funcNum++) {
51         struct func_info_s {
52             int src_bpp;
53             int dst_bpp;
54             const char *name;
55             void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
56         } func_info[] = {
57             FUNC(2, 2, rgb15to16),
58             FUNC(2, 3, rgb15to24),
59             FUNC(2, 4, rgb15to32),
60             FUNC(2, 3, rgb16to24),
61             FUNC(2, 4, rgb16to32),
62             FUNC(3, 2, rgb24to15),
63             FUNC(3, 2, rgb24to16),
64             FUNC(3, 4, rgb24to32),
65             FUNC(4, 2, rgb32to15),
66             FUNC(4, 2, rgb32to16),
67             FUNC(4, 3, rgb32to24),
68             FUNC(2, 2, rgb16to15),
69             FUNC(2, 2, rgb15tobgr15),
70             FUNC(2, 2, rgb15tobgr16),
71             FUNC(2, 3, rgb15tobgr24),
72             FUNC(2, 4, rgb15tobgr32),
73             FUNC(2, 2, rgb16tobgr15),
74             FUNC(2, 2, rgb16tobgr16),
75             FUNC(2, 3, rgb16tobgr24),
76             FUNC(2, 4, rgb16tobgr32),
77             FUNC(3, 2, rgb24tobgr15),
78             FUNC(3, 2, rgb24tobgr16),
79             FUNC(3, 3, rgb24tobgr24),
80             FUNC(3, 4, rgb24tobgr32),
81             FUNC(4, 2, rgb32tobgr15),
82             FUNC(4, 2, rgb32tobgr16),
83             FUNC(4, 3, rgb32tobgr24),
84             FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
85             FUNC(0, 0, NULL)
86         };
87         int width;
88         int failed=0;
89         int srcBpp=0;
90         int dstBpp=0;
91
92         if (!func_info[funcNum].func) break;
93
94         av_log(NULL, AV_LOG_INFO,".");
95         memset(srcBuffer, srcByte, SIZE);
96
97         for(width=63; width>0; width--) {
98             int dstOffset;
99             for(dstOffset=128; dstOffset<196; dstOffset+=4) {
100                 int srcOffset;
101                 memset(dstBuffer, dstByte, SIZE);
102
103                 for(srcOffset=128; srcOffset<196; srcOffset+=4) {
104                     uint8_t *src= srcBuffer+srcOffset;
105                     uint8_t *dst= dstBuffer+dstOffset;
106                     const char *name=NULL;
107
108                     if(failed) break; //don't fill the screen with shit ...
109
110                     srcBpp = func_info[funcNum].src_bpp;
111                     dstBpp = func_info[funcNum].dst_bpp;
112                     name   = func_info[funcNum].name;
113
114                     func_info[funcNum].func(src, dst, width*srcBpp);
115
116                     if(!srcBpp) break;
117
118                     for(i=0; i<SIZE; i++) {
119                         if(srcBuffer[i]!=srcByte) {
120                             av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
121                                    i, width, srcOffset, dstOffset, name);
122                             failed=1;
123                             break;
124                         }
125                     }
126                     for(i=0; i<dstOffset; i++) {
127                         if(dstBuffer[i]!=dstByte) {
128                             av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
129                                    i, width, srcOffset, dstOffset, name);
130                             failed=1;
131                             break;
132                         }
133                     }
134                     for(i=dstOffset + width*dstBpp; i<SIZE; i++) {
135                         if(dstBuffer[i]!=dstByte) {
136                             av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
137                                    i, width, srcOffset, dstOffset, name);
138                             failed=1;
139                             break;
140                         }
141                     }
142                 }
143             }
144         }
145         if(failed) failedNum++;
146         else if(srcBpp) passedNum++;
147     }
148
149     av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
150     return failedNum;
151 }