aasc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Autodesk RLE Decoder
  3. * Copyright (C) 2005 the ffmpeg project
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavcodec/aasc.c
  23. * Autodesk RLE Video Decoder by Konstantin Shishkov
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include "avcodec.h"
  29. #include "dsputil.h"
  30. #include "msrledec.h"
  31. typedef struct AascContext {
  32. AVCodecContext *avctx;
  33. AVFrame frame;
  34. } AascContext;
  35. #define FETCH_NEXT_STREAM_BYTE() \
  36. if (stream_ptr >= buf_size) \
  37. { \
  38. av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \
  39. break; \
  40. } \
  41. stream_byte = buf[stream_ptr++];
  42. static av_cold int aasc_decode_init(AVCodecContext *avctx)
  43. {
  44. AascContext *s = avctx->priv_data;
  45. s->avctx = avctx;
  46. avctx->pix_fmt = PIX_FMT_BGR24;
  47. s->frame.data[0] = NULL;
  48. return 0;
  49. }
  50. static int aasc_decode_frame(AVCodecContext *avctx,
  51. void *data, int *data_size,
  52. const uint8_t *buf, int buf_size)
  53. {
  54. AascContext *s = avctx->priv_data;
  55. int compr, i, stride;
  56. s->frame.reference = 1;
  57. s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
  58. if (avctx->reget_buffer(avctx, &s->frame)) {
  59. av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
  60. return -1;
  61. }
  62. compr = AV_RL32(buf);
  63. buf += 4;
  64. buf_size -= 4;
  65. switch(compr){
  66. case 0:
  67. stride = (avctx->width * 3 + 3) & ~3;
  68. for(i = avctx->height - 1; i >= 0; i--){
  69. memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
  70. buf += stride;
  71. }
  72. break;
  73. case 1:
  74. ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, buf - 4, buf_size + 4);
  75. break;
  76. default:
  77. av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
  78. return -1;
  79. }
  80. *data_size = sizeof(AVFrame);
  81. *(AVFrame*)data = s->frame;
  82. /* report that the buffer was completely consumed */
  83. return buf_size;
  84. }
  85. static av_cold int aasc_decode_end(AVCodecContext *avctx)
  86. {
  87. AascContext *s = avctx->priv_data;
  88. /* release the last frame */
  89. if (s->frame.data[0])
  90. avctx->release_buffer(avctx, &s->frame);
  91. return 0;
  92. }
  93. AVCodec aasc_decoder = {
  94. "aasc",
  95. CODEC_TYPE_VIDEO,
  96. CODEC_ID_AASC,
  97. sizeof(AascContext),
  98. aasc_decode_init,
  99. NULL,
  100. aasc_decode_end,
  101. aasc_decode_frame,
  102. CODEC_CAP_DR1,
  103. .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
  104. };