1be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#
220b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet# Copyright (C) 2015 The Android Open Source Project
3be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#
4be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# Licensed under the Apache License, Version 2.0 (the "License");
5be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# you may not use this file except in compliance with the License.
6be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# You may obtain a copy of the License at
7be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#
8be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#      http://www.apache.org/licenses/LICENSE-2.0
9be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#
10be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# Unless required by applicable law or agreed to in writing, software
11be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# distributed under the License is distributed on an "AS IS" BASIS,
12be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# See the License for the specific language governing permissions and
14be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet# limitations under the License.
15be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#
16be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
17be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletheader:
1820b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletsummary: Conversion Functions
19be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletdescription:
20f166ab62f7adae7d574c12e8f7373fe3993b7205Brian Carlstrom The functions below convert from a numerical vector type to another, or from one color
216386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouillet representation to another.
22be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
23be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
24be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: convert_#3#1
25be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletversion: 9
26be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
27be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletw: 2, 3, 4
28be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u8, u16, u32, i8, i16, i32, f32
29be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u8, u16, u32, i8, i16, i32, f32
30be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: #3#1
31be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: #2#1 v, compatible(#3)
3220b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletsummary: Convert numerical vectors
33be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletdescription:
346386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouillet Converts a vector from one numerical type to another.  The conversion are done entry per entry.
35be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
366386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouillet E.g calling <code>a = convert_short3(b);</code> is equivalent to doing
3720b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet <code>a.x = (short)b.x; a.y = (short)b.y; a.z = (short)b.z;</code>.
38be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
3920b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet Converting floating point values to integer types truncates.
4020b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet
4120b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet Converting numbers too large to fit the destination type yields undefined results.
42be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet For example, converting a float that contains 1.0e18 to a short is undefined.
43be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet Use @clamp() to avoid this.
44be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
45be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
46be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: convert_#3#1
47be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletversion: 21
48be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
49be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletw: 2, 3, 4
50be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u64, i64, f64
51be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u64, i64, f64
52be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: #3#1
53be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: #2#1 v, compatible(#3)
54be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
55be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
56be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: convert_#3#1
57be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletversion: 21
58be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
59be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletw: 2, 3, 4
60be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u64, i64, f64
61be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u8, u16, u32, i8, i16, i32, f32
62be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: #3#1
63be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: #2#1 v, compatible(#3)
64be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
65be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
66be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: convert_#3#1
67be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletversion: 21
68be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
69be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletw: 2, 3, 4
70be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u8, u16, u32, i8, i16, i32, f32
71be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u64, i64, f64
72be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: #3#1
73be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: #2#1 v, compatible(#3)
74be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
75be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
76193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarfunction: convert_#3#1
77132b31fdbbdf60ef914a78f5ea75ef2ebc3a3214Pirama Arumuga Nainarversion: 24
78193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarattrib: const
79193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarw: 2, 3, 4
80193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainart: f16
817c314dfce8f11e4b5b78589ba46606a63f11678ePirama Arumuga Nainart: u8, u16, u32, u64, i8, i16, i32, i64, f16, f32, f64
82193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarret: #3#1
83193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainararg: #2#1 v, compatible(#3)
84193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarend:
85193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainar
86193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarfunction: convert_#3#1
87132b31fdbbdf60ef914a78f5ea75ef2ebc3a3214Pirama Arumuga Nainarversion: 24
88193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarattrib: const
89193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarw: 2, 3, 4
90193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainart: u8, u16, u32, u64, i8, i16, i32, i64, f32, f64
91193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainart: f16
92193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarret: #3#1
93193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainararg: #2#1 v, compatible(#3)
94193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainarend:
95193847b4c48fa16d3cfa8f5b76c2fc496359a941Pirama Arumuga Nainar
96be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: rsPackColorTo8888
97be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
98be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: uchar4
9920b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletarg: float r, "Red component."
10020b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletarg: float g, "Green component."
10120b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletarg: float b, "Blue component."
10220b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletsummary: Create a uchar4 RGBA from floats
103be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletdescription:
104f1001ad7dea3814e499cf28e6d0d95852244edc6Jean-Luc Brouillet Packs three or four floating point RGBA values into a uchar4.
105f1001ad7dea3814e499cf28e6d0d95852244edc6Jean-Luc Brouillet
106ffc1710c382168e74386ef87d0101de65aca91b0Jean-Luc Brouillet The input values are typically between 0.0f and 1.0f inclusive.  For input values outside
107f1001ad7dea3814e499cf28e6d0d95852244edc6Jean-Luc Brouillet of this range, the resulting outputs will be clamped to be between 0 and 255.  As this
108f1001ad7dea3814e499cf28e6d0d95852244edc6Jean-Luc Brouillet clamping may be done after the input is multiplied by 255.f and converted to an integer,
109ffc1710c382168e74386ef87d0101de65aca91b0Jean-Luc Brouillet input numbers greater than INT_MAX/255.f or less than INT_MIN/255.f result in
110f1001ad7dea3814e499cf28e6d0d95852244edc6Jean-Luc Brouillet undefined behavior.
111be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
1126386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouillet If the alpha component is not specified, it is assumed to be 1.0, i.e. the result will
1136386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouillet have an alpha set to 255.
114be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillettest: none
115be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
116be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
117be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: rsPackColorTo8888
118be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
119be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: uchar4
120be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: float r
121be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: float g
122be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: float b
12320b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletarg: float a, "Alpha component."
124be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillettest: none
125be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
126be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
127be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: rsPackColorTo8888
128be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
129be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: uchar4
13020b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletarg: float3 color, "Vector of 3 or 4 floats containing the R, G, B, and A values."
131be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillettest: none
132be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
133be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
134be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: rsPackColorTo8888
135be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
136be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: uchar4
137be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: float4 color
138be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillettest: none
139be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
140be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
141be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: rsUnpackColor8888
14220b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet# NOTE: The = below indicates that the generator should not add "overloadable" by default.
14320b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet# We're doing this to stay backward compatible with the unusual declaration used when this
14420b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet# function was introduced.
145be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: =const
146be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: float4
147be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletarg: uchar4 c
14820b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletsummary: Create a float4 RGBA from uchar4
149be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletdescription:
1506386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouillet Unpacks a uchar4 color to float4.  The resulting floats will be between 0.0 and 1.0 inclusive.
151be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillettest: none
152be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
153be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet
154be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletfunction: rsYuvToRGBA_#2#1
155be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletattrib: const
156be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletw: 4
157be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillett: u8, f32
158be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletret: #2#1
1596386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouilletarg: uchar y, "Luminance component."
1606386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouilletarg: uchar u, "U chrominance component."
1616386ceb3bf25e442513224aaa45691dfe49562d9Jean-Luc Brouilletarg: uchar v, "V chrominance component."
16220b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouilletsummary: Convert a YUV value to RGBA
163be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletdescription:
16420b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet Converts a color from a YUV representation to RGBA.
16520b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet
16620b27d602a4778ed50a83df2147416a35b7c92beJean-Luc Brouillet We currently don't provide a function to do the reverse conversion.
167be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillettest: none
168be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouilletend:
169