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" |
11 #include "SkStream.h" | 11 #include "SkStream.h" |
12 #include "SkEndian.h" | 12 #include "SkEndian.h" |
13 | 13 |
14 #include "gl/GrGLDefines.h" | 14 #include "gl/GrGLDefines.h" |
15 #include "GrConfig.h" | 15 #include "GrConfig.h" |
16 | 16 |
17 #include "etc1.h" | 17 #include "etc1.h" |
18 | 18 |
19 static inline uint32_t compressed_fmt_to_gl_define(SkTextureCompressor::Format f
mt) { | 19 static inline uint32_t compressed_fmt_to_gl_define(SkTextureCompressor::Format f
mt) { |
20 static const uint32_t kGLDefineMap[SkTextureCompressor::kFormatCnt] = { | 20 static const uint32_t kGLDefineMap[SkTextureCompressor::kFormatCnt] = { |
21 GR_GL_COMPRESSED_LUMINANCE_LATC1, // kLATC_Format | 21 GR_GL_COMPRESSED_LUMINANCE_LATC1, // kLATC_Format |
22 GR_GL_COMPRESSED_R11, // kR11_EAC_Format | 22 GR_GL_COMPRESSED_R11, // kR11_EAC_Format |
23 GR_GL_COMPRESSED_RGB8_ETC1, // kETC1_Format | 23 GR_GL_COMPRESSED_RGB8_ETC1, // kETC1_Format |
24 GR_GL_COMPRESSED_RGBA_ASTC_4x4, // kASTC_4x4_Format | |
25 GR_GL_COMPRESSED_RGBA_ASTC_5x4, // kASTC_5x4_Format | |
26 GR_GL_COMPRESSED_RGBA_ASTC_5x5, // kASTC_5x5_Format | |
27 GR_GL_COMPRESSED_RGBA_ASTC_6x5, // kASTC_6x5_Format | |
28 GR_GL_COMPRESSED_RGBA_ASTC_6x6, // kASTC_6x6_Format | |
29 GR_GL_COMPRESSED_RGBA_ASTC_8x5, // kASTC_8x5_Format | |
30 GR_GL_COMPRESSED_RGBA_ASTC_8x6, // kASTC_8x6_Format | |
31 GR_GL_COMPRESSED_RGBA_ASTC_8x8, // kASTC_8x8_Format | |
32 GR_GL_COMPRESSED_RGBA_ASTC_10x5, // kASTC_10x5_Format | |
33 GR_GL_COMPRESSED_RGBA_ASTC_10x6, // kASTC_10x6_Format | |
34 GR_GL_COMPRESSED_RGBA_ASTC_10x8, // kASTC_10x8_Format | |
35 GR_GL_COMPRESSED_RGBA_ASTC_10x10, // kASTC_10x10_Format | |
36 GR_GL_COMPRESSED_RGBA_ASTC_12x10, // kASTC_12x10_Format | |
37 GR_GL_COMPRESSED_RGBA_ASTC_12x12, // kASTC_12x12_Format | 24 GR_GL_COMPRESSED_RGBA_ASTC_12x12, // kASTC_12x12_Format |
38 }; | 25 }; |
39 | 26 |
40 GR_STATIC_ASSERT(0 == SkTextureCompressor::kLATC_Format); | 27 GR_STATIC_ASSERT(0 == SkTextureCompressor::kLATC_Format); |
41 GR_STATIC_ASSERT(1 == SkTextureCompressor::kR11_EAC_Format); | 28 GR_STATIC_ASSERT(1 == SkTextureCompressor::kR11_EAC_Format); |
42 GR_STATIC_ASSERT(2 == SkTextureCompressor::kETC1_Format); | 29 GR_STATIC_ASSERT(2 == SkTextureCompressor::kETC1_Format); |
43 GR_STATIC_ASSERT(3 == SkTextureCompressor::kASTC_4x4_Format); | 30 GR_STATIC_ASSERT(3 == SkTextureCompressor::kASTC_12x12_Format); |
44 GR_STATIC_ASSERT(4 == SkTextureCompressor::kASTC_5x4_Format); | |
45 GR_STATIC_ASSERT(5 == SkTextureCompressor::kASTC_5x5_Format); | |
46 GR_STATIC_ASSERT(6 == SkTextureCompressor::kASTC_6x5_Format); | |
47 GR_STATIC_ASSERT(7 == SkTextureCompressor::kASTC_6x6_Format); | |
48 GR_STATIC_ASSERT(8 == SkTextureCompressor::kASTC_8x5_Format); | |
49 GR_STATIC_ASSERT(9 == SkTextureCompressor::kASTC_8x6_Format); | |
50 GR_STATIC_ASSERT(10 == SkTextureCompressor::kASTC_8x8_Format); | |
51 GR_STATIC_ASSERT(11 == SkTextureCompressor::kASTC_10x5_Format); | |
52 GR_STATIC_ASSERT(12 == SkTextureCompressor::kASTC_10x6_Format); | |
53 GR_STATIC_ASSERT(13 == SkTextureCompressor::kASTC_10x8_Format); | |
54 GR_STATIC_ASSERT(14 == SkTextureCompressor::kASTC_10x10_Format); | |
55 GR_STATIC_ASSERT(15 == SkTextureCompressor::kASTC_12x10_Format); | |
56 GR_STATIC_ASSERT(16 == SkTextureCompressor::kASTC_12x12_Format); | |
57 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kGLDefineMap) == SkTextureCompressor::kForma
tCnt); | 31 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kGLDefineMap) == SkTextureCompressor::kForma
tCnt); |
58 | 32 |
59 return kGLDefineMap[fmt]; | 33 return kGLDefineMap[fmt]; |
60 } | 34 } |
61 | 35 |
62 #define KTX_FILE_IDENTIFIER_SIZE 12 | 36 #define KTX_FILE_IDENTIFIER_SIZE 12 |
63 static const uint8_t KTX_FILE_IDENTIFIER[KTX_FILE_IDENTIFIER_SIZE] = { | 37 static const uint8_t KTX_FILE_IDENTIFIER[KTX_FILE_IDENTIFIER_SIZE] = { |
64 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A | 38 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A |
65 }; | 39 }; |
66 | 40 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 for (int i = 0; i < height; ++i) { | 519 for (int i = 0; i < height; ++i) { |
546 if (!stream->write(rowPtr, bpp*width)) { | 520 if (!stream->write(rowPtr, bpp*width)) { |
547 return false; | 521 return false; |
548 } | 522 } |
549 rowPtr += bitmap.rowBytes(); | 523 rowPtr += bitmap.rowBytes(); |
550 } | 524 } |
551 } | 525 } |
552 | 526 |
553 return true; | 527 return true; |
554 } | 528 } |
OLD | NEW |