herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed | dd9ffea | 2016-02-18 12:39:14 -0800 | [diff] [blame] | 7 | |
herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 8 | #include "SkLinearBitmapPipeline.h" |
herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 9 | #include "SkColor.h" |
reed | dd9ffea | 2016-02-18 12:39:14 -0800 | [diff] [blame] | 10 | #include "SkPM4f.h" |
herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 11 | #include "Test.h" |
| 12 | |
| 13 | struct SinkBilerpProcessor final : public PointProcessorInterface { |
| 14 | void pointListFew(int n, Sk4fArg xs, Sk4fArg ys) override { fXs = xs; fYs = ys; } |
| 15 | void pointList4(Sk4fArg Xs, Sk4fArg Ys) override { fXs = Xs; fYs = Ys; } |
herb | 3eb4895 | 2016-02-19 14:39:47 -0800 | [diff] [blame] | 16 | void pointSpan(SkPoint start, SkScalar length, int count) override { } |
herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 17 | Sk4f fXs; |
| 18 | Sk4f fYs; |
| 19 | }; |
| 20 | |
| 21 | using Pixel = float[4]; |
| 22 | DEF_TEST(SkBitmapFP, reporter) { |
| 23 | |
| 24 | int width = 10; |
| 25 | int height = 10; |
| 26 | uint32_t* bitmap = new uint32_t[width * height]; |
| 27 | for (int y = 0; y < height; y++) { |
| 28 | for (int x = 0; x < width; x++) { |
| 29 | bitmap[y * width + x] = (y << 8) + x + (128<<24); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | SkPM4f* FPbuffer = new SkPM4f[width * height]; |
| 34 | |
| 35 | SkMatrix m = SkMatrix::I(); |
| 36 | //m.setRotate(30.0f, 1.0f, 1.0f); |
| 37 | SkMatrix invert; |
| 38 | bool trash = m.invert(&invert); |
| 39 | sk_ignore_unused_variable(trash); |
| 40 | |
| 41 | const SkImageInfo info = |
| 42 | SkImageInfo::MakeN32Premul(width, height, kLinear_SkColorProfileType); |
| 43 | |
herb | ed54504 | 2016-02-18 13:55:02 -0800 | [diff] [blame] | 44 | SkPixmap srcPixmap{info, bitmap, static_cast<size_t>(4 * width)}; |
| 45 | |
herb | c5eddd7 | 2016-02-17 19:50:05 -0800 | [diff] [blame] | 46 | SkLinearBitmapPipeline pipeline{invert, kNone_SkFilterQuality, SkShader::kClamp_TileMode, |
herb | ed54504 | 2016-02-18 13:55:02 -0800 | [diff] [blame] | 47 | SkShader::kClamp_TileMode, srcPixmap}; |
herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 48 | |
| 49 | int count = 10; |
| 50 | |
| 51 | pipeline.shadeSpan4f(3, 6, FPbuffer, count); |
herb | ed54504 | 2016-02-18 13:55:02 -0800 | [diff] [blame] | 52 | #if 0 |
herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 53 | Pixel* pixelBuffer = (Pixel*)FPbuffer; |
| 54 | for (int i = 0; i < count; i++) { |
| 55 | printf("i: %d - (%g, %g, %g, %g)\n", i, |
| 56 | pixelBuffer[i][0] * 255.0f, |
| 57 | pixelBuffer[i][1] * 255.0f, |
| 58 | pixelBuffer[i][2] * 255.0f, |
| 59 | pixelBuffer[i][3] * 255.0f); |
| 60 | } |
herb | ed54504 | 2016-02-18 13:55:02 -0800 | [diff] [blame] | 61 | #endif |
herb | feec878 | 2016-02-17 10:00:07 -0800 | [diff] [blame] | 62 | |
| 63 | delete [] bitmap; |
| 64 | delete [] FPbuffer; |
| 65 | } |
| 66 | |