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.

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