Mercurial > mplayer.hg
comparison libswscale/swscale-test.c @ 31867:6ef694f86f3a
swscale-test: get strides using av_fill_image_linesizes() from libavcore
author | ramiro |
---|---|
date | Sun, 08 Aug 2010 18:14:43 +0000 |
parents | ee06f753ae93 |
children | 46473d005417 |
comparison
equal
deleted
inserted
replaced
31866:89ba6df5d766 | 31867:6ef694f86f3a |
---|---|
23 #include <string.h> | 23 #include <string.h> |
24 #include <inttypes.h> | 24 #include <inttypes.h> |
25 #include <stdarg.h> | 25 #include <stdarg.h> |
26 | 26 |
27 #undef HAVE_AV_CONFIG_H | 27 #undef HAVE_AV_CONFIG_H |
28 #include "libavcore/imgutils.h" | |
28 #include "libavutil/mem.h" | 29 #include "libavutil/mem.h" |
29 #include "libavutil/avutil.h" | 30 #include "libavutil/avutil.h" |
30 #include "libavutil/pixdesc.h" | 31 #include "libavutil/pixdesc.h" |
31 #include "libavutil/lfg.h" | 32 #include "libavutil/lfg.h" |
32 #include "swscale.h" | 33 #include "swscale.h" |
82 int i; | 83 int i; |
83 uint64_t ssdY, ssdU=0, ssdV=0, ssdA=0; | 84 uint64_t ssdY, ssdU=0, ssdV=0, ssdA=0; |
84 struct SwsContext *dstContext = NULL, *outContext = NULL; | 85 struct SwsContext *dstContext = NULL, *outContext = NULL; |
85 int res = 0; | 86 int res = 0; |
86 | 87 |
88 av_fill_image_linesizes(dstStride, dstFormat, dstW); | |
87 for (i=0; i<4; i++) { | 89 for (i=0; i<4; i++) { |
88 // avoid stride % bpp != 0 | |
89 if (dstFormat==PIX_FMT_RGB24 || dstFormat==PIX_FMT_BGR24) | |
90 dstStride[i]= dstW*3; | |
91 else if (dstFormat==PIX_FMT_RGB48BE || dstFormat==PIX_FMT_RGB48LE) | |
92 dstStride[i]= dstW*6; | |
93 else | |
94 dstStride[i]= dstW*4; | |
95 | |
96 /* Image buffers passed into libswscale can be allocated any way you | 90 /* Image buffers passed into libswscale can be allocated any way you |
97 * prefer, as long as they're aligned enough for the architecture, and | 91 * prefer, as long as they're aligned enough for the architecture, and |
98 * they're freed appropriately (such as using av_free for buffers | 92 * they're freed appropriately (such as using av_free for buffers |
99 * allocated with av_malloc). */ | 93 * allocated with av_malloc). */ |
100 /* An extra 16 bytes is being allocated because some scalers may write | 94 /* An extra 16 bytes is being allocated because some scalers may write |
101 * out of bounds. */ | 95 * out of bounds. */ |
96 if (dstStride[i]) | |
102 dst[i]= av_mallocz(dstStride[i]*dstH+16); | 97 dst[i]= av_mallocz(dstStride[i]*dstH+16); |
98 if (refStride[i]) | |
103 out[i]= av_mallocz(refStride[i]*h); | 99 out[i]= av_mallocz(refStride[i]*h); |
104 if (!dst[i] || !out[i]) { | 100 if ((dstStride[i] && !dst[i]) || (refStride[i] && !out[i])) { |
105 perror("Malloc"); | 101 perror("Malloc"); |
106 res = -1; | 102 res = -1; |
107 | 103 |
108 goto end; | 104 goto end; |
109 } | 105 } |
160 | 156 |
161 sws_freeContext(dstContext); | 157 sws_freeContext(dstContext); |
162 sws_freeContext(outContext); | 158 sws_freeContext(outContext); |
163 | 159 |
164 for (i=0; i<4; i++) { | 160 for (i=0; i<4; i++) { |
161 if (dstStride[i]) | |
165 av_free(dst[i]); | 162 av_free(dst[i]); |
163 if (refStride[i]) | |
166 av_free(out[i]); | 164 av_free(out[i]); |
167 } | 165 } |
168 | 166 |
169 return res; | 167 return res; |
170 } | 168 } |
199 for (k = 0; flags[k] && !res; k++) { | 197 for (k = 0; flags[k] && !res; k++) { |
200 struct SwsContext *srcContext = NULL; | 198 struct SwsContext *srcContext = NULL; |
201 uint8_t *src[4] = {0}; | 199 uint8_t *src[4] = {0}; |
202 int srcStride[4]; | 200 int srcStride[4]; |
203 int p; | 201 int p; |
202 av_fill_image_linesizes(srcStride, srcFormat, srcW); | |
204 for (p = 0; p < 4; p++) { | 203 for (p = 0; p < 4; p++) { |
205 if (srcFormat == PIX_FMT_RGB24 || | 204 if (srcStride[p]) |
206 srcFormat == PIX_FMT_BGR24) | |
207 srcStride[p] = srcW*3; | |
208 else if (srcFormat==PIX_FMT_RGB48BE || | |
209 srcFormat==PIX_FMT_RGB48LE) | |
210 srcStride[p] = srcW*6; | |
211 else | |
212 srcStride[p] = srcW*4; | |
213 src[p] = av_mallocz(srcStride[p]*srcH+16); | 205 src[p] = av_mallocz(srcStride[p]*srcH+16); |
214 if (!src[p]) { | 206 if (srcStride[p] && !src[p]) { |
215 perror("Malloc"); | 207 perror("Malloc"); |
216 return; | 208 return; |
217 } | 209 } |
218 } | 210 } |
219 srcContext = sws_getContext(w, h, PIX_FMT_YUVA420P, srcW, srcH, | 211 srcContext = sws_getContext(w, h, PIX_FMT_YUVA420P, srcW, srcH, |
232 srcFormat, dstFormat, | 224 srcFormat, dstFormat, |
233 srcW, srcH, dstW[i], dstH[j], flags[k]); | 225 srcW, srcH, dstW[i], dstH[j], flags[k]); |
234 | 226 |
235 sws_freeContext(srcContext); | 227 sws_freeContext(srcContext); |
236 for (p = 0; p < 4; p++) | 228 for (p = 0; p < 4; p++) |
229 if (srcStride[p]) | |
237 av_free(src[p]); | 230 av_free(src[p]); |
238 } | 231 } |
239 } | 232 } |
240 } | 233 } |
241 } | 234 } |