You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.2KB

  1. /*
  2. * Autodesk RLE Decoder
  3. * Copyright (C) 2005 the ffmpeg project
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  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 "msrledec.h"
  30. typedef struct AascContext {
  31. AVCodecContext *avctx;
  32. GetByteContext gb;
  33. AVFrame frame;
  34. } AascContext;
  35. static av_cold int aasc_decode_init(AVCodecContext *avctx)
  36. {
  37. AascContext *s = avctx->priv_data;
  38. s->avctx = avctx;
  39. avctx->pix_fmt = AV_PIX_FMT_BGR24;
  40. return 0;
  41. }
  42. static int aasc_decode_frame(AVCodecContext *avctx,
  43. void *data, int *got_frame,
  44. AVPacket *avpkt)
  45. {
  46. const uint8_t *buf = avpkt->data;
  47. int buf_size = avpkt->size;
  48. AascContext *s = avctx->priv_data;
  49. int compr, i, stride, ret;
  50. s->frame.reference = 1;
  51. s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
  52. if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) {
  53. av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
  54. return ret;
  55. }
  56. compr = AV_RL32(buf);
  57. buf += 4;
  58. buf_size -= 4;
  59. switch (compr) {
  60. case 0:
  61. stride = (avctx->width * 3 + 3) & ~3;
  62. for (i = avctx->height - 1; i >= 0; i--) {
  63. memcpy(s->frame.data[0] + i * s->frame.linesize[0], buf, avctx->width * 3);
  64. buf += stride;
  65. }
  66. break;
  67. case 1:
  68. bytestream2_init(&s->gb, buf, buf_size);
  69. ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
  70. break;
  71. default:
  72. av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
  73. return AVERROR_INVALIDDATA;
  74. }
  75. *got_frame = 1;
  76. *(AVFrame*)data = s->frame;
  77. /* report that the buffer was completely consumed */
  78. return buf_size;
  79. }
  80. static av_cold int aasc_decode_end(AVCodecContext *avctx)
  81. {
  82. AascContext *s = avctx->priv_data;
  83. /* release the last frame */
  84. if (s->frame.data[0])
  85. avctx->release_buffer(avctx, &s->frame);
  86. return 0;
  87. }
  88. AVCodec ff_aasc_decoder = {
  89. .name = "aasc",
  90. .type = AVMEDIA_TYPE_VIDEO,
  91. .id = AV_CODEC_ID_AASC,
  92. .priv_data_size = sizeof(AascContext),
  93. .init = aasc_decode_init,
  94. .close = aasc_decode_end,
  95. .decode = aasc_decode_frame,
  96. .capabilities = CODEC_CAP_DR1,
  97. .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
  98. };