blob: a5fcf7c96898cdcc178849025d2d98a4f5481639 [file] [log] [blame]
twiz@google.com6cf53032012-06-22 18:55:55 +00001/*
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.com6cf53032012-06-22 18:55:55 +000010
11class SkBitmap;
borenet@google.come21795e2012-09-14 14:34:28 +000012class SkString;
twiz@google.com6cf53032012-06-22 18:55:55 +000013
14namespace sk_tools {
keyar@chromium.org9299ede2012-08-21 19:05:08 +000015 // 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
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000023 /**
24 * Replaces all instances of oldChar with newChar in str.
25 *
26 * TODO: This function appears here and in skimage_main.cpp ;
27 * we should add the implementation to src/core/SkString.cpp, write tests for it,
28 * and remove it from elsewhere.
29 */
30 void replace_char(SkString* str, const char oldChar, const char newChar);
31
keyar@chromium.org163b5672012-08-01 17:53:29 +000032 // Returns true if the string ends with %
scroggo@google.com58b4ead2012-08-31 16:15:22 +000033 bool is_percentage(const char* const string);
keyar@chromium.org163b5672012-08-01 17:53:29 +000034
twiz@google.com6cf53032012-06-22 18:55:55 +000035 // Prepares the bitmap so that it can be written.
36 //
37 // Specifically, it configures the bitmap, allocates pixels and then
38 // erases the pixels to transparent black.
39 void setup_bitmap(SkBitmap* bitmap, int width, int height);
commit-bot@chromium.org3f045172014-05-15 15:10:48 +000040
41 /**
42 * Write a bitmap file to disk.
43 *
44 * @param bm the bitmap to record
45 * @param dirPath directory within which to write the image file
46 * @param subdirOrNull subdirectory within dirPath, or NULL to just write into dirPath
47 * @param baseName last part of the filename
48 *
49 * @return true if written out successfully
50 */
51 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath,
52 const char *subdirOrNull, const SkString& baseName);
53
54} // namespace sk_tools
twiz@google.com6cf53032012-06-22 18:55:55 +000055
56#endif // picture_utils_DEFINED