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

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

Issue 143073008: add installPixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: new signature: PixelRefFactory to go along with installPixels 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') | src/core/SkBitmap.cpp » ('J')
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 failure, the bitmap will be set to empty and return false.
265 */
266 bool allocPixels(const SkImageInfo& info) {
267 return this->allocPixels(info, NULL, NULL);
268 }
269
270 /**
271 * Install a pixelref that wraps the specified pixels and rowBytes, and
272 * optional ReleaseProc and context. When the pixels are no longer
273 * referenced, if ReleaseProc is not null, it will be called with the
274 * pixels and context as parameters.
275 * On failure, the bitmap will be set to empty and return false.
276 */
277 bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes,
278 void (*ReleaseProc)(void* addr, void* context),
279 void* context);
280
281 /**
253 * If the bitmap's config can be represented as SkImageInfo, return true, 282 * 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 283 * 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. 284 * represented as SkImageInfo, return false and ignore the info parameter.
256 */ 285 */
257 bool asImageInfo(SkImageInfo* info) const; 286 bool asImageInfo(SkImageInfo* info) const;
258 287
259 /** Use this to assign a new pixel address for an existing bitmap. This 288 /** Use this to assign a new pixel address for an existing bitmap. This
260 will automatically release any pixelref previously installed. Only call 289 will automatically release any pixelref previously installed. Only call
261 this if you are handling ownership/lifetime of the pixel memory. 290 this if you are handling ownership/lifetime of the pixel memory.
262 291
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 private: 659 private:
631 typedef SkRefCnt INHERITED; 660 typedef SkRefCnt INHERITED;
632 }; 661 };
633 662
634 /** Subclass of Allocator that returns a pixelref that allocates its pixel 663 /** Subclass of Allocator that returns a pixelref that allocates its pixel
635 memory from the heap. This is the default Allocator invoked by 664 memory from the heap. This is the default Allocator invoked by
636 allocPixels(). 665 allocPixels().
637 */ 666 */
638 class HeapAllocator : public Allocator { 667 class HeapAllocator : public Allocator {
639 public: 668 public:
640 virtual bool allocPixelRef(SkBitmap*, SkColorTable*); 669 virtual bool allocPixelRef(SkBitmap*, SkColorTable*) SK_OVERRIDE;
641 }; 670 };
642 671
643 class RLEPixels { 672 class RLEPixels {
644 public: 673 public:
645 RLEPixels(int width, int height); 674 RLEPixels(int width, int height);
646 virtual ~RLEPixels(); 675 virtual ~RLEPixels();
647 676
648 uint8_t* packedAtY(int y) const { 677 uint8_t* packedAtY(int y) const {
649 SkASSERT((unsigned)y < (unsigned)fHeight); 678 SkASSERT((unsigned)y < (unsigned)fHeight);
650 return fYPtrs[y]; 679 return fYPtrs[y];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 856
828 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { 857 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const {
829 SkASSERT(fPixels); 858 SkASSERT(fPixels);
830 SkASSERT(fConfig == kIndex8_Config); 859 SkASSERT(fConfig == kIndex8_Config);
831 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); 860 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight);
832 SkASSERT(fColorTable); 861 SkASSERT(fColorTable);
833 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; 862 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)];
834 } 863 }
835 864
836 #endif 865 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkMallocPixelRef.h » ('j') | src/core/SkBitmap.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698