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 10 11 class SkBitmap; 12 class SkString; 13 14 namespace sk_tools { 15 // since PNG insists on unpremultiplying our alpha, we take no precision 16 // chances and force all pixels to be 100% opaque, otherwise on compare we 17 // may not get a perfect match. 18 // 19 // This expects a bitmap with a config type of 8888 and for the pixels to 20 // not be on the GPU. 21 void force_all_opaque(const SkBitmap& bitmap); 22 23 /** 24 * Replaces all instances of oldChar with newChar in str. 25 */ 26 void replace_char(SkString* str, const char oldChar, const char newChar); 27 28 // Returns true if the string ends with % 29 bool is_percentage(const char* const string); 30 31 // Prepares the bitmap so that it can be written. 32 // 33 // Specifically, it configures the bitmap, allocates pixels and then 34 // erases the pixels to transparent black. 35 void setup_bitmap(SkBitmap* bitmap, int width, int height); 36 37 /** 38 * Write a bitmap file to disk. 39 * 40 * @param bm the bitmap to record 41 * @param dirPath directory within which to write the image file 42 * @param subdirOrNull subdirectory within dirPath, or nullptr to just write into dirPath 43 * @param baseName last part of the filename 44 * 45 * @return true if written out successfully 46 */ 47 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, 48 const char *subdirOrNull, const SkString& baseName); 49 50 } // namespace sk_tools 51 52 #endif // picture_utils_DEFINED 53