comparison spudec.c @ 31731:a0f828ae372d

Avoid useless malloc/frees
author reimar
date Sun, 25 Jul 2010 09:31:00 +0000
parents 8adcdb0b8ef6
children 0cf0df0ed136
comparison
equal deleted inserted replaced
31730:6be4d46328dd 31731:a0f828ae372d
196 // Some subtitles trigger this condition 196 // Some subtitles trigger this condition
197 if (last_y + 1 > first_y ) { 197 if (last_y + 1 > first_y ) {
198 this->height = last_y - first_y +1; 198 this->height = last_y - first_y +1;
199 } else { 199 } else {
200 this->height = 0; 200 this->height = 0;
201 this->image_size = 0;
202 return; 201 return;
203 } 202 }
204 203
205 // printf("new h %d new start %d (sz %d st %d)---\n\n", this->height, this->start_row, this->image_size, this->stride); 204 // printf("new h %d new start %d (sz %d st %d)---\n\n", this->height, this->start_row, this->image_size, this->stride);
206 205
207 image = malloc(2 * this->stride * this->height); 206 if (first_y > 0) {
208 if(image){ 207 memmove(this->image, this->image + this->stride * first_y, this->stride * this->height);
209 this->image_size = this->stride * this->height; 208 memmove(this->aimage, this->aimage + this->stride * first_y, this->stride * this->height);
210 aimage = image + this->image_size;
211 memcpy(image, this->image + this->stride * first_y, this->image_size);
212 memcpy(aimage, this->aimage + this->stride * first_y, this->image_size);
213 free(this->image);
214 this->image = image;
215 this->aimage = aimage;
216 } else {
217 mp_msg(MSGT_SPUDEC, MSGL_FATAL, "Fatal: update_spu: malloc requested %d bytes\n", 2 * this->stride * this->height);
218 } 209 }
219 } 210 }
220 211
221 212
222 static int spudec_alloc_image(spudec_handle_t *this, int stride, int height) 213 static int spudec_alloc_image(spudec_handle_t *this, int stride, int height)