Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: include/core/SkBitmap.h

Issue 143073008: add installPixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | include/core/SkMallocPixelRef.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkBitmap_DEFINED 8 #ifndef SkBitmap_DEFINED
9 #define SkBitmap_DEFINED 9 #define SkBitmap_DEFINED
10 10
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkColorTable.h" 12 #include "SkColorTable.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 #include "SkPoint.h" 14 #include "SkPoint.h"
15 #include "SkRefCnt.h" 15 #include "SkRefCnt.h"
16 16
17 struct SkIRect; 17 struct SkIRect;
18 struct SkRect; 18 struct SkRect;
19 class SkPaint; 19 class SkPaint;
20 class SkPixelRef; 20 class SkPixelRef;
21 class SkPixelRefFactory;
21 class SkRegion; 22 class SkRegion;
22 class SkString; 23 class SkString;
23 24
24 class GrTexture; 25 class GrTexture;
25 26
26 /** \class SkBitmap 27 /** \class SkBitmap
27 28
28 The SkBitmap class specifies a raster bitmap. A bitmap has an integer width 29 The SkBitmap class specifies a raster bitmap. A bitmap has an integer width
29 and height, and a format (config), and a pointer to the actual pixels. 30 and height, and a format (config), and a pointer to the actual pixels.
30 Bitmaps can be drawn into a SkCanvas, but they are also used to specify the 31 Bitmaps can be drawn into a SkCanvas, but they are also used to specify the
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); 244 bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType);
244 245
245 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { 246 bool setConfig(Config config, int width, int height, size_t rowBytes = 0) {
246 return this->setConfig(config, width, height, rowBytes, 247 return this->setConfig(config, width, height, rowBytes,
247 kPremul_SkAlphaType); 248 kPremul_SkAlphaType);
248 } 249 }
249 250
250 bool setConfig(const SkImageInfo& info, size_t rowBytes = 0); 251 bool setConfig(const SkImageInfo& info, size_t rowBytes = 0);
251 252
252 /** 253 /**
254 * Allocate a pixelref to match the specified image info. If the Factory
255 * is non-null, call it to allcoate the pixelref. If the ImageInfo requires
256 * a colortable, then ColorTable must be non-null, and will be ref'd.
257 * On failure, the bitmap will be set to empty and return false.
258 */
259 bool allocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*);
260
261 /**
262 * Allocate a pixelref to match the specified image info, using the default
263 * allocator.
264 * On success, the bitmap's pixels will be "locked", and return true.
265 * On failure, the bitmap will be set to empty and return false.
266 */
267 bool allocPixels(const SkImageInfo& info) {
268 return this->allocPixels(info, NULL, NULL);
269 }
270
271 /**
272 * Install a pixelref that wraps the specified pixels and rowBytes, and
273 * optional ReleaseProc and context. When the pixels are no longer
274 * referenced, if ReleaseProc is not null, it will be called with the
275 * pixels and context as parameters.
276 * On failure, the bitmap will be set to empty and return false.
277 */
278 bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes,
279 void (*ReleaseProc)(void* addr, void* context),
280 void* context);
281
282 /**
253 * If the bitmap's config can be represented as SkImageInfo, return true, 283 * If the bitmap's config can be represented as SkImageInfo, return true,
254 * and if info is not-null, set it to the bitmap's info. If it cannot be 284 * and if info is not-null, set it to the bitmap's info. If it cannot be
255 * represented as SkImageInfo, return false and ignore the info parameter. 285 * represented as SkImageInfo, return false and ignore the info parameter.
256 */ 286 */
257 bool asImageInfo(SkImageInfo* info) const; 287 bool asImageInfo(SkImageInfo* info) const;
258 288
259 /** Use this to assign a new pixel address for an existing bitmap. This 289 /** Use this to assign a new pixel address for an existing bitmap. This
260 will automatically release any pixelref previously installed. Only call 290 will automatically release any pixelref previously installed. Only call
261 this if you are handling ownership/lifetime of the pixel memory. 291 this if you are handling ownership/lifetime of the pixel memory.
262 292
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 private: 660 private:
631 typedef SkRefCnt INHERITED; 661 typedef SkRefCnt INHERITED;
632 }; 662 };
633 663
634 /** Subclass of Allocator that returns a pixelref that allocates its pixel 664 /** Subclass of Allocator that returns a pixelref that allocates its pixel
635 memory from the heap. This is the default Allocator invoked by 665 memory from the heap. This is the default Allocator invoked by
636 allocPixels(). 666 allocPixels().
637 */ 667 */
638 class HeapAllocator : public Allocator { 668 class HeapAllocator : public Allocator {
639 public: 669 public:
640 virtual bool allocPixelRef(SkBitmap*, SkColorTable*); 670 virtual bool allocPixelRef(SkBitmap*, SkColorTable*) SK_OVERRIDE;
641 }; 671 };
642 672
643 class RLEPixels { 673 class RLEPixels {
644 public: 674 public:
645 RLEPixels(int width, int height); 675 RLEPixels(int width, int height);
646 virtual ~RLEPixels(); 676 virtual ~RLEPixels();
647 677
648 uint8_t* packedAtY(int y) const { 678 uint8_t* packedAtY(int y) const {
649 SkASSERT((unsigned)y < (unsigned)fHeight); 679 SkASSERT((unsigned)y < (unsigned)fHeight);
650 return fYPtrs[y]; 680 return fYPtrs[y];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 857
828 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { 858 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const {
829 SkASSERT(fPixels); 859 SkASSERT(fPixels);
830 SkASSERT(fConfig == kIndex8_Config); 860 SkASSERT(fConfig == kIndex8_Config);
831 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); 861 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight);
832 SkASSERT(fColorTable); 862 SkASSERT(fColorTable);
833 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; 863 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)];
834 } 864 }
835 865
836 #endif 866 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkMallocPixelRef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698