orientation.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright 2018 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 "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkImage.h"
  10. #include "include/core/SkRefCnt.h"
  11. #include "include/core/SkString.h"
  12. #include "tools/Resources.h"
  13. // This gm draws 8 images that are mostly the same when respecting the
  14. // EXIF orientation tag. Each one has four quadrants (red, blue, green,
  15. // yellow), and labels on the left, top, right and bottom. The only
  16. // visual difference is a number in the middle corresponding to the
  17. // EXIF tag for that image's jpg file.
  18. DEF_SIMPLE_GM(orientation, canvas, 400, 320) {
  19. canvas->save();
  20. for (char i = '1'; i <= '8'; i++) {
  21. SkString path = SkStringPrintf("images/orientation/%c.jpg", i);
  22. auto image = GetResourceAsImage(path.c_str());
  23. if (!image) {
  24. continue;
  25. }
  26. canvas->drawImage(image, 0, 0);
  27. if ('4' == i) {
  28. canvas->restore();
  29. canvas->translate(0, image->height());
  30. } else {
  31. canvas->translate(image->width(), 0);
  32. }
  33. }
  34. }