| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 4 * | 3 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 #include "ktx.h" | 8 #include "ktx.h" |
| 10 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 11 #include "SkStream.h" | 10 #include "SkStream.h" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // !FIXME! If support is ever added for cube maps then the padding | 320 // !FIXME! If support is ever added for cube maps then the padding |
| 322 // needs to be taken into account here. | 321 // needs to be taken into account here. |
| 323 for (int arrayElement = 0; arrayElement < arrayElements; ++arrayElement)
{ | 322 for (int arrayElement = 0; arrayElement < arrayElements; ++arrayElement)
{ |
| 324 for (int face = 0; face < faces; ++face) { | 323 for (int face = 0; face < faces; ++face) { |
| 325 for (int z = 0; z < depth; ++z) { | 324 for (int z = 0; z < depth; ++z) { |
| 326 PixelData pd(buf, imgSize); | 325 PixelData pd(buf, imgSize); |
| 327 fPixelData.append(1, &pd); | 326 fPixelData.append(1, &pd); |
| 328 } | 327 } |
| 329 } | 328 } |
| 330 } | 329 } |
| 331 | 330 |
| 332 uint32_t imgSizePadded = (imgSize + 3) & ~3; | 331 uint32_t imgSizePadded = (imgSize + 3) & ~3; |
| 333 buf += imgSizePadded; | 332 buf += imgSizePadded; |
| 334 bytesLeft -= imgSizePadded; | 333 bytesLeft -= imgSizePadded; |
| 335 } | 334 } |
| 336 | 335 |
| 337 return bytesLeft == 0; | 336 return bytesLeft == 0; |
| 338 } | 337 } |
| 339 | 338 |
| 340 bool SkKTXFile::is_ktx(const uint8_t *data) { | 339 bool SkKTXFile::is_ktx(const uint8_t *data) { |
| 341 return 0 == memcmp(KTX_FILE_IDENTIFIER, data, KTX_FILE_IDENTIFIER_SIZE); | 340 return 0 == memcmp(KTX_FILE_IDENTIFIER, data, KTX_FILE_IDENTIFIER_SIZE); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 bool SkKTXFile::WriteETC1ToKTX(SkWStream* stream, const uint8_t *etc1Data, | 372 bool SkKTXFile::WriteETC1ToKTX(SkWStream* stream, const uint8_t *etc1Data, |
| 374 uint32_t width, uint32_t height) { | 373 uint32_t width, uint32_t height) { |
| 375 // First thing's first, write out the magic identifier and endianness... | 374 // First thing's first, write out the magic identifier and endianness... |
| 376 if (!stream->write(KTX_FILE_IDENTIFIER, KTX_FILE_IDENTIFIER_SIZE)) { | 375 if (!stream->write(KTX_FILE_IDENTIFIER, KTX_FILE_IDENTIFIER_SIZE)) { |
| 377 return false; | 376 return false; |
| 378 } | 377 } |
| 379 | 378 |
| 380 if (!stream->write(&kKTX_ENDIANNESS_CODE, 4)) { | 379 if (!stream->write(&kKTX_ENDIANNESS_CODE, 4)) { |
| 381 return false; | 380 return false; |
| 382 } | 381 } |
| 383 | 382 |
| 384 Header hdr; | 383 Header hdr; |
| 385 hdr.fGLType = 0; | 384 hdr.fGLType = 0; |
| 386 hdr.fGLTypeSize = 1; | 385 hdr.fGLTypeSize = 1; |
| 387 hdr.fGLFormat = 0; | 386 hdr.fGLFormat = 0; |
| 388 hdr.fGLInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8; | 387 hdr.fGLInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8; |
| 389 hdr.fGLBaseInternalFormat = GR_GL_RGB; | 388 hdr.fGLBaseInternalFormat = GR_GL_RGB; |
| 390 hdr.fPixelWidth = width; | 389 hdr.fPixelWidth = width; |
| 391 hdr.fPixelHeight = height; | 390 hdr.fPixelHeight = height; |
| 392 hdr.fNumberOfArrayElements = 0; | 391 hdr.fNumberOfArrayElements = 0; |
| 393 hdr.fNumberOfFaces = 1; | 392 hdr.fNumberOfFaces = 1; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 rowPtr += bitmap.rowBytes(); | 546 rowPtr += bitmap.rowBytes(); |
| 548 } | 547 } |
| 549 } else { | 548 } else { |
| 550 for (int i = 0; i < height; ++i) { | 549 for (int i = 0; i < height; ++i) { |
| 551 if (!stream->write(rowPtr, bpp*width)) { | 550 if (!stream->write(rowPtr, bpp*width)) { |
| 552 return false; | 551 return false; |
| 553 } | 552 } |
| 554 rowPtr += bitmap.rowBytes(); | 553 rowPtr += bitmap.rowBytes(); |
| 555 } | 554 } |
| 556 } | 555 } |
| 557 | 556 |
| 558 return true; | 557 return true; |
| 559 } | 558 } |
| OLD | NEW |