| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 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 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 if (info.width() < 0 || info.height() < 0) { | 172 if (info.width() < 0 || info.height() < 0) { |
| 173 return reset_return_false(this); | 173 return reset_return_false(this); |
| 174 } | 174 } |
| 175 | 175 |
| 176 if (kUnknown_SkColorType == info.colorType()) { | 176 if (kUnknown_SkColorType == info.colorType()) { |
| 177 rowBytes = 0; | 177 rowBytes = 0; |
| 178 } else if (0 == rowBytes) { | 178 } else if (0 == rowBytes) { |
| 179 rowBytes = (size_t)mrb; | 179 rowBytes = (size_t)mrb; |
| 180 } else if (rowBytes < info.minRowBytes()) { | 180 } else if (!info.validRowBytes(rowBytes)) { |
| 181 return reset_return_false(this); | 181 return reset_return_false(this); |
| 182 } | 182 } |
| 183 | 183 |
| 184 this->freePixels(); | 184 this->freePixels(); |
| 185 | 185 |
| 186 fInfo = info; | 186 fInfo = info; |
| 187 fRowBytes = SkToU32(rowBytes); | 187 fRowBytes = SkToU32(rowBytes); |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 | 190 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 332 } |
| 333 return allocator->allocPixelRef(this, ctable); | 333 return allocator->allocPixelRef(this, ctable); |
| 334 } | 334 } |
| 335 | 335 |
| 336 /////////////////////////////////////////////////////////////////////////////// | 336 /////////////////////////////////////////////////////////////////////////////// |
| 337 | 337 |
| 338 bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) { | 338 bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) { |
| 339 if (kIndex_8_SkColorType == requestedInfo.colorType()) { | 339 if (kIndex_8_SkColorType == requestedInfo.colorType()) { |
| 340 return reset_return_false(this); | 340 return reset_return_false(this); |
| 341 } | 341 } |
| 342 if (!this->setInfo(requestedInfo)) { | 342 if (!this->setInfo(requestedInfo, rowBytes)) { |
| 343 return reset_return_false(this); | 343 return reset_return_false(this); |
| 344 } | 344 } |
| 345 | 345 |
| 346 // setInfo may have corrected info (e.g. 565 is always opaque). | 346 // setInfo may have corrected info (e.g. 565 is always opaque). |
| 347 const SkImageInfo& correctedInfo = this->info(); | 347 const SkImageInfo& correctedInfo = this->info(); |
| 348 if (!correctedInfo.validRowBytes(rowBytes)) { | 348 // setInfo may have computed a valid rowbytes if 0 were passed in |
| 349 return reset_return_false(this); | 349 rowBytes = this->rowBytes(); |
| 350 } | 350 |
| 351 | |
| 352 SkMallocPixelRef::PRFactory defaultFactory; | 351 SkMallocPixelRef::PRFactory defaultFactory; |
| 353 | 352 |
| 354 SkPixelRef* pr = defaultFactory.create(correctedInfo, NULL); | 353 SkPixelRef* pr = defaultFactory.create(correctedInfo, rowBytes, NULL); |
| 355 if (NULL == pr) { | 354 if (NULL == pr) { |
| 356 return reset_return_false(this); | 355 return reset_return_false(this); |
| 357 } | 356 } |
| 358 this->setPixelRef(pr)->unref(); | 357 this->setPixelRef(pr)->unref(); |
| 359 | 358 |
| 360 // TODO: lockPixels could/should return bool or void*/NULL | 359 // TODO: lockPixels could/should return bool or void*/NULL |
| 361 this->lockPixels(); | 360 this->lockPixels(); |
| 362 if (NULL == this->getPixels()) { | 361 if (NULL == this->getPixels()) { |
| 363 return reset_return_false(this); | 362 return reset_return_false(this); |
| 364 } | 363 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 375 } | 374 } |
| 376 | 375 |
| 377 // setInfo may have corrected info (e.g. 565 is always opaque). | 376 // setInfo may have corrected info (e.g. 565 is always opaque). |
| 378 const SkImageInfo& correctedInfo = this->info(); | 377 const SkImageInfo& correctedInfo = this->info(); |
| 379 | 378 |
| 380 SkMallocPixelRef::PRFactory defaultFactory; | 379 SkMallocPixelRef::PRFactory defaultFactory; |
| 381 if (NULL == factory) { | 380 if (NULL == factory) { |
| 382 factory = &defaultFactory; | 381 factory = &defaultFactory; |
| 383 } | 382 } |
| 384 | 383 |
| 385 SkPixelRef* pr = factory->create(correctedInfo, ctable); | 384 SkPixelRef* pr = factory->create(correctedInfo, correctedInfo.minRowBytes(),
ctable); |
| 386 if (NULL == pr) { | 385 if (NULL == pr) { |
| 387 return reset_return_false(this); | 386 return reset_return_false(this); |
| 388 } | 387 } |
| 389 this->setPixelRef(pr)->unref(); | 388 this->setPixelRef(pr)->unref(); |
| 390 | 389 |
| 391 // TODO: lockPixels could/should return bool or void*/NULL | 390 // TODO: lockPixels could/should return bool or void*/NULL |
| 392 this->lockPixels(); | 391 this->lockPixels(); |
| 393 if (NULL == this->getPixels()) { | 392 if (NULL == this->getPixels()) { |
| 394 return reset_return_false(this); | 393 return reset_return_false(this); |
| 395 } | 394 } |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 /////////////////////////////////////////////////////////////////////////////// | 1424 /////////////////////////////////////////////////////////////////////////////// |
| 1426 | 1425 |
| 1427 #ifdef SK_DEBUG | 1426 #ifdef SK_DEBUG |
| 1428 void SkImageInfo::validate() const { | 1427 void SkImageInfo::validate() const { |
| 1429 SkASSERT(fWidth >= 0); | 1428 SkASSERT(fWidth >= 0); |
| 1430 SkASSERT(fHeight >= 0); | 1429 SkASSERT(fHeight >= 0); |
| 1431 SkASSERT(SkColorTypeIsValid(fColorType)); | 1430 SkASSERT(SkColorTypeIsValid(fColorType)); |
| 1432 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1431 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
| 1433 } | 1432 } |
| 1434 #endif | 1433 #endif |
| OLD | NEW |