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.

143 lines
4.2KB

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