- // FIXME: where to place this ?!?!
- if (compression_types[header.compression].algorithm == ALGO_RGB24H)
- s->avctx->pix_fmt = PIX_FMT_RGB32;
- else
- s->avctx->pix_fmt = PIX_FMT_RGB555; // RGB565 is supported as well
+ if (compression_types[header.compression].algorithm == ALGO_RGB24H) {
+ new_pix_fmt = AV_PIX_FMT_RGB32;
+ width_shift = 1;
+ } else
+ new_pix_fmt = AV_PIX_FMT_RGB555; // RGB565 is supported as well
+
+ s->w >>= width_shift;
+ if ((ret = av_image_check_size(s->w, s->h, 0, s->avctx)) < 0)
+ return ret;
+
+ if (s->w != s->avctx->width || s->h != s->avctx->height ||
+ new_pix_fmt != s->avctx->pix_fmt) {
+ av_frame_unref(&s->frame);
+ s->avctx->sample_aspect_ratio = (AVRational){ 1 << width_shift, 1 };
+ s->avctx->pix_fmt = new_pix_fmt;
+ avcodec_set_dimensions(s->avctx, s->w, s->h);
+ av_fast_malloc(&s->vert_pred, &s->vert_pred_size, s->avctx->width * sizeof(unsigned int));
+ }
+
+ /* There is 1 change bit per 4 pixels, so each change byte represents
+ * 32 pixels; divide width by 4 to obtain the number of change bits and
+ * then round up to the nearest byte. */
+ s->mb_change_bits_row_size = ((s->avctx->width >> (2 - width_shift)) + 7) >> 3;