refactor a bit

Centralize XYZD50 profile (public) and 252 random bytes (private).

Change-Id: I9fabc9d6c0f35130c62a093b1d79b406b4d53597
Reviewed-on: https://skia-review.googlesource.com/121793
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/skcms.h b/skcms.h
index 4d0ffc9..39e3cbc 100644
--- a/skcms.h
+++ b/skcms.h
@@ -101,6 +101,8 @@
 
 // The sRGB color profile is so commonly used that we offer a canonical skcms_ICCProfile for it.
 extern const skcms_ICCProfile skcms_sRGB_profile;
+// Ditto for XYZD50, the most common profile connection space.
+extern const skcms_ICCProfile skcms_XYZD50_profile;
 
 // Practical equality test for two skcms_ICCProfiles.
 // The implementation is subject to change, but it will always try to answer
diff --git a/src/ICCProfile.c b/src/ICCProfile.c
index 42c942b..c9b7065 100644
--- a/src/ICCProfile.c
+++ b/src/ICCProfile.c
@@ -8,6 +8,7 @@
 #include "../skcms.h"
 #include "Macros.h"
 #include "PortableMath.h"
+#include "RandomBytes.h"
 #include "TransferFunction.h"
 #include <assert.h>
 #include <limits.h>
@@ -802,6 +803,49 @@
     }},
 };
 
+const skcms_ICCProfile skcms_XYZD50_profile = {
+    .buffer           = NULL,
+    .size             = 0,
+    .tag_count        = 0,
+
+    .data_color_space = make_signature('R', 'G', 'B', ' '),
+    .pcs              = make_signature('X', 'Y', 'Z', ' '),
+    .has_trc          = true,
+    .has_toXYZD50     = true,
+    .has_A2B          = false,
+
+    .trc = {
+        {{0, {1,1,0,0,0,0,0}}},
+        {{0, {1,1,0,0,0,0,0}}},
+        {{0, {1,1,0,0,0,0,0}}},
+    },
+
+    .toXYZD50 = {{
+        {1,0,0},
+        {0,1,0},
+        {0,0,1},
+    }},
+};
+
+const uint8_t skcms_252_random_bytes[] = {
+    8, 179, 128, 204, 253, 38, 134, 184, 68, 102, 32, 138, 99, 39, 169, 215,
+    119, 26, 3, 223, 95, 239, 52, 132, 114, 74, 81, 234, 97, 116, 244, 205, 30,
+    154, 173, 12, 51, 159, 122, 153, 61, 226, 236, 178, 229, 55, 181, 220, 191,
+    194, 160, 126, 168, 82, 131, 18, 180, 245, 163, 22, 246, 69, 235, 252, 57,
+    108, 14, 6, 152, 240, 255, 171, 242, 20, 227, 177, 238, 96, 85, 16, 211,
+    70, 200, 149, 155, 146, 127, 145, 100, 151, 109, 19, 165, 208, 195, 164,
+    137, 254, 182, 248, 64, 201, 45, 209, 5, 147, 207, 210, 113, 162, 83, 225,
+    9, 31, 15, 231, 115, 37, 58, 53, 24, 49, 197, 56, 120, 172, 48, 21, 214,
+    129, 111, 11, 50, 187, 196, 34, 60, 103, 71, 144, 47, 203, 77, 80, 232,
+    140, 222, 250, 206, 166, 247, 139, 249, 221, 72, 106, 27, 199, 117, 54,
+    219, 135, 118, 40, 79, 41, 251, 46, 93, 212, 92, 233, 148, 28, 121, 63,
+    123, 158, 105, 59, 29, 42, 143, 23, 0, 107, 176, 87, 104, 183, 156, 193,
+    189, 90, 188, 65, 190, 17, 198, 7, 186, 161, 1, 124, 78, 125, 170, 133,
+    174, 218, 67, 157, 75, 101, 89, 217, 62, 33, 141, 228, 25, 35, 91, 230, 4,
+    2, 13, 73, 86, 167, 237, 84, 243, 44, 185, 66, 130, 110, 150, 142, 216, 88,
+    112, 36, 224, 136, 202, 76, 94, 98, 175, 213
+};
+
 bool skcms_ApproximatelyEqualProfiles(const skcms_ICCProfile* A, const skcms_ICCProfile* B) {
     // For now this is the essentially the same strategy we use in test_only.c
     // for our skcms_Transform() smoke tests:
@@ -812,48 +856,6 @@
 
     // Here are 252 of a random shuffle of all possible bytes.
     // 252 is evenly divisible by 3 and 4.  Only 192, 10, 241, and 43 are missing.
-    static const uint8_t k252_bytes[] = {
-        8, 179, 128, 204, 253, 38, 134, 184, 68, 102, 32, 138, 99, 39, 169, 215,
-        119, 26, 3, 223, 95, 239, 52, 132, 114, 74, 81, 234, 97, 116, 244, 205, 30,
-        154, 173, 12, 51, 159, 122, 153, 61, 226, 236, 178, 229, 55, 181, 220, 191,
-        194, 160, 126, 168, 82, 131, 18, 180, 245, 163, 22, 246, 69, 235, 252, 57,
-        108, 14, 6, 152, 240, 255, 171, 242, 20, 227, 177, 238, 96, 85, 16, 211,
-        70, 200, 149, 155, 146, 127, 145, 100, 151, 109, 19, 165, 208, 195, 164,
-        137, 254, 182, 248, 64, 201, 45, 209, 5, 147, 207, 210, 113, 162, 83, 225,
-        9, 31, 15, 231, 115, 37, 58, 53, 24, 49, 197, 56, 120, 172, 48, 21, 214,
-        129, 111, 11, 50, 187, 196, 34, 60, 103, 71, 144, 47, 203, 77, 80, 232,
-        140, 222, 250, 206, 166, 247, 139, 249, 221, 72, 106, 27, 199, 117, 54,
-        219, 135, 118, 40, 79, 41, 251, 46, 93, 212, 92, 233, 148, 28, 121, 63,
-        123, 158, 105, 59, 29, 42, 143, 23, 0, 107, 176, 87, 104, 183, 156, 193,
-        189, 90, 188, 65, 190, 17, 198, 7, 186, 161, 1, 124, 78, 125, 170, 133,
-        174, 218, 67, 157, 75, 101, 89, 217, 62, 33, 141, 228, 25, 35, 91, 230, 4,
-        2, 13, 73, 86, 167, 237, 84, 243, 44, 185, 66, 130, 110, 150, 142, 216, 88,
-        112, 36, 224, 136, 202, 76, 94, 98, 175, 213
-    };
-
-    static const skcms_ICCProfile kXYZD50 = {
-        .buffer           = NULL,
-        .size             = 0,
-        .tag_count        = 0,
-
-        .data_color_space = make_signature('R', 'G', 'B', ' '),
-        .pcs              = make_signature('X', 'Y', 'Z', ' '),
-        .has_trc          = true,
-        .has_toXYZD50     = true,
-        .has_A2B          = false,
-
-        .trc = {
-            {{0, {1,1,0,0,0,0,0}}},
-            {{0, {1,1,0,0,0,0,0}}},
-            {{0, {1,1,0,0,0,0,0}}},
-        },
-
-        .toXYZD50 = {{
-            {1,0,0},
-            {0,1,0},
-            {0,0,1},
-        }},
-    };
 
     if (A->data_color_space != B->data_color_space) {
         return false;
@@ -869,14 +871,16 @@
 
     uint8_t dstA[252],
             dstB[252];
-    if (!skcms_Transform(k252_bytes,                 fmt, skcms_AlphaFormat_Unpremul, A,
-                         dstA, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &kXYZD50,
-                         npixels)) {
+    if (!skcms_Transform(
+                skcms_252_random_bytes,     fmt, skcms_AlphaFormat_Unpremul, A,
+                dstA, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &skcms_XYZD50_profile,
+                npixels)) {
         return false;
     }
-    if (!skcms_Transform(k252_bytes,                 fmt, skcms_AlphaFormat_Unpremul, B,
-                         dstB, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &kXYZD50,
-                         npixels)) {
+    if (!skcms_Transform(
+                skcms_252_random_bytes,     fmt, skcms_AlphaFormat_Unpremul, B,
+                dstB, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &skcms_XYZD50_profile,
+                npixels)) {
         return false;
     }
 
diff --git a/src/RandomBytes.h b/src/RandomBytes.h
new file mode 100644
index 0000000..a6191a5
--- /dev/null
+++ b/src/RandomBytes.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+// 252 of a random shuffle of all possible bytes.
+// 252 is evenly divisible by 3 and 4.  Only 192, 10, 241, and 43 are missing.
+extern const uint8_t skcms_252_random_bytes[252];
diff --git a/test_only.c b/test_only.c
index 522a489..893c4c1 100644
--- a/test_only.c
+++ b/test_only.c
@@ -11,56 +11,13 @@
 
 #include "skcms.h"
 #include "src/PortableMath.h"
+#include "src/RandomBytes.h"
 #include "src/TransferFunction.h"
 #include "test_only.h"
 #include <stdlib.h>
 #include <string.h>
 
 static void dump_transform_to_XYZD50(FILE* fp, const skcms_ICCProfile* profile) {
-    // Here are 252 of a random shuffle of all possible bytes.
-    // 252 is evenly divisible by 3 and 4.  Only 192, 10, 241, and 43 are missing.
-    static const uint8_t k252_bytes[] = {
-        8, 179, 128, 204, 253, 38, 134, 184, 68, 102, 32, 138, 99, 39, 169, 215,
-        119, 26, 3, 223, 95, 239, 52, 132, 114, 74, 81, 234, 97, 116, 244, 205, 30,
-        154, 173, 12, 51, 159, 122, 153, 61, 226, 236, 178, 229, 55, 181, 220, 191,
-        194, 160, 126, 168, 82, 131, 18, 180, 245, 163, 22, 246, 69, 235, 252, 57,
-        108, 14, 6, 152, 240, 255, 171, 242, 20, 227, 177, 238, 96, 85, 16, 211,
-        70, 200, 149, 155, 146, 127, 145, 100, 151, 109, 19, 165, 208, 195, 164,
-        137, 254, 182, 248, 64, 201, 45, 209, 5, 147, 207, 210, 113, 162, 83, 225,
-        9, 31, 15, 231, 115, 37, 58, 53, 24, 49, 197, 56, 120, 172, 48, 21, 214,
-        129, 111, 11, 50, 187, 196, 34, 60, 103, 71, 144, 47, 203, 77, 80, 232,
-        140, 222, 250, 206, 166, 247, 139, 249, 221, 72, 106, 27, 199, 117, 54,
-        219, 135, 118, 40, 79, 41, 251, 46, 93, 212, 92, 233, 148, 28, 121, 63,
-        123, 158, 105, 59, 29, 42, 143, 23, 0, 107, 176, 87, 104, 183, 156, 193,
-        189, 90, 188, 65, 190, 17, 198, 7, 186, 161, 1, 124, 78, 125, 170, 133,
-        174, 218, 67, 157, 75, 101, 89, 217, 62, 33, 141, 228, 25, 35, 91, 230, 4,
-        2, 13, 73, 86, 167, 237, 84, 243, 44, 185, 66, 130, 110, 150, 142, 216, 88,
-        112, 36, 224, 136, 202, 76, 94, 98, 175, 213
-    };
-
-    static const skcms_ICCProfile XYZD50 = {
-        .buffer           = NULL,
-        .size             = 0,
-        .data_color_space = 0x52474220, // 'RGB '
-        .pcs              = 0x58595A20, // 'XYZ '
-        .tag_count        = 0,
-        .has_trc          = true,
-        .has_toXYZD50     = true,
-        .has_A2B          = false,
-
-        .trc = {
-            {{0, {1,1,0,0,0,0,0}}},
-            {{0, {1,1,0,0,0,0,0}}},
-            {{0, {1,1,0,0,0,0,0}}},
-        },
-
-        .toXYZD50 = {{
-            {1,0,0},
-            {0,1,0},
-            {0,0,1},
-        }},
-    };
-
     // Interpret as RGB_888 if data color space is RGB or GRAY, RGBA_8888 if CMYK.
     skcms_PixelFormat fmt = skcms_PixelFormat_RGB_888;
     size_t npixels = 84;
@@ -71,9 +28,10 @@
 
     uint8_t dst[252];
 
-    if (!skcms_Transform(k252_bytes,                fmt, skcms_AlphaFormat_Unpremul, profile,
-                         dst, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &XYZD50,
-                         npixels)) {
+    if (!skcms_Transform(
+                skcms_252_random_bytes,    fmt, skcms_AlphaFormat_Unpremul, profile,
+                dst, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &skcms_XYZD50_profile,
+                npixels)) {
         fprintf(fp, "We can parse this profile, but not transform it XYZD50!\n");
         return;
     }