• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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  */
7 
8 #include "SkRasterPipeline.h"
9 #include "Test.h"
10 
DEF_TEST(F16Stages,r)11 DEF_TEST(F16Stages, r) {
12     // Make sure SkRasterPipeline::load_f16 and store_f16 can handle a range of
13     // ordinary (0<=x<=1) and interesting (x<0, x>1) values.
14     float floats[16] = {
15         0.0f, 0.25f, 0.5f, 1.0f,
16         -1.25f, -0.5f, 1.25f, 2.0f,
17         0,0,0,0, 0,0,0,0,  // pad a bit to make sure we qualify for platform-specific code
18     };
19     uint16_t halfs[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
20 
21     float*    f32 = floats;
22     uint16_t* f16 = halfs;
23 
24     {
25         SkRasterPipeline_<256> p;
26         p.append(SkRasterPipeline:: load_f32, &f32);
27         p.append(SkRasterPipeline::store_f16, &f16);
28         p.run(0,0,16/4);
29     }
30     REPORTER_ASSERT(r, f16[0] == 0x0000);
31     REPORTER_ASSERT(r, f16[1] == 0x3400);
32     REPORTER_ASSERT(r, f16[2] == 0x3800);
33     REPORTER_ASSERT(r, f16[3] == 0x3c00);
34     REPORTER_ASSERT(r, f16[4] == 0xbd00);
35     REPORTER_ASSERT(r, f16[5] == 0xb800);
36     REPORTER_ASSERT(r, f16[6] == 0x3d00);
37     REPORTER_ASSERT(r, f16[7] == 0x4000);
38 
39     {
40         SkRasterPipeline_<256> p;
41         p.append(SkRasterPipeline:: load_f16, &f16);
42         p.append(SkRasterPipeline::store_f32, &f32);
43         p.run(0,0,16/4);
44     }
45     REPORTER_ASSERT(r, f32[0] ==  0.00f);
46     REPORTER_ASSERT(r, f32[1] ==  0.25f);
47     REPORTER_ASSERT(r, f32[2] ==  0.50f);
48     REPORTER_ASSERT(r, f32[3] ==  1.00f);
49     REPORTER_ASSERT(r, f32[4] == -1.25f);
50     REPORTER_ASSERT(r, f32[5] == -0.50f);
51     REPORTER_ASSERT(r, f32[6] ==  1.25f);
52     REPORTER_ASSERT(r, f32[7] ==  2.00f);
53 }
54