skia2/tools/skqp/make_skqp_model.cpp
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

83 lines
3.0 KiB
C++

// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "include/codec/SkCodec.h"
#include "include/core/SkBitmap.h"
#include "include/encode/SkPngEncoder.h"
#include "src/core/SkOSFile.h"
static void update(SkBitmap* maxBitmap, SkBitmap* minBitmap, const SkBitmap& bm) {
SkASSERT(!bm.drawsNothing());
SkASSERT(4 == bm.bytesPerPixel());
if (maxBitmap->drawsNothing()) {
maxBitmap->allocPixels(bm.info());
maxBitmap->eraseColor(0x00000000);
minBitmap->allocPixels(bm.info());
minBitmap->eraseColor(0xFFFFFFFF);
}
SkASSERT_RELEASE(maxBitmap->info() == bm.info());
const SkPixmap& pmin = minBitmap->pixmap();
const SkPixmap& pmax = maxBitmap->pixmap();
const SkPixmap& pm = bm.pixmap();
for (int y = 0; y < pm.height(); ++y) {
for (int x = 0; x < pm.width(); ++x) {
uint32_t* minPtr = pmin.writable_addr32(x, y);
uint32_t* maxPtr = pmax.writable_addr32(x, y);
uint8_t minColor[4], maxColor[4], color[4];
memcpy(minColor, minPtr, 4);
memcpy(maxColor, maxPtr, 4);
memcpy(color, pm.addr32(x, y), 4);
for (unsigned i = 0; i < 4; ++i) {
minColor[i] = std::min(minColor[i], color[i]);
maxColor[i] = std::max(maxColor[i], color[i]);
}
memcpy(minPtr, minColor, 4);
memcpy(maxPtr, maxColor, 4);
}
}
}
static SkBitmap decode_to_srgb_8888_unpremul(const char* path) {
SkBitmap dst;
if (auto codec = SkCodec::MakeFromData(SkData::MakeFromFileName(path))) {
SkISize size = codec->getInfo().dimensions();
SkASSERT(!size.isEmpty());
dst.allocPixels(SkImageInfo::Make(
size.width(), size.height(), kRGBA_8888_SkColorType,
kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()));
if (SkCodec::kSuccess != codec->getPixels(dst.pixmap())) {
dst.reset();
}
}
return dst;
}
bool encode_png(const char* path, const SkPixmap& pixmap) {
if (!pixmap.addr()) {
return false;
}
SkPngEncoder::Options encOpts;
encOpts.fZLibLevel = 9; // slow encode;
SkFILEWStream o(path);
return o.isValid() && SkPngEncoder::Encode(&o, pixmap, encOpts);
}
int main(int argc, char** argv) {
SkASSERT_RELEASE(argc > 2);
const char* src_dir = argv[1];
const char* dst_dir = argv[2];
SkBitmap maxBitmap, minBitmap;
SkOSFile::Iter iter(src_dir);
SkString name;
while (iter.next(&name)) {
name.prependf("%s/", src_dir);
SkBitmap bm = decode_to_srgb_8888_unpremul(name.c_str());
if (!bm.drawsNothing()) {
update(&maxBitmap, &minBitmap, bm);
}
}
SkASSERT_RELEASE(sk_mkdir(dst_dir));
encode_png(SkStringPrintf("%s/min.png", dst_dir).c_str(), minBitmap.pixmap());
encode_png(SkStringPrintf("%s/max.png", dst_dir).c_str(), maxBitmap.pixmap());
}