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

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

Issue 16410009: Add an option to create unpremultiplied bitmaps. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkBitmap_DEFINED 10 #ifndef SkBitmap_DEFINED
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 dimensions of the bitmap are > 0 (see empty()). 97 dimensions of the bitmap are > 0 (see empty()).
98 */ 98 */
99 bool isNull() const { return NULL == fPixelRef; } 99 bool isNull() const { return NULL == fPixelRef; }
100 100
101 /** Return the config for the bitmap. 101 /** Return the config for the bitmap.
102 */ 102 */
103 Config config() const { return (Config)fConfig; } 103 Config config() const { return (Config)fConfig; }
104 /** DEPRECATED, use config() 104 /** DEPRECATED, use config()
105 */ 105 */
106 Config getConfig() const { return this->config(); } 106 Config getConfig() const { return this->config(); }
107
108 /** Whether the colors are stored premultiplied. If the bitmap is opaque,
109 the return value is undefined.
110 */
111 bool premultiplied() const { return 0 == (fFlags & kColorsAreNotPremultiplie d_Flag); }
reed1 2013/06/12 20:20:00 isPremultiplied() ? isUnpremultiplied() ?
112
107 /** Return the bitmap's width, in pixels. 113 /** Return the bitmap's width, in pixels.
108 */ 114 */
109 int width() const { return fWidth; } 115 int width() const { return fWidth; }
110 /** Return the bitmap's height, in pixels. 116 /** Return the bitmap's height, in pixels.
111 */ 117 */
112 int height() const { return fHeight; } 118 int height() const { return fHeight; }
113 /** Return the number of bytes between subsequent rows of the bitmap. 119 /** Return the number of bytes between subsequent rows of the bitmap.
114 */ 120 */
115 size_t rowBytes() const { return fRowBytes; } 121 size_t rowBytes() const { return fRowBytes; }
116 122
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 249
244 /** 250 /**
245 * Return the bitmap's bounds [0, 0, width, height] as an SkRect 251 * Return the bitmap's bounds [0, 0, width, height] as an SkRect
246 */ 252 */
247 void getBounds(SkRect* bounds) const; 253 void getBounds(SkRect* bounds) const;
248 void getBounds(SkIRect* bounds) const; 254 void getBounds(SkIRect* bounds) const;
249 255
250 /** Set the bitmap's config and dimensions. If rowBytes is 0, then 256 /** Set the bitmap's config and dimensions. If rowBytes is 0, then
251 ComputeRowBytes() is called to compute the optimal value. This resets 257 ComputeRowBytes() is called to compute the optimal value. This resets
252 any pixel/colortable ownership, just like reset(). 258 any pixel/colortable ownership, just like reset().
259 @param premul Whether the color values are premultiplied. A value of
260 false will only be respected if Config supports unpremultiplied
261 colors, which is currently only true for kARGB_8888.
262 A bitmap with unpremultiplied pixels cannot be drawn to or from
263 by Skia, but may be used by other libraries.
253 */ 264 */
254 void setConfig(Config, int width, int height, size_t rowBytes = 0); 265 void setConfig(Config, int width, int height, size_t rowBytes = 0,
266 bool premul = true);
djsollen 2013/06/12 17:59:21 why not just add a new config for unpremultiplied
scroggo 2013/06/12 18:24:42 That was my first approach, but it was brought up
255 /** Use this to assign a new pixel address for an existing bitmap. This 267 /** Use this to assign a new pixel address for an existing bitmap. This
256 will automatically release any pixelref previously installed. Only call 268 will automatically release any pixelref previously installed. Only call
257 this if you are handling ownership/lifetime of the pixel memory. 269 this if you are handling ownership/lifetime of the pixel memory.
258 270
259 If the bitmap retains a reference to the colortable (assuming it is 271 If the bitmap retains a reference to the colortable (assuming it is
260 not null) it will take care of incrementing the reference count. 272 not null) it will take care of incrementing the reference count.
261 273
262 @param pixels Address for the pixels, managed by the caller. 274 @param pixels Address for the pixels, managed by the caller.
263 @param ctable ColorTable (or null) that matches the specified pixels 275 @param ctable ColorTable (or null) that matches the specified pixels
264 */ 276 */
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 bool lockPixelsAreWritable() const; 369 bool lockPixelsAreWritable() const;
358 370
359 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. 371 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e.
360 it has non-null pixels, and if required by its config, it has a 372 it has non-null pixels, and if required by its config, it has a
361 non-null colortable. Returns true if all of the above are met. 373 non-null colortable. Returns true if all of the above are met.
362 */ 374 */
363 bool readyToDraw() const { 375 bool readyToDraw() const {
364 return this->getPixels() != NULL && 376 return this->getPixels() != NULL &&
365 ((this->config() != kIndex8_Config && 377 ((this->config() != kIndex8_Config &&
366 this->config() != kRLE_Index8_Config) || 378 this->config() != kRLE_Index8_Config) ||
367 fColorTable != NULL); 379 fColorTable != NULL) && this->premultiplied();
368 } 380 }
369 381
370 /** Returns the pixelRef's texture, or NULL 382 /** Returns the pixelRef's texture, or NULL
371 */ 383 */
372 SkGpuTexture* getTexture() const; 384 SkGpuTexture* getTexture() const;
373 385
374 /** Return the bitmap's colortable, if it uses one (i.e. fConfig is 386 /** Return the bitmap's colortable, if it uses one (i.e. fConfig is
375 kIndex8_Config or kRLE_Index8_Config) and the pixels are locked. 387 kIndex8_Config or kRLE_Index8_Config) and the pixels are locked.
376 Otherwise returns NULL. Does not affect the colortable's 388 Otherwise returns NULL. Does not affect the colortable's
377 reference count. 389 reference count.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 661
650 mutable SkPixelRef* fPixelRef; 662 mutable SkPixelRef* fPixelRef;
651 mutable size_t fPixelRefOffset; 663 mutable size_t fPixelRefOffset;
652 mutable int fPixelLockCount; 664 mutable int fPixelLockCount;
653 // either user-specified (in which case it is not treated as mutable) 665 // either user-specified (in which case it is not treated as mutable)
654 // or a cache of the returned value from fPixelRef->lockPixels() 666 // or a cache of the returned value from fPixelRef->lockPixels()
655 mutable void* fPixels; 667 mutable void* fPixels;
656 mutable SkColorTable* fColorTable; // only meaningful for kIndex8 668 mutable SkColorTable* fColorTable; // only meaningful for kIndex8
657 669
658 enum Flags { 670 enum Flags {
659 kImageIsOpaque_Flag = 0x01, 671 kImageIsOpaque_Flag = 0x01,
660 kImageIsVolatile_Flag = 0x02, 672 kImageIsVolatile_Flag = 0x02,
661 kImageIsImmutable_Flag = 0x04, 673 kImageIsImmutable_Flag = 0x04,
662 #ifdef SK_BUILD_FOR_ANDROID 674 #ifdef SK_BUILD_FOR_ANDROID
663 /* A hint for the renderer responsible for drawing this bitmap 675 /* A hint for the renderer responsible for drawing this bitmap
664 * indicating that it should attempt to use mipmaps when this bitmap 676 * indicating that it should attempt to use mipmaps when this bitmap
665 * is drawn scaled down. 677 * is drawn scaled down.
666 */ 678 */
667 kHasHardwareMipMap_Flag = 0x08, 679 kHasHardwareMipMap_Flag = 0x08,
668 #endif 680 #endif
681 kColorsAreNotPremultiplied_Flag = 0x10,
669 }; 682 };
670 683
671 uint32_t fRowBytes; 684 uint32_t fRowBytes;
672 uint32_t fWidth; 685 uint32_t fWidth;
673 uint32_t fHeight; 686 uint32_t fHeight;
674 uint8_t fConfig; 687 uint8_t fConfig;
675 uint8_t fFlags; 688 uint8_t fFlags;
676 uint8_t fBytesPerPixel; // based on config 689 uint8_t fBytesPerPixel; // based on config
677 690
678 /* Internal computations for safe size. 691 /* Internal computations for safe size.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 812
800 // returns the address of the byte that contains the x coordinate 813 // returns the address of the byte that contains the x coordinate
801 inline uint8_t* SkBitmap::getAddr1(int x, int y) const { 814 inline uint8_t* SkBitmap::getAddr1(int x, int y) const {
802 SkASSERT(fPixels); 815 SkASSERT(fPixels);
803 SkASSERT(fConfig == kA1_Config); 816 SkASSERT(fConfig == kA1_Config);
804 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight); 817 SkASSERT((unsigned)x < fWidth && (unsigned)y < fHeight);
805 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3); 818 return (uint8_t*)fPixels + y * fRowBytes + (x >> 3);
806 } 819 }
807 820
808 #endif 821 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gyp ('k') | include/core/SkColor.h » ('j') | include/core/SkColor.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698