tests: Move all test programs to a subdirectory
[libav.git] / libswscale / tests / colorspace.c
CommitLineData
a28ea2c0 1/*
d026b45e
DB
2 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
3 *
2912e87a 4 * This file is part of Libav.
d026b45e 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
54e3ae2e
DB
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.
d026b45e 10 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
d026b45e 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54e3ae2e
DB
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
d026b45e 15 *
54e3ae2e 16 * You should have received a copy of the GNU Lesser General Public
2912e87a 17 * License along with Libav; if not, write to the Free Software
b19bcbaa 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d026b45e 19 */
a28ea2c0
MN
20
21#include <stdio.h>
7f3f497a 22#include <string.h> /* for memset() */
a28ea2c0
MN
23#include <stdlib.h>
24#include <inttypes.h>
25
1d9c2dc8 26#include "libavutil/mem.h"
a28ea2c0 27
a6a750c7
DB
28#include "libswscale/rgb2rgb.h"
29#include "libswscale/swscale.h"
30
999484c9 31#define SIZE 1000
a28ea2c0
MN
32#define srcByte 0x55
33#define dstByte 0xBB
34
999484c9 35#define FUNC(s, d, n) { s, d, #n, n }
a31de956 36
2e3fb9e3 37int main(void)
a28ea2c0 38{
3a74415d 39 int i, funcNum;
44b0edda
DB
40 uint8_t *srcBuffer = av_malloc(SIZE);
41 uint8_t *dstBuffer = av_malloc(SIZE);
999484c9
DB
42 int failedNum = 0;
43 int passedNum = 0;
6a4970ab 44
7248797c
RP
45 if (!srcBuffer || !dstBuffer)
46 return -1;
47
3a74415d 48 av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
e66149e7 49 sws_rgb2rgb_init();
6a4970ab 50
999484c9 51 for (funcNum = 0; ; funcNum++) {
3a74415d
IP
52 struct func_info_s {
53 int src_bpp;
54 int dst_bpp;
dcc37c9b 55 const char *name;
b8e89339 56 void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
3a74415d
IP
57 } func_info[] = {
58 FUNC(2, 2, rgb15to16),
59 FUNC(2, 3, rgb15to24),
60 FUNC(2, 4, rgb15to32),
61 FUNC(2, 3, rgb16to24),
62 FUNC(2, 4, rgb16to32),
63 FUNC(3, 2, rgb24to15),
64 FUNC(3, 2, rgb24to16),
65 FUNC(3, 4, rgb24to32),
66 FUNC(4, 2, rgb32to15),
67 FUNC(4, 2, rgb32to16),
68 FUNC(4, 3, rgb32to24),
69 FUNC(2, 2, rgb16to15),
70 FUNC(2, 2, rgb15tobgr15),
71 FUNC(2, 2, rgb15tobgr16),
72 FUNC(2, 3, rgb15tobgr24),
73 FUNC(2, 4, rgb15tobgr32),
74 FUNC(2, 2, rgb16tobgr15),
75 FUNC(2, 2, rgb16tobgr16),
76 FUNC(2, 3, rgb16tobgr24),
77 FUNC(2, 4, rgb16tobgr32),
78 FUNC(3, 2, rgb24tobgr15),
79 FUNC(3, 2, rgb24tobgr16),
80 FUNC(3, 3, rgb24tobgr24),
81 FUNC(3, 4, rgb24tobgr32),
82 FUNC(4, 2, rgb32tobgr15),
83 FUNC(4, 2, rgb32tobgr16),
84 FUNC(4, 3, rgb32tobgr24),
b494baf0 85 FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
3a74415d
IP
86 FUNC(0, 0, NULL)
87 };
88 int width;
999484c9
DB
89 int failed = 0;
90 int srcBpp = 0;
91 int dstBpp = 0;
3a74415d 92
999484c9
DB
93 if (!func_info[funcNum].func)
94 break;
3a74415d 95
999484c9 96 av_log(NULL, AV_LOG_INFO, ".");
3a74415d
IP
97 memset(srcBuffer, srcByte, SIZE);
98
999484c9 99 for (width = 63; width > 0; width--) {
3a74415d 100 int dstOffset;
999484c9 101 for (dstOffset = 128; dstOffset < 196; dstOffset += 4) {
3a74415d
IP
102 int srcOffset;
103 memset(dstBuffer, dstByte, SIZE);
104
999484c9
DB
105 for (srcOffset = 128; srcOffset < 196; srcOffset += 4) {
106 uint8_t *src = srcBuffer + srcOffset;
107 uint8_t *dst = dstBuffer + dstOffset;
108 const char *name = NULL;
6a4970ab 109
999484c9
DB
110 // don't fill the screen with shit ...
111 if (failed)
112 break;
3a74415d
IP
113
114 srcBpp = func_info[funcNum].src_bpp;
115 dstBpp = func_info[funcNum].dst_bpp;
116 name = func_info[funcNum].name;
117
999484c9 118 func_info[funcNum].func(src, dst, width * srcBpp);
3a74415d 119
999484c9
DB
120 if (!srcBpp)
121 break;
3a74415d 122
999484c9
DB
123 for (i = 0; i < SIZE; i++) {
124 if (srcBuffer[i] != srcByte) {
125 av_log(NULL, AV_LOG_INFO,
126 "src damaged at %d w:%d src:%d dst:%d %s\n",
6e42e6c4 127 i, width, srcOffset, dstOffset, name);
999484c9 128 failed = 1;
3a74415d
IP
129 break;
130 }
131 }
999484c9
DB
132 for (i = 0; i < dstOffset; i++) {
133 if (dstBuffer[i] != dstByte) {
134 av_log(NULL, AV_LOG_INFO,
135 "dst damaged at %d w:%d src:%d dst:%d %s\n",
6e42e6c4 136 i, width, srcOffset, dstOffset, name);
999484c9 137 failed = 1;
3a74415d
IP
138 break;
139 }
140 }
999484c9
DB
141 for (i = dstOffset + width * dstBpp; i < SIZE; i++) {
142 if (dstBuffer[i] != dstByte) {
143 av_log(NULL, AV_LOG_INFO,
144 "dst damaged at %d w:%d src:%d dst:%d %s\n",
6e42e6c4 145 i, width, srcOffset, dstOffset, name);
999484c9 146 failed = 1;
3a74415d
IP
147 break;
148 }
149 }
150 }
151 }
152 }
999484c9
DB
153 if (failed)
154 failedNum++;
155 else if (srcBpp)
156 passedNum++;
3a74415d 157 }
6a4970ab 158
999484c9
DB
159 av_log(NULL, AV_LOG_INFO,
160 "\n%d converters passed, %d converters randomly overwrote memory\n",
161 passedNum, failedNum);
3a74415d 162 return failedNum;
a31de956 163}