| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 fBufferSize = RB * H; | 115 fBufferSize = RB * H; |
| 116 fBuffer = sk_malloc_throw(fBufferSize); | 116 fBuffer = sk_malloc_throw(fBufferSize); |
| 117 fSize.set(SkIntToScalar(W), SkIntToScalar(H)); | 117 fSize.set(SkIntToScalar(W), SkIntToScalar(H)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 virtual ~ImageGM() { | 120 virtual ~ImageGM() { |
| 121 sk_free(fBuffer); | 121 sk_free(fBuffer); |
| 122 } | 122 } |
| 123 | 123 |
| 124 protected: | 124 protected: |
| 125 SkString onShortName() SK_OVERRIDE { | 125 SkString onShortName() override { |
| 126 return SkString("image-surface"); | 126 return SkString("image-surface"); |
| 127 } | 127 } |
| 128 | 128 |
| 129 SkISize onISize() SK_OVERRIDE { | 129 SkISize onISize() override { |
| 130 return SkISize::Make(960, 1200); | 130 return SkISize::Make(960, 1200); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 133 void onDraw(SkCanvas* canvas) override { |
| 134 drawJpeg(canvas, this->getISize()); | 134 drawJpeg(canvas, this->getISize()); |
| 135 | 135 |
| 136 canvas->scale(2, 2); | 136 canvas->scale(2, 2); |
| 137 | 137 |
| 138 static const char* kLabel1 = "Original Img"; | 138 static const char* kLabel1 = "Original Img"; |
| 139 static const char* kLabel2 = "Modified Img"; | 139 static const char* kLabel2 = "Modified Img"; |
| 140 static const char* kLabel3 = "Cur Surface"; | 140 static const char* kLabel3 = "Cur Surface"; |
| 141 static const char* kLabel4 = "Full Crop"; | 141 static const char* kLabel4 = "Full Crop"; |
| 142 static const char* kLabel5 = "Over-crop"; | 142 static const char* kLabel5 = "Over-crop"; |
| 143 static const char* kLabel6 = "Upper-left"; | 143 static const char* kLabel6 = "Upper-left"; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 class ImageResizeGM : public skiagm::GM { | 196 class ImageResizeGM : public skiagm::GM { |
| 197 enum { | 197 enum { |
| 198 W = 100, | 198 W = 100, |
| 199 H = 100, | 199 H = 100, |
| 200 }; | 200 }; |
| 201 public: | 201 public: |
| 202 ImageResizeGM() {} | 202 ImageResizeGM() {} |
| 203 | 203 |
| 204 protected: | 204 protected: |
| 205 SkString onShortName() SK_OVERRIDE { return SkString("image-resize"); } | 205 SkString onShortName() override { return SkString("image-resize"); } |
| 206 | 206 |
| 207 SkISize onISize() SK_OVERRIDE { return SkISize::Make(510, 480); } | 207 SkISize onISize() override { return SkISize::Make(510, 480); } |
| 208 | 208 |
| 209 void drawIntoImage(SkCanvas* canvas) { | 209 void drawIntoImage(SkCanvas* canvas) { |
| 210 SkPaint paint; | 210 SkPaint paint; |
| 211 paint.setAntiAlias(true); | 211 paint.setAntiAlias(true); |
| 212 paint.setStyle(SkPaint::kStroke_Style); | 212 paint.setStyle(SkPaint::kStroke_Style); |
| 213 paint.setStrokeWidth(3); | 213 paint.setStrokeWidth(3); |
| 214 SkRandom rand; | 214 SkRandom rand; |
| 215 for (int i = 0; i < 60; ++i) { | 215 for (int i = 0; i < 60; ++i) { |
| 216 paint.setColor(rand.nextU()); | 216 paint.setColor(rand.nextU()); |
| 217 SkScalar x = rand.nextUScalar1() * W; | 217 SkScalar x = rand.nextUScalar1() * W; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void drawImage(SkCanvas* canvas, SkImage* image, SkFilterQuality fq) { | 253 void drawImage(SkCanvas* canvas, SkImage* image, SkFilterQuality fq) { |
| 254 | 254 |
| 255 canvas->drawImage(image, 0, 0, NULL); | 255 canvas->drawImage(image, 0, 0, NULL); |
| 256 canvas->translate(image->width() + 20.0f, 0); | 256 canvas->translate(image->width() + 20.0f, 0); |
| 257 this->drawResized(canvas, image, image->width()*4/10, image->height()*4/
10, NULL, fq); | 257 this->drawResized(canvas, image, image->width()*4/10, image->height()*4/
10, NULL, fq); |
| 258 | 258 |
| 259 SkIRect subset = SkIRect::MakeLTRB(W/4, H/4, W/2, H/2); | 259 SkIRect subset = SkIRect::MakeLTRB(W/4, H/4, W/2, H/2); |
| 260 this->drawResized(canvas, image, W, H, &subset, fq); | 260 this->drawResized(canvas, image, W, H, &subset, fq); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 263 void onDraw(SkCanvas* canvas) override { |
| 264 canvas->translate(10, 10); | 264 canvas->translate(10, 10); |
| 265 | 265 |
| 266 SkAutoTUnref<SkImage> image(this->makeImage(canvas)); | 266 SkAutoTUnref<SkImage> image(this->makeImage(canvas)); |
| 267 | 267 |
| 268 const SkFilterQuality fq[] = { | 268 const SkFilterQuality fq[] = { |
| 269 kNone_SkFilterQuality, | 269 kNone_SkFilterQuality, |
| 270 kLow_SkFilterQuality, | 270 kLow_SkFilterQuality, |
| 271 kMedium_SkFilterQuality, | 271 kMedium_SkFilterQuality, |
| 272 kHigh_SkFilterQuality, | 272 kHigh_SkFilterQuality, |
| 273 }; | 273 }; |
| 274 for (size_t i = 0; i < SK_ARRAY_COUNT(fq); ++i) { | 274 for (size_t i = 0; i < SK_ARRAY_COUNT(fq); ++i) { |
| 275 { | 275 { |
| 276 SkAutoCanvasRestore acr(canvas, true); | 276 SkAutoCanvasRestore acr(canvas, true); |
| 277 this->drawImage(canvas, image, fq[i]); | 277 this->drawImage(canvas, image, fq[i]); |
| 278 } | 278 } |
| 279 canvas->translate(0, image->height() + 20.0f); | 279 canvas->translate(0, image->height() + 20.0f); |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | 282 |
| 283 private: | 283 private: |
| 284 typedef skiagm::GM INHERITED; | 284 typedef skiagm::GM INHERITED; |
| 285 }; | 285 }; |
| 286 DEF_GM( return new ImageResizeGM; ) | 286 DEF_GM( return new ImageResizeGM; ) |
| 287 | 287 |
| OLD | NEW |