| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkAndroidCodec.h" | 8 #include "SkAndroidCodec.h" |
| 9 #include "SkBitmapRegionCodec.h" | 9 #include "SkBitmapRegionCodec.h" |
| 10 #include "SkBitmapRegionDecoderPriv.h" | 10 #include "SkBitmapRegionDecoderPriv.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 SkISize scaledSize = fCodec->getSampledSubsetDimensions(sampleSize, subset); | 50 SkISize scaledSize = fCodec->getSampledSubsetDimensions(sampleSize, subset); |
| 51 | 51 |
| 52 // Create the image info for the decode | 52 // Create the image info for the decode |
| 53 SkColorType dstColorType = fCodec->computeOutputColorType(prefColorType); | 53 SkColorType dstColorType = fCodec->computeOutputColorType(prefColorType); |
| 54 SkAlphaType dstAlphaType = fCodec->computeOutputAlphaType(requireUnpremul); | 54 SkAlphaType dstAlphaType = fCodec->computeOutputAlphaType(requireUnpremul); |
| 55 SkImageInfo decodeInfo = SkImageInfo::Make(scaledSize.width(), scaledSize.he
ight(), | 55 SkImageInfo decodeInfo = SkImageInfo::Make(scaledSize.width(), scaledSize.he
ight(), |
| 56 dstColorType, dstAlphaType); | 56 dstColorType, dstAlphaType); |
| 57 | 57 |
| 58 // Construct a color table for the decode if necessary | 58 // Construct a color table for the decode if necessary |
| 59 SkAutoTUnref<SkColorTable> colorTable(nullptr); | 59 SkAutoTUnref<SkColorTable> colorTable(nullptr); |
| 60 SkPMColor* colorPtr = nullptr; | |
| 61 int* colorCountPtr = nullptr; | |
| 62 int maxColors = 256; | 60 int maxColors = 256; |
| 63 SkPMColor colors[256]; | 61 SkPMColor colors[256]; |
| 64 if (kIndex_8_SkColorType == dstColorType) { | 62 if (kIndex_8_SkColorType == dstColorType) { |
| 65 // TODO (msarett): This performs a copy that is unnecessary since | |
| 66 // we have not yet initialized the color table. | |
| 67 // And then we need to use a const cast to get | |
| 68 // a pointer to the color table that we can | |
| 69 // modify during the decode. We could alternatively | |
| 70 // perform the decode before creating the bitmap and | |
| 71 // the color table. We still would need to copy the | |
| 72 // colors into the color table after the decode. | |
| 73 colorTable.reset(new SkColorTable(colors, maxColors)); | 63 colorTable.reset(new SkColorTable(colors, maxColors)); |
| 74 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); | |
| 75 colorCountPtr = &maxColors; | |
| 76 } | 64 } |
| 77 | 65 |
| 78 // Initialize the destination bitmap | 66 // Initialize the destination bitmap |
| 79 int scaledOutX = 0; | 67 int scaledOutX = 0; |
| 80 int scaledOutY = 0; | 68 int scaledOutY = 0; |
| 81 int scaledOutWidth = scaledSize.width(); | 69 int scaledOutWidth = scaledSize.width(); |
| 82 int scaledOutHeight = scaledSize.height(); | 70 int scaledOutHeight = scaledSize.height(); |
| 83 if (SubsetType::kPartiallyInside_SubsetType == type) { | 71 if (SubsetType::kPartiallyInside_SubsetType == type) { |
| 84 scaledOutX = outX / sampleSize; | 72 scaledOutX = outX / sampleSize; |
| 85 scaledOutY = outY / sampleSize; | 73 scaledOutY = outY / sampleSize; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 115 SkCodec::kNo_ZeroInitialized == zeroInit) { | 103 SkCodec::kNo_ZeroInitialized == zeroInit) { |
| 116 void* pixels = bitmap->getPixels(); | 104 void* pixels = bitmap->getPixels(); |
| 117 size_t bytes = outInfo.getSafeSize(bitmap->rowBytes()); | 105 size_t bytes = outInfo.getSafeSize(bitmap->rowBytes()); |
| 118 memset(pixels, 0, bytes); | 106 memset(pixels, 0, bytes); |
| 119 } | 107 } |
| 120 | 108 |
| 121 // Decode into the destination bitmap | 109 // Decode into the destination bitmap |
| 122 SkAndroidCodec::AndroidOptions options; | 110 SkAndroidCodec::AndroidOptions options; |
| 123 options.fSampleSize = sampleSize; | 111 options.fSampleSize = sampleSize; |
| 124 options.fSubset = ⊂ | 112 options.fSubset = ⊂ |
| 125 options.fColorPtr = colorPtr; | 113 options.fColorPtr = colors; |
| 126 options.fColorCount = colorCountPtr; | 114 options.fColorCount = &maxColors; |
| 127 options.fZeroInitialized = zeroInit; | 115 options.fZeroInitialized = zeroInit; |
| 128 void* dst = bitmap->getAddr(scaledOutX, scaledOutY); | 116 void* dst = bitmap->getAddr(scaledOutX, scaledOutY); |
| 129 | 117 |
| 130 // FIXME: skbug.com/4538 | 118 // FIXME: skbug.com/4538 |
| 131 // It is important that we use the rowBytes on the pixelRef. They may not b
e | 119 // It is important that we use the rowBytes on the pixelRef. They may not b
e |
| 132 // set properly on the bitmap. | 120 // set properly on the bitmap. |
| 133 SkPixelRef* pr = SkRef(bitmap->pixelRef()); | 121 SkPixelRef* pr = SkRef(bitmap->pixelRef()); |
| 134 size_t rowBytes = pr->rowBytes(); | 122 size_t rowBytes = pr->rowBytes(); |
| 135 bitmap->setInfo(outInfo, rowBytes); | 123 bitmap->setInfo(outInfo, rowBytes); |
| 136 bitmap->setPixelRef(pr)->unref(); | 124 bitmap->setPixelRef(pr)->unref(); |
| 137 bitmap->lockPixels(); | 125 bitmap->lockPixels(); |
| 138 SkCodec::Result result = fCodec->getAndroidPixels(decodeInfo, dst, rowBytes,
&options); | 126 SkCodec::Result result = fCodec->getAndroidPixels(decodeInfo, dst, rowBytes,
&options); |
| 139 if (SkCodec::kSuccess != result && SkCodec::kIncompleteInput != result) { | 127 if (SkCodec::kSuccess != result && SkCodec::kIncompleteInput != result) { |
| 140 SkCodecPrintf("Error: Could not get pixels.\n"); | 128 SkCodecPrintf("Error: Could not get pixels.\n"); |
| 141 return false; | 129 return false; |
| 142 } | 130 } |
| 143 | 131 |
| 132 // Intialize the color table |
| 133 if (kIndex_8_SkColorType == dstColorType) { |
| 134 colorTable->dangerous_overwriteColors(colors, maxColors); |
| 135 } |
| 136 |
| 144 return true; | 137 return true; |
| 145 } | 138 } |
| 146 | 139 |
| 147 bool SkBitmapRegionCodec::conversionSupported(SkColorType colorType) { | 140 bool SkBitmapRegionCodec::conversionSupported(SkColorType colorType) { |
| 148 // FIXME: Call virtual function when it lands. | 141 // FIXME: Call virtual function when it lands. |
| 149 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fCodec->getInfo().alph
aType(), | 142 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fCodec->getInfo().alph
aType(), |
| 150 fCodec->getInfo().profileType()); | 143 fCodec->getInfo().profileType()); |
| 151 return conversion_possible(info, fCodec->getInfo()); | 144 return conversion_possible(info, fCodec->getInfo()); |
| 152 } | 145 } |
| OLD | NEW |