2 * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of Libav.
6 * Libav 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 * Libav 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 Libav; 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() */
28 #include "libavutil/mem.h"
34 #define FUNC(s, d, n) { s, d, #n, n }
39 uint8_t *srcBuffer
= av_malloc(SIZE
);
40 uint8_t *dstBuffer
= av_malloc(SIZE
);
44 if (!srcBuffer
|| !dstBuffer
)
47 av_log(NULL
, AV_LOG_INFO
, "memory corruption test ...\n");
50 for (funcNum
= 0; ; funcNum
++) {
55 void (*func
)(const uint8_t *src
, uint8_t *dst
, int src_size
);
57 FUNC(2, 2, rgb15to16
),
58 FUNC(2, 3, rgb15to24
),
59 FUNC(2, 4, rgb15to32
),
60 FUNC(2, 3, rgb16to24
),
61 FUNC(2, 4, rgb16to32
),
62 FUNC(3, 2, rgb24to15
),
63 FUNC(3, 2, rgb24to16
),
64 FUNC(3, 4, rgb24to32
),
65 FUNC(4, 2, rgb32to15
),
66 FUNC(4, 2, rgb32to16
),
67 FUNC(4, 3, rgb32to24
),
68 FUNC(2, 2, rgb16to15
),
69 FUNC(2, 2, rgb15tobgr15
),
70 FUNC(2, 2, rgb15tobgr16
),
71 FUNC(2, 3, rgb15tobgr24
),
72 FUNC(2, 4, rgb15tobgr32
),
73 FUNC(2, 2, rgb16tobgr15
),
74 FUNC(2, 2, rgb16tobgr16
),
75 FUNC(2, 3, rgb16tobgr24
),
76 FUNC(2, 4, rgb16tobgr32
),
77 FUNC(3, 2, rgb24tobgr15
),
78 FUNC(3, 2, rgb24tobgr16
),
79 FUNC(3, 3, rgb24tobgr24
),
80 FUNC(3, 4, rgb24tobgr32
),
81 FUNC(4, 2, rgb32tobgr15
),
82 FUNC(4, 2, rgb32tobgr16
),
83 FUNC(4, 3, rgb32tobgr24
),
84 FUNC(4, 4, shuffle_bytes_2103
), /* rgb32tobgr32 */
92 if (!func_info
[funcNum
].func
)
95 av_log(NULL
, AV_LOG_INFO
, ".");
96 memset(srcBuffer
, srcByte
, SIZE
);
98 for (width
= 63; width
> 0; width
--) {
100 for (dstOffset
= 128; dstOffset
< 196; dstOffset
+= 4) {
102 memset(dstBuffer
, dstByte
, SIZE
);
104 for (srcOffset
= 128; srcOffset
< 196; srcOffset
+= 4) {
105 uint8_t *src
= srcBuffer
+ srcOffset
;
106 uint8_t *dst
= dstBuffer
+ dstOffset
;
107 const char *name
= NULL
;
109 // don't fill the screen with shit ...
113 srcBpp
= func_info
[funcNum
].src_bpp
;
114 dstBpp
= func_info
[funcNum
].dst_bpp
;
115 name
= func_info
[funcNum
].name
;
117 func_info
[funcNum
].func(src
, dst
, width
* srcBpp
);
122 for (i
= 0; i
< SIZE
; i
++) {
123 if (srcBuffer
[i
] != srcByte
) {
124 av_log(NULL
, AV_LOG_INFO
,
125 "src damaged at %d w:%d src:%d dst:%d %s\n",
126 i
, width
, srcOffset
, dstOffset
, name
);
131 for (i
= 0; i
< dstOffset
; i
++) {
132 if (dstBuffer
[i
] != dstByte
) {
133 av_log(NULL
, AV_LOG_INFO
,
134 "dst damaged at %d w:%d src:%d dst:%d %s\n",
135 i
, width
, srcOffset
, dstOffset
, name
);
140 for (i
= dstOffset
+ width
* dstBpp
; i
< SIZE
; i
++) {
141 if (dstBuffer
[i
] != dstByte
) {
142 av_log(NULL
, AV_LOG_INFO
,
143 "dst damaged at %d w:%d src:%d dst:%d %s\n",
144 i
, width
, srcOffset
, dstOffset
, name
);
158 av_log(NULL
, AV_LOG_INFO
,
159 "\n%d converters passed, %d converters randomly overwrote memory\n",
160 passedNum
, failedNum
);