2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef WEBGLTEXELCONVERSIONS_H_
29 #define WEBGLTEXELCONVERSIONS_H_
35 #include "WebGLTypes.h"
37 #include "mozilla/Attributes.h"
41 MOZ_BEGIN_ENUM_CLASS(WebGLTexelPremultiplicationOp
, int)
45 MOZ_END_ENUM_CLASS(WebGLTexelPremultiplicationOp
)
47 namespace WebGLTexelConversions
{
49 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
>
52 static const bool Value
=
53 Format
== WebGLTexelFormat::RGBA32F
||
54 Format
== WebGLTexelFormat::RGB32F
||
55 Format
== WebGLTexelFormat::RA32F
||
56 Format
== WebGLTexelFormat::R32F
||
57 Format
== WebGLTexelFormat::A32F
;
60 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
>
63 static const bool Value
=
64 Format
== WebGLTexelFormat::RGBA4444
||
65 Format
== WebGLTexelFormat::RGBA5551
||
66 Format
== WebGLTexelFormat::RGB565
;
69 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
,
70 bool IsFloat
= IsFloatFormat
<Format
>::Value
,
71 bool Is16bpp
= Is16bppFormat
<Format
>::Value
>
72 struct DataTypeForFormat
77 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
>
78 struct DataTypeForFormat
<Format
, true, false>
83 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
>
84 struct DataTypeForFormat
<Format
, false, true>
86 typedef uint16_t Type
;
89 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
>
90 struct IntermediateFormat
92 static const MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Value
93 = IsFloatFormat
<Format
>::Value
94 ? WebGLTexelFormat::RGBA32F
95 : WebGLTexelFormat::RGBA8
;
98 inline size_t TexelBytesForFormat(WebGLTexelFormat format
) {
100 case WebGLTexelFormat::R8
:
101 case WebGLTexelFormat::A8
:
103 case WebGLTexelFormat::RA8
:
104 case WebGLTexelFormat::RGBA5551
:
105 case WebGLTexelFormat::RGBA4444
:
106 case WebGLTexelFormat::RGB565
:
107 case WebGLTexelFormat::D16
:
109 case WebGLTexelFormat::RGB8
:
111 case WebGLTexelFormat::RGBA8
:
112 case WebGLTexelFormat::BGRA8
:
113 case WebGLTexelFormat::BGRX8
:
114 case WebGLTexelFormat::R32F
:
115 case WebGLTexelFormat::A32F
:
116 case WebGLTexelFormat::D32
:
117 case WebGLTexelFormat::D24S8
:
119 case WebGLTexelFormat::RA32F
:
121 case WebGLTexelFormat::RGB32F
:
123 case WebGLTexelFormat::RGBA32F
:
126 MOZ_ASSERT(false, "Unknown texel format. Coding mistake?");
131 MOZ_ALWAYS_INLINE
bool HasAlpha(WebGLTexelFormat format
) {
132 return format
== WebGLTexelFormat::A8
||
133 format
== WebGLTexelFormat::A32F
||
134 format
== WebGLTexelFormat::RA8
||
135 format
== WebGLTexelFormat::RA32F
||
136 format
== WebGLTexelFormat::RGBA8
||
137 format
== WebGLTexelFormat::BGRA8
||
138 format
== WebGLTexelFormat::RGBA32F
||
139 format
== WebGLTexelFormat::RGBA4444
||
140 format
== WebGLTexelFormat::RGBA5551
;
143 MOZ_ALWAYS_INLINE
bool HasColor(WebGLTexelFormat format
) {
144 return format
== WebGLTexelFormat::R8
||
145 format
== WebGLTexelFormat::R32F
||
146 format
== WebGLTexelFormat::RA8
||
147 format
== WebGLTexelFormat::RA32F
||
148 format
== WebGLTexelFormat::RGB8
||
149 format
== WebGLTexelFormat::BGRX8
||
150 format
== WebGLTexelFormat::RGB565
||
151 format
== WebGLTexelFormat::RGB32F
||
152 format
== WebGLTexelFormat::RGBA8
||
153 format
== WebGLTexelFormat::BGRA8
||
154 format
== WebGLTexelFormat::RGBA32F
||
155 format
== WebGLTexelFormat::RGBA4444
||
156 format
== WebGLTexelFormat::RGBA5551
;
160 /****** BEGIN CODE SHARED WITH WEBKIT ******/
162 // the pack/unpack functions here are originally from this file:
163 // http://trac.webkit.org/browser/trunk/WebCore/platform/graphics/GraphicsContext3D.cpp
165 //----------------------------------------------------------------------
166 // Pixel unpacking routines.
168 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
, typename SrcType
, typename DstType
>
169 MOZ_ALWAYS_INLINE
void
170 unpack(const SrcType
* __restrict src
,
171 DstType
* __restrict dst
)
173 MOZ_ASSERT(false, "Unimplemented texture format conversion");
176 template<> MOZ_ALWAYS_INLINE
void
177 unpack
<WebGLTexelFormat::RGBA8
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
185 template<> MOZ_ALWAYS_INLINE
void
186 unpack
<WebGLTexelFormat::RGB8
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
194 template<> MOZ_ALWAYS_INLINE
void
195 unpack
<WebGLTexelFormat::BGRA8
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
203 template<> MOZ_ALWAYS_INLINE
void
204 unpack
<WebGLTexelFormat::BGRX8
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
212 template<> MOZ_ALWAYS_INLINE
void
213 unpack
<WebGLTexelFormat::RGBA5551
, uint16_t, uint8_t>(const uint16_t* __restrict src
, uint8_t* __restrict dst
)
215 uint16_t packedValue
= src
[0];
216 uint8_t r
= (packedValue
>> 11) & 0x1F;
217 uint8_t g
= (packedValue
>> 6) & 0x1F;
218 uint8_t b
= (packedValue
>> 1) & 0x1F;
219 dst
[0] = (r
<< 3) | (r
& 0x7);
220 dst
[1] = (g
<< 3) | (g
& 0x7);
221 dst
[2] = (b
<< 3) | (b
& 0x7);
222 dst
[3] = (packedValue
& 0x1) ? 0xFF : 0;
225 template<> MOZ_ALWAYS_INLINE
void
226 unpack
<WebGLTexelFormat::RGBA4444
, uint16_t, uint8_t>(const uint16_t* __restrict src
, uint8_t* __restrict dst
)
228 uint16_t packedValue
= src
[0];
229 uint8_t r
= (packedValue
>> 12) & 0x0F;
230 uint8_t g
= (packedValue
>> 8) & 0x0F;
231 uint8_t b
= (packedValue
>> 4) & 0x0F;
232 uint8_t a
= packedValue
& 0x0F;
233 dst
[0] = (r
<< 4) | r
;
234 dst
[1] = (g
<< 4) | g
;
235 dst
[2] = (b
<< 4) | b
;
236 dst
[3] = (a
<< 4) | a
;
239 template<> MOZ_ALWAYS_INLINE
void
240 unpack
<WebGLTexelFormat::RGB565
, uint16_t, uint8_t>(const uint16_t* __restrict src
, uint8_t* __restrict dst
)
242 uint16_t packedValue
= src
[0];
243 uint8_t r
= (packedValue
>> 11) & 0x1F;
244 uint8_t g
= (packedValue
>> 5) & 0x3F;
245 uint8_t b
= packedValue
& 0x1F;
246 dst
[0] = (r
<< 3) | (r
& 0x7);
247 dst
[1] = (g
<< 2) | (g
& 0x3);
248 dst
[2] = (b
<< 3) | (b
& 0x7);
252 template<> MOZ_ALWAYS_INLINE
void
253 unpack
<WebGLTexelFormat::R8
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
261 template<> MOZ_ALWAYS_INLINE
void
262 unpack
<WebGLTexelFormat::RA8
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
270 template<> MOZ_ALWAYS_INLINE
void
271 unpack
<WebGLTexelFormat::A8
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
279 template<> MOZ_ALWAYS_INLINE
void
280 unpack
<WebGLTexelFormat::RGBA32F
, float, float>(const float* __restrict src
, float* __restrict dst
)
288 template<> MOZ_ALWAYS_INLINE
void
289 unpack
<WebGLTexelFormat::RGB32F
, float, float>(const float* __restrict src
, float* __restrict dst
)
297 template<> MOZ_ALWAYS_INLINE
void
298 unpack
<WebGLTexelFormat::R32F
, float, float>(const float* __restrict src
, float* __restrict dst
)
306 template<> MOZ_ALWAYS_INLINE
void
307 unpack
<WebGLTexelFormat::RA32F
, float, float>(const float* __restrict src
, float* __restrict dst
)
315 template<> MOZ_ALWAYS_INLINE
void
316 unpack
<WebGLTexelFormat::A32F
, float, float>(const float* __restrict src
, float* __restrict dst
)
324 //----------------------------------------------------------------------
325 // Pixel packing routines.
328 template<MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelFormat
) Format
,
329 MOZ_ENUM_CLASS_ENUM_TYPE(WebGLTexelPremultiplicationOp
) PremultiplicationOp
,
332 MOZ_ALWAYS_INLINE
void
333 pack(const SrcType
* __restrict src
,
334 DstType
* __restrict dst
)
336 MOZ_ASSERT(false, "Unimplemented texture format conversion");
339 template<> MOZ_ALWAYS_INLINE
void
340 pack
<WebGLTexelFormat::A8
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
345 template<> MOZ_ALWAYS_INLINE
void
346 pack
<WebGLTexelFormat::A8
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
351 template<> MOZ_ALWAYS_INLINE
void
352 pack
<WebGLTexelFormat::A8
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
357 template<> MOZ_ALWAYS_INLINE
void
358 pack
<WebGLTexelFormat::R8
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
363 template<> MOZ_ALWAYS_INLINE
void
364 pack
<WebGLTexelFormat::R8
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
366 float scaleFactor
= src
[3] / 255.0f
;
367 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
371 template<> MOZ_ALWAYS_INLINE
void
372 pack
<WebGLTexelFormat::R8
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
374 float scaleFactor
= src
[3] ? 255.0f
/ src
[3] : 1.0f
;
375 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
379 template<> MOZ_ALWAYS_INLINE
void
380 pack
<WebGLTexelFormat::RA8
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
386 template<> MOZ_ALWAYS_INLINE
void
387 pack
<WebGLTexelFormat::RA8
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
389 float scaleFactor
= src
[3] / 255.0f
;
390 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
395 // FIXME: this routine is lossy and must be removed.
396 template<> MOZ_ALWAYS_INLINE
void
397 pack
<WebGLTexelFormat::RA8
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
399 float scaleFactor
= src
[3] ? 255.0f
/ src
[3] : 1.0f
;
400 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
405 template<> MOZ_ALWAYS_INLINE
void
406 pack
<WebGLTexelFormat::RGB8
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
413 template<> MOZ_ALWAYS_INLINE
void
414 pack
<WebGLTexelFormat::RGB8
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
416 float scaleFactor
= src
[3] / 255.0f
;
417 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
418 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
419 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
425 template<> MOZ_ALWAYS_INLINE
void
426 pack
<WebGLTexelFormat::RGB8
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
428 float scaleFactor
= src
[3] ? 255.0f
/ src
[3] : 1.0f
;
429 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
430 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
431 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
437 template<> MOZ_ALWAYS_INLINE
void
438 pack
<WebGLTexelFormat::RGBA8
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
446 template<> MOZ_ALWAYS_INLINE
void
447 pack
<WebGLTexelFormat::RGBA8
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
449 float scaleFactor
= src
[3] / 255.0f
;
450 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
451 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
452 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
459 // FIXME: this routine is lossy and must be removed.
460 template<> MOZ_ALWAYS_INLINE
void
461 pack
<WebGLTexelFormat::RGBA8
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
463 float scaleFactor
= src
[3] ? 255.0f
/ src
[3] : 1.0f
;
464 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
465 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
466 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
473 template<> MOZ_ALWAYS_INLINE
void
474 pack
<WebGLTexelFormat::RGBA4444
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
476 *dst
= ( ((src
[0] & 0xF0) << 8)
477 | ((src
[1] & 0xF0) << 4)
482 template<> MOZ_ALWAYS_INLINE
void
483 pack
<WebGLTexelFormat::RGBA4444
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
485 float scaleFactor
= src
[3] / 255.0f
;
486 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
487 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
488 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
489 *dst
= ( ((srcR
& 0xF0) << 8)
490 | ((srcG
& 0xF0) << 4)
495 // FIXME: this routine is lossy and must be removed.
496 template<> MOZ_ALWAYS_INLINE
void
497 pack
<WebGLTexelFormat::RGBA4444
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
499 float scaleFactor
= src
[3] ? 255.0f
/ src
[3] : 1.0f
;
500 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
501 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
502 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
503 *dst
= ( ((srcR
& 0xF0) << 8)
504 | ((srcG
& 0xF0) << 4)
509 template<> MOZ_ALWAYS_INLINE
void
510 pack
<WebGLTexelFormat::RGBA5551
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
512 *dst
= ( ((src
[0] & 0xF8) << 8)
513 | ((src
[1] & 0xF8) << 3)
514 | ((src
[2] & 0xF8) >> 2)
518 template<> MOZ_ALWAYS_INLINE
void
519 pack
<WebGLTexelFormat::RGBA5551
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
521 float scaleFactor
= src
[3] / 255.0f
;
522 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
523 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
524 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
525 *dst
= ( ((srcR
& 0xF8) << 8)
526 | ((srcG
& 0xF8) << 3)
527 | ((srcB
& 0xF8) >> 2)
531 // FIXME: this routine is lossy and must be removed.
532 template<> MOZ_ALWAYS_INLINE
void
533 pack
<WebGLTexelFormat::RGBA5551
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
535 float scaleFactor
= src
[3] ? 255.0f
/ src
[3] : 1.0f
;
536 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
537 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
538 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
539 *dst
= ( ((srcR
& 0xF8) << 8)
540 | ((srcG
& 0xF8) << 3)
541 | ((srcB
& 0xF8) >> 2)
545 template<> MOZ_ALWAYS_INLINE
void
546 pack
<WebGLTexelFormat::RGB565
, WebGLTexelPremultiplicationOp::None
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
548 *dst
= ( ((src
[0] & 0xF8) << 8)
549 | ((src
[1] & 0xFC) << 3)
550 | ((src
[2] & 0xF8) >> 3));
553 template<> MOZ_ALWAYS_INLINE
void
554 pack
<WebGLTexelFormat::RGB565
, WebGLTexelPremultiplicationOp::Premultiply
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
556 float scaleFactor
= src
[3] / 255.0f
;
557 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
558 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
559 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
560 *dst
= ( ((srcR
& 0xF8) << 8)
561 | ((srcG
& 0xFC) << 3)
562 | ((srcB
& 0xF8) >> 3));
565 // FIXME: this routine is lossy and must be removed.
566 template<> MOZ_ALWAYS_INLINE
void
567 pack
<WebGLTexelFormat::RGB565
, WebGLTexelPremultiplicationOp::Unpremultiply
, uint8_t, uint16_t>(const uint8_t* __restrict src
, uint16_t* __restrict dst
)
569 float scaleFactor
= src
[3] ? 255.0f
/ src
[3] : 1.0f
;
570 uint8_t srcR
= static_cast<uint8_t>(src
[0] * scaleFactor
);
571 uint8_t srcG
= static_cast<uint8_t>(src
[1] * scaleFactor
);
572 uint8_t srcB
= static_cast<uint8_t>(src
[2] * scaleFactor
);
573 *dst
= ( ((srcR
& 0xF8) << 8)
574 | ((srcG
& 0xFC) << 3)
575 | ((srcB
& 0xF8) >> 3));
578 template<> MOZ_ALWAYS_INLINE
void
579 pack
<WebGLTexelFormat::RGB32F
, WebGLTexelPremultiplicationOp::None
, float, float>(const float* __restrict src
, float* __restrict dst
)
586 template<> MOZ_ALWAYS_INLINE
void
587 pack
<WebGLTexelFormat::RGB32F
, WebGLTexelPremultiplicationOp::Premultiply
, float, float>(const float* __restrict src
, float* __restrict dst
)
589 float scaleFactor
= src
[3];
590 dst
[0] = src
[0] * scaleFactor
;
591 dst
[1] = src
[1] * scaleFactor
;
592 dst
[2] = src
[2] * scaleFactor
;
595 template<> MOZ_ALWAYS_INLINE
void
596 pack
<WebGLTexelFormat::RGBA32F
, WebGLTexelPremultiplicationOp::None
, float, float>(const float* __restrict src
, float* __restrict dst
)
604 template<> MOZ_ALWAYS_INLINE
void
605 pack
<WebGLTexelFormat::RGBA32F
, WebGLTexelPremultiplicationOp::Premultiply
, float, float>(const float* __restrict src
, float* __restrict dst
)
607 float scaleFactor
= src
[3];
608 dst
[0] = src
[0] * scaleFactor
;
609 dst
[1] = src
[1] * scaleFactor
;
610 dst
[2] = src
[2] * scaleFactor
;
614 template<> MOZ_ALWAYS_INLINE
void
615 pack
<WebGLTexelFormat::A32F
, WebGLTexelPremultiplicationOp::None
, float, float>(const float* __restrict src
, float* __restrict dst
)
620 template<> MOZ_ALWAYS_INLINE
void
621 pack
<WebGLTexelFormat::A32F
, WebGLTexelPremultiplicationOp::Premultiply
, float, float>(const float* __restrict src
, float* __restrict dst
)
626 template<> MOZ_ALWAYS_INLINE
void
627 pack
<WebGLTexelFormat::R32F
, WebGLTexelPremultiplicationOp::None
, float, float>(const float* __restrict src
, float* __restrict dst
)
632 template<> MOZ_ALWAYS_INLINE
void
633 pack
<WebGLTexelFormat::R32F
, WebGLTexelPremultiplicationOp::Premultiply
, float, float>(const float* __restrict src
, float* __restrict dst
)
635 float scaleFactor
= src
[3];
636 dst
[0] = src
[0] * scaleFactor
;
639 template<> MOZ_ALWAYS_INLINE
void
640 pack
<WebGLTexelFormat::RA32F
, WebGLTexelPremultiplicationOp::None
, float, float>(const float* __restrict src
, float* __restrict dst
)
646 template<> MOZ_ALWAYS_INLINE
void
647 pack
<WebGLTexelFormat::RA32F
, WebGLTexelPremultiplicationOp::Premultiply
, float, float>(const float* __restrict src
, float* __restrict dst
)
649 float scaleFactor
= src
[3];
650 dst
[0] = src
[0] * scaleFactor
;
651 dst
[1] = scaleFactor
;
654 /****** END CODE SHARED WITH WEBKIT ******/
656 template<typename SrcType
, typename DstType
> MOZ_ALWAYS_INLINE
void
657 convertType(const SrcType
* __restrict src
, DstType
* __restrict dst
)
659 MOZ_ASSERT(false, "Unimplemented texture format conversion");
662 template<> MOZ_ALWAYS_INLINE
void
663 convertType
<uint8_t, uint8_t>(const uint8_t* __restrict src
, uint8_t* __restrict dst
)
671 template<> MOZ_ALWAYS_INLINE
void
672 convertType
<float, float>(const float* __restrict src
, float* __restrict dst
)
680 template<> MOZ_ALWAYS_INLINE
void
681 convertType
<uint8_t, float>(const uint8_t* __restrict src
, float* __restrict dst
)
683 const float scaleFactor
= 1.f
/ 255.0f
;
684 dst
[0] = src
[0] * scaleFactor
;
685 dst
[1] = src
[1] * scaleFactor
;
686 dst
[2] = src
[2] * scaleFactor
;
687 dst
[3] = src
[3] * scaleFactor
;
690 } // end namespace WebGLTexelConversions
692 } // end namespace mozilla
694 #endif // WEBGLTEXELCONVERSIONS_H_