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.

85 lines
2.5KB

  1. /*
  2. * libquicktime yuv4 decoder
  3. *
  4. * Copyright (c) 2011 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. static av_cold int yuv4_decode_init(AVCodecContext *avctx)
  25. {
  26. avctx->pix_fmt = AV_PIX_FMT_YUV420P;
  27. return 0;
  28. }
  29. static int yuv4_decode_frame(AVCodecContext *avctx, void *data,
  30. int *got_frame, AVPacket *avpkt)
  31. {
  32. AVFrame *pic = data;
  33. const uint8_t *src = avpkt->data;
  34. uint8_t *y, *u, *v;
  35. int i, j, ret;
  36. if (avpkt->size < 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1)) {
  37. av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
  38. return AVERROR(EINVAL);
  39. }
  40. if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
  41. return ret;
  42. pic->key_frame = 1;
  43. pic->pict_type = AV_PICTURE_TYPE_I;
  44. y = pic->data[0];
  45. u = pic->data[1];
  46. v = pic->data[2];
  47. for (i = 0; i < (avctx->height + 1) >> 1; i++) {
  48. for (j = 0; j < (avctx->width + 1) >> 1; j++) {
  49. u[j] = *src++ ^ 0x80;
  50. v[j] = *src++ ^ 0x80;
  51. y[ 2 * j ] = *src++;
  52. y[ 2 * j + 1] = *src++;
  53. y[pic->linesize[0] + 2 * j ] = *src++;
  54. y[pic->linesize[0] + 2 * j + 1] = *src++;
  55. }
  56. y += 2 * pic->linesize[0];
  57. u += pic->linesize[1];
  58. v += pic->linesize[2];
  59. }
  60. *got_frame = 1;
  61. return avpkt->size;
  62. }
  63. AVCodec ff_yuv4_decoder = {
  64. .name = "yuv4",
  65. .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"),
  66. .type = AVMEDIA_TYPE_VIDEO,
  67. .id = AV_CODEC_ID_YUV4,
  68. .init = yuv4_decode_init,
  69. .decode = yuv4_decode_frame,
  70. .capabilities = AV_CODEC_CAP_DR1,
  71. };