twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef picture_utils_DEFINED |
| 9 | #define picture_utils_DEFINED |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 10 | |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 11 | #include "SkBitmap.h" |
| 12 | |
| 13 | class SkData; |
borenet@google.com | e21795e | 2012-09-14 14:34:28 +0000 | [diff] [blame] | 14 | class SkString; |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 15 | |
| 16 | namespace sk_tools { |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 17 | // since PNG insists on unpremultiplying our alpha, we take no precision |
| 18 | // chances and force all pixels to be 100% opaque, otherwise on compare we |
| 19 | // may not get a perfect match. |
| 20 | // |
| 21 | // This expects a bitmap with a config type of 8888 and for the pixels to |
| 22 | // not be on the GPU. |
| 23 | void force_all_opaque(const SkBitmap& bitmap); |
| 24 | |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Replaces all instances of oldChar with newChar in str. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 27 | */ |
| 28 | void replace_char(SkString* str, const char oldChar, const char newChar); |
| 29 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 30 | // Returns true if the string ends with % |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 31 | bool is_percentage(const char* const string); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 32 | |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 33 | // Prepares the bitmap so that it can be written. |
| 34 | // |
| 35 | // Specifically, it configures the bitmap, allocates pixels and then |
| 36 | // erases the pixels to transparent black. |
| 37 | void setup_bitmap(SkBitmap* bitmap, int width, int height); |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Write a bitmap file to disk. |
| 41 | * |
| 42 | * @param bm the bitmap to record |
| 43 | * @param dirPath directory within which to write the image file |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 44 | * @param subdirOrNull subdirectory within dirPath, or nullptr to just write into dirPath |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 45 | * @param baseName last part of the filename |
| 46 | * |
| 47 | * @return true if written out successfully |
| 48 | */ |
| 49 | bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, |
| 50 | const char *subdirOrNull, const SkString& baseName); |
| 51 | |
brianosman | 3c579dc | 2016-04-19 09:18:11 -0700 | [diff] [blame] | 52 | // Return raw unpremultiplied RGBA bytes, suitable for storing in a PNG. The output |
| 53 | // colors are assumed to be sRGB values. This is only guaranteed to work for the |
| 54 | // cases that are currently emitted by tools: |
| 55 | // Linear premul 8888, sRGB premul 8888, Linear premul F16 |
| 56 | sk_sp<SkData> encode_bitmap_for_png(SkBitmap bitmap); |
| 57 | |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 58 | } // namespace sk_tools |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 59 | |
| 60 | #endif // picture_utils_DEFINED |