]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/g2meet.c
avframe: add AV_FRAME_DATA_MATRIXENCODING side data type.
[ffmpeg] / libavcodec / g2meet.c
index a617df61ff7123b48c5b4bd2c9542cda3d47c6fb..0b36dbd0d5e3a1f73d9301e5d4f77f0c7409edc3 100644 (file)
@@ -236,16 +236,14 @@ static int jpg_decode_data(JPGContext *c, int width, int height,
                            int swapuv)
 {
     GetBitContext gb;
-    uint8_t *tmp;
     int mb_w, mb_h, mb_x, mb_y, i, j;
     int bx, by;
     int unesc_size;
     int ret;
 
-    tmp = av_realloc(c->buf, src_size + FF_INPUT_BUFFER_PADDING_SIZE);
-    if (!tmp)
-        return AVERROR(ENOMEM);
-    c->buf = tmp;
+    if ((ret = av_reallocp(&c->buf,
+                           src_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
+        return ret;
     jpg_unescape(src, src_size, c->buf, &unesc_size);
     memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
     init_get_bits(&gb, c->buf, unesc_size * 8);
@@ -478,8 +476,7 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
     uint32_t bits;
     uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
     uint32_t cursor_hot_x, cursor_hot_y;
-    int cursor_fmt;
-    uint8_t *tmp;
+    int cursor_fmt, err;
 
     cur_size      = bytestream2_get_be32(gb);
     cursor_w      = bytestream2_get_byte(gb);
@@ -488,7 +485,7 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
     cursor_hot_y  = bytestream2_get_byte(gb);
     cursor_fmt    = bytestream2_get_byte(gb);
 
-    cursor_stride = cursor_w * 4;
+    cursor_stride = FFALIGN(cursor_w, 32) * 4;
 
     if (cursor_w < 1 || cursor_w > 256 ||
         cursor_h < 1 || cursor_h > 256) {
@@ -514,13 +511,11 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
         return AVERROR_PATCHWELCOME;
     }
 
-    tmp = av_realloc(c->cursor, cursor_stride * cursor_h);
-    if (!tmp) {
+    if ((err = av_reallocp(&c->cursor, cursor_stride * cursor_h)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "Cannot allocate cursor buffer\n");
-        return AVERROR(ENOMEM);
+        return err;
     }
 
-    c->cursor        = tmp;
     c->cursor_w      = cursor_w;
     c->cursor_h      = cursor_h;
     c->cursor_hot_x  = cursor_hot_x;
@@ -540,6 +535,7 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
                     bits <<= 1;
                 }
             }
+            dst += c->cursor_stride - c->cursor_w * 4;
         }
 
         dst = c->cursor;
@@ -565,6 +561,7 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
                     bits <<= 1;
                 }
             }
+            dst += c->cursor_stride - c->cursor_w * 4;
         }
         break;
     case 32: // full colour
@@ -578,6 +575,7 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
                 *dst++ = val >> 16;
                 *dst++ = val >> 24;
             }
+            dst += c->cursor_stride - c->cursor_w * 4;
         }
         break;
     default:
@@ -699,7 +697,7 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
                 goto header_fail;
             }
             if (c->width != avctx->width || c->height != avctx->height)
-                avcodec_set_dimensions(avctx, c->width, c->height);
+                ff_set_dimensions(avctx, c->width, c->height);
             c->compression = bytestream2_get_be32(&bc);
             if (c->compression != 2 && c->compression != 3) {
                 av_log(avctx, AV_LOG_ERROR,
@@ -709,7 +707,8 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
             }
             c->tile_width  = bytestream2_get_be32(&bc);
             c->tile_height = bytestream2_get_be32(&bc);
-            if (!c->tile_width || !c->tile_height) {
+            if (!c->tile_width || !c->tile_height ||
+                ((c->tile_width | c->tile_height) & 0xF)) {
                 av_log(avctx, AV_LOG_ERROR,
                        "Invalid tile dimensions %dx%d\n",
                        c->tile_width, c->tile_height);
@@ -835,7 +834,7 @@ static av_cold int g2m_decode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
     }
 
-    avctx->pix_fmt     = PIX_FMT_RGB24;
+    avctx->pix_fmt = AV_PIX_FMT_RGB24;
 
     return 0;
 }