Use size_t for rowBytes.
Previously, we were using uint32_t sometimes, int sometimes, and size_t sometimes. Switch to using size_t, since we are actually talking about a number of bytes. In copyPixelsTo, use 0 as a flag to use the internal rowBytes, which is more consistent with setConfig. Review URL: https://codereview.appspot.com/7370047 git-svn-id: http://skia.googlecode.com/svn/trunk@7843 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
9447103029
commit
0ba4bf427a
@ -112,7 +112,7 @@ public:
|
||||
int height() const { return fHeight; }
|
||||
/** Return the number of bytes between subsequent rows of the bitmap.
|
||||
*/
|
||||
int rowBytes() const { return fRowBytes; }
|
||||
size_t rowBytes() const { return fRowBytes; }
|
||||
|
||||
/** Return the shift amount per pixel (i.e. 0 for 1-byte per pixel, 1 for
|
||||
2-bytes per pixel configs, 2 for 4-bytes per pixel configs). Return 0
|
||||
@ -206,7 +206,7 @@ public:
|
||||
/** Given a config and a width, this computes the optimal rowBytes value. This is called automatically
|
||||
if you pass 0 for rowBytes to setConfig().
|
||||
*/
|
||||
static int ComputeRowBytes(Config c, int width);
|
||||
static size_t ComputeRowBytes(Config c, int width);
|
||||
|
||||
/** Return the bytes-per-pixel for the specified config. If the config is
|
||||
not at least 1-byte per pixel, return 0, including for kNo_Config.
|
||||
@ -251,7 +251,7 @@ public:
|
||||
ComputeRowBytes() is called to compute the optimal value. This resets
|
||||
any pixel/colortable ownership, just like reset().
|
||||
*/
|
||||
void setConfig(Config, int width, int height, int rowBytes = 0);
|
||||
void setConfig(Config, int width, int height, size_t rowBytes = 0);
|
||||
/** Use this to assign a new pixel address for an existing bitmap. This
|
||||
will automatically release any pixelref previously installed. Only call
|
||||
this if you are handling ownership/lifetime of the pixel memory.
|
||||
@ -278,13 +278,12 @@ public:
|
||||
@param dst Location of destination buffer.
|
||||
@param dstSize Size of destination buffer. Must be large enough to hold
|
||||
pixels using indicated stride.
|
||||
@param dstRowBytes Width of each line in the buffer. If -1, uses
|
||||
@param dstRowBytes Width of each line in the buffer. If 0, uses
|
||||
bitmap's internal stride.
|
||||
@param preserveDstPad Must we preserve padding in the dst
|
||||
*/
|
||||
bool copyPixelsTo(void* const dst, size_t dstSize, int dstRowBytes = -1,
|
||||
bool preserveDstPad = false)
|
||||
const;
|
||||
bool copyPixelsTo(void* const dst, size_t dstSize, size_t dstRowBytes = 0,
|
||||
bool preserveDstPad = false) const;
|
||||
|
||||
/** Use the standard HeapAllocator to create the pixelref that manages the
|
||||
pixel memory. It will be sized based on the current width/height/config.
|
||||
@ -646,7 +645,7 @@ private:
|
||||
kImageIsImmutable_Flag = 0x04
|
||||
};
|
||||
|
||||
uint32_t fRowBytes;
|
||||
size_t fRowBytes;
|
||||
uint32_t fWidth;
|
||||
uint32_t fHeight;
|
||||
uint8_t fConfig;
|
||||
@ -655,14 +654,14 @@ private:
|
||||
|
||||
/* Internal computations for safe size.
|
||||
*/
|
||||
static Sk64 ComputeSafeSize64(Config config,
|
||||
static Sk64 ComputeSafeSize64(Config config,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t rowBytes);
|
||||
size_t rowBytes);
|
||||
static size_t ComputeSafeSize(Config config,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t rowBytes);
|
||||
size_t rowBytes);
|
||||
|
||||
/* Unreference any pixelrefs or colortables
|
||||
*/
|
||||
|
@ -181,7 +181,7 @@ int SkBitmap::ComputeBytesPerPixel(SkBitmap::Config config) {
|
||||
return bpp;
|
||||
}
|
||||
|
||||
int SkBitmap::ComputeRowBytes(Config c, int width) {
|
||||
size_t SkBitmap::ComputeRowBytes(Config c, int width) {
|
||||
if (width < 0) {
|
||||
return 0;
|
||||
}
|
||||
@ -232,7 +232,7 @@ size_t SkBitmap::ComputeSize(Config c, int width, int height) {
|
||||
Sk64 SkBitmap::ComputeSafeSize64(Config config,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t rowBytes) {
|
||||
size_t rowBytes) {
|
||||
Sk64 safeSize;
|
||||
safeSize.setZero();
|
||||
if (height > 0) {
|
||||
@ -248,7 +248,7 @@ Sk64 SkBitmap::ComputeSafeSize64(Config config,
|
||||
size_t SkBitmap::ComputeSafeSize(Config config,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t rowBytes) {
|
||||
size_t rowBytes) {
|
||||
Sk64 safeSize = ComputeSafeSize64(config, width, height, rowBytes);
|
||||
return (safeSize.is32() ? safeSize.get32() : 0);
|
||||
}
|
||||
@ -266,10 +266,10 @@ void SkBitmap::getBounds(SkIRect* bounds) const {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkBitmap::setConfig(Config c, int width, int height, int rowBytes) {
|
||||
void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) {
|
||||
this->freePixels();
|
||||
|
||||
if ((width | height | rowBytes) < 0) {
|
||||
if ((width | height) < 0) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -465,11 +465,11 @@ Sk64 SkBitmap::getSafeSize64() const {
|
||||
}
|
||||
|
||||
bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize,
|
||||
int dstRowBytes, bool preserveDstPad) const {
|
||||
size_t dstRowBytes, bool preserveDstPad) const {
|
||||
|
||||
if (dstRowBytes == -1)
|
||||
if (0 == dstRowBytes) {
|
||||
dstRowBytes = fRowBytes;
|
||||
SkASSERT(dstRowBytes >= 0);
|
||||
}
|
||||
|
||||
if (getConfig() == kRLE_Index8_Config ||
|
||||
dstRowBytes < ComputeRowBytes(getConfig(), fWidth) ||
|
||||
|
@ -39,7 +39,7 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
|
||||
// always skip a full 256 number of entries, even if we memcpy'd fewer
|
||||
dst += kGrColorTableSize;
|
||||
|
||||
if (bitmap.width() == bitmap.rowBytes()) {
|
||||
if ((unsigned)bitmap.width() == bitmap.rowBytes()) {
|
||||
memcpy(dst, bitmap.getPixels(), bitmap.getSize());
|
||||
} else {
|
||||
// need to trim off the extra bytes per row
|
||||
|
Loading…
Reference in New Issue
Block a user