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.

132 lines
3.9KB

  1. /*
  2. * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "avcodec.h"
  21. #include "internal.h"
  22. #include "libavutil/bswap.h"
  23. #include "libavutil/internal.h"
  24. #include "libavutil/mem.h"
  25. static av_cold int decode_init(AVCodecContext *avctx)
  26. {
  27. if (avctx->width & 1) {
  28. av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
  29. return AVERROR(EINVAL);
  30. }
  31. avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
  32. avctx->bits_per_raw_sample = 10;
  33. return 0;
  34. }
  35. static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
  36. AVPacket *avpkt)
  37. {
  38. const uint32_t *src = (const uint32_t *)avpkt->data;
  39. AVFrame *pic = data;
  40. int width = avctx->width;
  41. int y = 0;
  42. uint16_t *ydst, *udst, *vdst, *yend;
  43. int ret;
  44. if (avpkt->size < avctx->width * avctx->height * 8 / 3) {
  45. av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
  46. return AVERROR_INVALIDDATA;
  47. }
  48. if (avpkt->size > avctx->width * avctx->height * 8 / 3) {
  49. avpriv_request_sample(avctx, "(Probably) padded data");
  50. }
  51. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  52. return ret;
  53. ydst = (uint16_t *)pic->data[0];
  54. udst = (uint16_t *)pic->data[1];
  55. vdst = (uint16_t *)pic->data[2];
  56. yend = ydst + width;
  57. pic->pict_type = AV_PICTURE_TYPE_I;
  58. pic->key_frame = 1;
  59. for (;;) {
  60. uint32_t v = av_be2ne32(*src++);
  61. *udst++ = (v >> 16) & 0xFFC0;
  62. *ydst++ = (v >> 6 ) & 0xFFC0;
  63. *vdst++ = (v << 4 ) & 0xFFC0;
  64. v = av_be2ne32(*src++);
  65. *ydst++ = (v >> 16) & 0xFFC0;
  66. if (ydst >= yend) {
  67. ydst += pic->linesize[0] / 2 - width;
  68. udst += pic->linesize[1] / 2 - width / 2;
  69. vdst += pic->linesize[2] / 2 - width / 2;
  70. yend = ydst + width;
  71. if (++y >= avctx->height)
  72. break;
  73. }
  74. *udst++ = (v >> 6 ) & 0xFFC0;
  75. *ydst++ = (v << 4 ) & 0xFFC0;
  76. v = av_be2ne32(*src++);
  77. *vdst++ = (v >> 16) & 0xFFC0;
  78. *ydst++ = (v >> 6 ) & 0xFFC0;
  79. if (ydst >= yend) {
  80. ydst += pic->linesize[0] / 2 - width;
  81. udst += pic->linesize[1] / 2 - width / 2;
  82. vdst += pic->linesize[2] / 2 - width / 2;
  83. yend = ydst + width;
  84. if (++y >= avctx->height)
  85. break;
  86. }
  87. *udst++ = (v << 4 ) & 0xFFC0;
  88. v = av_be2ne32(*src++);
  89. *ydst++ = (v >> 16) & 0xFFC0;
  90. *vdst++ = (v >> 6 ) & 0xFFC0;
  91. *ydst++ = (v << 4 ) & 0xFFC0;
  92. if (ydst >= yend) {
  93. ydst += pic->linesize[0] / 2 - width;
  94. udst += pic->linesize[1] / 2 - width / 2;
  95. vdst += pic->linesize[2] / 2 - width / 2;
  96. yend = ydst + width;
  97. if (++y >= avctx->height)
  98. break;
  99. }
  100. }
  101. *got_frame = 1;
  102. return avpkt->size;
  103. }
  104. AVCodec ff_v210x_decoder = {
  105. .name = "v210x",
  106. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
  107. .type = AVMEDIA_TYPE_VIDEO,
  108. .id = AV_CODEC_ID_V210X,
  109. .init = decode_init,
  110. .decode = decode_frame,
  111. .capabilities = AV_CODEC_CAP_DR1,
  112. };