colorspace-test.c 5.11 KB
Newer Older
1
/*
2 3
 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
 *
4
 * This file is part of Libav.
5
 *
6
 * Libav is free software; you can redistribute it and/or
7 8 9
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * Libav is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * 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 Libav; 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 23
#include <string.h>              /* for memset() */
#include <unistd.h>
24 25 26
#include <stdlib.h>
#include <inttypes.h>

Alex Beregszaszi's avatar
Alex Beregszaszi committed
27
#include "swscale.h"
28 29 30 31 32 33
#include "rgb2rgb.h"

#define SIZE 1000
#define srcByte 0x55
#define dstByte 0xBB

34
#define FUNC(s,d,n) {s,d,#n,n}
35

Diego Biurrun's avatar
Diego Biurrun committed
36
int main(int argc, char **argv)
37
{
38 39 40 41 42
    int i, funcNum;
    uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
    uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
    int failedNum=0;
    int passedNum=0;
43

44 45 46
    if (!srcBuffer || !dstBuffer)
        return -1;

47
    av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
48
    sws_rgb2rgb_init();
49

Ramiro Polla's avatar
Ramiro Polla committed
50
    for(funcNum=0; ; funcNum++) {
51 52 53
        struct func_info_s {
            int src_bpp;
            int dst_bpp;
54
            const char *name;
55
            void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        } func_info[] = {
            FUNC(2, 2, rgb15to16),
            FUNC(2, 3, rgb15to24),
            FUNC(2, 4, rgb15to32),
            FUNC(2, 3, rgb16to24),
            FUNC(2, 4, rgb16to32),
            FUNC(3, 2, rgb24to15),
            FUNC(3, 2, rgb24to16),
            FUNC(3, 4, rgb24to32),
            FUNC(4, 2, rgb32to15),
            FUNC(4, 2, rgb32to16),
            FUNC(4, 3, rgb32to24),
            FUNC(2, 2, rgb16to15),
            FUNC(2, 2, rgb15tobgr15),
            FUNC(2, 2, rgb15tobgr16),
            FUNC(2, 3, rgb15tobgr24),
            FUNC(2, 4, rgb15tobgr32),
            FUNC(2, 2, rgb16tobgr15),
            FUNC(2, 2, rgb16tobgr16),
            FUNC(2, 3, rgb16tobgr24),
            FUNC(2, 4, rgb16tobgr32),
            FUNC(3, 2, rgb24tobgr15),
            FUNC(3, 2, rgb24tobgr16),
            FUNC(3, 3, rgb24tobgr24),
            FUNC(3, 4, rgb24tobgr32),
            FUNC(4, 2, rgb32tobgr15),
            FUNC(4, 2, rgb32tobgr16),
            FUNC(4, 3, rgb32tobgr24),
84
            FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
85 86 87 88 89 90 91 92 93 94 95 96
            FUNC(0, 0, NULL)
        };
        int width;
        int failed=0;
        int srcBpp=0;
        int dstBpp=0;

        if (!func_info[funcNum].func) break;

        av_log(NULL, AV_LOG_INFO,".");
        memset(srcBuffer, srcByte, SIZE);

Ramiro Polla's avatar
Ramiro Polla committed
97
        for(width=63; width>0; width--) {
98
            int dstOffset;
Ramiro Polla's avatar
Ramiro Polla committed
99
            for(dstOffset=128; dstOffset<196; dstOffset+=4) {
100 101 102
                int srcOffset;
                memset(dstBuffer, dstByte, SIZE);

Ramiro Polla's avatar
Ramiro Polla committed
103
                for(srcOffset=128; srcOffset<196; srcOffset+=4) {
104 105
                    uint8_t *src= srcBuffer+srcOffset;
                    uint8_t *dst= dstBuffer+dstOffset;
106
                    const char *name=NULL;
107

108 109 110 111 112 113 114 115 116 117
                    if(failed) break; //don't fill the screen with shit ...

                    srcBpp = func_info[funcNum].src_bpp;
                    dstBpp = func_info[funcNum].dst_bpp;
                    name   = func_info[funcNum].name;

                    func_info[funcNum].func(src, dst, width*srcBpp);

                    if(!srcBpp) break;

Ramiro Polla's avatar
Ramiro Polla committed
118 119
                    for(i=0; i<SIZE; i++) {
                        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 123 124 125
                            failed=1;
                            break;
                        }
                    }
Ramiro Polla's avatar
Ramiro Polla committed
126 127
                    for(i=0; i<dstOffset; i++) {
                        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 131 132 133
                            failed=1;
                            break;
                        }
                    }
Ramiro Polla's avatar
Ramiro Polla committed
134 135
                    for(i=dstOffset + width*dstBpp; i<SIZE; i++) {
                        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 139 140 141 142 143 144 145 146 147
                            failed=1;
                            break;
                        }
                    }
                }
            }
        }
        if(failed) failedNum++;
        else if(srcBpp) passedNum++;
    }
148

149 150
    av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
    return failedNum;
151
}