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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 const uint32_t width = brd->width(); | 120 const uint32_t width = brd->width(); |
121 const uint32_t height = brd->height(); | 121 const uint32_t height = brd->height(); |
122 // Visually inspecting very small output images is not necessary. | 122 // Visually inspecting very small output images is not necessary. |
123 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl
eSize) { | 123 if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampl
eSize) { |
124 return Error::Nonfatal("Scaling very small images is uninteresting."); | 124 return Error::Nonfatal("Scaling very small images is uninteresting."); |
125 } | 125 } |
126 switch (fMode) { | 126 switch (fMode) { |
127 case kFullImage_Mode: { | 127 case kFullImage_Mode: { |
128 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, width, height
, fSampleSize, | 128 SkBitmap bitmap; |
129 colorType)); | 129 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, wid
th, height), |
130 if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { | 130 fSampleSize, colorType, false)) { |
| 131 // FIXME: Make this a fatal error. We need to disable webps for
kCanvas_Strategy |
| 132 // because we have not implemented kCanvas_Strategy for webp. W
e may also need to |
| 133 // deal with color conversion errors for kOriginal_Strategy. |
| 134 return Error::Nonfatal("Cannot decode region.\n"); |
| 135 } |
| 136 if (colorType != bitmap.colorType()) { |
131 return Error::Nonfatal("Cannot convert to color type.\n"); | 137 return Error::Nonfatal("Cannot convert to color type.\n"); |
132 } | 138 } |
133 canvas->drawBitmap(*bitmap, 0, 0); | 139 canvas->drawBitmap(bitmap, 0, 0); |
134 return ""; | 140 return ""; |
135 } | 141 } |
136 case kDivisor_Mode: { | 142 case kDivisor_Mode: { |
137 const uint32_t divisor = 2; | 143 const uint32_t divisor = 2; |
138 if (width < divisor || height < divisor) { | 144 if (width < divisor || height < divisor) { |
139 return Error::Nonfatal("Divisor is larger than image dimension.\
n"); | 145 return Error::Nonfatal("Divisor is larger than image dimension.\
n"); |
140 } | 146 } |
141 | 147 |
142 // Use a border to test subsets that extend outside the image. | 148 // 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 | 149 // 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 | 177 // 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 | 178 // divisor does not divide evenly into the image dimensions |
173 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; | 179 subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; |
174 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | 180 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
175 | 181 |
176 // Increase the size of the subset in order to have a border
on each side | 182 // Increase the size of the subset in order to have a border
on each side |
177 const int decodeLeft = left - unscaledBorder; | 183 const int decodeLeft = left - unscaledBorder; |
178 const int decodeTop = top - unscaledBorder; | 184 const int decodeTop = top - unscaledBorder; |
179 const uint32_t decodeWidth = subsetWidth + unscaledBorder *
2; | 185 const uint32_t decodeWidth = subsetWidth + unscaledBorder *
2; |
180 const uint32_t decodeHeight = subsetHeight + unscaledBorder
* 2; | 186 const uint32_t decodeHeight = subsetHeight + unscaledBorder
* 2; |
181 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, | 187 SkBitmap bitmap; |
182 decodeTop, decodeWidth, decodeHeight, fSampleSize, c
olorType)); | 188 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(d
ecodeLeft, |
183 if (nullptr == bitmap.get() || colorType != bitmap->colorTyp
e()) { | 189 decodeTop, decodeWidth, decodeHeight), fSampleSize,
colorType, false)) { |
| 190 // FIXME: Make this a fatal error. We need to disable w
ebps for |
| 191 // kCanvas_Strategy because we have not implemented kCan
vas_Strategy for |
| 192 // webp. We may also need to deal with color conversion
errors for |
| 193 // kOriginal_Strategy. |
| 194 return Error::Nonfatal("Cannot not decode region.\n"); |
| 195 } |
| 196 if (colorType != bitmap.colorType()) { |
184 return Error::Nonfatal("Cannot convert to color type.\n"
); | 197 return Error::Nonfatal("Cannot convert to color type.\n"
); |
185 } | 198 } |
186 | 199 |
187 canvas->drawBitmapRect(*bitmap, | 200 canvas->drawBitmapRect(bitmap, |
188 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar)
scaledBorder, | 201 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar)
scaledBorder, |
189 (SkScalar) (subsetWidth / fSampleSize), | 202 (SkScalar) (subsetWidth / fSampleSize), |
190 (SkScalar) (subsetHeight / fSampleSize)), | 203 (SkScalar) (subsetHeight / fSampleSize)), |
191 SkRect::MakeXYWH((SkScalar) (left / fSampleSize), | 204 SkRect::MakeXYWH((SkScalar) (left / fSampleSize), |
192 (SkScalar) (top / fSampleSize), | 205 (SkScalar) (top / fSampleSize), |
193 (SkScalar) (subsetWidth / fSampleSize), | 206 (SkScalar) (subsetWidth / fSampleSize), |
194 (SkScalar) (subsetHeight / fSampleSize)), | 207 (SkScalar) (subsetHeight / fSampleSize)), |
195 nullptr); | 208 nullptr); |
196 } | 209 } |
197 } | 210 } |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 skr.visit<void>(i, drawsAsSingletonPictures); | 1381 skr.visit<void>(i, drawsAsSingletonPictures); |
1369 } | 1382 } |
1370 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1383 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1371 | 1384 |
1372 canvas->drawPicture(macroPic); | 1385 canvas->drawPicture(macroPic); |
1373 return ""; | 1386 return ""; |
1374 }); | 1387 }); |
1375 } | 1388 } |
1376 | 1389 |
1377 } // namespace DM | 1390 } // namespace DM |
OLD | NEW |