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
4.1KB

  1. /*
  2. * R210 encoder
  3. *
  4. * Copyright (c) 2012 Paul B Mahol
  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 "bytestream.h"
  25. static av_cold int encode_init(AVCodecContext *avctx)
  26. {
  27. int aligned_width = FFALIGN(avctx->width,
  28. avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64);
  29. avctx->bits_per_coded_sample = 32;
  30. if (avctx->width > 0)
  31. avctx->bit_rate = ff_guess_coded_bitrate(avctx) * aligned_width / avctx->width;
  32. return 0;
  33. }
  34. static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  35. const AVFrame *pic, int *got_packet)
  36. {
  37. int i, j, ret;
  38. int aligned_width = FFALIGN(avctx->width,
  39. avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64);
  40. int pad = (aligned_width - avctx->width) * 4;
  41. uint8_t *srcr_line, *srcg_line, *srcb_line;
  42. uint8_t *dst;
  43. if ((ret = ff_alloc_packet2(avctx, pkt, 4 * aligned_width * avctx->height, 0)) < 0)
  44. return ret;
  45. srcg_line = pic->data[0];
  46. srcb_line = pic->data[1];
  47. srcr_line = pic->data[2];
  48. dst = pkt->data;
  49. for (i = 0; i < avctx->height; i++) {
  50. uint16_t *srcr = (uint16_t *)srcr_line;
  51. uint16_t *srcg = (uint16_t *)srcg_line;
  52. uint16_t *srcb = (uint16_t *)srcb_line;
  53. for (j = 0; j < avctx->width; j++) {
  54. uint32_t pixel;
  55. unsigned r = *srcr++;
  56. unsigned g = *srcg++;
  57. unsigned b = *srcb++;
  58. if (avctx->codec_id == AV_CODEC_ID_R210)
  59. pixel = (r << 20) | (g << 10) | b;
  60. else
  61. pixel = (r << 22) | (g << 12) | (b << 2);
  62. if (avctx->codec_id == AV_CODEC_ID_AVRP)
  63. bytestream_put_le32(&dst, pixel);
  64. else
  65. bytestream_put_be32(&dst, pixel);
  66. }
  67. memset(dst, 0, pad);
  68. dst += pad;
  69. srcr_line += pic->linesize[2];
  70. srcg_line += pic->linesize[0];
  71. srcb_line += pic->linesize[1];
  72. }
  73. pkt->flags |= AV_PKT_FLAG_KEY;
  74. *got_packet = 1;
  75. return 0;
  76. }
  77. #if CONFIG_R210_ENCODER
  78. AVCodec ff_r210_encoder = {
  79. .name = "r210",
  80. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
  81. .type = AVMEDIA_TYPE_VIDEO,
  82. .id = AV_CODEC_ID_R210,
  83. .init = encode_init,
  84. .encode2 = encode_frame,
  85. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE },
  86. .capabilities = AV_CODEC_CAP_INTRA_ONLY,
  87. };
  88. #endif
  89. #if CONFIG_R10K_ENCODER
  90. AVCodec ff_r10k_encoder = {
  91. .name = "r10k",
  92. .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
  93. .type = AVMEDIA_TYPE_VIDEO,
  94. .id = AV_CODEC_ID_R10K,
  95. .init = encode_init,
  96. .encode2 = encode_frame,
  97. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE },
  98. .capabilities = AV_CODEC_CAP_INTRA_ONLY,
  99. };
  100. #endif
  101. #if CONFIG_AVRP_ENCODER
  102. AVCodec ff_avrp_encoder = {
  103. .name = "avrp",
  104. .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
  105. .type = AVMEDIA_TYPE_VIDEO,
  106. .id = AV_CODEC_ID_AVRP,
  107. .init = encode_init,
  108. .encode2 = encode_frame,
  109. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRP10, AV_PIX_FMT_NONE },
  110. .capabilities = AV_CODEC_CAP_INTRA_ONLY,
  111. };
  112. #endif