Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(983)

Unified Diff: dm/DM.cpp

Issue 1901113002: Move DM png code to picture_utils, for use by other tools. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move to picture_utils. Better fit, fewer dependencies when adding to skiaserve Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/dm.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DM.cpp
diff --git a/dm/DM.cpp b/dm/DM.cpp
index ecf231ed63b73bc378b36b6f7096765cb1035228..58cb773e032a5f1bb9182dc3db4b0b08043fb8c6 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -17,6 +17,7 @@
#include "SkColorPriv.h"
#include "SkCommonFlags.h"
#include "SkCommonFlagsConfig.h"
+#include "SkData.h"
#include "SkFontMgr.h"
#include "SkGraphics.h"
#include "SkHalf.h"
@@ -30,6 +31,7 @@
#include "SkThreadUtils.h"
#include "Test.h"
#include "Timer.h"
+#include "picture_utils.h"
#include "sk_tool_utils.h"
#ifdef SK_PDF_IMAGE_STATS
@@ -924,72 +926,12 @@ static void gather_sinks() {
static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
const int w = bitmap.width(),
h = bitmap.height();
- // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine too).
- // We leave the gamma of these bytes unspecified, to continue the status quo,
- // which we think generally is to interpret them as sRGB.
-
- SkAutoTMalloc<uint32_t> rgba(w*h);
-
- if (bitmap. colorType() == kN32_SkColorType &&
- bitmap.profileType() == kSRGB_SkColorProfileType) {
- // These are premul sRGB 8-bit pixels in SkPMColor order.
- // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats.
- bitmap.lockPixels();
- auto px = (const uint32_t*)bitmap.getPixels();
- if (!px) {
- return false;
- }
- for (int i = 0; i < w*h; i++) {
- Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear floats.
- #if defined(SK_PMCOLOR_IS_BGRA)
- fs = SkNx_shuffle<2,1,0,3>(fs); // Shuffle to RGBA, if not there already.
- #endif
- float invA = 1.0f / fs[3];
- fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply.
- rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes.
- }
-
- } else if (bitmap.colorType() == kRGBA_F16_SkColorType) {
- // These are premul linear half-float pixels in RGBA order.
- // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats.
- bitmap.lockPixels();
- auto px = (const uint64_t*)bitmap.getPixels();
- if (!px) {
- return false;
- }
- for (int i = 0; i < w*h; i++) {
- // Convert up to linear floats.
- Sk4f fs(SkHalfToFloat(static_cast<SkHalf>(px[i] >> (0 * 16))),
- SkHalfToFloat(static_cast<SkHalf>(px[i] >> (1 * 16))),
- SkHalfToFloat(static_cast<SkHalf>(px[i] >> (2 * 16))),
- SkHalfToFloat(static_cast<SkHalf>(px[i] >> (3 * 16))));
- fs = Sk4f::Max(0.0f, Sk4f::Min(fs, 1.0f)); // Clamp
- float invA = 1.0f / fs[3];
- fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply.
- rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes.
- }
-
- } else {
- // We "should" gamma correct in here but we don't.
- // We want Gold to show exactly what our clients are seeing, broken gamma.
-
- // Convert smaller formats up to premul linear 8-bit (in SkPMColor order).
- if (bitmap.colorType() != kN32_SkColorType) {
- SkBitmap n32;
- if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
- return false;
- }
- bitmap = n32;
- }
-
- // Convert premul linear 8-bit to unpremul linear 8-bit RGBA.
- if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType,
- kUnpremul_SkAlphaType),
- rgba, 4*w, 0,0)) {
- return false;
- }
+ sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(bitmap);
+ if (encodedBitmap.get() == nullptr) {
+ return false;
}
+ uint32_t* rgba = static_cast<uint32_t*>(encodedBitmap.get()->writable_data());
// We don't need bitmap anymore. Might as well drop our ref.
bitmap.reset();
@@ -1036,7 +978,7 @@ static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png, info);
for (int j = 0; j < h; j++) {
- png_bytep row = (png_bytep)(rgba.get() + w*j);
+ png_bytep row = (png_bytep)(rgba + w*j);
png_write_rows(png, &row, 1);
}
png_write_end(png, info);
« no previous file with comments | « no previous file | gyp/dm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698