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.

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