diff --git a/public.bzl b/public.bzl index abe0045aec..eeb918f13c 100644 --- a/public.bzl +++ b/public.bzl @@ -473,7 +473,6 @@ DM_SRCS_ALL = struct( "tools/gpu/**/*.h", "tools/random_parse_path.cpp", "tools/random_parse_path.h", - "tools/sk_pixel_iter.h", "tools/ToolUtils.cpp", "tools/ToolUtils.h", "tools/timer/*.cpp", diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp index 963f23626a..40a911a232 100644 --- a/tests/BlurTest.cpp +++ b/tests/BlurTest.cpp @@ -38,7 +38,7 @@ #include "SkSurface.h" #include "SkTypes.h" #include "Test.h" -#include "sk_pixel_iter.h" +#include "ToolUtils.h" #include "GrContextFactory.h" diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index e97d36d473..cafc06cac9 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -30,7 +30,6 @@ #include "Resources.h" #include "ToolUtils.h" -#include "sk_pixel_iter.h" #include "GrContextPriv.h" #include "GrContextThreadSafeProxy.h" diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp index 52c2f33287..27cc0a1677 100644 --- a/tests/VerticesTest.cpp +++ b/tests/VerticesTest.cpp @@ -8,8 +8,8 @@ #include "SkCanvas.h" #include "SkSurface.h" #include "SkVertices.h" -#include "sk_pixel_iter.h" #include "Test.h" +#include "ToolUtils.h" static bool equal(const SkVertices* v0, const SkVertices* v1) { if (v0->mode() != v1->mode()) { diff --git a/tools/ToolUtils.h b/tools/ToolUtils.h index e236abbde5..f01244821b 100644 --- a/tools/ToolUtils.h +++ b/tools/ToolUtils.h @@ -16,11 +16,13 @@ #include "SkFontTypes.h" #include "SkImageEncoder.h" #include "SkImageInfo.h" +#include "SkPixmap.h" #include "SkRandom.h" #include "SkRect.h" #include "SkRefCnt.h" #include "SkScalar.h" #include "SkStream.h" +#include "SkSurface.h" #include "SkTArray.h" #include "SkTDArray.h" #include "SkTypeface.h" @@ -229,6 +231,48 @@ inline bool EncodeImageToFile(const char* path, const T& src, SkEncodedImageForm bool copy_to(SkBitmap* dst, SkColorType dstCT, const SkBitmap& src); void copy_to_g8(SkBitmap* dst, const SkBitmap& src); + +class PixelIter { +public: + PixelIter(); + PixelIter(SkSurface* surf) { + SkPixmap pm; + if (!surf->peekPixels(&pm)) { + pm.reset(); + } + this->reset(pm); + } + + void reset(const SkPixmap& pm) { + fPM = pm; + fLoc = {-1, 0}; + } + + void* next(SkIPoint* loc = nullptr) { + if (!fPM.addr()) { + return nullptr; + } + fLoc.fX += 1; + if (fLoc.fX >= fPM.width()) { + fLoc.fX = 0; + if (++fLoc.fY >= fPM.height()) { + this->setDone(); + return nullptr; + } + } + if (loc) { + *loc = fLoc; + } + return fPM.writable_addr(fLoc.fX, fLoc.fY); + } + + void setDone() { fPM.reset(); } + +private: + SkPixmap fPM; + SkIPoint fLoc; +}; + } // namespace ToolUtils #endif // ToolUtils_DEFINED diff --git a/tools/sk_pixel_iter.h b/tools/sk_pixel_iter.h deleted file mode 100644 index d84ebbbe19..0000000000 --- a/tools/sk_pixel_iter.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef sk_pixel_iter_DEFINED -#define sk_pixel_iter_DEFINED - -#include "SkPixmap.h" -#include "SkSurface.h" - -namespace ToolUtils { - -class PixelIter { -public: - PixelIter(); - PixelIter(SkSurface* surf) { - SkPixmap pm; - if (!surf->peekPixels(&pm)) { - pm.reset(); - } - this->reset(pm); - } - - void reset(const SkPixmap& pm) { - fPM = pm; - fLoc = {-1, 0}; - } - - void* next(SkIPoint* loc = nullptr) { - if (!fPM.addr()) { - return nullptr; - } - fLoc.fX += 1; - if (fLoc.fX >= fPM.width()) { - fLoc.fX = 0; - if (++fLoc.fY >= fPM.height()) { - this->setDone(); - return nullptr; - } - } - if (loc) { - *loc = fLoc; - } - return fPM.writable_addr(fLoc.fX, fLoc.fY); - } - - void setDone() { fPM.reset(); } - -private: - SkPixmap fPM; - SkIPoint fLoc; -}; - -} // namespace ToolUtils - -#endif // ToolUtils_DEFINED