|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +syntax = "proto3"; |
| 16 | + |
| 17 | +package google.type; |
| 18 | + |
| 19 | +import "google/protobuf/wrappers.proto"; |
| 20 | + |
| 21 | +option cc_enable_arenas = true; |
| 22 | +option go_package = "google.golang.org/genproto/googleapis/type/color;color"; |
| 23 | +option java_multiple_files = true; |
| 24 | +option java_outer_classname = "ColorProto"; |
| 25 | +option java_package = "com.google.type"; |
| 26 | +option objc_class_prefix = "GTP"; |
| 27 | + |
| 28 | +// Represents a color in the RGBA color space. This representation is designed |
| 29 | +// for simplicity of conversion to/from color representations in various |
| 30 | +// languages over compactness. For example, the fields of this representation |
| 31 | +// can be trivially provided to the constructor of `java.awt.Color` in Java; it |
| 32 | +// can also be trivially provided to UIColor's `+colorWithRed:green:blue:alpha` |
| 33 | +// method in iOS; and, with just a little work, it can be easily formatted into |
| 34 | +// a CSS `rgba()` string in JavaScript. |
| 35 | +// |
| 36 | +// This reference page doesn't carry information about the absolute color |
| 37 | +// space |
| 38 | +// that should be used to interpret the RGB value (e.g. sRGB, Adobe RGB, |
| 39 | +// DCI-P3, BT.2020, etc.). By default, applications should assume the sRGB color |
| 40 | +// space. |
| 41 | +// |
| 42 | +// When color equality needs to be decided, implementations, unless |
| 43 | +// documented otherwise, treat two colors as equal if all their red, |
| 44 | +// green, blue, and alpha values each differ by at most 1e-5. |
| 45 | +// |
| 46 | +// Example (Java): |
| 47 | +// |
| 48 | +// import com.google.type.Color; |
| 49 | +// |
| 50 | +// // ... |
| 51 | +// public static java.awt.Color fromProto(Color protocolor) { |
| 52 | +// float alpha = protocolor.hasAlpha() |
| 53 | +// ? protocolor.getAlpha().getValue() |
| 54 | +// : 1.0; |
| 55 | +// |
| 56 | +// return new java.awt.Color( |
| 57 | +// protocolor.getRed(), |
| 58 | +// protocolor.getGreen(), |
| 59 | +// protocolor.getBlue(), |
| 60 | +// alpha); |
| 61 | +// } |
| 62 | +// |
| 63 | +// public static Color toProto(java.awt.Color color) { |
| 64 | +// float red = (float) color.getRed(); |
| 65 | +// float green = (float) color.getGreen(); |
| 66 | +// float blue = (float) color.getBlue(); |
| 67 | +// float denominator = 255.0; |
| 68 | +// Color.Builder resultBuilder = |
| 69 | +// Color |
| 70 | +// .newBuilder() |
| 71 | +// .setRed(red / denominator) |
| 72 | +// .setGreen(green / denominator) |
| 73 | +// .setBlue(blue / denominator); |
| 74 | +// int alpha = color.getAlpha(); |
| 75 | +// if (alpha != 255) { |
| 76 | +// result.setAlpha( |
| 77 | +// FloatValue |
| 78 | +// .newBuilder() |
| 79 | +// .setValue(((float) alpha) / denominator) |
| 80 | +// .build()); |
| 81 | +// } |
| 82 | +// return resultBuilder.build(); |
| 83 | +// } |
| 84 | +// // ... |
| 85 | +// |
| 86 | +// Example (iOS / Obj-C): |
| 87 | +// |
| 88 | +// // ... |
| 89 | +// static UIColor* fromProto(Color* protocolor) { |
| 90 | +// float red = [protocolor red]; |
| 91 | +// float green = [protocolor green]; |
| 92 | +// float blue = [protocolor blue]; |
| 93 | +// FloatValue* alpha_wrapper = [protocolor alpha]; |
| 94 | +// float alpha = 1.0; |
| 95 | +// if (alpha_wrapper != nil) { |
| 96 | +// alpha = [alpha_wrapper value]; |
| 97 | +// } |
| 98 | +// return [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; |
| 99 | +// } |
| 100 | +// |
| 101 | +// static Color* toProto(UIColor* color) { |
| 102 | +// CGFloat red, green, blue, alpha; |
| 103 | +// if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) { |
| 104 | +// return nil; |
| 105 | +// } |
| 106 | +// Color* result = [[Color alloc] init]; |
| 107 | +// [result setRed:red]; |
| 108 | +// [result setGreen:green]; |
| 109 | +// [result setBlue:blue]; |
| 110 | +// if (alpha <= 0.9999) { |
| 111 | +// [result setAlpha:floatWrapperWithValue(alpha)]; |
| 112 | +// } |
| 113 | +// [result autorelease]; |
| 114 | +// return result; |
| 115 | +// } |
| 116 | +// // ... |
| 117 | +// |
| 118 | +// Example (JavaScript): |
| 119 | +// |
| 120 | +// // ... |
| 121 | +// |
| 122 | +// var protoToCssColor = function(rgb_color) { |
| 123 | +// var redFrac = rgb_color.red || 0.0; |
| 124 | +// var greenFrac = rgb_color.green || 0.0; |
| 125 | +// var blueFrac = rgb_color.blue || 0.0; |
| 126 | +// var red = Math.floor(redFrac * 255); |
| 127 | +// var green = Math.floor(greenFrac * 255); |
| 128 | +// var blue = Math.floor(blueFrac * 255); |
| 129 | +// |
| 130 | +// if (!('alpha' in rgb_color)) { |
| 131 | +// return rgbToCssColor(red, green, blue); |
| 132 | +// } |
| 133 | +// |
| 134 | +// var alphaFrac = rgb_color.alpha.value || 0.0; |
| 135 | +// var rgbParams = [red, green, blue].join(','); |
| 136 | +// return ['rgba(', rgbParams, ',', alphaFrac, ')'].join(''); |
| 137 | +// }; |
| 138 | +// |
| 139 | +// var rgbToCssColor = function(red, green, blue) { |
| 140 | +// var rgbNumber = new Number((red << 16) | (green << 8) | blue); |
| 141 | +// var hexString = rgbNumber.toString(16); |
| 142 | +// var missingZeros = 6 - hexString.length; |
| 143 | +// var resultBuilder = ['#']; |
| 144 | +// for (var i = 0; i < missingZeros; i++) { |
| 145 | +// resultBuilder.push('0'); |
| 146 | +// } |
| 147 | +// resultBuilder.push(hexString); |
| 148 | +// return resultBuilder.join(''); |
| 149 | +// }; |
| 150 | +// |
| 151 | +// // ... |
| 152 | +message Color { |
| 153 | + // The amount of red in the color as a value in the interval [0, 1]. |
| 154 | + float red = 1; |
| 155 | + |
| 156 | + // The amount of green in the color as a value in the interval [0, 1]. |
| 157 | + float green = 2; |
| 158 | + |
| 159 | + // The amount of blue in the color as a value in the interval [0, 1]. |
| 160 | + float blue = 3; |
| 161 | + |
| 162 | + // The fraction of this color that should be applied to the pixel. That is, |
| 163 | + // the final pixel color is defined by the equation: |
| 164 | + // |
| 165 | + // `pixel color = alpha * (this color) + (1.0 - alpha) * (background color)` |
| 166 | + // |
| 167 | + // This means that a value of 1.0 corresponds to a solid color, whereas |
| 168 | + // a value of 0.0 corresponds to a completely transparent color. This |
| 169 | + // uses a wrapper message rather than a simple float scalar so that it is |
| 170 | + // possible to distinguish between a default value and the value being unset. |
| 171 | + // If omitted, this color object is rendered as a solid color |
| 172 | + // (as if the alpha value had been explicitly given a value of 1.0). |
| 173 | + google.protobuf.FloatValue alpha = 4; |
| 174 | +} |
0 commit comments