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.

154 lines
4.9KB

  1. /*
  2. * 012v decoder
  3. *
  4. * Copyright (C) 2012 Carl Eugen Hoyos
  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/intreadwrite.h"
  25. static av_cold int zero12v_decode_init(AVCodecContext *avctx)
  26. {
  27. avctx->pix_fmt = PIX_FMT_YUV422P16;
  28. avctx->bits_per_raw_sample = 10;
  29. if (avctx->codec_tag == MKTAG('a', '1', '2', 'v'))
  30. av_log_ask_for_sample(avctx, "Samples with actual transparency needed\n");
  31. return 0;
  32. }
  33. static int zero12v_decode_frame(AVCodecContext *avctx, void *data,
  34. int *got_frame, AVPacket *avpkt)
  35. {
  36. int line = 0, ret;
  37. const int width = avctx->width;
  38. AVFrame *pic = data;
  39. uint16_t *y, *u, *v;
  40. const uint8_t *line_end, *src = avpkt->data;
  41. int stride = avctx->width * 8 / 3;
  42. if (width == 1) {
  43. av_log(avctx, AV_LOG_ERROR, "Width 1 not supported.\n");
  44. return AVERROR_INVALIDDATA;
  45. }
  46. if (avpkt->size < avctx->height * stride) {
  47. av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
  48. avpkt->size, avctx->height * stride);
  49. return AVERROR_INVALIDDATA;
  50. }
  51. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  52. return ret;
  53. pic->pict_type = AV_PICTURE_TYPE_I;
  54. pic->key_frame = 1;
  55. y = (uint16_t *)pic->data[0];
  56. u = (uint16_t *)pic->data[1];
  57. v = (uint16_t *)pic->data[2];
  58. line_end = avpkt->data + stride;
  59. while (line++ < avctx->height) {
  60. while (1) {
  61. uint32_t t = AV_RL32(src);
  62. src += 4;
  63. *u++ = t << 6 & 0xFFC0;
  64. *y++ = t >> 4 & 0xFFC0;
  65. *v++ = t >> 14 & 0xFFC0;
  66. if (src >= line_end - 1) {
  67. *y = 0x80;
  68. src++;
  69. line_end += stride;
  70. y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
  71. u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
  72. v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
  73. break;
  74. }
  75. t = AV_RL32(src);
  76. src += 4;
  77. *y++ = t << 6 & 0xFFC0;
  78. *u++ = t >> 4 & 0xFFC0;
  79. *y++ = t >> 14 & 0xFFC0;
  80. if (src >= line_end - 2) {
  81. if (!(width & 1)) {
  82. *y = 0x80;
  83. src += 2;
  84. }
  85. line_end += stride;
  86. y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
  87. u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
  88. v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
  89. break;
  90. }
  91. t = AV_RL32(src);
  92. src += 4;
  93. *v++ = t << 6 & 0xFFC0;
  94. *y++ = t >> 4 & 0xFFC0;
  95. *u++ = t >> 14 & 0xFFC0;
  96. if (src >= line_end - 1) {
  97. *y = 0x80;
  98. src++;
  99. line_end += stride;
  100. y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
  101. u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
  102. v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
  103. break;
  104. }
  105. t = AV_RL32(src);
  106. src += 4;
  107. *y++ = t << 6 & 0xFFC0;
  108. *v++ = t >> 4 & 0xFFC0;
  109. *y++ = t >> 14 & 0xFFC0;
  110. if (src >= line_end - 2) {
  111. if (width & 1) {
  112. *y = 0x80;
  113. src += 2;
  114. }
  115. line_end += stride;
  116. y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
  117. u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
  118. v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
  119. break;
  120. }
  121. }
  122. }
  123. *got_frame = 1;
  124. return avpkt->size;
  125. }
  126. AVCodec ff_zero12v_decoder = {
  127. .name = "012v",
  128. .type = AVMEDIA_TYPE_VIDEO,
  129. .id = AV_CODEC_ID_012V,
  130. .init = zero12v_decode_init,
  131. .decode = zero12v_decode_frame,
  132. .capabilities = CODEC_CAP_DR1,
  133. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
  134. };