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.

93 lines
2.6KB

  1. /*
  2. * Dxtory decoder
  3. *
  4. * Copyright (c) 2011 Konstantin Shishkov
  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 "internal.h"
  24. #include "libavutil/common.h"
  25. #include "libavutil/intreadwrite.h"
  26. static av_cold int decode_init(AVCodecContext *avctx)
  27. {
  28. avctx->pix_fmt = AV_PIX_FMT_YUV420P;
  29. return 0;
  30. }
  31. static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
  32. AVPacket *avpkt)
  33. {
  34. int h, w;
  35. AVFrame *pic = data;
  36. const uint8_t *src = avpkt->data;
  37. uint8_t *Y1, *Y2, *U, *V;
  38. int ret;
  39. if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
  40. av_log(avctx, AV_LOG_ERROR, "packet too small\n");
  41. return AVERROR_INVALIDDATA;
  42. }
  43. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  44. return ret;
  45. pic->pict_type = AV_PICTURE_TYPE_I;
  46. pic->key_frame = 1;
  47. if (AV_RL32(src) != 0x01000002) {
  48. av_log_ask_for_sample(avctx, "Unknown frame header %X\n", AV_RL32(src));
  49. return AVERROR_PATCHWELCOME;
  50. }
  51. src += 16;
  52. Y1 = pic->data[0];
  53. Y2 = pic->data[0] + pic->linesize[0];
  54. U = pic->data[1];
  55. V = pic->data[2];
  56. for (h = 0; h < avctx->height; h += 2) {
  57. for (w = 0; w < avctx->width; w += 2) {
  58. AV_COPY16(Y1 + w, src);
  59. AV_COPY16(Y2 + w, src + 2);
  60. U[w >> 1] = src[4] + 0x80;
  61. V[w >> 1] = src[5] + 0x80;
  62. src += 6;
  63. }
  64. Y1 += pic->linesize[0] << 1;
  65. Y2 += pic->linesize[0] << 1;
  66. U += pic->linesize[1];
  67. V += pic->linesize[2];
  68. }
  69. *got_frame = 1;
  70. return avpkt->size;
  71. }
  72. AVCodec ff_dxtory_decoder = {
  73. .name = "dxtory",
  74. .long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
  75. .type = AVMEDIA_TYPE_VIDEO,
  76. .id = AV_CODEC_ID_DXTORY,
  77. .init = decode_init,
  78. .decode = decode_frame,
  79. .capabilities = CODEC_CAP_DR1,
  80. };