2 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
22 #include <string.h> /* for memset() */
34 #define FUNC(s,d,n) {s,d,#n,n}
38 static char *args_parse(int argc
, char *argv
[])
42 while ((o
= getopt(argc
, argv
, "m23")) != -1) {
45 cpu_caps
|= SWS_CPU_CAPS_MMX
;
48 cpu_caps
|= SWS_CPU_CAPS_MMX2
;
51 cpu_caps
|= SWS_CPU_CAPS_3DNOW
;
54 av_log(NULL
, AV_LOG_ERROR
, "Unknown option %c\n", o
);
61 int main(int argc
, char **argv
)
64 uint8_t *srcBuffer
= (uint8_t*)av_malloc(SIZE
);
65 uint8_t *dstBuffer
= (uint8_t*)av_malloc(SIZE
);
69 if (!srcBuffer
|| !dstBuffer
)
72 av_log(NULL
, AV_LOG_INFO
, "memory corruption test ...\n");
73 args_parse(argc
, argv
);
74 av_log(NULL
, AV_LOG_INFO
, "CPU capabilities forced to %x\n", cpu_caps
);
75 sws_rgb2rgb_init(cpu_caps
);
77 for(funcNum
=0; ; funcNum
++) {
82 void (*func
)(const uint8_t *src
, uint8_t *dst
, long src_size
);
84 FUNC(2, 2, rgb15to16
),
85 FUNC(2, 3, rgb15to24
),
86 FUNC(2, 4, rgb15to32
),
87 FUNC(2, 3, rgb16to24
),
88 FUNC(2, 4, rgb16to32
),
89 FUNC(3, 2, rgb24to15
),
90 FUNC(3, 2, rgb24to16
),
91 FUNC(3, 4, rgb24to32
),
92 FUNC(4, 2, rgb32to15
),
93 FUNC(4, 2, rgb32to16
),
94 FUNC(4, 3, rgb32to24
),
95 FUNC(2, 2, rgb16to15
),
96 FUNC(2, 2, rgb15tobgr15
),
97 FUNC(2, 2, rgb15tobgr16
),
98 FUNC(2, 3, rgb15tobgr24
),
99 FUNC(2, 4, rgb15tobgr32
),
100 FUNC(2, 2, rgb16tobgr15
),
101 FUNC(2, 2, rgb16tobgr16
),
102 FUNC(2, 3, rgb16tobgr24
),
103 FUNC(2, 4, rgb16tobgr32
),
104 FUNC(3, 2, rgb24tobgr15
),
105 FUNC(3, 2, rgb24tobgr16
),
106 FUNC(3, 3, rgb24tobgr24
),
107 FUNC(3, 4, rgb24tobgr32
),
108 FUNC(4, 2, rgb32tobgr15
),
109 FUNC(4, 2, rgb32tobgr16
),
110 FUNC(4, 3, rgb32tobgr24
),
111 FUNC(4, 4, rgb32tobgr32
),
119 if (!func_info
[funcNum
].func
) break;
121 av_log(NULL
, AV_LOG_INFO
,".");
122 memset(srcBuffer
, srcByte
, SIZE
);
124 for(width
=63; width
>0; width
--) {
126 for(dstOffset
=128; dstOffset
<196; dstOffset
+=4) {
128 memset(dstBuffer
, dstByte
, SIZE
);
130 for(srcOffset
=128; srcOffset
<196; srcOffset
+=4) {
131 uint8_t *src
= srcBuffer
+srcOffset
;
132 uint8_t *dst
= dstBuffer
+dstOffset
;
133 const char *name
=NULL
;
135 if(failed
) break; //don't fill the screen with shit ...
137 srcBpp
= func_info
[funcNum
].src_bpp
;
138 dstBpp
= func_info
[funcNum
].dst_bpp
;
139 name
= func_info
[funcNum
].name
;
141 func_info
[funcNum
].func(src
, dst
, width
*srcBpp
);
145 for(i
=0; i
<SIZE
; i
++) {
146 if(srcBuffer
[i
]!=srcByte
) {
147 av_log(NULL
, AV_LOG_INFO
, "src damaged at %d w:%d src:%d dst:%d %s\n",
148 i
, width
, srcOffset
, dstOffset
, name
);
153 for(i
=0; i
<dstOffset
; i
++) {
154 if(dstBuffer
[i
]!=dstByte
) {
155 av_log(NULL
, AV_LOG_INFO
, "dst damaged at %d w:%d src:%d dst:%d %s\n",
156 i
, width
, srcOffset
, dstOffset
, name
);
161 for(i
=dstOffset
+ width
*dstBpp
; i
<SIZE
; i
++) {
162 if(dstBuffer
[i
]!=dstByte
) {
163 av_log(NULL
, AV_LOG_INFO
, "dst damaged at %d w:%d src:%d dst:%d %s\n",
164 i
, width
, srcOffset
, dstOffset
, name
);
172 if(failed
) failedNum
++;
173 else if(srcBpp
) passedNum
++;
176 av_log(NULL
, AV_LOG_INFO
, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum
, failedNum
);