Statistics
| Branch: | Revision:

ffmpeg / libswscale / colorspace-test.c @ aa2ead82

History | View | Annotate | Download (5.72 KB)

1 a28ea2c0 Michael Niedermayer
/*
2 d026b45e Diego Biurrun
 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
3
 *
4
 * This file is part of FFmpeg.
5
 *
6 54e3ae2e Diego Biurrun
 * 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 d026b45e Diego Biurrun
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 54e3ae2e Diego Biurrun
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15 d026b45e Diego Biurrun
 *
16 54e3ae2e Diego Biurrun
 * 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 b19bcbaa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 d026b45e Diego Biurrun
 */
20 a28ea2c0 Michael Niedermayer
21
#include <stdio.h>
22 7f3f497a Luca Abeni
#include <string.h>              /* for memset() */
23
#include <unistd.h>
24 a28ea2c0 Michael Niedermayer
#include <stdlib.h>
25
#include <inttypes.h>
26
27 b76ee469 Alex Beregszaszi
#include "swscale.h"
28 a28ea2c0 Michael Niedermayer
#include "rgb2rgb.h"
29
30
#define SIZE 1000
31
#define srcByte 0x55
32
#define dstByte 0xBB
33
34 2a80b21d Ivo van Poorten
#define FUNC(s,d,n) {s,d,#n,n}
35 a31de956 Michael Niedermayer
36 7f3f497a Luca Abeni
static int cpu_caps;
37
38
static char *args_parse(int argc, char *argv[])
39 b76ee469 Alex Beregszaszi
{
40 7f3f497a Luca Abeni
    int o;
41
42
    while ((o = getopt(argc, argv, "m23")) != -1) {
43
        switch (o) {
44 9b734d44 Ramiro Polla
        case 'm':
45
            cpu_caps |= SWS_CPU_CAPS_MMX;
46
            break;
47
        case '2':
48
            cpu_caps |= SWS_CPU_CAPS_MMX2;
49
            break;
50
        case '3':
51
            cpu_caps |= SWS_CPU_CAPS_3DNOW;
52
            break;
53
        default:
54
            av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o);
55 7f3f497a Luca Abeni
        }
56
    }
57
58
    return argv[optind];
59 b76ee469 Alex Beregszaszi
}
60
61 b2c4e354 Diego Biurrun
int main(int argc, char **argv)
62 a28ea2c0 Michael Niedermayer
{
63 3a74415d Ivo van Poorten
    int i, funcNum;
64
    uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
65
    uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
66
    int failedNum=0;
67
    int passedNum=0;
68 6a4970ab Diego Biurrun
69 7248797c Ramiro Polla
    if (!srcBuffer || !dstBuffer)
70
        return -1;
71
72 3a74415d Ivo van Poorten
    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);
76 6a4970ab Diego Biurrun
77 dd68318c Ramiro Polla
    for(funcNum=0; ; funcNum++) {
78 3a74415d Ivo van Poorten
        struct func_info_s {
79
            int src_bpp;
80
            int dst_bpp;
81 dcc37c9b Diego Biurrun
            const char *name;
82 3a74415d Ivo van Poorten
            void (*func)(const uint8_t *src, uint8_t *dst, long src_size);
83
        } func_info[] = {
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),
112
            FUNC(0, 0, NULL)
113
        };
114
        int width;
115
        int failed=0;
116
        int srcBpp=0;
117
        int dstBpp=0;
118
119
        if (!func_info[funcNum].func) break;
120
121
        av_log(NULL, AV_LOG_INFO,".");
122
        memset(srcBuffer, srcByte, SIZE);
123
124 dd68318c Ramiro Polla
        for(width=63; width>0; width--) {
125 3a74415d Ivo van Poorten
            int dstOffset;
126 dd68318c Ramiro Polla
            for(dstOffset=128; dstOffset<196; dstOffset+=4) {
127 3a74415d Ivo van Poorten
                int srcOffset;
128
                memset(dstBuffer, dstByte, SIZE);
129
130 dd68318c Ramiro Polla
                for(srcOffset=128; srcOffset<196; srcOffset+=4) {
131 3a74415d Ivo van Poorten
                    uint8_t *src= srcBuffer+srcOffset;
132
                    uint8_t *dst= dstBuffer+dstOffset;
133 dcc37c9b Diego Biurrun
                    const char *name=NULL;
134 6a4970ab Diego Biurrun
135 3a74415d Ivo van Poorten
                    if(failed) break; //don't fill the screen with shit ...
136
137
                    srcBpp = func_info[funcNum].src_bpp;
138
                    dstBpp = func_info[funcNum].dst_bpp;
139
                    name   = func_info[funcNum].name;
140
141
                    func_info[funcNum].func(src, dst, width*srcBpp);
142
143
                    if(!srcBpp) break;
144
145 dd68318c Ramiro Polla
                    for(i=0; i<SIZE; i++) {
146
                        if(srcBuffer[i]!=srcByte) {
147 6a4970ab Diego Biurrun
                            av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
148 6e42e6c4 Diego Biurrun
                                   i, width, srcOffset, dstOffset, name);
149 3a74415d Ivo van Poorten
                            failed=1;
150
                            break;
151
                        }
152
                    }
153 dd68318c Ramiro Polla
                    for(i=0; i<dstOffset; i++) {
154
                        if(dstBuffer[i]!=dstByte) {
155 6a4970ab Diego Biurrun
                            av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
156 6e42e6c4 Diego Biurrun
                                   i, width, srcOffset, dstOffset, name);
157 3a74415d Ivo van Poorten
                            failed=1;
158
                            break;
159
                        }
160
                    }
161 dd68318c Ramiro Polla
                    for(i=dstOffset + width*dstBpp; i<SIZE; i++) {
162
                        if(dstBuffer[i]!=dstByte) {
163 6a4970ab Diego Biurrun
                            av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
164 6e42e6c4 Diego Biurrun
                                   i, width, srcOffset, dstOffset, name);
165 3a74415d Ivo van Poorten
                            failed=1;
166
                            break;
167
                        }
168
                    }
169
                }
170
            }
171
        }
172
        if(failed) failedNum++;
173
        else if(srcBpp) passedNum++;
174
    }
175 6a4970ab Diego Biurrun
176 3a74415d Ivo van Poorten
    av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
177
    return failedNum;
178 a31de956 Michael Niedermayer
}