]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/rpza.c
bink: Factorize bink put_pixel
[ffmpeg] / libavcodec / rpza.c
index 585b1eafda770d8ec07007bb74967657862c653f..83dde7a9c3c5aaddd32de18df4b7ccc3622cae61 100644 (file)
@@ -34,6 +34,7 @@
  * pixels shall be stored in native CPU endianness.
  */
 
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -73,13 +74,10 @@ static void rpza_decode_stream(RpzaContext *s)
     int stride = s->frame->linesize[0] / 2;
     int row_inc = stride - 4;
     int chunk_size;
-    unsigned char opcode;
-    int n_blocks;
-    unsigned short colorA = 0, colorB;
-    unsigned short color4[4];
-    unsigned char index, idx;
-    unsigned short ta, tb;
-    unsigned short *pixels = (unsigned short *)s->frame->data[0];
+    uint16_t colorA = 0, colorB;
+    uint16_t color4[4];
+    uint16_t ta, tb;
+    uint16_t *pixels = (uint16_t *)s->frame->data[0];
 
     int row_ptr = 0;
     int pixel_ptr = 0;
@@ -104,9 +102,9 @@ static void rpza_decode_stream(RpzaContext *s)
 
     /* Process chunk data */
     while (bytestream2_get_bytes_left(&s->gb)) {
-        opcode = bytestream2_get_byte(&s->gb); /* Get opcode */
+        uint8_t opcode = bytestream2_get_byte(&s->gb); /* Get opcode */
 
-        n_blocks = (opcode & 0x1f) + 1; /* Extract block counter from opcode */
+        int n_blocks = (opcode & 0x1f) + 1; /* Extract block counter from opcode */
 
         /* If opcode MSbit is 0, we need more data to decide what to do */
         if ((opcode & 0x80) == 0) {
@@ -121,6 +119,8 @@ static void rpza_decode_stream(RpzaContext *s)
             }
         }
 
+        n_blocks = FFMIN(n_blocks, total_blocks);
+
         switch (opcode & 0xe0) {
 
         /* Skip blocks */
@@ -181,9 +181,9 @@ static void rpza_decode_stream(RpzaContext *s)
             while (n_blocks--) {
                 block_ptr = row_ptr + pixel_ptr;
                 for (pixel_y = 0; pixel_y < 4; pixel_y++) {
-                    index = bytestream2_get_byteu(&s->gb);
+                    uint8_t index = bytestream2_get_byteu(&s->gb);
                     for (pixel_x = 0; pixel_x < 4; pixel_x++){
-                        idx = (index >> (2 * (3 - pixel_x))) & 0x03;
+                        uint8_t idx = (index >> (2 * (3 - pixel_x))) & 0x03;
                         pixels[block_ptr] = color4[idx];
                         block_ptr++;
                     }