OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkImageEncoder.h" | 8 #include "SkImageEncoder.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 for (int i = 0; i < width; ++i) { | 64 for (int i = 0; i < width; ++i) { |
65 const uint32_t c = ctable[*src++]; | 65 const uint32_t c = ctable[*src++]; |
66 argb[0] = SkGetPackedA32(c); | 66 argb[0] = SkGetPackedA32(c); |
67 argb[1] = SkGetPackedR32(c); | 67 argb[1] = SkGetPackedR32(c); |
68 argb[2] = SkGetPackedG32(c); | 68 argb[2] = SkGetPackedG32(c); |
69 argb[3] = SkGetPackedB32(c); | 69 argb[3] = SkGetPackedB32(c); |
70 argb += 4; | 70 argb += 4; |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 static ScanlineImporter ChooseImporter(const SkBitmap::Config& config) { | 74 static ScanlineImporter ChooseImporter(SkColorType ct) { |
75 switch (config) { | 75 switch (ct) { |
76 case SkBitmap::kARGB_8888_Config: | 76 case kN32_SkColorType: |
77 return ARGB_8888_To_ARGB; | 77 return ARGB_8888_To_ARGB; |
78 case SkBitmap::kRGB_565_Config: | 78 case kRGB_565_SkColorType: |
79 return RGB_565_To_ARGB; | 79 return RGB_565_To_ARGB; |
80 case SkBitmap::kARGB_4444_Config: | 80 case kARGB_4444_SkColorType: |
81 return ARGB_4444_To_ARGB; | 81 return ARGB_4444_To_ARGB; |
82 case SkBitmap::kIndex8_Config: | 82 case kIndex_8_SkColorType: |
83 return Index8_To_ARGB; | 83 return Index8_To_ARGB; |
84 default: | 84 default: |
85 return NULL; | 85 return NULL; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 bool SkARGBImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int
) { | 89 bool SkARGBImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int
) { |
90 const SkBitmap::Config config = bitmap.config(); | 90 const ScanlineImporter scanline_import = ChooseImporter(bitmap.colorType()); |
91 const ScanlineImporter scanline_import = ChooseImporter(config); | |
92 if (NULL == scanline_import) { | 91 if (NULL == scanline_import) { |
93 return false; | 92 return false; |
94 } | 93 } |
95 | 94 |
96 SkAutoLockPixels alp(bitmap); | 95 SkAutoLockPixels alp(bitmap); |
97 const uint8_t* src = (uint8_t*)bitmap.getPixels(); | 96 const uint8_t* src = (uint8_t*)bitmap.getPixels(); |
98 if (NULL == bitmap.getPixels()) { | 97 if (NULL == bitmap.getPixels()) { |
99 return false; | 98 return false; |
100 } | 99 } |
101 | 100 |
102 SkAutoLockColors ctLocker; | 101 SkAutoLockColors ctLocker; |
103 const SkPMColor* colors = ctLocker.lockColors(bitmap); | 102 const SkPMColor* colors = ctLocker.lockColors(bitmap); |
104 | 103 |
105 const int argbStride = bitmap.width() * 4; | 104 const int argbStride = bitmap.width() * 4; |
106 SkAutoTDeleteArray<uint8_t> ada(new uint8_t[argbStride]); | 105 SkAutoTDeleteArray<uint8_t> ada(new uint8_t[argbStride]); |
107 uint8_t* argb = ada.get(); | 106 uint8_t* argb = ada.get(); |
108 for (int y = 0; y < bitmap.height(); ++y) { | 107 for (int y = 0; y < bitmap.height(); ++y) { |
109 scanline_import(src + y * bitmap.rowBytes(), argb, bitmap.width(), color
s); | 108 scanline_import(src + y * bitmap.rowBytes(), argb, bitmap.width(), color
s); |
110 stream->write(argb, argbStride); | 109 stream->write(argb, argbStride); |
111 } | 110 } |
112 | 111 |
113 return true; | 112 return true; |
114 } | 113 } |
115 | 114 |
116 | 115 |
117 /////////////////////////////////////////////////////////////////////////////// | 116 /////////////////////////////////////////////////////////////////////////////// |
118 DEFINE_ENCODER_CREATOR(ARGBImageEncoder); | 117 DEFINE_ENCODER_CREATOR(ARGBImageEncoder); |
119 /////////////////////////////////////////////////////////////////////////////// | 118 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |