Scale.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "Scale.h"
  5. #ifdef USE_SKIA
  6. #include "HelpersSkia.h"
  7. #include "skia/include/core/SkBitmap.h"
  8. #include "image_operations.h"
  9. #endif
  10. namespace mozilla {
  11. namespace gfx {
  12. bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride,
  13. uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride,
  14. SurfaceFormat format)
  15. {
  16. #ifdef USE_SKIA
  17. SkBitmap imgSrc;
  18. imgSrc.installPixels(MakeSkiaImageInfo(IntSize(srcWidth, srcHeight), format),
  19. srcData, srcStride);
  20. // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed.
  21. if (imgSrc.colorType() != kBGRA_8888_SkColorType) {
  22. imgSrc.copyTo(&imgSrc, kBGRA_8888_SkColorType);
  23. }
  24. // This returns an SkBitmap backed by dstData; since it also wrote to dstData,
  25. // we don't need to look at that SkBitmap.
  26. SkBitmap result = skia::ImageOperations::Resize(imgSrc,
  27. skia::ImageOperations::RESIZE_BEST,
  28. dstWidth, dstHeight,
  29. dstData);
  30. return !result.isNull();
  31. #else
  32. return false;
  33. #endif
  34. }
  35. } // namespace gfx
  36. } // namespace mozilla