comparison spudec.c @ 31593:22272cbfaf28

Extract spudec image allocation code to a separate function.
author reimar
date Sat, 10 Jul 2010 10:22:28 +0000
parents fd422d385a19
children 8f8d3775d564
comparison
equal deleted inserted replaced
31592:a4ceb52caa30 31593:22272cbfaf28
222 } else { 222 } else {
223 mp_msg(MSGT_SPUDEC, MSGL_FATAL, "Fatal: update_spu: malloc requested %d bytes\n", 2 * this->stride * this->height); 223 mp_msg(MSGT_SPUDEC, MSGL_FATAL, "Fatal: update_spu: malloc requested %d bytes\n", 2 * this->stride * this->height);
224 } 224 }
225 } 225 }
226 226
227
228 static int spudec_alloc_image(spudec_handle_t *this, int stride, int height)
229 {
230 if (this->width > stride) // just a safeguard
231 this->width = stride;
232 this->stride = stride;
233 this->height = height;
234 if (this->image_size < this->stride * this->height) {
235 if (this->image != NULL) {
236 free(this->image);
237 this->image_size = 0;
238 }
239 this->image = malloc(2 * this->stride * this->height);
240 if (this->image) {
241 this->image_size = this->stride * this->height;
242 this->aimage = this->image + this->image_size;
243 }
244 }
245 return this->image != NULL;
246 }
247
227 static void spudec_process_data(spudec_handle_t *this, packet_t *packet) 248 static void spudec_process_data(spudec_handle_t *this, packet_t *packet)
228 { 249 {
229 unsigned int cmap[4], alpha[4]; 250 unsigned int cmap[4], alpha[4];
230 unsigned int i, x, y; 251 unsigned int i, x, y;
231 252
254 if (cmap[i] + alpha[i] > 255) 275 if (cmap[i] + alpha[i] > 255)
255 cmap[i] = 256 - alpha[i]; 276 cmap[i] = 256 - alpha[i];
256 } 277 }
257 } 278 }
258 279
259 if (this->image_size < this->stride * this->height) { 280 if (!spudec_alloc_image(this, this->stride, this->height))
260 if (this->image != NULL) {
261 free(this->image);
262 this->image_size = 0;
263 }
264 this->image = malloc(2 * this->stride * this->height);
265 if (this->image) {
266 this->image_size = this->stride * this->height;
267 this->aimage = this->image + this->image_size;
268 }
269 }
270 if (this->image == NULL)
271 return; 281 return;
272 282
273 /* Kludge: draw_alpha needs width multiple of 8. */ 283 /* Kludge: draw_alpha needs width multiple of 8. */
274 if (this->width < this->stride) 284 if (this->width < this->stride)
275 for (y = 0; y < this->height; ++y) { 285 for (y = 0; y < this->height; ++y) {