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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
9 #include "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 case CodecSrc::kGetFromCanvas_DstColorType: | 101 case CodecSrc::kGetFromCanvas_DstColorType: |
102 break; | 102 break; |
103 case CodecSrc::kIndex8_Always_DstColorType: | 103 case CodecSrc::kIndex8_Always_DstColorType: |
104 colorType = kIndex_8_SkColorType; | 104 colorType = kIndex_8_SkColorType; |
105 break; | 105 break; |
106 case CodecSrc::kGrayscale_Always_DstColorType: | 106 case CodecSrc::kGrayscale_Always_DstColorType: |
107 colorType = kGray_8_SkColorType; | 107 colorType = kGray_8_SkColorType; |
108 break; | 108 break; |
109 } | 109 } |
110 | 110 |
| 111 // Construct a color table for the decode if necessary |
| 112 SkAutoTUnref<SkColorTable> colorTable(nullptr); |
| 113 if (kIndex_8_SkColorType == colorType) { |
| 114 SkPMColor colors[256]; |
| 115 colorTable.reset(new SkColorTable(colors, 256)); |
| 116 } |
| 117 |
111 SkAutoTDelete<SkBitmapRegionDecoderInterface> brd(create_brd(fPath, fStrateg
y)); | 118 SkAutoTDelete<SkBitmapRegionDecoderInterface> brd(create_brd(fPath, fStrateg
y)); |
112 if (nullptr == brd.get()) { | 119 if (nullptr == brd.get()) { |
113 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fP
ath.c_str())); | 120 return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fP
ath.c_str())); |
114 } | 121 } |
115 | 122 |
116 if (!brd->conversionSupported(colorType)) { | |
117 return Error::Nonfatal("Cannot convert to color type.\n"); | |
118 } | |
119 | |
120 const uint32_t width = brd->width(); | 123 const uint32_t width = brd->width(); |
121 const uint32_t height = brd->height(); | 124 const uint32_t height = brd->height(); |
122 // Visually inspecting very small output images is not necessary. | 125 // Visually inspecting very small output images is not necessary. |
123 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl
eSize) { | 126 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl
eSize) { |
124 return Error::Nonfatal("Scaling very small images is uninteresting."); | 127 return Error::Nonfatal("Scaling very small images is uninteresting."); |
125 } | 128 } |
126 switch (fMode) { | 129 switch (fMode) { |
127 case kFullImage_Mode: { | 130 case kFullImage_Mode: { |
128 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, width, height
, fSampleSize, | 131 SkImageInfo info; |
129 colorType)); | 132 SkIRect subset = SkIRect::MakeXYWH(0, 0, width, height); |
130 if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { | 133 if (!brd->prepareRegion(subset, fSampleSize, colorType, false, &info
)) { |
| 134 return Error::Nonfatal("Cannot set up for subset decode.\n"); |
| 135 } |
| 136 |
| 137 SkBitmap bitmap; |
| 138 if (SkBitmapRegionDecoderInterface::kOriginal_Strategy != fStrategy)
{ |
| 139 if (!bitmap.tryAllocPixels(info, nullptr, colorTable)) { |
| 140 return "Could not allocate pixels."; |
| 141 } |
| 142 } |
| 143 if (!brd->decodeRegion(bitmap)) { |
| 144 return "Failed to decode subset"; |
| 145 } |
| 146 if (colorType != bitmap.colorType()) { |
131 return Error::Nonfatal("Cannot convert to color type.\n"); | 147 return Error::Nonfatal("Cannot convert to color type.\n"); |
132 } | 148 } |
133 canvas->drawBitmap(*bitmap, 0, 0); | 149 canvas->drawBitmap(bitmap, 0, 0); |
134 return ""; | 150 return ""; |
135 } | 151 } |
136 case kDivisor_Mode: { | 152 case kDivisor_Mode: { |
137 const uint32_t divisor = 2; | 153 const uint32_t divisor = 2; |
138 if (width < divisor || height < divisor) { | 154 if (width < divisor || height < divisor) { |
139 return Error::Nonfatal("Divisor is larger than image dimension.\
n"); | 155 return Error::Nonfatal("Divisor is larger than image dimension.\
n"); |
140 } | 156 } |
141 | 157 |
142 // Use a border to test subsets that extend outside the image. | 158 // Use a border to test subsets that extend outside the image. |
143 // We will not allow the border to be larger than the image dimensio
ns. Allowing | 159 // We will not allow the border to be larger than the image dimensio
ns. Allowing |
(...skipping 27 matching lines...) Expand all Loading... |
171 // Increase the size of the last subset in each row or colum
n, when the | 187 // Increase the size of the last subset in each row or colum
n, when the |
172 // divisor does not divide evenly into the image dimensions | 188 // divisor does not divide evenly into the image dimensions |
173 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; | 189 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; |
174 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | 190 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
175 | 191 |
176 // Increase the size of the subset in order to have a border
on each side | 192 // Increase the size of the subset in order to have a border
on each side |
177 const int decodeLeft = left - unscaledBorder; | 193 const int decodeLeft = left - unscaledBorder; |
178 const int decodeTop = top - unscaledBorder; | 194 const int decodeTop = top - unscaledBorder; |
179 const uint32_t decodeWidth = subsetWidth + unscaledBorder *
2; | 195 const uint32_t decodeWidth = subsetWidth + unscaledBorder *
2; |
180 const uint32_t decodeHeight = subsetHeight + unscaledBorder
* 2; | 196 const uint32_t decodeHeight = subsetHeight + unscaledBorder
* 2; |
181 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, | 197 |
182 decodeTop, decodeWidth, decodeHeight, fSampleSize, c
olorType)); | 198 SkImageInfo info; |
183 if (nullptr == bitmap.get() || colorType != bitmap->colorTyp
e()) { | 199 SkIRect subset = SkIRect::MakeXYWH(decodeLeft, decodeTop, de
codeWidth, |
| 200 decodeHeight); |
| 201 if (!brd->prepareRegion(subset, fSampleSize, colorType, fals
e, &info)) { |
| 202 return Error::Nonfatal("Cannot set up for subset decode.
\n"); |
| 203 } |
| 204 |
| 205 SkBitmap bitmap; |
| 206 if (SkBitmapRegionDecoderInterface::kOriginal_Strategy != fS
trategy) { |
| 207 if (!bitmap.tryAllocPixels(info, nullptr, colorTable)) { |
| 208 return "Could not allocate pixels."; |
| 209 } |
| 210 } |
| 211 if (!brd->decodeRegion(bitmap)) { |
| 212 return "Failed to decode subset"; |
| 213 } |
| 214 if (colorType != bitmap.colorType()) { |
184 return Error::Nonfatal("Cannot convert to color type.\n"
); | 215 return Error::Nonfatal("Cannot convert to color type.\n"
); |
185 } | 216 } |
186 | 217 |
187 canvas->drawBitmapRect(*bitmap, | 218 canvas->drawBitmapRect(bitmap, |
188 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar)
scaledBorder, | 219 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar)
scaledBorder, |
189 (SkScalar) (subsetWidth / fSampleSize), | 220 (SkScalar) (subsetWidth / fSampleSize), |
190 (SkScalar) (subsetHeight / fSampleSize)), | 221 (SkScalar) (subsetHeight / fSampleSize)), |
191 SkRect::MakeXYWH((SkScalar) (left / fSampleSize), | 222 SkRect::MakeXYWH((SkScalar) (left / fSampleSize), |
192 (SkScalar) (top / fSampleSize), | 223 (SkScalar) (top / fSampleSize), |
193 (SkScalar) (subsetWidth / fSampleSize), | 224 (SkScalar) (subsetWidth / fSampleSize), |
194 (SkScalar) (subsetHeight / fSampleSize)), | 225 (SkScalar) (subsetHeight / fSampleSize)), |
195 nullptr); | 226 nullptr); |
196 } | 227 } |
197 } | 228 } |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 skr.visit<void>(i, drawsAsSingletonPictures); | 1394 skr.visit<void>(i, drawsAsSingletonPictures); |
1364 } | 1395 } |
1365 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1396 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1366 | 1397 |
1367 canvas->drawPicture(macroPic); | 1398 canvas->drawPicture(macroPic); |
1368 return ""; | 1399 return ""; |
1369 }); | 1400 }); |
1370 } | 1401 } |
1371 | 1402 |
1372 } // namespace DM | 1403 } // namespace DM |
OLD | NEW |