Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.18 KB | None | 0 0
  1. diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c
  2. index e5b3c59..f6af1c1 100644
  3. --- a/libavcodec/sgidec.c
  4. +++ b/libavcodec/sgidec.c
  5. @@ -123,26 +123,33 @@ static int read_rle_sgi(unsigned char* out_buf, const uin$
  6.   * @return 0 if read success, otherwise return -1.
  7.   */
  8.  static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end,
  9. -                const uint8_t *in_buf, const uint8_t *in_end, SgiState* s)
  10. +                                 GetByteContext *g, SgiState* s)
  11.  {
  12.      int x, y, z;
  13. -    const uint8_t *ptr;
  14.      unsigned int offset = s->height * s->width * s->bytes_per_channel;
  15. +    GetByteContext gp[4];
  16.  
  17.      /* Test buffer size. */
  18. -    if (offset * s->depth > in_end - in_buf) {
  19. +    if (offset * s->depth > bytestream2_get_bytes_left(g)) {
  20.         return -1;
  21.      }
  22.  
  23. +    for (z = 0; z < s->depth; z++) {
  24. +        gp[z] = *g;
  25. +        bytestream2_skip(&gp[z], z * offset);
  26. +    }
  27. +
  28.      for (y = s->height - 1; y >= 0; y--) {
  29.          out_end = out_buf + (y * s->linesize);
  30. -        for (x = s->width; x > 0; x--) {
  31. -            ptr = in_buf += s->bytes_per_channel;
  32. -            for(z = 0; z < s->depth; z ++) {
  33. -                memcpy(out_end, ptr, s->bytes_per_channel);
  34. -                out_end += s->bytes_per_channel;
  35. -                ptr += offset;
  36. -            }
  37. +        if (s->bytes_per_channel == 1) {
  38. +            for (x = s->width; x > 0; x--)
  39. +                for (z = 0; z < s->depth; z++)
  40. +                    *out_end++ = bytestream2_get_byte(&gp[z]);
  41. +        } else {
  42. +            uint16_t *out_line = (uint16_t *)out_end;
  43. +            for (x = s->width; x > 0; x--)
  44. +                for (z = 0; z < s->depth; z++)
  45. +                    *out_line++ = bytestream2_get_be16(&gp[z]);
  46.          }
  47.      }
  48.      return 0;
  49. @@ -228,7 +235,9 @@ static int decode_frame(AVCodecContext *avctx,
  50.      if (rle) {
  51.          ret = read_rle_sgi(out_end, in_buf, in_end, s);
  52.      } else {
  53. -        ret = read_uncompressed_sgi(out_buf, out_end, in_buf, in_end, s);
  54. +        GetByteContext g;
  55. +        bytestream2_init(&g, in_buf, in_end - in_buf);
  56. +        ret = read_uncompressed_sgi(out_buf, out_end, &g, s);
  57.      }
  58.  
  59.      if (ret == 0) {
Add Comment
Please, Sign In to add comment