2010-10-16 01:50:15 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Apple Inc. All rights reserved.
|
|
|
|
* Copyright (C) 2010 Google Inc. All rights reserved.
|
|
|
|
* Copyright (C) 2010 Mozilla Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
|
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WEBGLTEXELCONVERSIONS_H_
|
|
|
|
#define WEBGLTEXELCONVERSIONS_H_
|
|
|
|
|
2011-07-28 07:42:22 +04:00
|
|
|
#ifdef __SUNPRO_CC
|
|
|
|
#define __restrict
|
|
|
|
#endif
|
|
|
|
|
2013-06-11 00:00:35 +04:00
|
|
|
#include "WebGLTypes.h"
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2013-10-11 17:16:44 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-10-16 01:50:15 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
// single precision float
|
|
|
|
// seeeeeeeemmmmmmmmmmmmmmmmmmmmmmm
|
|
|
|
|
|
|
|
// half precision float
|
|
|
|
// seeeeemmmmmmmmmm
|
|
|
|
|
|
|
|
// IEEE 16bits floating point:
|
|
|
|
const uint16_t kFloat16Value_Zero = 0x0000; // = 0000000000000000b
|
|
|
|
const uint16_t kFloat16Value_One = 0x3C00; // = 0011110000000000b
|
|
|
|
const uint16_t kFloat16Value_Infinity = 0x7C00; // = 0111110000000000b
|
|
|
|
const uint16_t kFloat16Value_NaN = 0x7FFF; // = 011111yyyyyyyyyyb (nonzero y)
|
|
|
|
|
|
|
|
MOZ_ALWAYS_INLINE uint16_t
|
|
|
|
packToFloat16(float v)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
float f32Value;
|
|
|
|
uint32_t f32Bits;
|
|
|
|
};
|
|
|
|
|
|
|
|
f32Value = v;
|
|
|
|
|
|
|
|
// pull the sign from v into f16bits
|
|
|
|
uint16_t f16Bits = uint16_t(f32Bits >> 16) & 0x8000;
|
2014-08-01 03:44:18 +04:00
|
|
|
const uint32_t mantissa = f32Bits & 0x7FFFFF;
|
|
|
|
const uint32_t exp = (f32Bits >> 23) & 0xFF;
|
|
|
|
|
|
|
|
// Adapted from: OpenGL ES 2.0 Programming Guide Appx.
|
|
|
|
// Converting Float to Half-Float
|
|
|
|
// 143 = 255 - 127 + 15
|
|
|
|
// = sp_max - sp_bias + hp_bias
|
|
|
|
if (exp >= 143) {
|
|
|
|
if (mantissa && exp == 0xFF) {
|
|
|
|
// Single precision was NaN
|
|
|
|
return f16Bits | kFloat16Value_NaN;
|
|
|
|
} else {
|
|
|
|
// Outside range, store as infinity
|
|
|
|
return f16Bits | kFloat16Value_Infinity;
|
|
|
|
}
|
2014-01-24 01:47:37 +04:00
|
|
|
}
|
|
|
|
|
2014-08-01 03:44:18 +04:00
|
|
|
// too small, try to make a denormalized number
|
|
|
|
// 112 = 255 - 127 - (15 + 1)
|
|
|
|
// = sp_max - sp_bias - (hp_bias + 1)
|
|
|
|
if (exp <= 112) {
|
|
|
|
return f16Bits | uint16_t(mantissa >> (14 + 112 - exp));
|
2014-01-24 01:47:37 +04:00
|
|
|
}
|
|
|
|
|
2014-08-01 03:44:18 +04:00
|
|
|
f16Bits |= uint16_t(exp - 112) << 10;
|
|
|
|
f16Bits |= uint16_t(mantissa >> 13) & 0x03FF;
|
2014-01-24 01:47:37 +04:00
|
|
|
|
|
|
|
return f16Bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ALWAYS_INLINE float
|
|
|
|
unpackFromFloat16(uint16_t v)
|
|
|
|
{
|
2014-08-01 03:44:18 +04:00
|
|
|
union {
|
2014-01-24 01:47:37 +04:00
|
|
|
float f32Value;
|
|
|
|
uint32_t f32Bits;
|
|
|
|
};
|
|
|
|
|
|
|
|
// grab sign bit
|
|
|
|
f32Bits = uint32_t(v & 0x8000) << 16;
|
2014-08-01 03:44:18 +04:00
|
|
|
uint16_t exp = (v >> 10) & 0x001F;
|
|
|
|
uint16_t mantissa = v & 0x03FF;
|
|
|
|
|
2015-02-25 01:09:09 +03:00
|
|
|
if (!exp) {
|
2014-08-01 03:44:18 +04:00
|
|
|
// Handle denormalized numbers
|
|
|
|
// Adapted from: OpenGL ES 2.0 Programming Guide Appx.
|
|
|
|
// Converting Float to Half-Float
|
|
|
|
if (mantissa) {
|
|
|
|
exp = 112; // See packToFloat16
|
|
|
|
mantissa <<= 1;
|
|
|
|
// For every leading zero, decrement the exponent
|
|
|
|
// and shift the mantissa to the left
|
|
|
|
while ((mantissa & (1 << 10)) == 0) {
|
|
|
|
mantissa <<= 1;
|
|
|
|
--exp;
|
|
|
|
}
|
|
|
|
mantissa &= 0x03FF;
|
|
|
|
|
|
|
|
f32Bits |= (exp << 23) | (mantissa << 13);
|
|
|
|
|
|
|
|
// Denormalized number
|
|
|
|
return f32Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// +/- zero
|
2014-01-24 01:47:37 +04:00
|
|
|
return f32Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exp == 0x001F) {
|
|
|
|
if (v & 0x03FF) {
|
|
|
|
// this is a NaN
|
|
|
|
f32Bits |= 0x7FFFFFFF;
|
|
|
|
} else {
|
|
|
|
// this is -inf or +inf
|
|
|
|
f32Bits |= 0x7F800000;
|
|
|
|
}
|
|
|
|
return f32Value;
|
|
|
|
}
|
|
|
|
|
2014-07-29 02:06:55 +04:00
|
|
|
f32Bits |= uint32_t(exp + (-15 + 127)) << 23;
|
2014-01-24 01:47:37 +04:00
|
|
|
f32Bits |= uint32_t(v & 0x03FF) << 13;
|
|
|
|
|
|
|
|
return f32Value;
|
|
|
|
}
|
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLTexelPremultiplicationOp : int {
|
2013-10-11 17:16:44 +04:00
|
|
|
None,
|
2012-05-07 21:05:32 +04:00
|
|
|
Premultiply,
|
|
|
|
Unpremultiply
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-10-11 17:16:44 +04:00
|
|
|
|
|
|
|
namespace WebGLTexelConversions {
|
2012-05-07 21:05:32 +04:00
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format>
|
2012-05-07 21:05:32 +04:00
|
|
|
struct IsFloatFormat
|
|
|
|
{
|
|
|
|
static const bool Value =
|
2013-10-11 17:16:43 +04:00
|
|
|
Format == WebGLTexelFormat::RGBA32F ||
|
|
|
|
Format == WebGLTexelFormat::RGB32F ||
|
|
|
|
Format == WebGLTexelFormat::RA32F ||
|
|
|
|
Format == WebGLTexelFormat::R32F ||
|
|
|
|
Format == WebGLTexelFormat::A32F;
|
2012-05-07 21:05:32 +04:00
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format>
|
2014-01-24 01:47:37 +04:00
|
|
|
struct IsHalfFloatFormat
|
|
|
|
{
|
|
|
|
static const bool Value =
|
|
|
|
Format == WebGLTexelFormat::RGBA16F ||
|
|
|
|
Format == WebGLTexelFormat::RGB16F ||
|
|
|
|
Format == WebGLTexelFormat::RA16F ||
|
|
|
|
Format == WebGLTexelFormat::R16F ||
|
|
|
|
Format == WebGLTexelFormat::A16F;
|
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format>
|
2012-05-07 21:05:32 +04:00
|
|
|
struct Is16bppFormat
|
|
|
|
{
|
|
|
|
static const bool Value =
|
2013-10-11 17:16:43 +04:00
|
|
|
Format == WebGLTexelFormat::RGBA4444 ||
|
|
|
|
Format == WebGLTexelFormat::RGBA5551 ||
|
|
|
|
Format == WebGLTexelFormat::RGB565;
|
2012-05-07 21:05:32 +04:00
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format,
|
2012-05-07 21:05:32 +04:00
|
|
|
bool IsFloat = IsFloatFormat<Format>::Value,
|
2014-01-24 01:47:37 +04:00
|
|
|
bool Is16bpp = Is16bppFormat<Format>::Value,
|
|
|
|
bool IsHalfFloat = IsHalfFloatFormat<Format>::Value>
|
2012-05-07 21:05:32 +04:00
|
|
|
struct DataTypeForFormat
|
|
|
|
{
|
|
|
|
typedef uint8_t Type;
|
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format>
|
2014-01-24 01:47:37 +04:00
|
|
|
struct DataTypeForFormat<Format, true, false, false>
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
|
|
|
typedef float Type;
|
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format>
|
2014-01-24 01:47:37 +04:00
|
|
|
struct DataTypeForFormat<Format, false, true, false>
|
|
|
|
{
|
|
|
|
typedef uint16_t Type;
|
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format>
|
2014-01-24 01:47:37 +04:00
|
|
|
struct DataTypeForFormat<Format, false, false, true>
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
|
|
|
typedef uint16_t Type;
|
|
|
|
};
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format>
|
2012-05-07 21:05:32 +04:00
|
|
|
struct IntermediateFormat
|
|
|
|
{
|
2015-01-26 01:22:08 +03:00
|
|
|
static const WebGLTexelFormat Value
|
2013-10-11 17:16:43 +04:00
|
|
|
= IsFloatFormat<Format>::Value
|
|
|
|
? WebGLTexelFormat::RGBA32F
|
2014-01-24 01:47:37 +04:00
|
|
|
: IsHalfFloatFormat<Format>::Value ? WebGLTexelFormat::RGBA16F
|
|
|
|
: WebGLTexelFormat::RGBA8;
|
2012-05-07 21:05:32 +04:00
|
|
|
};
|
|
|
|
|
2014-01-24 07:53:53 +04:00
|
|
|
inline GLenum
|
|
|
|
GLFormatForTexelFormat(WebGLTexelFormat format) {
|
|
|
|
switch (format) {
|
|
|
|
case WebGLTexelFormat::R8: return LOCAL_GL_LUMINANCE;
|
|
|
|
case WebGLTexelFormat::A8: return LOCAL_GL_ALPHA;
|
|
|
|
case WebGLTexelFormat::RA8: return LOCAL_GL_LUMINANCE_ALPHA;
|
|
|
|
case WebGLTexelFormat::RGBA5551: return LOCAL_GL_RGBA;
|
|
|
|
case WebGLTexelFormat::RGBA4444: return LOCAL_GL_RGBA;
|
|
|
|
case WebGLTexelFormat::RGB565: return LOCAL_GL_RGB;
|
|
|
|
case WebGLTexelFormat::RGB8: return LOCAL_GL_RGB;
|
|
|
|
case WebGLTexelFormat::RGBA8: return LOCAL_GL_RGBA;
|
|
|
|
case WebGLTexelFormat::BGRA8: return LOCAL_GL_BGRA;
|
|
|
|
case WebGLTexelFormat::BGRX8: return LOCAL_GL_BGR;
|
|
|
|
case WebGLTexelFormat::R32F: return LOCAL_GL_LUMINANCE;
|
|
|
|
case WebGLTexelFormat::A32F: return LOCAL_GL_ALPHA;
|
|
|
|
case WebGLTexelFormat::RA32F: return LOCAL_GL_LUMINANCE_ALPHA;
|
|
|
|
case WebGLTexelFormat::RGB32F: return LOCAL_GL_RGB;
|
|
|
|
case WebGLTexelFormat::RGBA32F: return LOCAL_GL_RGBA;
|
2014-01-24 01:47:37 +04:00
|
|
|
case WebGLTexelFormat::R16F: return LOCAL_GL_LUMINANCE;
|
|
|
|
case WebGLTexelFormat::A16F: return LOCAL_GL_ALPHA;
|
|
|
|
case WebGLTexelFormat::RA16F: return LOCAL_GL_LUMINANCE_ALPHA;
|
|
|
|
case WebGLTexelFormat::RGB16F: return LOCAL_GL_RGB;
|
|
|
|
case WebGLTexelFormat::RGBA16F: return LOCAL_GL_RGBA;
|
2014-01-24 07:53:53 +04:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown texel format. Coding mistake?");
|
|
|
|
return LOCAL_GL_INVALID_ENUM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
inline size_t TexelBytesForFormat(WebGLTexelFormat format) {
|
2012-05-07 21:05:32 +04:00
|
|
|
switch (format) {
|
2013-10-11 17:16:43 +04:00
|
|
|
case WebGLTexelFormat::R8:
|
|
|
|
case WebGLTexelFormat::A8:
|
2012-05-07 21:05:32 +04:00
|
|
|
return 1;
|
2013-10-11 17:16:43 +04:00
|
|
|
case WebGLTexelFormat::RA8:
|
|
|
|
case WebGLTexelFormat::RGBA5551:
|
|
|
|
case WebGLTexelFormat::RGBA4444:
|
|
|
|
case WebGLTexelFormat::RGB565:
|
2014-01-24 01:47:37 +04:00
|
|
|
case WebGLTexelFormat::R16F:
|
|
|
|
case WebGLTexelFormat::A16F:
|
2012-05-07 21:05:32 +04:00
|
|
|
return 2;
|
2013-10-11 17:16:43 +04:00
|
|
|
case WebGLTexelFormat::RGB8:
|
2012-05-07 21:05:32 +04:00
|
|
|
return 3;
|
2013-10-11 17:16:43 +04:00
|
|
|
case WebGLTexelFormat::RGBA8:
|
|
|
|
case WebGLTexelFormat::BGRA8:
|
|
|
|
case WebGLTexelFormat::BGRX8:
|
|
|
|
case WebGLTexelFormat::R32F:
|
|
|
|
case WebGLTexelFormat::A32F:
|
2014-01-24 01:47:37 +04:00
|
|
|
case WebGLTexelFormat::RA16F:
|
2012-05-07 21:05:32 +04:00
|
|
|
return 4;
|
2014-01-24 01:47:37 +04:00
|
|
|
case WebGLTexelFormat::RGB16F:
|
|
|
|
return 6;
|
|
|
|
case WebGLTexelFormat::RGBA16F:
|
2013-10-11 17:16:43 +04:00
|
|
|
case WebGLTexelFormat::RA32F:
|
2012-05-07 21:05:32 +04:00
|
|
|
return 8;
|
2013-10-11 17:16:43 +04:00
|
|
|
case WebGLTexelFormat::RGB32F:
|
2012-05-07 21:05:32 +04:00
|
|
|
return 12;
|
2013-10-11 17:16:43 +04:00
|
|
|
case WebGLTexelFormat::RGBA32F:
|
2012-05-07 21:05:32 +04:00
|
|
|
return 16;
|
|
|
|
default:
|
2013-10-11 17:16:43 +04:00
|
|
|
MOZ_ASSERT(false, "Unknown texel format. Coding mistake?");
|
2012-05-07 21:05:32 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
MOZ_ALWAYS_INLINE bool HasAlpha(WebGLTexelFormat format) {
|
2013-10-11 17:16:43 +04:00
|
|
|
return format == WebGLTexelFormat::A8 ||
|
2014-01-24 01:47:37 +04:00
|
|
|
format == WebGLTexelFormat::A16F ||
|
2013-10-11 17:16:43 +04:00
|
|
|
format == WebGLTexelFormat::A32F ||
|
|
|
|
format == WebGLTexelFormat::RA8 ||
|
2014-01-24 01:47:37 +04:00
|
|
|
format == WebGLTexelFormat::RA16F ||
|
2013-10-11 17:16:43 +04:00
|
|
|
format == WebGLTexelFormat::RA32F ||
|
|
|
|
format == WebGLTexelFormat::RGBA8 ||
|
|
|
|
format == WebGLTexelFormat::BGRA8 ||
|
2014-01-24 01:47:37 +04:00
|
|
|
format == WebGLTexelFormat::RGBA16F ||
|
2013-10-11 17:16:43 +04:00
|
|
|
format == WebGLTexelFormat::RGBA32F ||
|
|
|
|
format == WebGLTexelFormat::RGBA4444 ||
|
|
|
|
format == WebGLTexelFormat::RGBA5551;
|
2012-05-07 21:05:32 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
MOZ_ALWAYS_INLINE bool HasColor(WebGLTexelFormat format) {
|
2013-10-11 17:16:43 +04:00
|
|
|
return format == WebGLTexelFormat::R8 ||
|
2014-01-24 01:47:37 +04:00
|
|
|
format == WebGLTexelFormat::R16F ||
|
2013-10-11 17:16:43 +04:00
|
|
|
format == WebGLTexelFormat::R32F ||
|
|
|
|
format == WebGLTexelFormat::RA8 ||
|
2014-01-24 01:47:37 +04:00
|
|
|
format == WebGLTexelFormat::RA16F ||
|
2013-10-11 17:16:43 +04:00
|
|
|
format == WebGLTexelFormat::RA32F ||
|
|
|
|
format == WebGLTexelFormat::RGB8 ||
|
|
|
|
format == WebGLTexelFormat::BGRX8 ||
|
|
|
|
format == WebGLTexelFormat::RGB565 ||
|
2014-01-24 01:47:37 +04:00
|
|
|
format == WebGLTexelFormat::RGB16F ||
|
2013-10-11 17:16:43 +04:00
|
|
|
format == WebGLTexelFormat::RGB32F ||
|
|
|
|
format == WebGLTexelFormat::RGBA8 ||
|
|
|
|
format == WebGLTexelFormat::BGRA8 ||
|
2014-01-24 01:47:37 +04:00
|
|
|
format == WebGLTexelFormat::RGBA16F ||
|
2013-10-11 17:16:43 +04:00
|
|
|
format == WebGLTexelFormat::RGBA32F ||
|
|
|
|
format == WebGLTexelFormat::RGBA4444 ||
|
|
|
|
format == WebGLTexelFormat::RGBA5551;
|
2012-05-07 21:05:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-27 00:00:44 +04:00
|
|
|
/****** BEGIN CODE SHARED WITH WEBKIT ******/
|
2010-10-16 01:50:15 +04:00
|
|
|
|
2012-05-07 21:05:32 +04:00
|
|
|
// the pack/unpack functions here are originally from this file:
|
|
|
|
// http://trac.webkit.org/browser/trunk/WebCore/platform/graphics/GraphicsContext3D.cpp
|
|
|
|
|
2010-10-16 01:50:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Pixel unpacking routines.
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format, typename SrcType, typename DstType>
|
2013-10-11 17:16:44 +04:00
|
|
|
MOZ_ALWAYS_INLINE void
|
2012-05-07 21:05:32 +04:00
|
|
|
unpack(const SrcType* __restrict src,
|
|
|
|
DstType* __restrict dst)
|
|
|
|
{
|
2013-10-11 17:16:43 +04:00
|
|
|
MOZ_ASSERT(false, "Unimplemented texture format conversion");
|
2012-05-07 21:05:32 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RGBA8, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RGB8, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = 0xFF;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::BGRA8, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[2];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::BGRX8, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[2];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = 0xFF;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RGBA5551, uint16_t, uint8_t>(const uint16_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
uint16_t packedValue = src[0];
|
|
|
|
uint8_t r = (packedValue >> 11) & 0x1F;
|
2010-10-16 01:50:15 +04:00
|
|
|
uint8_t g = (packedValue >> 6) & 0x1F;
|
|
|
|
uint8_t b = (packedValue >> 1) & 0x1F;
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = (r << 3) | (r & 0x7);
|
|
|
|
dst[1] = (g << 3) | (g & 0x7);
|
|
|
|
dst[2] = (b << 3) | (b & 0x7);
|
|
|
|
dst[3] = (packedValue & 0x1) ? 0xFF : 0;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RGBA4444, uint16_t, uint8_t>(const uint16_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
uint16_t packedValue = src[0];
|
|
|
|
uint8_t r = (packedValue >> 12) & 0x0F;
|
2010-10-16 01:50:15 +04:00
|
|
|
uint8_t g = (packedValue >> 8) & 0x0F;
|
|
|
|
uint8_t b = (packedValue >> 4) & 0x0F;
|
|
|
|
uint8_t a = packedValue & 0x0F;
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = (r << 4) | r;
|
|
|
|
dst[1] = (g << 4) | g;
|
|
|
|
dst[2] = (b << 4) | b;
|
|
|
|
dst[3] = (a << 4) | a;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RGB565, uint16_t, uint8_t>(const uint16_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
uint16_t packedValue = src[0];
|
|
|
|
uint8_t r = (packedValue >> 11) & 0x1F;
|
2010-10-16 01:50:15 +04:00
|
|
|
uint8_t g = (packedValue >> 5) & 0x3F;
|
|
|
|
uint8_t b = packedValue & 0x1F;
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = (r << 3) | (r & 0x7);
|
|
|
|
dst[1] = (g << 2) | (g & 0x3);
|
|
|
|
dst[2] = (b << 3) | (b & 0x7);
|
|
|
|
dst[3] = 0xFF;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::R8, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[0];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = 0xFF;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RA8, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[0];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = src[1];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::A8, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = 0;
|
|
|
|
dst[1] = 0;
|
|
|
|
dst[2] = 0;
|
|
|
|
dst[3] = src[0];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RGBA32F, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RGB32F, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = 1.0f;
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::R32F, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[0];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = 1.0f;
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::RA32F, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[0];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = src[1];
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:43 +04:00
|
|
|
unpack<WebGLTexelFormat::A32F, float, float>(const float* __restrict src, float* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
|
|
|
dst[0] = 0;
|
|
|
|
dst[1] = 0;
|
|
|
|
dst[2] = 0;
|
|
|
|
dst[3] = src[0];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
unpack<WebGLTexelFormat::RGBA16F, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
unpack<WebGLTexelFormat::RGB16F, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = kFloat16Value_One;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
unpack<WebGLTexelFormat::R16F, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[0];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = kFloat16Value_One;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
unpack<WebGLTexelFormat::RA16F, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[0];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = src[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
unpack<WebGLTexelFormat::A16F, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = kFloat16Value_Zero;
|
|
|
|
dst[1] = kFloat16Value_Zero;
|
|
|
|
dst[2] = kFloat16Value_Zero;
|
|
|
|
dst[3] = src[0];
|
|
|
|
}
|
|
|
|
|
2010-10-16 01:50:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Pixel packing routines.
|
|
|
|
//
|
|
|
|
|
2015-01-26 01:22:08 +03:00
|
|
|
template<WebGLTexelFormat Format,
|
|
|
|
WebGLTexelPremultiplicationOp PremultiplicationOp,
|
2013-10-11 17:16:44 +04:00
|
|
|
typename SrcType,
|
|
|
|
typename DstType>
|
2013-10-11 17:16:44 +04:00
|
|
|
MOZ_ALWAYS_INLINE void
|
2012-05-07 21:05:32 +04:00
|
|
|
pack(const SrcType* __restrict src,
|
|
|
|
DstType* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2015-07-09 05:00:47 +03:00
|
|
|
MOZ_CRASH("Unimplemented texture format conversion");
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::A8, WebGLTexelPremultiplicationOp::None, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::A8, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::A8, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::R8, WebGLTexelPremultiplicationOp::None, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::R8, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] / 255.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::R8, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
2012-05-07 21:05:32 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RA8, WebGLTexelPremultiplicationOp::None, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[3];
|
2012-05-07 21:05:32 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RA8, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] / 255.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
|
|
|
dst[1] = src[3];
|
2012-05-07 21:05:32 +04:00
|
|
|
}
|
|
|
|
|
2012-05-07 22:04:10 +04:00
|
|
|
// FIXME: this routine is lossy and must be removed.
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RA8, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
|
|
|
float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
|
|
|
dst[1] = src[3];
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB8, WebGLTexelPremultiplicationOp::None, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB8, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
|
|
|
float scaleFactor = src[3] / 255.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
|
|
|
dst[1] = srcG;
|
|
|
|
dst[2] = srcB;
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB8, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
|
|
|
dst[1] = srcG;
|
|
|
|
dst[2] = srcB;
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA8, WebGLTexelPremultiplicationOp::None, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA8, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] / 255.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
|
|
|
dst[1] = srcG;
|
|
|
|
dst[2] = srcB;
|
|
|
|
dst[3] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: this routine is lossy and must be removed.
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA8, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
dst[0] = srcR;
|
|
|
|
dst[1] = srcG;
|
|
|
|
dst[2] = srcB;
|
|
|
|
dst[3] = src[3];
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA4444, WebGLTexelPremultiplicationOp::None, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
*dst = ( ((src[0] & 0xF0) << 8)
|
|
|
|
| ((src[1] & 0xF0) << 4)
|
|
|
|
| (src[2] & 0xF0)
|
|
|
|
| (src[3] >> 4) );
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA4444, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] / 255.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
*dst = ( ((srcR & 0xF0) << 8)
|
|
|
|
| ((srcG & 0xF0) << 4)
|
|
|
|
| (srcB & 0xF0)
|
|
|
|
| (src[3] >> 4));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: this routine is lossy and must be removed.
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA4444, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
*dst = ( ((srcR & 0xF0) << 8)
|
|
|
|
| ((srcG & 0xF0) << 4)
|
|
|
|
| (srcB & 0xF0)
|
|
|
|
| (src[3] >> 4));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA5551, WebGLTexelPremultiplicationOp::None, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
*dst = ( ((src[0] & 0xF8) << 8)
|
|
|
|
| ((src[1] & 0xF8) << 3)
|
|
|
|
| ((src[2] & 0xF8) >> 2)
|
|
|
|
| (src[3] >> 7));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA5551, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] / 255.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
*dst = ( ((srcR & 0xF8) << 8)
|
|
|
|
| ((srcG & 0xF8) << 3)
|
|
|
|
| ((srcB & 0xF8) >> 2)
|
|
|
|
| (src[3] >> 7));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: this routine is lossy and must be removed.
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA5551, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
*dst = ( ((srcR & 0xF8) << 8)
|
|
|
|
| ((srcG & 0xF8) << 3)
|
|
|
|
| ((srcB & 0xF8) >> 2)
|
|
|
|
| (src[3] >> 7));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB565, WebGLTexelPremultiplicationOp::None, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
*dst = ( ((src[0] & 0xF8) << 8)
|
|
|
|
| ((src[1] & 0xFC) << 3)
|
|
|
|
| ((src[2] & 0xF8) >> 3));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB565, WebGLTexelPremultiplicationOp::Premultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] / 255.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
*dst = ( ((srcR & 0xF8) << 8)
|
|
|
|
| ((srcG & 0xFC) << 3)
|
|
|
|
| ((srcB & 0xF8) >> 3));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: this routine is lossy and must be removed.
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB565, WebGLTexelPremultiplicationOp::Unpremultiply, uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
2010-10-16 01:50:15 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3] ? 255.0f / src[3] : 1.0f;
|
|
|
|
uint8_t srcR = static_cast<uint8_t>(src[0] * scaleFactor);
|
|
|
|
uint8_t srcG = static_cast<uint8_t>(src[1] * scaleFactor);
|
|
|
|
uint8_t srcB = static_cast<uint8_t>(src[2] * scaleFactor);
|
|
|
|
*dst = ( ((srcR & 0xF8) << 8)
|
|
|
|
| ((srcG & 0xFC) << 3)
|
|
|
|
| ((srcB & 0xF8) >> 3));
|
2010-10-16 01:50:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB32F, WebGLTexelPremultiplicationOp::None, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGB32F, WebGLTexelPremultiplicationOp::Premultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3];
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
dst[1] = src[1] * scaleFactor;
|
|
|
|
dst[2] = src[2] * scaleFactor;
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2015-07-21 22:00:08 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGB32F, WebGLTexelPremultiplicationOp::Unpremultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
|
|
|
{
|
|
|
|
float scaleFactor = src[3] ? 1.0f / src[3] : 1.0f;
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
dst[1] = src[1] * scaleFactor;
|
|
|
|
dst[2] = src[2] * scaleFactor;
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA32F, WebGLTexelPremultiplicationOp::None, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RGBA32F, WebGLTexelPremultiplicationOp::Premultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3];
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
dst[1] = src[1] * scaleFactor;
|
|
|
|
dst[2] = src[2] * scaleFactor;
|
|
|
|
dst[3] = src[3];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2015-07-09 05:00:47 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGBA32F, WebGLTexelPremultiplicationOp::Unpremultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
|
|
|
{
|
2015-07-21 22:00:08 +03:00
|
|
|
float scaleFactor = src[3] ? 1.0f / src[3] : 1.0f;
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
dst[1] = src[1] * scaleFactor;
|
|
|
|
dst[2] = src[2] * scaleFactor;
|
|
|
|
dst[3] = src[3];
|
2015-07-09 05:00:47 +03:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::A32F, WebGLTexelPremultiplicationOp::None, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[3];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::A32F, WebGLTexelPremultiplicationOp::Premultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[3];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2015-07-21 22:00:08 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::A32F, WebGLTexelPremultiplicationOp::Unpremultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[3];
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::R32F, WebGLTexelPremultiplicationOp::None, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::R32F, WebGLTexelPremultiplicationOp::Premultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
2012-05-07 21:05:32 +04:00
|
|
|
{
|
|
|
|
float scaleFactor = src[3];
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
}
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2015-07-21 22:00:08 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::R32F, WebGLTexelPremultiplicationOp::Unpremultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
|
|
|
{
|
|
|
|
float scaleFactor = src[3] ? 1.0f / src[3] : 1.0f;
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RA32F, WebGLTexelPremultiplicationOp::None, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[3];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2013-10-11 17:16:44 +04:00
|
|
|
pack<WebGLTexelFormat::RA32F, WebGLTexelPremultiplicationOp::Premultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
2011-05-20 23:53:53 +04:00
|
|
|
{
|
2012-05-07 21:05:32 +04:00
|
|
|
float scaleFactor = src[3];
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
2015-07-21 22:24:45 +03:00
|
|
|
dst[1] = src[3];
|
2011-05-20 23:53:53 +04:00
|
|
|
}
|
|
|
|
|
2015-07-21 22:00:08 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RA32F, WebGLTexelPremultiplicationOp::Unpremultiply, float, float>(const float* __restrict src, float* __restrict dst)
|
|
|
|
{
|
|
|
|
float scaleFactor = src[3] ? 1.0f / src[3] : 1.0f;
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
dst[1] = src[3];
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGB16F, WebGLTexelPremultiplicationOp::None, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGB16F, WebGLTexelPremultiplicationOp::Premultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float scaleFactor = unpackFromFloat16(src[3]);
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
|
|
|
dst[1] = packToFloat16(unpackFromFloat16(src[1]) * scaleFactor);
|
|
|
|
dst[2] = packToFloat16(unpackFromFloat16(src[2]) * scaleFactor);
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:37:32 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGB16F, WebGLTexelPremultiplicationOp::Unpremultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float unpackedAlpha = unpackFromFloat16(src[3]);
|
|
|
|
float scaleFactor = unpackedAlpha ? 1.0f / unpackedAlpha : 1.0f;
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
|
|
|
dst[1] = packToFloat16(unpackFromFloat16(src[1]) * scaleFactor);
|
|
|
|
dst[2] = packToFloat16(unpackFromFloat16(src[2]) * scaleFactor);
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGBA16F, WebGLTexelPremultiplicationOp::None, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGBA16F, WebGLTexelPremultiplicationOp::Premultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float scaleFactor = unpackFromFloat16(src[3]);
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
|
|
|
dst[1] = packToFloat16(unpackFromFloat16(src[1]) * scaleFactor);
|
|
|
|
dst[2] = packToFloat16(unpackFromFloat16(src[2]) * scaleFactor);
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:37:32 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RGBA16F, WebGLTexelPremultiplicationOp::Unpremultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float unpackedAlpha = unpackFromFloat16(src[3]);
|
|
|
|
float scaleFactor = unpackedAlpha ? 1.0f / unpackedAlpha : 1.0f;
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
|
|
|
dst[1] = packToFloat16(unpackFromFloat16(src[1]) * scaleFactor);
|
|
|
|
dst[2] = packToFloat16(unpackFromFloat16(src[2]) * scaleFactor);
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::A16F, WebGLTexelPremultiplicationOp::None, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::A16F, WebGLTexelPremultiplicationOp::Premultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[3];
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:37:32 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::A16F, WebGLTexelPremultiplicationOp::Unpremultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[3];
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::R16F, WebGLTexelPremultiplicationOp::None, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::R16F, WebGLTexelPremultiplicationOp::Premultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float scaleFactor = unpackFromFloat16(src[3]);
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:37:32 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::R16F, WebGLTexelPremultiplicationOp::Unpremultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float unpackedAlpha = unpackFromFloat16(src[3]);
|
|
|
|
float scaleFactor = unpackedAlpha ? 1.0f / unpackedAlpha : 1.0f;
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RA16F, WebGLTexelPremultiplicationOp::None, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RA16F, WebGLTexelPremultiplicationOp::Premultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float scaleFactor = unpackFromFloat16(src[3]);
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
2015-07-21 22:24:45 +03:00
|
|
|
dst[1] = src[3];
|
2014-01-24 01:47:37 +04:00
|
|
|
}
|
|
|
|
|
2015-07-21 21:37:32 +03:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
pack<WebGLTexelFormat::RA16F, WebGLTexelPremultiplicationOp::Unpremultiply, uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
float unpackedAlpha = unpackFromFloat16(src[3]);
|
|
|
|
float scaleFactor = unpackedAlpha ? 1.0f / unpackedAlpha : 1.0f;
|
|
|
|
dst[0] = packToFloat16(unpackFromFloat16(src[0]) * scaleFactor);
|
|
|
|
dst[1] = src[3];
|
|
|
|
}
|
|
|
|
|
2011-10-27 00:00:44 +04:00
|
|
|
/****** END CODE SHARED WITH WEBKIT ******/
|
2010-10-16 01:50:15 +04:00
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<typename SrcType, typename DstType> MOZ_ALWAYS_INLINE void
|
2012-05-07 21:05:32 +04:00
|
|
|
convertType(const SrcType* __restrict src, DstType* __restrict dst)
|
|
|
|
{
|
2013-10-11 17:16:43 +04:00
|
|
|
MOZ_ASSERT(false, "Unimplemented texture format conversion");
|
2012-05-07 21:05:32 +04:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2012-05-07 21:05:32 +04:00
|
|
|
convertType<uint8_t, uint8_t>(const uint8_t* __restrict src, uint8_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
convertType<uint16_t, uint16_t>(const uint16_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2012-05-07 21:05:32 +04:00
|
|
|
convertType<float, float>(const float* __restrict src, float* __restrict dst)
|
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:16:44 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
2012-05-07 21:05:32 +04:00
|
|
|
convertType<uint8_t, float>(const uint8_t* __restrict src, float* __restrict dst)
|
|
|
|
{
|
|
|
|
const float scaleFactor = 1.f / 255.0f;
|
|
|
|
dst[0] = src[0] * scaleFactor;
|
|
|
|
dst[1] = src[1] * scaleFactor;
|
|
|
|
dst[2] = src[2] * scaleFactor;
|
|
|
|
dst[3] = src[3] * scaleFactor;
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:47:37 +04:00
|
|
|
template<> MOZ_ALWAYS_INLINE void
|
|
|
|
convertType<uint8_t, uint16_t>(const uint8_t* __restrict src, uint16_t* __restrict dst)
|
|
|
|
{
|
|
|
|
const float scaleFactor = 1.f / 255.0f;
|
|
|
|
dst[0] = packToFloat16(src[0] * scaleFactor);
|
|
|
|
dst[1] = packToFloat16(src[1] * scaleFactor);
|
|
|
|
dst[2] = packToFloat16(src[2] * scaleFactor);
|
|
|
|
dst[3] = packToFloat16(src[3] * scaleFactor);
|
|
|
|
}
|
|
|
|
|
2010-10-16 01:50:15 +04:00
|
|
|
} // end namespace WebGLTexelConversions
|
|
|
|
|
|
|
|
} // end namespace mozilla
|
|
|
|
|
|
|
|
#endif // WEBGLTEXELCONVERSIONS_H_
|