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.

124 lines
3.6KB

  1. /*
  2. * R210 decoder
  3. *
  4. * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; 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 = AV_PIX_FMT_RGB48;
  28. avctx->bits_per_raw_sample = 10;
  29. avctx->coded_frame = avcodec_alloc_frame();
  30. return 0;
  31. }
  32. static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
  33. AVPacket *avpkt)
  34. {
  35. int h, w;
  36. AVFrame *pic = avctx->coded_frame;
  37. const uint32_t *src = (const uint32_t *)avpkt->data;
  38. int aligned_width = FFALIGN(avctx->width, 64);
  39. uint8_t *dst_line;
  40. if (pic->data[0])
  41. avctx->release_buffer(avctx, pic);
  42. if (avpkt->size < 4 * aligned_width * avctx->height) {
  43. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  44. return -1;
  45. }
  46. pic->reference = 0;
  47. if (avctx->get_buffer(avctx, pic) < 0)
  48. return -1;
  49. pic->pict_type = AV_PICTURE_TYPE_I;
  50. pic->key_frame = 1;
  51. dst_line = pic->data[0];
  52. for (h = 0; h < avctx->height; h++) {
  53. uint16_t *dst = (uint16_t *)dst_line;
  54. for (w = 0; w < avctx->width; w++) {
  55. uint32_t pixel = av_be2ne32(*src++);
  56. uint16_t r, g, b;
  57. if (avctx->codec_id==AV_CODEC_ID_R210) {
  58. b = pixel << 6;
  59. g = (pixel >> 4) & 0xffc0;
  60. r = (pixel >> 14) & 0xffc0;
  61. } else {
  62. b = pixel << 4;
  63. g = (pixel >> 6) & 0xffc0;
  64. r = (pixel >> 16) & 0xffc0;
  65. }
  66. *dst++ = r | (r >> 10);
  67. *dst++ = g | (g >> 10);
  68. *dst++ = b | (b >> 10);
  69. }
  70. src += aligned_width - avctx->width;
  71. dst_line += pic->linesize[0];
  72. }
  73. *data_size = sizeof(AVFrame);
  74. *(AVFrame*)data = *avctx->coded_frame;
  75. return avpkt->size;
  76. }
  77. static av_cold int decode_close(AVCodecContext *avctx)
  78. {
  79. AVFrame *pic = avctx->coded_frame;
  80. if (pic->data[0])
  81. avctx->release_buffer(avctx, pic);
  82. av_freep(&avctx->coded_frame);
  83. return 0;
  84. }
  85. #if CONFIG_R210_DECODER
  86. AVCodec ff_r210_decoder = {
  87. .name = "r210",
  88. .type = AVMEDIA_TYPE_VIDEO,
  89. .id = AV_CODEC_ID_R210,
  90. .init = decode_init,
  91. .close = decode_close,
  92. .decode = decode_frame,
  93. .capabilities = CODEC_CAP_DR1,
  94. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
  95. };
  96. #endif
  97. #if CONFIG_R10K_DECODER
  98. AVCodec ff_r10k_decoder = {
  99. .name = "r10k",
  100. .type = AVMEDIA_TYPE_VIDEO,
  101. .id = AV_CODEC_ID_R10K,
  102. .init = decode_init,
  103. .close = decode_close,
  104. .decode = decode_frame,
  105. .capabilities = CODEC_CAP_DR1,
  106. .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
  107. };
  108. #endif