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.

121 lines
3.2KB

  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. /* make the palette available */
  69. memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
  70. if (s->avctx->palctrl->palette_changed) {
  71. s->frame.palette_has_changed = 1;
  72. s->avctx->palctrl->palette_changed = 0;
  73. }
  74. ff_msrle_decode(avctx, (AVPicture*)&s->frame, avctx->bits_per_coded_sample, buf, buf_size);
  75. *data_size = sizeof(AVFrame);
  76. *(AVFrame*)data = s->frame;
  77. /* report that the buffer was completely consumed */
  78. return buf_size;
  79. }
  80. static av_cold int msrle_decode_end(AVCodecContext *avctx)
  81. {
  82. MsrleContext *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 msrle_decoder = {
  89. "msrle",
  90. CODEC_TYPE_VIDEO,
  91. CODEC_ID_MSRLE,
  92. sizeof(MsrleContext),
  93. msrle_decode_init,
  94. NULL,
  95. msrle_decode_end,
  96. msrle_decode_frame,
  97. CODEC_CAP_DR1,
  98. .long_name= NULL_IF_CONFIG_SMALL("Microsoft RLE"),
  99. };