BitmapGetColorTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2011 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/core/SkBitmap.h"
  8. #include "include/core/SkColor.h"
  9. #include "include/core/SkImageInfo.h"
  10. #include "include/core/SkRect.h"
  11. #include "include/core/SkTypes.h"
  12. #include "tests/Test.h"
  13. DEF_TEST(GetColor, reporter) {
  14. static const struct Rec {
  15. SkColorType fColorType;
  16. SkColor fInColor;
  17. SkColor fOutColor;
  18. } gRec[] = {
  19. // todo: add some tests that involve alpha, so we exercise the
  20. // unpremultiply aspect of getColor()
  21. { kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 },
  22. { kAlpha_8_SkColorType, 0, 0 },
  23. { kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 },
  24. { kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF },
  25. { kN32_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
  26. { kN32_SkColorType, 0, 0 },
  27. { kN32_SkColorType, 0xFF224466, 0xFF224466 },
  28. };
  29. // specify an area that doesn't touch (0,0) and may extend beyond the
  30. // bitmap bounds (to test that we catch that in eraseArea
  31. const SkColor initColor = 0xFF0000FF;
  32. const SkIRect area = { 1, 1, 3, 3 };
  33. for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
  34. SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType,
  35. kPremul_SkAlphaType);
  36. SkBitmap bm;
  37. uint32_t storage[4];
  38. bm.installPixels(info, storage, info.minRowBytes());
  39. bm.eraseColor(initColor);
  40. bm.eraseArea(area, gRec[i].fInColor);
  41. SkColor c = bm.getColor(1, 1);
  42. REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
  43. }
  44. }