Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "SkImageDecoder_ktx.h" | |
| 7 | 8 |
| 8 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 9 #include "SkImageDecoder.h" | |
| 10 #include "SkImageEncoder.h" | |
| 11 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
| 12 #include "SkScaledBitmapSampler.h" | 11 #include "SkScaledBitmapSampler.h" |
| 13 #include "SkStream.h" | 12 #include "SkStream.h" |
| 14 #include "SkStreamPriv.h" | 13 #include "SkStreamPriv.h" |
| 15 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 16 | 15 |
| 17 #include "ktx.h" | 16 #include "ktx.h" |
| 18 #include "etc1.h" | 17 #include "etc1.h" |
| 19 | 18 |
| 20 //////////////////////////////////////////////////////////////////////////////// ///////// | 19 //////////////////////////////////////////////////////////////////////////////// ///////// |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 sampler.next(srcRow); | 236 sampler.next(srcRow); |
| 238 srcRow += sampler.srcDY() * srcRowBytes; | 237 srcRow += sampler.srcDY() * srcRowBytes; |
| 239 } | 238 } |
| 240 | 239 |
| 241 return true; | 240 return true; |
| 242 } | 241 } |
| 243 | 242 |
| 244 return false; | 243 return false; |
| 245 } | 244 } |
| 246 | 245 |
| 246 SkImageDecoder::Format SkDetectFormatKTXImageDecoder(SkStreamRewindable* stream) { | |
| 247 if (SkKTXFile::is_ktx(stream)) { | |
| 248 return SkImageDecoder::kKTX_Format; | |
|
scroggo
2014/11/12 18:00:12
indent 4 spaces
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
| |
| 249 } | |
| 250 return SkImageDecoder::kUnknown_Format; | |
| 251 } | |
| 252 | |
| 253 SkImageDecoder* SkCreateKTXImageDecoder(SkStreamRewindable* stream) { | |
| 254 if (SkDetectFormatKTXImageDecoder(stream) == SkImageDecoder::kKTX_Format) { | |
|
scroggo
2014/11/12 18:00:12
Why not call SkKTXFile::is_ktx?
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
| |
| 255 return SkNEW(SkKTXImageDecoder); | |
|
scroggo
2014/11/12 18:00:12
indent 4 spaces.
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
| |
| 256 } | |
| 257 return NULL; | |
| 258 } | |
| 247 /////////////////////////////////////////////////////////////////////////////// | 259 /////////////////////////////////////////////////////////////////////////////// |
| 248 | 260 |
| 249 // KTX Image Encoder | 261 // KTX Image Encoder |
| 250 // | 262 // |
| 251 // This encoder takes a best guess at how to encode the bitmap passed to it. If | 263 // This encoder takes a best guess at how to encode the bitmap passed to it. If |
| 252 // there is an installed discardable pixel ref with existing PKM data, then we | 264 // there is an installed discardable pixel ref with existing PKM data, then we |
| 253 // will repurpose the existing ETC1 data into a KTX file. If the data contains | 265 // will repurpose the existing ETC1 data into a KTX file. If the data contains |
| 254 // KTX data, then we simply return a copy of the same data. For all other files, | 266 // KTX data, then we simply return a copy of the same data. For all other files, |
| 255 // the underlying KTX library tries to do its best to encode the appropriate | 267 // the underlying KTX library tries to do its best to encode the appropriate |
| 256 // data specified by the bitmap based on the config. (i.e. kAlpha8_Config will | 268 // data specified by the bitmap based on the config. (i.e. kAlpha8_Config will |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 // that our dimensions are valid. | 314 // that our dimensions are valid. |
| 303 if (width == 0 || (width & 3) != 0 || height == 0 || (height & 3) != 0) { | 315 if (width == 0 || (width & 3) != 0 || height == 0 || (height & 3) != 0) { |
| 304 return false; | 316 return false; |
| 305 } | 317 } |
| 306 | 318 |
| 307 // Advance pointer to etc1 data. | 319 // Advance pointer to etc1 data. |
| 308 bytes += ETC_PKM_HEADER_SIZE; | 320 bytes += ETC_PKM_HEADER_SIZE; |
| 309 | 321 |
| 310 return SkKTXFile::WriteETC1ToKTX(stream, bytes, width, height); | 322 return SkKTXFile::WriteETC1ToKTX(stream, bytes, width, height); |
| 311 } | 323 } |
| 312 | 324 SkImageEncoder* SkCreateKTXImageEncoder(SkImageEncoder::Type t) { |
| 313 //////////////////////////////////////////////////////////////////////////////// ///////// | 325 return (SkImageEncoder::kKTX_Type == t) ? SkNEW(SkKTXImageEncoder) : NULL; |
|
scroggo
2014/11/12 18:00:12
4 spaces.
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
| |
| 314 DEFINE_DECODER_CREATOR(KTXImageDecoder); | |
| 315 DEFINE_ENCODER_CREATOR(KTXImageEncoder); | |
| 316 //////////////////////////////////////////////////////////////////////////////// ///////// | |
| 317 | |
| 318 static SkImageDecoder* sk_libktx_dfactory(SkStreamRewindable* stream) { | |
| 319 if (SkKTXFile::is_ktx(stream)) { | |
| 320 return SkNEW(SkKTXImageDecoder); | |
| 321 } | |
| 322 return NULL; | |
| 323 } | 326 } |
| 324 | |
| 325 static SkImageDecoder::Format get_format_ktx(SkStreamRewindable* stream) { | |
| 326 if (SkKTXFile::is_ktx(stream)) { | |
| 327 return SkImageDecoder::kKTX_Format; | |
| 328 } | |
| 329 return SkImageDecoder::kUnknown_Format; | |
| 330 } | |
| 331 | |
| 332 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { | |
| 333 return (SkImageEncoder::kKTX_Type == t) ? SkNEW(SkKTXImageEncoder) : NULL; | |
| 334 } | |
| 335 | |
| 336 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory); | |
| 337 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx); | |
| 338 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory); | |
| OLD | NEW |