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.

123 lines
3.3KB

  1. /*
  2. * Micrsoft RLE Video Decoder
  3. * Copyright (C) 2003 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/msrle.c
  23. * MS RLE Video Decoder by Mike Melanson (melanson@pcisys.net)
  24. * For more information about the MS RLE format, visit:
  25. * http://www.pcisys.net/~melanson/codecs/
  26. *
  27. * The MS RLE decoder outputs PAL8 colorspace data.
  28. *
  29. * Note that this decoder expects the palette colors from the end of the
  30. * BITMAPINFO header passed through palctrl.
  31. */
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <unistd.h>
  36. #include "avcodec.h"
  37. #include "dsputil.h"
  38. #include "msrledec.h"
  39. typedef struct MsrleContext {
  40. AVCodecContext *avctx;
  41. AVFrame frame;
  42. const unsigned char *buf;
  43. int size;
  44. } MsrleContext;
  45. static av_cold int msrle_decode_init(AVCodecContext *avctx)
  46. {
  47. MsrleContext *s = avctx->priv_data;
  48. s->avctx = avctx;
  49. avctx->pix_fmt = PIX_FMT_PAL8;
  50. s->frame.data[0] = NULL;
  51. return 0;
  52. }
  53. static int msrle_decode_frame(AVCodecContext *avctx,
  54. void *data, int *data_size,
  55. AVPacket *avpkt)
  56. {
  57. const uint8_t *buf = avpkt->data;
  58. int buf_size = avpkt->size;
  59. MsrleContext *s = avctx->priv_data;
  60. s->buf = buf;
  61. s->size = buf_size;
  62. s->frame.reference = 1;
  63. s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
  64. if (avctx->reget_buffer(avctx, &s->frame)) {
  65. av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
  66. return -1;
  67. }
  68. if (s->avctx->palctrl) {
  69. /* make the palette available */
  70. memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
  71. if (s->avctx->palctrl->palette_changed) {
  72. s->frame.palette_has_changed = 1;
  73. s->avctx->palctrl->palette_changed = 0;
  74. }
  75. }
  76. ff_msrle_decode(avctx, (AVPicture*)&s->frame, avctx->bits_per_coded_sample, buf, buf_size);
  77. *data_size = sizeof(AVFrame);
  78. *(AVFrame*)data = s->frame;
  79. /* report that the buffer was completely consumed */
  80. return buf_size;
  81. }
  82. static av_cold int msrle_decode_end(AVCodecContext *avctx)
  83. {
  84. MsrleContext *s = avctx->priv_data;
  85. /* release the last frame */
  86. if (s->frame.data[0])
  87. avctx->release_buffer(avctx, &s->frame);
  88. return 0;
  89. }
  90. AVCodec msrle_decoder = {
  91. "msrle",
  92. CODEC_TYPE_VIDEO,
  93. CODEC_ID_MSRLE,
  94. sizeof(MsrleContext),
  95. msrle_decode_init,
  96. NULL,
  97. msrle_decode_end,
  98. msrle_decode_frame,
  99. CODEC_CAP_DR1,
  100. .long_name= NULL_IF_CONFIG_SMALL("Microsoft RLE"),
  101. };