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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkBitmap bitmap; | 128 SkBitmap bitmap; |
129 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, wid
th, height), | 129 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, wid
th, height), |
130 fSampleSize, colorType, false)) { | 130 fSampleSize, colorType, false)) { |
131 // FIXME: Make this a fatal error. We need to disable webps for
kCanvas_Strategy | 131 return "Cannot decode region.\n"; |
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 } | 132 } |
136 if (colorType != bitmap.colorType()) { | 133 if (colorType != bitmap.colorType()) { |
137 return Error::Nonfatal("Cannot convert to color type.\n"); | 134 return Error::Nonfatal("Cannot convert to color type.\n"); |
138 } | 135 } |
139 canvas->drawBitmap(bitmap, 0, 0); | 136 canvas->drawBitmap(bitmap, 0, 0); |
140 return ""; | 137 return ""; |
141 } | 138 } |
142 case kDivisor_Mode: { | 139 case kDivisor_Mode: { |
143 const uint32_t divisor = 2; | 140 const uint32_t divisor = 2; |
144 if (width < divisor || height < divisor) { | 141 if (width < divisor || height < divisor) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; | 177 subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
181 | 178 |
182 // Increase the size of the subset in order to have a border
on each side | 179 // Increase the size of the subset in order to have a border
on each side |
183 const int decodeLeft = left - unscaledBorder; | 180 const int decodeLeft = left - unscaledBorder; |
184 const int decodeTop = top - unscaledBorder; | 181 const int decodeTop = top - unscaledBorder; |
185 const uint32_t decodeWidth = subsetWidth + unscaledBorder *
2; | 182 const uint32_t decodeWidth = subsetWidth + unscaledBorder *
2; |
186 const uint32_t decodeHeight = subsetHeight + unscaledBorder
* 2; | 183 const uint32_t decodeHeight = subsetHeight + unscaledBorder
* 2; |
187 SkBitmap bitmap; | 184 SkBitmap bitmap; |
188 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(d
ecodeLeft, | 185 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(d
ecodeLeft, |
189 decodeTop, decodeWidth, decodeHeight), fSampleSize,
colorType, false)) { | 186 decodeTop, decodeWidth, decodeHeight), fSampleSize,
colorType, false)) { |
190 // FIXME: Make this a fatal error. We need to disable w
ebps for | 187 return "Cannot not decode region.\n"; |
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 } | 188 } |
196 if (colorType != bitmap.colorType()) { | 189 if (colorType != bitmap.colorType()) { |
197 return Error::Nonfatal("Cannot convert to color type.\n"
); | 190 return Error::Nonfatal("Cannot convert to color type.\n"
); |
198 } | 191 } |
199 | 192 |
200 canvas->drawBitmapRect(bitmap, | 193 canvas->drawBitmapRect(bitmap, |
201 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar)
scaledBorder, | 194 SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar)
scaledBorder, |
202 (SkScalar) (subsetWidth / fSampleSize), | 195 (SkScalar) (subsetWidth / fSampleSize), |
203 (SkScalar) (subsetHeight / fSampleSize)), | 196 (SkScalar) (subsetHeight / fSampleSize)), |
204 SkRect::MakeXYWH((SkScalar) (left / fSampleSize), | 197 SkRect::MakeXYWH((SkScalar) (left / fSampleSize), |
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 skr.visit<void>(i, drawsAsSingletonPictures); | 1374 skr.visit<void>(i, drawsAsSingletonPictures); |
1382 } | 1375 } |
1383 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1376 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1384 | 1377 |
1385 canvas->drawPicture(macroPic); | 1378 canvas->drawPicture(macroPic); |
1386 return ""; | 1379 return ""; |
1387 }); | 1380 }); |
1388 } | 1381 } |
1389 | 1382 |
1390 } // namespace DM | 1383 } // namespace DM |
OLD | NEW |