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.

140 lines
4.5KB

  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_GBRP10;
  29. avctx->bits_per_raw_sample = 10;
  30. return 0;
  31. }
  32. static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
  33. AVPacket *avpkt)
  34. {
  35. int h, w, ret;
  36. AVFrame *pic = data;
  37. const uint32_t *src = (const uint32_t *)avpkt->data;
  38. int aligned_width = FFALIGN(avctx->width,
  39. avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64);
  40. uint8_t *g_line, *b_line, *r_line;
  41. int r10 = (avctx->codec_tag & 0xFFFFFF) == MKTAG('r', '1', '0', 0);
  42. int le = avctx->codec_tag == MKTAG('R', '1', '0', 'k') &&
  43. avctx->extradata_size >= 12 && !memcmp(&avctx->extradata[4], "DpxE", 4) &&
  44. !avctx->extradata[11];
  45. if (avpkt->size < 4 * aligned_width * avctx->height) {
  46. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  47. return AVERROR_INVALIDDATA;
  48. }
  49. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  50. return ret;
  51. pic->pict_type = AV_PICTURE_TYPE_I;
  52. pic->key_frame = 1;
  53. g_line = pic->data[0];
  54. b_line = pic->data[1];
  55. r_line = pic->data[2];
  56. for (h = 0; h < avctx->height; h++) {
  57. uint16_t *dstg = (uint16_t *)g_line;
  58. uint16_t *dstb = (uint16_t *)b_line;
  59. uint16_t *dstr = (uint16_t *)r_line;
  60. for (w = 0; w < avctx->width; w++) {
  61. uint32_t pixel;
  62. uint16_t r, g, b;
  63. if (avctx->codec_id == AV_CODEC_ID_AVRP || r10 || le) {
  64. pixel = av_le2ne32(*src++);
  65. } else {
  66. pixel = av_be2ne32(*src++);
  67. }
  68. if (avctx->codec_id == AV_CODEC_ID_R210) {
  69. b = pixel & 0x3ff;
  70. g = (pixel >> 10) & 0x3ff;
  71. r = (pixel >> 20) & 0x3ff;
  72. } else if (r10) {
  73. r = pixel & 0x3ff;
  74. g = (pixel >> 10) & 0x3ff;
  75. b = (pixel >> 20) & 0x3ff;
  76. } else {
  77. b = (pixel >> 2) & 0x3ff;
  78. g = (pixel >> 12) & 0x3ff;
  79. r = (pixel >> 22) & 0x3ff;
  80. }
  81. *dstr++ = r;
  82. *dstg++ = g;
  83. *dstb++ = b;
  84. }
  85. src += aligned_width - avctx->width;
  86. g_line += pic->linesize[0];
  87. b_line += pic->linesize[1];
  88. r_line += pic->linesize[2];
  89. }
  90. *got_frame = 1;
  91. return avpkt->size;
  92. }
  93. #if CONFIG_R210_DECODER
  94. AVCodec ff_r210_decoder = {
  95. .name = "r210",
  96. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
  97. .type = AVMEDIA_TYPE_VIDEO,
  98. .id = AV_CODEC_ID_R210,
  99. .init = decode_init,
  100. .decode = decode_frame,
  101. .capabilities = AV_CODEC_CAP_DR1,
  102. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  103. };
  104. #endif
  105. #if CONFIG_R10K_DECODER
  106. AVCodec ff_r10k_decoder = {
  107. .name = "r10k",
  108. .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
  109. .type = AVMEDIA_TYPE_VIDEO,
  110. .id = AV_CODEC_ID_R10K,
  111. .init = decode_init,
  112. .decode = decode_frame,
  113. .capabilities = AV_CODEC_CAP_DR1,
  114. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  115. };
  116. #endif
  117. #if CONFIG_AVRP_DECODER
  118. AVCodec ff_avrp_decoder = {
  119. .name = "avrp",
  120. .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
  121. .type = AVMEDIA_TYPE_VIDEO,
  122. .id = AV_CODEC_ID_AVRP,
  123. .init = decode_init,
  124. .decode = decode_frame,
  125. .capabilities = AV_CODEC_CAP_DR1,
  126. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  127. };
  128. #endif