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.

124 lines
3.5KB

  1. /*
  2. * Forward Uncompressed
  3. *
  4. * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
  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 "bytestream.h"
  24. #include "libavutil/intreadwrite.h"
  25. static av_cold int decode_init(AVCodecContext *avctx)
  26. {
  27. if (avctx->width & 1) {
  28. av_log(avctx, AV_LOG_ERROR, "FRWU needs even width\n");
  29. return -1;
  30. }
  31. avctx->pix_fmt = PIX_FMT_UYVY422;
  32. avctx->coded_frame = avcodec_alloc_frame();
  33. return 0;
  34. }
  35. static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
  36. AVPacket *avpkt)
  37. {
  38. int field;
  39. AVFrame *pic = avctx->coded_frame;
  40. const uint8_t *buf = avpkt->data;
  41. const uint8_t *buf_end = buf + avpkt->size;
  42. if (pic->data[0])
  43. avctx->release_buffer(avctx, pic);
  44. if (avpkt->size < avctx->width * 2 * avctx->height + 4 + 2*8) {
  45. av_log(avctx, AV_LOG_ERROR, "Packet is too small.\n");
  46. return -1;
  47. }
  48. if (bytestream_get_le32(&buf) != AV_RL32("FRW1")) {
  49. av_log(avctx, AV_LOG_ERROR, "incorrect marker\n");
  50. return -1;
  51. }
  52. pic->reference = 0;
  53. if (avctx->get_buffer(avctx, pic) < 0)
  54. return -1;
  55. pic->pict_type = FF_I_TYPE;
  56. pic->key_frame = 1;
  57. pic->interlaced_frame = 1;
  58. pic->top_field_first = 1;
  59. for (field = 0; field < 2; field++) {
  60. int i;
  61. int field_h = (avctx->height + !field) >> 1;
  62. int field_size, min_field_size = avctx->width * 2 * field_h;
  63. uint8_t *dst = pic->data[0];
  64. if (buf_end - buf < 8)
  65. return -1;
  66. buf += 4; // flags? 0x80 == bottom field maybe?
  67. field_size = bytestream_get_le32(&buf);
  68. if (field_size < min_field_size) {
  69. av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size);
  70. return -1;
  71. }
  72. if (buf_end - buf < field_size) {
  73. av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf));
  74. return -1;
  75. }
  76. if (field)
  77. dst += pic->linesize[0];
  78. for (i = 0; i < field_h; i++) {
  79. memcpy(dst, buf, avctx->width * 2);
  80. buf += avctx->width * 2;
  81. dst += pic->linesize[0] << 1;
  82. }
  83. buf += field_size - min_field_size;
  84. }
  85. *data_size = sizeof(AVFrame);
  86. *(AVFrame*)data = *pic;
  87. return avpkt->size;
  88. }
  89. static av_cold int decode_close(AVCodecContext *avctx)
  90. {
  91. AVFrame *pic = avctx->coded_frame;
  92. if (pic->data[0])
  93. avctx->release_buffer(avctx, pic);
  94. av_freep(&avctx->coded_frame);
  95. return 0;
  96. }
  97. AVCodec frwu_decoder = {
  98. "FRWU",
  99. AVMEDIA_TYPE_VIDEO,
  100. CODEC_ID_FRWU,
  101. 0,
  102. decode_init,
  103. NULL,
  104. decode_close,
  105. decode_frame,
  106. CODEC_CAP_DR1,
  107. .long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"),
  108. };