| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 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 #include "ktx.h" | 9 #include "ktx.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 493 |
| 494 // Calculate the key value data size | 494 // Calculate the key value data size |
| 495 hdr.fBytesOfKeyValueData = 0; | 495 hdr.fBytesOfKeyValueData = 0; |
| 496 for (KeyValue *kv = kvPairs.begin(); kv != kvPairs.end(); ++kv) { | 496 for (KeyValue *kv = kvPairs.begin(); kv != kvPairs.end(); ++kv) { |
| 497 // Key value size is the size of the key value data, | 497 // Key value size is the size of the key value data, |
| 498 // four bytes for saying how big the key value size is | 498 // four bytes for saying how big the key value size is |
| 499 // and then additional bytes for padding to four byte boundary | 499 // and then additional bytes for padding to four byte boundary |
| 500 size_t kvsize = kv->size(); | 500 size_t kvsize = kv->size(); |
| 501 kvsize += 4; | 501 kvsize += 4; |
| 502 kvsize = (kvsize + 3) & ~3; | 502 kvsize = (kvsize + 3) & ~3; |
| 503 hdr.fBytesOfKeyValueData += kvsize; | 503 hdr.fBytesOfKeyValueData = SkToU32(hdr.fBytesOfKeyValueData + kvsize); |
| 504 } | 504 } |
| 505 | 505 |
| 506 // Write the header | 506 // Write the header |
| 507 if (!stream->write(&hdr, sizeof(hdr))) { | 507 if (!stream->write(&hdr, sizeof(hdr))) { |
| 508 return false; | 508 return false; |
| 509 } | 509 } |
| 510 | 510 |
| 511 // Write out each key value pair | 511 // Write out each key value pair |
| 512 for (KeyValue *kv = kvPairs.begin(); kv != kvPairs.end(); ++kv) { | 512 for (KeyValue *kv = kvPairs.begin(); kv != kvPairs.end(); ++kv) { |
| 513 if (!kv->writeKeyAndValueForKTX(stream)) { | 513 if (!kv->writeKeyAndValueForKTX(stream)) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 for (int i = 0; i < height; ++i) { | 550 for (int i = 0; i < height; ++i) { |
| 551 if (!stream->write(rowPtr, bpp*width)) { | 551 if (!stream->write(rowPtr, bpp*width)) { |
| 552 return false; | 552 return false; |
| 553 } | 553 } |
| 554 rowPtr += bitmap.rowBytes(); | 554 rowPtr += bitmap.rowBytes(); |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 | 557 |
| 558 return true; | 558 return true; |
| 559 } | 559 } |
| OLD | NEW |