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 | |
borenet@google.com | e21795e | 2012-09-14 14:34:28 +0000 | [diff] [blame] | 11 | #include "SkTypes.h" |
borenet@google.com | e21795e | 2012-09-14 14:34:28 +0000 | [diff] [blame] | 12 | |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 13 | class SkBitmap; |
| 14 | class SkFILEStream; |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 15 | class SkPicture; |
borenet@google.com | e21795e | 2012-09-14 14:34:28 +0000 | [diff] [blame] | 16 | class SkString; |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 17 | |
| 18 | namespace sk_tools { |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 19 | // since PNG insists on unpremultiplying our alpha, we take no precision |
| 20 | // chances and force all pixels to be 100% opaque, otherwise on compare we |
| 21 | // may not get a perfect match. |
| 22 | // |
| 23 | // This expects a bitmap with a config type of 8888 and for the pixels to |
| 24 | // not be on the GPU. |
| 25 | void force_all_opaque(const SkBitmap& bitmap); |
| 26 | |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 27 | /** |
| 28 | * Replaces all instances of oldChar with newChar in str. |
| 29 | * |
| 30 | * TODO: This function appears here and in skimage_main.cpp ; |
| 31 | * we should add the implementation to src/core/SkString.cpp, write tests for it, |
| 32 | * and remove it from elsewhere. |
| 33 | */ |
| 34 | void replace_char(SkString* str, const char oldChar, const char newChar); |
| 35 | |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 36 | // Creates a posix style filepath by concatenating name onto dir with a |
| 37 | // forward slash into path. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 38 | // TODO(epoger): delete in favor of SkOSPath::SkPathJoin()? |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 39 | void make_filepath(SkString* path, const SkString&, const SkString& name); |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 40 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 41 | // Returns the last part of the path (file name or leaf directory name) |
| 42 | // |
| 43 | // This basically just looks for a foward slash or backslash (windows |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 44 | // only). |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 45 | // TODO(epoger): delete in favor of SkOSPath::SkBasename()? |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 46 | void get_basename(SkString* basename, const SkString& path); |
| 47 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 48 | // Returns true if the string ends with % |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 49 | bool is_percentage(const char* const string); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 50 | |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 51 | // Prepares the bitmap so that it can be written. |
| 52 | // |
| 53 | // Specifically, it configures the bitmap, allocates pixels and then |
| 54 | // erases the pixels to transparent black. |
| 55 | void setup_bitmap(SkBitmap* bitmap, int width, int height); |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Write a bitmap file to disk. |
| 59 | * |
| 60 | * @param bm the bitmap to record |
| 61 | * @param dirPath directory within which to write the image file |
| 62 | * @param subdirOrNull subdirectory within dirPath, or NULL to just write into dirPath |
| 63 | * @param baseName last part of the filename |
| 64 | * |
| 65 | * @return true if written out successfully |
| 66 | */ |
| 67 | bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, |
| 68 | const char *subdirOrNull, const SkString& baseName); |
| 69 | |
| 70 | } // namespace sk_tools |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 71 | |
| 72 | #endif // picture_utils_DEFINED |