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.

145 lines
4.3KB

  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 "internal.h"
  24. #include "libavutil/bswap.h"
  25. #include "libavutil/common.h"
  26. static av_cold int decode_init(AVCodecContext *avctx)
  27. {
  28. avctx->pix_fmt = AV_PIX_FMT_RGB48;
  29. avctx->bits_per_raw_sample = 10;
  30. avctx->coded_frame = avcodec_alloc_frame();
  31. if (!avctx->coded_frame)
  32. return AVERROR(ENOMEM);
  33. return 0;
  34. }
  35. static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
  36. AVPacket *avpkt)
  37. {
  38. int h, w, ret;
  39. AVFrame *pic = avctx->coded_frame;
  40. const uint32_t *src = (const uint32_t *)avpkt->data;
  41. int aligned_width = FFALIGN(avctx->width,
  42. avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64);
  43. uint8_t *dst_line;
  44. if (pic->data[0])
  45. avctx->release_buffer(avctx, pic);
  46. if (avpkt->size < 4 * aligned_width * avctx->height) {
  47. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  48. return AVERROR_INVALIDDATA;
  49. }
  50. pic->reference = 0;
  51. if ((ret = ff_get_buffer(avctx, pic)) < 0)
  52. return ret;
  53. pic->pict_type = AV_PICTURE_TYPE_I;
  54. pic->key_frame = 1;
  55. dst_line = pic->data[0];
  56. for (h = 0; h < avctx->height; h++) {
  57. uint16_t *dst = (uint16_t *)dst_line;
  58. for (w = 0; w < avctx->width; w++) {
  59. uint32_t pixel;
  60. uint16_t r, g, b;
  61. if (avctx->codec_id==AV_CODEC_ID_AVRP) {
  62. pixel = av_le2ne32(*src++);
  63. } else {
  64. pixel = av_be2ne32(*src++);
  65. }
  66. if (avctx->codec_id==AV_CODEC_ID_R210) {
  67. b = pixel << 6;
  68. g = (pixel >> 4) & 0xffc0;
  69. r = (pixel >> 14) & 0xffc0;
  70. } else {
  71. b = pixel << 4;
  72. g = (pixel >> 6) & 0xffc0;
  73. r = (pixel >> 16) & 0xffc0;
  74. }
  75. *dst++ = r | (r >> 10);
  76. *dst++ = g | (g >> 10);
  77. *dst++ = b | (b >> 10);
  78. }
  79. src += aligned_width - avctx->width;
  80. dst_line += pic->linesize[0];
  81. }
  82. *got_frame = 1;
  83. *(AVFrame*)data = *avctx->coded_frame;
  84. return avpkt->size;
  85. }
  86. static av_cold int decode_close(AVCodecContext *avctx)
  87. {
  88. AVFrame *pic = avctx->coded_frame;
  89. if (pic->data[0])
  90. avctx->release_buffer(avctx, pic);
  91. av_freep(&avctx->coded_frame);
  92. return 0;
  93. }
  94. #if CONFIG_R210_DECODER
  95. AVCodec ff_r210_decoder = {
  96. .name = "r210",
  97. .type = AVMEDIA_TYPE_VIDEO,
  98. .id = AV_CODEC_ID_R210,
  99. .init = decode_init,
  100. .close = decode_close,
  101. .decode = decode_frame,
  102. .capabilities = CODEC_CAP_DR1,
  103. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
  104. };
  105. #endif
  106. #if CONFIG_R10K_DECODER
  107. AVCodec ff_r10k_decoder = {
  108. .name = "r10k",
  109. .type = AVMEDIA_TYPE_VIDEO,
  110. .id = AV_CODEC_ID_R10K,
  111. .init = decode_init,
  112. .close = decode_close,
  113. .decode = decode_frame,
  114. .capabilities = CODEC_CAP_DR1,
  115. .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
  116. };
  117. #endif
  118. #if CONFIG_AVRP_DECODER
  119. AVCodec ff_avrp_decoder = {
  120. .name = "avrp",
  121. .type = AVMEDIA_TYPE_VIDEO,
  122. .id = AV_CODEC_ID_AVRP,
  123. .init = decode_init,
  124. .close = decode_close,
  125. .decode = decode_frame,
  126. .capabilities = CODEC_CAP_DR1,
  127. .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
  128. };
  129. #endif