Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: third_party/ktx/ktx.cpp

Issue 340533002: hide SkBitmap::Config entirely (behind a flag) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/KtxTest.cpp ('k') | tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
352 // Write the actual image data 352 // Write the actual image data
353 if (!stream->write(etc1Data, dataSize)) { 353 if (!stream->write(etc1Data, dataSize)) {
354 return false; 354 return false;
355 } 355 }
356 356
357 return true; 357 return true;
358 } 358 }
359 359
360 bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) { 360 bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
361 const SkBitmap::Config config = bitmap.config(); 361 const SkColorType ct = bitmap.colorType();
362 SkAutoLockPixels alp(bitmap); 362 SkAutoLockPixels alp(bitmap);
363 363
364 const int width = bitmap.width(); 364 const int width = bitmap.width();
365 const int height = bitmap.width(); 365 const int height = bitmap.width();
366 const uint8_t* src = reinterpret_cast<uint8_t*>(bitmap.getPixels()); 366 const uint8_t* src = reinterpret_cast<uint8_t*>(bitmap.getPixels());
367 if (NULL == bitmap.getPixels()) { 367 if (NULL == bitmap.getPixels()) {
368 return false; 368 return false;
369 } 369 }
370 370
371 // First thing's first, write out the magic identifier and endianness... 371 // First thing's first, write out the magic identifier and endianness...
372 if (!stream->write(KTX_FILE_IDENTIFIER, KTX_FILE_IDENTIFIER_SIZE) || 372 if (!stream->write(KTX_FILE_IDENTIFIER, KTX_FILE_IDENTIFIER_SIZE) ||
373 !stream->write(&kKTX_ENDIANNESS_CODE, 4)) { 373 !stream->write(&kKTX_ENDIANNESS_CODE, 4)) {
374 return false; 374 return false;
375 } 375 }
376 376
377 // Collect our key/value pairs... 377 // Collect our key/value pairs...
378 SkTArray<KeyValue> kvPairs; 378 SkTArray<KeyValue> kvPairs;
379 379
380 // Next, write the header based on the bitmap's config. 380 // Next, write the header based on the bitmap's config.
381 Header hdr; 381 Header hdr;
382 switch (config) { 382 switch (ct) {
383 case SkBitmap::kIndex8_Config: 383 case kIndex_8_SkColorType:
384 // There is a compressed format for this, but we don't support it ye t. 384 // There is a compressed format for this, but we don't support it ye t.
385 SkDebugf("Writing indexed bitmap to KTX unsupported.\n"); 385 SkDebugf("Writing indexed bitmap to KTX unsupported.\n");
386 // VVV fall through VVV 386 // VVV fall through VVV
387 default: 387 default:
388 case SkBitmap::kNo_Config: 388 case kUnknown_SkColorType:
389 // Bitmap hasn't been configured. 389 // Bitmap hasn't been configured.
390 return false; 390 return false;
391 391
392 case SkBitmap::kA8_Config: 392 case kAlpha_8_SkColorType:
393 hdr.fGLType = GR_GL_UNSIGNED_BYTE; 393 hdr.fGLType = GR_GL_UNSIGNED_BYTE;
394 hdr.fGLTypeSize = 1; 394 hdr.fGLTypeSize = 1;
395 hdr.fGLFormat = GR_GL_RED; 395 hdr.fGLFormat = GR_GL_RED;
396 hdr.fGLInternalFormat = GR_GL_R8; 396 hdr.fGLInternalFormat = GR_GL_R8;
397 hdr.fGLBaseInternalFormat = GR_GL_RED; 397 hdr.fGLBaseInternalFormat = GR_GL_RED;
398 break; 398 break;
399 399
400 case SkBitmap::kRGB_565_Config: 400 case kRGB_565_SkColorType:
401 hdr.fGLType = GR_GL_UNSIGNED_SHORT_5_6_5; 401 hdr.fGLType = GR_GL_UNSIGNED_SHORT_5_6_5;
402 hdr.fGLTypeSize = 2; 402 hdr.fGLTypeSize = 2;
403 hdr.fGLFormat = GR_GL_RGB; 403 hdr.fGLFormat = GR_GL_RGB;
404 hdr.fGLInternalFormat = GR_GL_RGB; 404 hdr.fGLInternalFormat = GR_GL_RGB;
405 hdr.fGLBaseInternalFormat = GR_GL_RGB; 405 hdr.fGLBaseInternalFormat = GR_GL_RGB;
406 break; 406 break;
407 407
408 case SkBitmap::kARGB_4444_Config: 408 case kARGB_4444_SkColorType:
409 hdr.fGLType = GR_GL_UNSIGNED_SHORT_4_4_4_4; 409 hdr.fGLType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
410 hdr.fGLTypeSize = 2; 410 hdr.fGLTypeSize = 2;
411 hdr.fGLFormat = GR_GL_RGBA; 411 hdr.fGLFormat = GR_GL_RGBA;
412 hdr.fGLInternalFormat = GR_GL_RGBA4; 412 hdr.fGLInternalFormat = GR_GL_RGBA4;
413 hdr.fGLBaseInternalFormat = GR_GL_RGBA; 413 hdr.fGLBaseInternalFormat = GR_GL_RGBA;
414 kvPairs.push_back(CreateKeyValue("KTXPremultipliedAlpha", "True")); 414 kvPairs.push_back(CreateKeyValue("KTXPremultipliedAlpha", "True"));
415 break; 415 break;
416 416
417 case SkBitmap::kARGB_8888_Config: 417 case kN32_SkColorType:
418 hdr.fGLType = GR_GL_UNSIGNED_BYTE; 418 hdr.fGLType = GR_GL_UNSIGNED_BYTE;
419 hdr.fGLTypeSize = 1; 419 hdr.fGLTypeSize = 1;
420 hdr.fGLFormat = GR_GL_RGBA; 420 hdr.fGLFormat = GR_GL_RGBA;
421 hdr.fGLInternalFormat = GR_GL_RGBA8; 421 hdr.fGLInternalFormat = GR_GL_RGBA8;
422 hdr.fGLBaseInternalFormat = GR_GL_RGBA; 422 hdr.fGLBaseInternalFormat = GR_GL_RGBA;
423 kvPairs.push_back(CreateKeyValue("KTXPremultipliedAlpha", "True")); 423 kvPairs.push_back(CreateKeyValue("KTXPremultipliedAlpha", "True"));
424 break; 424 break;
425 } 425 }
426 426
427 // Everything else in the header is shared. 427 // Everything else in the header is shared.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 return false; 463 return false;
464 } 464 }
465 465
466 // Write it into the buffer 466 // Write it into the buffer
467 if (!stream->write(&dataSz, 4)) { 467 if (!stream->write(&dataSz, 4)) {
468 return false; 468 return false;
469 } 469 }
470 470
471 // Write the pixel data... 471 // Write the pixel data...
472 const uint8_t* rowPtr = src; 472 const uint8_t* rowPtr = src;
473 if (SkBitmap::kARGB_8888_Config == config) { 473 if (kN32_SkColorType == ct) {
474 for (int j = 0; j < height; ++j) { 474 for (int j = 0; j < height; ++j) {
475 const uint32_t* pixelsPtr = reinterpret_cast<const uint32_t*>(rowPtr ); 475 const uint32_t* pixelsPtr = reinterpret_cast<const uint32_t*>(rowPtr );
476 for (int i = 0; i < width; ++i) { 476 for (int i = 0; i < width; ++i) {
477 uint32_t pixel = pixelsPtr[i]; 477 uint32_t pixel = pixelsPtr[i];
478 uint8_t dstPixel[4]; 478 uint8_t dstPixel[4];
479 dstPixel[0] = pixel >> SK_R32_SHIFT; 479 dstPixel[0] = pixel >> SK_R32_SHIFT;
480 dstPixel[1] = pixel >> SK_G32_SHIFT; 480 dstPixel[1] = pixel >> SK_G32_SHIFT;
481 dstPixel[2] = pixel >> SK_B32_SHIFT; 481 dstPixel[2] = pixel >> SK_B32_SHIFT;
482 dstPixel[3] = pixel >> SK_A32_SHIFT; 482 dstPixel[3] = pixel >> SK_A32_SHIFT;
483 if (!stream->write(dstPixel, 4)) { 483 if (!stream->write(dstPixel, 4)) {
484 return false; 484 return false;
485 } 485 }
486 } 486 }
487 rowPtr += bitmap.rowBytes(); 487 rowPtr += bitmap.rowBytes();
488 } 488 }
489 } else { 489 } else {
490 for (int i = 0; i < height; ++i) { 490 for (int i = 0; i < height; ++i) {
491 if (!stream->write(rowPtr, bpp*width)) { 491 if (!stream->write(rowPtr, bpp*width)) {
492 return false; 492 return false;
493 } 493 }
494 rowPtr += bitmap.rowBytes(); 494 rowPtr += bitmap.rowBytes();
495 } 495 }
496 } 496 }
497 497
498 return true; 498 return true;
499 } 499 }
OLDNEW
« no previous file with comments | « tests/KtxTest.cpp ('k') | tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698