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.

103 lines
3.4KB

  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 int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  26. const AVFrame *pic, int *got_packet)
  27. {
  28. int i, j, ret;
  29. int aligned_width = FFALIGN(avctx->width,
  30. avctx->codec_id == AV_CODEC_ID_R10K ? 1 : 64);
  31. int pad = (aligned_width - avctx->width) * 4;
  32. uint8_t *src_line;
  33. uint8_t *dst;
  34. if ((ret = ff_alloc_packet2(avctx, pkt, 4 * aligned_width * avctx->height, 0)) < 0)
  35. return ret;
  36. src_line = pic->data[0];
  37. dst = pkt->data;
  38. for (i = 0; i < avctx->height; i++) {
  39. uint16_t *src = (uint16_t *)src_line;
  40. for (j = 0; j < avctx->width; j++) {
  41. uint32_t pixel;
  42. uint16_t r = *src++ >> 6;
  43. uint16_t g = *src++ >> 6;
  44. uint16_t b = *src++ >> 6;
  45. if (avctx->codec_id == AV_CODEC_ID_R210)
  46. pixel = (r << 20) | (g << 10) | b;
  47. else
  48. pixel = (r << 22) | (g << 12) | (b << 2);
  49. if (avctx->codec_id == AV_CODEC_ID_AVRP)
  50. bytestream_put_le32(&dst, pixel);
  51. else
  52. bytestream_put_be32(&dst, pixel);
  53. }
  54. memset(dst, 0, pad);
  55. dst += pad;
  56. src_line += pic->linesize[0];
  57. }
  58. pkt->flags |= AV_PKT_FLAG_KEY;
  59. *got_packet = 1;
  60. return 0;
  61. }
  62. #if CONFIG_R210_ENCODER
  63. AVCodec ff_r210_encoder = {
  64. .name = "r210",
  65. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
  66. .type = AVMEDIA_TYPE_VIDEO,
  67. .id = AV_CODEC_ID_R210,
  68. .encode2 = encode_frame,
  69. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE },
  70. .capabilities = AV_CODEC_CAP_INTRA_ONLY,
  71. };
  72. #endif
  73. #if CONFIG_R10K_ENCODER
  74. AVCodec ff_r10k_encoder = {
  75. .name = "r10k",
  76. .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
  77. .type = AVMEDIA_TYPE_VIDEO,
  78. .id = AV_CODEC_ID_R10K,
  79. .encode2 = encode_frame,
  80. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE },
  81. .capabilities = AV_CODEC_CAP_INTRA_ONLY,
  82. };
  83. #endif
  84. #if CONFIG_AVRP_ENCODER
  85. AVCodec ff_avrp_encoder = {
  86. .name = "avrp",
  87. .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
  88. .type = AVMEDIA_TYPE_VIDEO,
  89. .id = AV_CODEC_ID_AVRP,
  90. .encode2 = encode_frame,
  91. .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB48, AV_PIX_FMT_NONE },
  92. .capabilities = AV_CODEC_CAP_INTRA_ONLY,
  93. };
  94. #endif