port ok to SkPngEncoder
I can't tell you how excited I am to turn down the libpng settings... anything that saves me a few seconds is a nice quality of life win. This CL makes ok run in about half the time when producing .pngs. Profile running `ok gm srgb png` before: 10.59 s 16.5% 10.59 s longest_match 8.98 s 14.0% 8.98 s png_setup_paeth_row 8.93 s 13.9% 8.93 s skia_png_write_find_filter 7.75 s 12.1% 7.75 s deflate_slow 4.63 s 7.2% 4.63 s std::wait_until(...) const 959.00 ms 1.5% 959.00 ms SkPathRef::validate() const 935.00 ms 1.4% 935.00 ms sk_to_srgb_hsw ... After: 2.35 s 8.7% 2.35 s std::wait_until(...) const 1.70 s 6.2% 1.70 s longest_match 1.19 s 4.4% 1.19 s deflate_fast 931.00 ms 3.4% 931.00 ms SkPathRef::validate() const 898.00 ms 3.3% 898.00 ms sk_to_srgb_hsw ... Change-Id: I425c30b2ecd97a0e4a4392779de6301db473ee47 Reviewed-on: https://skia-review.googlesource.com/15547 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Matt Sarett <msarett@google.com>
This commit is contained in:
parent
ee06ffe455
commit
39748b2771
@ -8,6 +8,7 @@
|
||||
#include "SkImage.h"
|
||||
#include "SkOSFile.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
#include "SkPngEncoder.h"
|
||||
#include "ok.h"
|
||||
#include <regex>
|
||||
|
||||
@ -75,13 +76,23 @@ struct Png : Dst {
|
||||
return status;
|
||||
}
|
||||
|
||||
auto image = target->image();
|
||||
sk_sp<SkData> png{image->encode()};
|
||||
SkBitmap bm;
|
||||
SkPixmap pm;
|
||||
if (!target->image()->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode) ||
|
||||
!bm.peekPixels(&pm)) {
|
||||
return Status::Failed;
|
||||
}
|
||||
|
||||
sk_mkdir(dir.c_str());
|
||||
SkFILEWStream{(dir + "/" + src->name() + ".png").c_str()}
|
||||
.write(png->data(), png->size());
|
||||
return Status::OK;
|
||||
SkFILEWStream dst{(dir + "/" + src->name() + ".png").c_str()};
|
||||
|
||||
SkPngEncoder::Options options;
|
||||
options.fFilterFlags = SkPngEncoder::FilterFlag::kNone;
|
||||
options.fZLibLevel = 1;
|
||||
options.fUnpremulBehavior = pm.colorSpace() ? SkTransferFunctionBehavior::kRespect
|
||||
: SkTransferFunctionBehavior::kIgnore;
|
||||
return SkPngEncoder::Encode(&dst, pm, options) ? Status::OK
|
||||
: Status::Failed;
|
||||
}
|
||||
|
||||
sk_sp<SkImage> image() override {
|
||||
|
Loading…
Reference in New Issue
Block a user