• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libswscale/colorspace-test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of Libav.
00005  *
00006  * Libav is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * Libav is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with Libav; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include <stdio.h>
00022 #include <string.h>              /* for memset() */
00023 #include <unistd.h>
00024 #include <stdlib.h>
00025 #include <inttypes.h>
00026 
00027 #include "swscale.h"
00028 #include "rgb2rgb.h"
00029 
00030 #define SIZE    1000
00031 #define srcByte 0x55
00032 #define dstByte 0xBB
00033 
00034 #define FUNC(s, d, n) { s, d, #n, n }
00035 
00036 int main(int argc, char **argv)
00037 {
00038     int i, funcNum;
00039     uint8_t *srcBuffer = av_malloc(SIZE);
00040     uint8_t *dstBuffer = av_malloc(SIZE);
00041     int failedNum      = 0;
00042     int passedNum      = 0;
00043 
00044     if (!srcBuffer || !dstBuffer)
00045         return -1;
00046 
00047     av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
00048     sws_rgb2rgb_init();
00049 
00050     for (funcNum = 0; ; funcNum++) {
00051         struct func_info_s {
00052             int src_bpp;
00053             int dst_bpp;
00054             const char *name;
00055             void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
00056         } func_info[] = {
00057             FUNC(2, 2, rgb15to16),
00058             FUNC(2, 3, rgb15to24),
00059             FUNC(2, 4, rgb15to32),
00060             FUNC(2, 3, rgb16to24),
00061             FUNC(2, 4, rgb16to32),
00062             FUNC(3, 2, rgb24to15),
00063             FUNC(3, 2, rgb24to16),
00064             FUNC(3, 4, rgb24to32),
00065             FUNC(4, 2, rgb32to15),
00066             FUNC(4, 2, rgb32to16),
00067             FUNC(4, 3, rgb32to24),
00068             FUNC(2, 2, rgb16to15),
00069             FUNC(2, 2, rgb15tobgr15),
00070             FUNC(2, 2, rgb15tobgr16),
00071             FUNC(2, 3, rgb15tobgr24),
00072             FUNC(2, 4, rgb15tobgr32),
00073             FUNC(2, 2, rgb16tobgr15),
00074             FUNC(2, 2, rgb16tobgr16),
00075             FUNC(2, 3, rgb16tobgr24),
00076             FUNC(2, 4, rgb16tobgr32),
00077             FUNC(3, 2, rgb24tobgr15),
00078             FUNC(3, 2, rgb24tobgr16),
00079             FUNC(3, 3, rgb24tobgr24),
00080             FUNC(3, 4, rgb24tobgr32),
00081             FUNC(4, 2, rgb32tobgr15),
00082             FUNC(4, 2, rgb32tobgr16),
00083             FUNC(4, 3, rgb32tobgr24),
00084             FUNC(4, 4, shuffle_bytes_2103), /* rgb32tobgr32 */
00085             FUNC(0, 0, NULL)
00086         };
00087         int width;
00088         int failed = 0;
00089         int srcBpp = 0;
00090         int dstBpp = 0;
00091 
00092         if (!func_info[funcNum].func)
00093             break;
00094 
00095         av_log(NULL, AV_LOG_INFO, ".");
00096         memset(srcBuffer, srcByte, SIZE);
00097 
00098         for (width = 63; width > 0; width--) {
00099             int dstOffset;
00100             for (dstOffset = 128; dstOffset < 196; dstOffset += 4) {
00101                 int srcOffset;
00102                 memset(dstBuffer, dstByte, SIZE);
00103 
00104                 for (srcOffset = 128; srcOffset < 196; srcOffset += 4) {
00105                     uint8_t *src     = srcBuffer + srcOffset;
00106                     uint8_t *dst     = dstBuffer + dstOffset;
00107                     const char *name = NULL;
00108 
00109                     // don't fill the screen with shit ...
00110                     if (failed)
00111                         break;
00112 
00113                     srcBpp = func_info[funcNum].src_bpp;
00114                     dstBpp = func_info[funcNum].dst_bpp;
00115                     name   = func_info[funcNum].name;
00116 
00117                     func_info[funcNum].func(src, dst, width * srcBpp);
00118 
00119                     if (!srcBpp)
00120                         break;
00121 
00122                     for (i = 0; i < SIZE; i++) {
00123                         if (srcBuffer[i] != srcByte) {
00124                             av_log(NULL, AV_LOG_INFO,
00125                                    "src damaged at %d w:%d src:%d dst:%d %s\n",
00126                                    i, width, srcOffset, dstOffset, name);
00127                             failed = 1;
00128                             break;
00129                         }
00130                     }
00131                     for (i = 0; i < dstOffset; i++) {
00132                         if (dstBuffer[i] != dstByte) {
00133                             av_log(NULL, AV_LOG_INFO,
00134                                    "dst damaged at %d w:%d src:%d dst:%d %s\n",
00135                                    i, width, srcOffset, dstOffset, name);
00136                             failed = 1;
00137                             break;
00138                         }
00139                     }
00140                     for (i = dstOffset + width * dstBpp; i < SIZE; i++) {
00141                         if (dstBuffer[i] != dstByte) {
00142                             av_log(NULL, AV_LOG_INFO,
00143                                    "dst damaged at %d w:%d src:%d dst:%d %s\n",
00144                                    i, width, srcOffset, dstOffset, name);
00145                             failed = 1;
00146                             break;
00147                         }
00148                     }
00149                 }
00150             }
00151         }
00152         if (failed)
00153             failedNum++;
00154         else if (srcBpp)
00155             passedNum++;
00156     }
00157 
00158     av_log(NULL, AV_LOG_INFO,
00159            "\n%d converters passed, %d converters randomly overwrote memory\n",
00160            passedNum, failedNum);
00161     return failedNum;
00162 }
Generated on Thu Jan 24 2013 17:08:56 for Libav by doxygen 1.7.1