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.

123 lines
3.7KB

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