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.

75 lines
3.4KB

  1. /*
  2. * Copyright (C) 2015 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "swscale_internal.h"
  21. int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[],
  22. int srcStride[], int srcSliceY, int srcSliceH,
  23. uint8_t *dst[], int dstStride[])
  24. {
  25. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
  26. int nb_components = desc->nb_components;
  27. int plane, x, y;
  28. int plane_count = isGray(c->srcFormat) ? 1 : 3;
  29. int sixteen_bits = desc->comp[0].depth_minus1 >= 8;
  30. unsigned off = 1<<desc->comp[0].depth_minus1;
  31. unsigned shift = desc->comp[0].depth_minus1 + 1;
  32. unsigned max = (1<<shift) - 1;
  33. av_assert0(plane_count == nb_components - 1);
  34. if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) {
  35. for (plane = 0; plane < plane_count; plane++) {
  36. int w = plane ? c->chrSrcW : c->srcW;
  37. int y_subsample = plane ? desc->log2_chroma_h: 0;
  38. for (y = srcSliceY >> y_subsample; y < FF_CEIL_RSHIFT(srcSliceH, y_subsample); y++) {
  39. if (sixteen_bits) {
  40. const uint16_t *s = src[plane ] + srcStride[plane] * y;
  41. const uint16_t *a = src[plane_count] + srcStride[plane_count] * y;
  42. uint16_t *d = dst[plane ] + dstStride[plane] * y;
  43. unsigned target = plane && !(desc->flags & AV_PIX_FMT_FLAG_RGB) ? 1<<desc->comp[0].depth_minus1 : 0;
  44. if ((!isBE(c->dstFormat)) == !HAVE_BIGENDIAN) {
  45. for (x = 0; x < w; x++) {
  46. unsigned u = s[x]*a[x] + target*(max-a[x]) + off;
  47. d[x] = av_clip((u + (u >> shift)) >> shift, 0, max);
  48. }
  49. } else {
  50. for (x = 0; x < w; x++) {
  51. unsigned aswap =av_bswap16(a[x]);
  52. unsigned u = av_bswap16(s[x])*aswap + target*(max-aswap) + off;
  53. d[x] = av_clip((u + (u >> shift)) >> shift, 0, max);
  54. }
  55. }
  56. } else {
  57. const uint8_t *s = src[plane ] + srcStride[plane] * y;
  58. const uint8_t *a = src[plane_count] + srcStride[plane_count] * y;
  59. uint8_t *d = dst[plane ] + dstStride[plane] * y;
  60. unsigned target = plane && !(desc->flags & AV_PIX_FMT_FLAG_RGB) ? 128 : 0;
  61. for (x = 0; x < w; x++) {
  62. unsigned u = s[x]*a[x] + target*(255-a[x]) + 128;
  63. d[x] = (257*u) >> 16;
  64. }
  65. }
  66. }
  67. }
  68. }
  69. return 0;
  70. }