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.

105 lines
2.8KB

  1. /*
  2. * R210 decoder
  3. *
  4. * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "avcodec.h"
  23. #include "libavutil/bswap.h"
  24. static av_cold int decode_init(AVCodecContext *avctx)
  25. {
  26. avctx->pix_fmt = PIX_FMT_RGB48;
  27. avctx->bits_per_raw_sample = 10;
  28. avctx->coded_frame = avcodec_alloc_frame();
  29. return 0;
  30. }
  31. static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
  32. AVPacket *avpkt)
  33. {
  34. int h, w;
  35. AVFrame *pic = avctx->coded_frame;
  36. const uint32_t *src = (const uint32_t *)avpkt->data;
  37. int aligned_width = FFALIGN(avctx->width, 64);
  38. uint8_t *dst_line;
  39. if (pic->data[0])
  40. avctx->release_buffer(avctx, pic);
  41. if (avpkt->size < 4 * aligned_width * avctx->height) {
  42. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  43. return -1;
  44. }
  45. pic->reference = 0;
  46. if (avctx->get_buffer(avctx, pic) < 0)
  47. return -1;
  48. pic->pict_type = FF_I_TYPE;
  49. pic->key_frame = 1;
  50. dst_line = pic->data[0];
  51. for (h = 0; h < avctx->height; h++) {
  52. uint16_t *dst = (uint16_t *)dst_line;
  53. for (w = 0; w < avctx->width; w++) {
  54. uint32_t pixel = be2me_32(*src++);
  55. uint16_t r, g, b;
  56. b = pixel << 6;
  57. g = (pixel >> 4) & 0xffc0;
  58. r = (pixel >> 14) & 0xffc0;
  59. *dst++ = r | (r >> 10);
  60. *dst++ = g | (g >> 10);
  61. *dst++ = b | (b >> 10);
  62. }
  63. src += aligned_width - avctx->width;
  64. dst_line += pic->linesize[0];
  65. }
  66. *data_size = sizeof(AVFrame);
  67. *(AVFrame*)data = *avctx->coded_frame;
  68. return avpkt->size;
  69. }
  70. static av_cold int decode_close(AVCodecContext *avctx)
  71. {
  72. AVFrame *pic = avctx->coded_frame;
  73. if (pic->data[0])
  74. avctx->release_buffer(avctx, pic);
  75. av_freep(&avctx->coded_frame);
  76. return 0;
  77. }
  78. AVCodec r210_decoder = {
  79. "r210",
  80. AVMEDIA_TYPE_VIDEO,
  81. CODEC_ID_R210,
  82. 0,
  83. decode_init,
  84. NULL,
  85. decode_close,
  86. decode_frame,
  87. CODEC_CAP_DR1,
  88. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
  89. };