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

Side by Side Diff: src/images/SkImageDecoder_ktx.cpp

Issue 1671193002: Make SkPicture/SkImageGenerator default to SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move ImageGenerator impl into ktx code to share with nanobench Created 4 years, 10 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 | « src/core/SkPicture.cpp ('k') | src/ports/SkImageGenerator_skia.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 * 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 7
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkImageGenerator.h"
10 #include "SkPixelRef.h" 11 #include "SkPixelRef.h"
11 #include "SkScaledBitmapSampler.h" 12 #include "SkScaledBitmapSampler.h"
12 #include "SkStream.h" 13 #include "SkStream.h"
13 #include "SkStreamPriv.h" 14 #include "SkStreamPriv.h"
14 #include "SkTypes.h" 15 #include "SkTypes.h"
15 16
16 #include "ktx.h" 17 #include "ktx.h"
17 #include "etc1.h" 18 #include "etc1.h"
18 19
19 //////////////////////////////////////////////////////////////////////////////// ///////// 20 //////////////////////////////////////////////////////////////////////////////// /////////
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 return SkImageDecoder::kUnknown_Format; 322 return SkImageDecoder::kUnknown_Format;
322 } 323 }
323 324
324 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { 325 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) {
325 return (SkImageEncoder::kKTX_Type == t) ? new SkKTXImageEncoder : nullptr; 326 return (SkImageEncoder::kKTX_Type == t) ? new SkKTXImageEncoder : nullptr;
326 } 327 }
327 328
328 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory); 329 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory);
329 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx); 330 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx);
330 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory); 331 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory);
332
333 //////////////////////////////////////////////////////////////////////////////// /////////
334 // Old implementation of SkImageGenerator::NewFromEncoded which uses SkImageDeco der.
335 // Here because it is only needed by DM and tests for Ktx.
336 class BareMemoryAllocator : public SkBitmap::Allocator {
337 const SkImageInfo fInfo;
338 void* const fMemory;
339 const size_t fRowBytes;
340
341 public:
342 BareMemoryAllocator(const SkImageInfo& info, void* memory, size_t rowBytes)
343 : fInfo(info), fMemory(memory), fRowBytes(rowBytes)
344 {}
345
346 protected:
347 bool allocPixelRef(SkBitmap* bm, SkColorTable* ctable) override {
348 const SkImageInfo bmi = bm->info();
349 if (bmi.width() != fInfo.width() || bmi.height() != fInfo.height() ||
350 bmi.colorType() != fInfo.colorType())
351 {
352 return false;
353 }
354 return bm->installPixels(bmi, fMemory, fRowBytes, ctable, nullptr, nullp tr);
355 }
356 };
357
358 class SkImageDecoderGenerator : public SkImageGenerator {
359 const SkImageInfo fInfo;
360 SkAutoTDelete<SkImageDecoder> fDecoder;
361 SkAutoTUnref<SkData> fData;
362
363 public:
364 SkImageDecoderGenerator(const SkImageInfo& info, SkImageDecoder* decoder, Sk Data* data)
365 : INHERITED(info), fInfo(info), fDecoder(decoder), fData(SkRef(data))
366 {}
367
368 protected:
369 SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override {
370 return SkRef(fData.get());
371 }
372 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
373 SkPMColor ctableEntries[], int* ctableCount) override {
374 SkMemoryStream stream(fData->data(), fData->size(), false);
375 SkAutoTUnref<BareMemoryAllocator> allocator(
376 new BareMemoryAllocator(info, pixels, rowBytes));
377 fDecoder->setAllocator(allocator);
378 fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info. alphaType());
379
380 SkBitmap bm;
381 const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, inf o.colorType(),
382 SkImageDecoder::k DecodePixels_Mode);
383 if (SkImageDecoder::kFailure == result) {
384 return false;
385 }
386
387 SkASSERT(info.colorType() == bm.info().colorType());
388
389 if (kIndex_8_SkColorType == info.colorType()) {
390 SkASSERT(ctableEntries);
391
392 SkColorTable* ctable = bm.getColorTable();
393 if (nullptr == ctable) {
394 return false;
395 }
396 const int count = ctable->count();
397 memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor ));
398 *ctableCount = count;
399 }
400 return true;
401 }
402
403 bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
404 SkYUVColorSpace* colorSpace) override {
405 SkMemoryStream stream(fData->data(), fData->size(), false);
406 return fDecoder->decodeYUV8Planes(&stream, sizes, planes, rowBytes, colo rSpace);
407 }
408
409 private:
410 typedef SkImageGenerator INHERITED;
411 };
412
413 SkImageGenerator* decoder_image_generator(SkData* data) {
414 SkMemoryStream stream(data->data(), data->size(), false);
415 SkImageDecoder* decoder = SkImageDecoder::Factory(&stream);
416 if (nullptr == decoder) {
417 return nullptr;
418 }
419
420 SkBitmap bm;
421 stream.rewind();
422 if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDe codeBounds_Mode)) {
423 delete decoder;
424 return nullptr;
425 }
426
427 return new SkImageDecoderGenerator(bm.info(), decoder, data);
428 }
429
OLDNEW
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/ports/SkImageGenerator_skia.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698