CodecRecommendedTypeTest.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2017 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/codec/SkAndroidCodec.h"
  8. #include "include/core/SkBitmap.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkColorSpace.h"
  11. #include "include/core/SkData.h"
  12. #include "include/core/SkEncodedImageFormat.h"
  13. #include "include/core/SkImageEncoder.h"
  14. #include "include/core/SkImageInfo.h"
  15. #include "include/core/SkStream.h"
  16. #include "tests/Test.h"
  17. #include <memory>
  18. #include <utility>
  19. DEF_TEST(Codec_recommendedF16, r) {
  20. // Encode an F16 bitmap. SkEncodeImage will encode this to a true-color PNG
  21. // with a bit depth of 16. SkAndroidCodec should always recommend F16 for
  22. // such a PNG.
  23. SkBitmap bm;
  24. bm.allocPixels(SkImageInfo::Make(10, 10, kRGBA_F16_SkColorType,
  25. kPremul_SkAlphaType, SkColorSpace::MakeSRGB()));
  26. // What is drawn is not important.
  27. bm.eraseColor(SK_ColorBLUE);
  28. SkDynamicMemoryWStream wstream;
  29. REPORTER_ASSERT(r, SkEncodeImage(&wstream, bm, SkEncodedImageFormat::kPNG, 100));
  30. auto data = wstream.detachAsData();
  31. auto androidCodec = SkAndroidCodec::MakeFromData(std::move(data));
  32. if (!androidCodec) {
  33. ERRORF(r, "Failed to create SkAndroidCodec");
  34. return;
  35. }
  36. REPORTER_ASSERT(r, androidCodec->computeOutputColorType(kN32_SkColorType)
  37. == kRGBA_F16_SkColorType);
  38. }