| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 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 #include "ktx.h" | 8 #include "ktx.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 329 } |
| 330 | 330 |
| 331 uint32_t imgSizePadded = (imgSize + 3) & ~3; | 331 uint32_t imgSizePadded = (imgSize + 3) & ~3; |
| 332 buf += imgSizePadded; | 332 buf += imgSizePadded; |
| 333 bytesLeft -= imgSizePadded; | 333 bytesLeft -= imgSizePadded; |
| 334 } | 334 } |
| 335 | 335 |
| 336 return bytesLeft == 0; | 336 return bytesLeft == 0; |
| 337 } | 337 } |
| 338 | 338 |
| 339 bool SkKTXFile::is_ktx(const uint8_t *data) { | 339 bool SkKTXFile::is_ktx(const uint8_t data[], size_t size) { |
| 340 return 0 == memcmp(KTX_FILE_IDENTIFIER, data, KTX_FILE_IDENTIFIER_SIZE); | 340 return size >= KTX_FILE_IDENTIFIER_SIZE && |
| 341 0 == memcmp(KTX_FILE_IDENTIFIER, data, KTX_FILE_IDENTIFIER_SIZE); |
| 341 } | 342 } |
| 342 | 343 |
| 343 bool SkKTXFile::is_ktx(SkStreamRewindable* stream) { | 344 bool SkKTXFile::is_ktx(SkStreamRewindable* stream) { |
| 344 // Read the KTX header and make sure it's valid. | 345 // Read the KTX header and make sure it's valid. |
| 345 unsigned char buf[KTX_FILE_IDENTIFIER_SIZE]; | 346 unsigned char buf[KTX_FILE_IDENTIFIER_SIZE]; |
| 346 bool largeEnough = | 347 bool largeEnough = |
| 347 stream->read((void*)buf, KTX_FILE_IDENTIFIER_SIZE) == KTX_FILE_IDENTIFIE
R_SIZE; | 348 stream->read((void*)buf, KTX_FILE_IDENTIFIER_SIZE) == KTX_FILE_IDENTIFIE
R_SIZE; |
| 348 stream->rewind(); | 349 stream->rewind(); |
| 349 if (!largeEnough) { | 350 if (!largeEnough) { |
| 350 return false; | 351 return false; |
| 351 } | 352 } |
| 352 return is_ktx(buf); | 353 return is_ktx(buf, KTX_FILE_IDENTIFIER_SIZE); |
| 353 } | 354 } |
| 354 | 355 |
| 355 SkKTXFile::KeyValue SkKTXFile::CreateKeyValue(const char *cstrKey, const char *c
strValue) { | 356 SkKTXFile::KeyValue SkKTXFile::CreateKeyValue(const char *cstrKey, const char *c
strValue) { |
| 356 SkString key(cstrKey); | 357 SkString key(cstrKey); |
| 357 SkString value(cstrValue); | 358 SkString value(cstrValue); |
| 358 | 359 |
| 359 // Size of buffer is length of string plus the null terminators... | 360 // Size of buffer is length of string plus the null terminators... |
| 360 size_t size = key.size() + 1 + value.size() + 1; | 361 size_t size = key.size() + 1 + value.size() + 1; |
| 361 | 362 |
| 362 SkAutoSMalloc<256> buf(size); | 363 SkAutoSMalloc<256> buf(size); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 for (int i = 0; i < height; ++i) { | 550 for (int i = 0; i < height; ++i) { |
| 550 if (!stream->write(rowPtr, bpp*width)) { | 551 if (!stream->write(rowPtr, bpp*width)) { |
| 551 return false; | 552 return false; |
| 552 } | 553 } |
| 553 rowPtr += bitmap.rowBytes(); | 554 rowPtr += bitmap.rowBytes(); |
| 554 } | 555 } |
| 555 } | 556 } |
| 556 | 557 |
| 557 return true; | 558 return true; |
| 558 } | 559 } |
| OLD | NEW |