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.

67 lines
2.1KB

  1. /*
  2. * Raw video utils
  3. * Copyright (c) 2016 Michael Niedermayer
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avformat.h"
  22. #include "internal.h"
  23. int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *enc, int expected_stride)
  24. {
  25. int ret;
  26. AVPacket *pkt = *ppkt;
  27. int64_t bpc = enc->bits_per_coded_sample != 15 ? enc->bits_per_coded_sample : 16;
  28. int min_stride = (enc->width * bpc + 7) >> 3;
  29. int with_pal_size = min_stride * enc->height + 1024;
  30. int size = bpc == 8 && pkt->size == with_pal_size ? min_stride * enc->height : pkt->size;
  31. int stride = size / enc->height;
  32. int padding = expected_stride - FFMIN(expected_stride, stride);
  33. int y;
  34. AVPacket *new_pkt;
  35. if (pkt->size == expected_stride * enc->height)
  36. return 0;
  37. if (size != stride * enc->height)
  38. return 0;
  39. new_pkt = av_packet_alloc();
  40. if (!new_pkt)
  41. return AVERROR(ENOMEM);
  42. ret = av_new_packet(new_pkt, expected_stride * enc->height);
  43. if (ret < 0)
  44. goto fail;
  45. ret = av_packet_copy_props(new_pkt, pkt);
  46. if (ret < 0)
  47. goto fail;
  48. for (y = 0; y<enc->height; y++) {
  49. memcpy(new_pkt->data + y*expected_stride, pkt->data + y*stride, FFMIN(expected_stride, stride));
  50. memset(new_pkt->data + y*expected_stride + expected_stride - padding, 0, padding);
  51. }
  52. *ppkt = new_pkt;
  53. return 1;
  54. fail:
  55. av_packet_free(&new_pkt);
  56. return ret;
  57. }