diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/colorspaceinfo.cpp | 6 | ||||
-rw-r--r-- | tools/get_images_from_skps.cpp | 16 | ||||
-rw-r--r-- | tools/imgblur.cpp | 2 | ||||
-rw-r--r-- | tools/picture_utils.cpp | 4 | ||||
-rw-r--r-- | tools/sk_tool_utils.h | 25 | ||||
-rw-r--r-- | tools/skdiff/skdiff_utils.cpp | 5 | ||||
-rw-r--r-- | tools/skiaserve/Request.cpp | 3 |
7 files changed, 46 insertions, 15 deletions
diff --git a/tools/colorspaceinfo.cpp b/tools/colorspaceinfo.cpp index 301f47dc5a..945c4a5fca 100644 --- a/tools/colorspaceinfo.cpp +++ b/tools/colorspaceinfo.cpp @@ -17,6 +17,8 @@ #include "SkMatrix44.h" #include "SkOSFile.h" +#include "sk_tool_utils.h" + __SK_FORCE_IMAGE_DECODER_LINKING; DEFINE_string(input, "input.png", "A path to the input image or icc profile."); @@ -219,7 +221,7 @@ int main(int argc, char** argv) { } // Finally, encode the result to the output file. - sk_sp<SkData> out(SkImageEncoder::EncodeData(gamut, SkImageEncoder::kPNG_Type, 100)); + sk_sp<SkData> out = sk_tool_utils::EncodeImageToData(gamut, SkEncodedImageFormat::kPNG, 100); if (!out) { SkDebugf("Failed to encode gamut output.\n"); return -1; @@ -243,7 +245,7 @@ int main(int argc, char** argv) { SkDebugf("Could not decode input image.\n"); return -1; } - out.reset(SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100)); + out = sk_tool_utils::EncodeImageToData(bitmap, SkEncodedImageFormat::kPNG, 100); if (!out) { SkDebugf("Failed to encode uncorrected image.\n"); return -1; diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp index 6cd35122ad..d3a2343b88 100644 --- a/tools/get_images_from_skps.cpp +++ b/tools/get_images_from_skps.cpp @@ -65,14 +65,14 @@ struct Sniffer : public SkPixelSerializer { } SkString ext; switch (codec->getEncodedFormat()) { - case SkEncodedFormat::kBMP_SkEncodedFormat: ext = "bmp"; break; - case SkEncodedFormat::kGIF_SkEncodedFormat: ext = "gif"; break; - case SkEncodedFormat::kICO_SkEncodedFormat: ext = "ico"; break; - case SkEncodedFormat::kJPEG_SkEncodedFormat: ext = "jpg"; break; - case SkEncodedFormat::kPNG_SkEncodedFormat: ext = "png"; break; - case SkEncodedFormat::kDNG_SkEncodedFormat: ext = "dng"; break; - case SkEncodedFormat::kWBMP_SkEncodedFormat: ext = "wbmp"; break; - case SkEncodedFormat::kWEBP_SkEncodedFormat: ext = "webp"; break; + case SkEncodedImageFormat::kBMP: ext = "bmp"; break; + case SkEncodedImageFormat::kGIF: ext = "gif"; break; + case SkEncodedImageFormat::kICO: ext = "ico"; break; + case SkEncodedImageFormat::kJPEG: ext = "jpg"; break; + case SkEncodedImageFormat::kPNG: ext = "png"; break; + case SkEncodedImageFormat::kDNG: ext = "dng"; break; + case SkEncodedImageFormat::kWBMP: ext = "wbmp"; break; + case SkEncodedImageFormat::kWEBP: ext = "webp"; break; default: // This should be unreachable because we cannot create a codec if we do not know // the image type. diff --git a/tools/imgblur.cpp b/tools/imgblur.cpp index 3a0ae00f3b..28d8447ef0 100644 --- a/tools/imgblur.cpp +++ b/tools/imgblur.cpp @@ -66,7 +66,7 @@ int tool_main(int argc, char** argv) { SkBitmap dst = sk_tool_utils::slow_blur(src, (float) FLAGS_sigma); - if (!SkImageEncoder::EncodeFile(FLAGS_out[0], dst, SkImageEncoder::kPNG_Type, 100)) { + if (!sk_tool_utils::EncodeImageToFile(FLAGS_out[0], dst, SkEncodedImageFormat::kPNG, 100)) { if (!FLAGS_quiet) { SkDebugf("Couldn't write to file: %s\n", FLAGS_out[0]); } diff --git a/tools/picture_utils.cpp b/tools/picture_utils.cpp index 43ca2f07bf..84925b4dad 100644 --- a/tools/picture_utils.cpp +++ b/tools/picture_utils.cpp @@ -17,6 +17,8 @@ #include "SkStream.h" #include "SkString.h" +#include "sk_tool_utils.h" + namespace sk_tools { void force_all_opaque(const SkBitmap& bitmap) { SkASSERT(kN32_SkColorType == bitmap.colorType()); @@ -63,7 +65,7 @@ namespace sk_tools { partialPath.set(dirPath); } SkString fullPath = SkOSPath::Join(partialPath.c_str(), baseName.c_str()); - if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPNG_Type, 100)) { + if (sk_tool_utils::EncodeImageToFile(fullPath.c_str(), bm, SkEncodedImageFormat::kPNG, 100)) { return true; } else { SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str()); diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h index c6abbcf7c2..526f0ef505 100644 --- a/tools/sk_tool_utils.h +++ b/tools/sk_tool_utils.h @@ -225,6 +225,31 @@ namespace sk_tool_utils { SkTDArray<TopoTestNode*> fDependencies; }; + template <typename T> + inline bool EncodeImageToFile(const char* path, const T& src, SkEncodedImageFormat f, int q) { + SkFILEWStream file(path); + return file.isValid() && SkEncodeImage(&file, src, f, q); + } + + template <typename T> + inline sk_sp<SkData> EncodeImageToData(const T& src, SkEncodedImageFormat f, int q) { + SkDynamicMemoryWStream buf; + return SkEncodeImage(&buf, src , f, q) ? buf.detachAsData() : nullptr; + } + + /** + * Uses SkEncodeImage to serialize images that are not already + * encoded as SkEncodedImageFormat::kPNG images. + */ + inline sk_sp<SkPixelSerializer> MakePixelSerializer() { + struct EncodeImagePixelSerializer final : SkPixelSerializer { + bool onUseEncodedData(const void*, size_t) override { return true; } + SkData* onEncode(const SkPixmap& pmap) override { + return EncodeImageToData(pmap, SkEncodedImageFormat::kPNG, 100).release(); + } + }; + return sk_make_sp<EncodeImagePixelSerializer>(); + } } // namespace sk_tool_utils #endif // sk_tool_utils_DEFINED diff --git a/tools/skdiff/skdiff_utils.cpp b/tools/skdiff/skdiff_utils.cpp index f788ec8cef..f8eed908b7 100644 --- a/tools/skdiff/skdiff_utils.cpp +++ b/tools/skdiff/skdiff_utils.cpp @@ -6,6 +6,7 @@ */ #include "skdiff.h" #include "skdiff_utils.h" +#include "sk_tool_utils.h" #include "SkBitmap.h" #include "SkCodec.h" #include "SkData.h" @@ -82,8 +83,8 @@ bool write_bitmap(const SkString& path, const SkBitmap& bitmap) { SkBitmap copy; bitmap.copyTo(©, kN32_SkColorType); force_all_opaque(copy); - return SkImageEncoder::EncodeFile(path.c_str(), copy, - SkImageEncoder::kPNG_Type, 100); + return sk_tool_utils::EncodeImageToFile(path.c_str(), copy, + SkEncodedImageFormat::kPNG, 100); } /// Return a copy of the "input" string, within which we have replaced all instances diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp index c1b3b25cdd..2064a464f0 100644 --- a/tools/skiaserve/Request.cpp +++ b/tools/skiaserve/Request.cpp @@ -11,6 +11,7 @@ #include "SkPixelSerializer.h" #include "SkPM4fPriv.h" #include "picture_utils.h" +#include "sk_tool_utils.h" using namespace sk_gpu_test; @@ -117,7 +118,7 @@ sk_sp<SkData> Request::writeOutSkp() { SkDynamicMemoryWStream outStream; - sk_sp<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerializer()); + sk_sp<SkPixelSerializer> serializer = sk_tool_utils::MakePixelSerializer(); picture->serialize(&outStream, serializer.get()); return outStream.detachAsData(); |