1 /* 2 * Copyright 2011 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 SkImageEncoder_DEFINED 9 #define SkImageEncoder_DEFINED 10 11 #include "SkBitmap.h" 12 #include "SkEncodedImageFormat.h" 13 #include "SkStream.h" 14 15 /** 16 * Encode SkPixmap in the given binary image format. 17 * 18 * @param dst results are written to this stream. 19 * @param src source pixels. 20 * @param format image format, not all formats are supported. 21 * @param quality range from 0-100, not all formats respect quality. 22 * 23 * @return false iff input is bad or format is unsupported. 24 * 25 * Will always return false if Skia is compiled without image 26 * encoders. 27 * 28 * For examples of encoding an image to a file or to a block of memory, 29 * see tools/sk_tool_utils.h. 30 */ 31 SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, 32 SkEncodedImageFormat format, int quality); 33 /** 34 * The following helper function wraps SkEncodeImage(). 35 */ 36 inline bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q) { 37 SkAutoLockPixels autoLockPixels(src); 38 SkPixmap pixmap; 39 return src.peekPixels(&pixmap) && SkEncodeImage(dst, pixmap, f, q); 40 } 41 42 #endif // SkImageEncoder_DEFINED 43