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" |
| 12 | #include "SkSize.h" |
| 13 | |
| 14 | template <typename T> class SkAutoTUnref; |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 15 | class SkBitmap; |
| 16 | class SkFILEStream; |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 17 | class SkPicture; |
borenet@google.com | e21795e | 2012-09-14 14:34:28 +0000 | [diff] [blame^] | 18 | class SkString; |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 19 | |
| 20 | namespace sk_tools { |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 21 | // since PNG insists on unpremultiplying our alpha, we take no precision |
| 22 | // chances and force all pixels to be 100% opaque, otherwise on compare we |
| 23 | // may not get a perfect match. |
| 24 | // |
| 25 | // This expects a bitmap with a config type of 8888 and for the pixels to |
| 26 | // not be on the GPU. |
| 27 | void force_all_opaque(const SkBitmap& bitmap); |
| 28 | |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 29 | // Creates a posix style filepath by concatenating name onto dir with a |
| 30 | // forward slash into path. |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 31 | void make_filepath(SkString* path, const SkString&, const SkString& name); |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 32 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 33 | // Returns the last part of the path (file name or leaf directory name) |
| 34 | // |
| 35 | // This basically just looks for a foward slash or backslash (windows |
keyar@chromium.org | 9299ede | 2012-08-21 19:05:08 +0000 | [diff] [blame] | 36 | // only). |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 37 | void get_basename(SkString* basename, const SkString& path); |
| 38 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 39 | // Returns true if the string ends with % |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 40 | bool is_percentage(const char* const string); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 41 | |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 42 | // Prepares the bitmap so that it can be written. |
| 43 | // |
| 44 | // Specifically, it configures the bitmap, allocates pixels and then |
| 45 | // erases the pixels to transparent black. |
| 46 | void setup_bitmap(SkBitmap* bitmap, int width, int height); |
borenet@google.com | e21795e | 2012-09-14 14:34:28 +0000 | [diff] [blame^] | 47 | |
| 48 | // Determines whether the given dimensions are too large and suggests a new |
| 49 | // size. |
| 50 | bool area_too_big(int w, int h, SkISize* newSize); |
| 51 | |
| 52 | // Determines whether the given SkPicture is too large and, if so, replaces |
| 53 | // it with a new, scaled-down SkPicture. |
| 54 | void resize_if_needed(SkAutoTUnref<SkPicture>* aur); |
twiz@google.com | 6cf5303 | 2012-06-22 18:55:55 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | #endif // picture_utils_DEFINED |