193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/* 293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2010 Mozilla Corporation. All rights reserved. 493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * modification, are permitted provided that the following conditions 793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * are met: 893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) */ 2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "config.h" 2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/platform/graphics/GraphicsContext3D.h" 2993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 3093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/html/ImageData.h" 3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/html/canvas/CheckedInt.h" 3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/platform/graphics/ImageObserver.h" 3393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/platform/graphics/cpu/arm/GraphicsContext3DNEON.h" 3493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/platform/image-decoders/ImageDecoder.h" 3593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 3693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)namespace WebCore { 3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 3893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)namespace { 3993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 4093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)GraphicsContext3D::DataFormat getDataFormat(GC3Denum destinationFormat, GC3Denum destinationType) 4193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 4293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) GraphicsContext3D::DataFormat dstFormat = GraphicsContext3D::DataFormatRGBA8; 4393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (destinationType) { 4493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::UNSIGNED_BYTE: 4593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (destinationFormat) { 4693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::RGB: 4793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGB8; 4893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 4993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::RGBA: 5093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGBA8; 5193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 5293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::ALPHA: 5393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatA8; 5493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::LUMINANCE: 5693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatR8; 5793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 5893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::LUMINANCE_ALPHA: 5993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRA8; 6093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 6193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 6293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 6493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 6593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4: 6693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGBA4444; 6793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 6893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1: 6993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGBA5551; 7093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::UNSIGNED_SHORT_5_6_5: 7293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGB565; 7393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 7493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::HALF_FLOAT_OES: // OES_texture_half_float 7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (destinationFormat) { 7693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::RGB: 7793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGB16F; 7893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 7993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::RGBA: 8093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGBA16F; 8193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 8293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::ALPHA: 8393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatA16F; 8493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 8593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::LUMINANCE: 8693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatR16F; 8793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 8893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::LUMINANCE_ALPHA: 8993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRA16F; 9093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 9193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 9293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 9393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 9493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 9593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::FLOAT: // OES_texture_float 9693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (destinationFormat) { 9793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::RGB: 9893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGB32F; 9993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 10093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::RGBA: 10193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRGBA32F; 10293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 10393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::ALPHA: 10493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatA32F; 10593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 10693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::LUMINANCE: 10793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatR32F; 10893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 10993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::LUMINANCE_ALPHA: 11093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstFormat = GraphicsContext3D::DataFormatRA32F; 11193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 11293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 11393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 11493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 11593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) break; 11693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 11793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 11893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 11993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return dstFormat; 12093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 12193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 12293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// Following Float to Half-Float converion code is from the implementation of ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf, 12393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September 2010). 12493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// Specially, the basetable[512] and shifttable[512] are generated as follows: 12593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/* 12693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)unsigned short basetable[512]; 12793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)unsigned char shifttable[512]; 12893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 12993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)void generatetables(){ 13093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned int i; 13193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int e; 13293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (i = 0; i < 256; ++i){ 13393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) e = i - 127; 13493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (e < -24){ // Very small numbers map to zero 13593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i | 0x000] = 0x0000; 13693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i | 0x100] = 0x8000; 13793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i | 0x000] = 24; 13893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i | 0x100] = 24; 13993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 14093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) else if (e < -14) { // Small numbers map to denorms 14193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i | 0x000] = (0x0400>>(-e-14)); 14293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i | 0x100] = (0x0400>>(-e-14)) | 0x8000; 14393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i | 0x000] = -e-1; 14493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i | 0x100] = -e-1; 14593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 14693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) else if (e <= 15){ // Normal numbers just lose precision 14793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i | 0x000] = ((e+15)<<10); 14893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i| 0x100] = ((e+15)<<10) | 0x8000; 14993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i|0x000] = 13; 15093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i|0x100] = 13; 15193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 15293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) else if (e<128){ // Large numbers map to Infinity 15393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i|0x000] = 0x7C00; 15493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i|0x100] = 0xFC00; 15593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i|0x000] = 24; 15693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i|0x100] = 24; 15793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 15893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) else { // Infinity and NaN's stay Infinity and NaN's 15993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i|0x000] = 0x7C00; 16093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) basetable[i|0x100] = 0xFC00; 16193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i|0x000] = 13; 16293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) shifttable[i|0x100] = 13; 16393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 16493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 16593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 16693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)*/ 16793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 16893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)unsigned short baseTable[512] = { 16993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 17693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)512, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360, 17793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552, 24576, 25600, 26624, 27648, 28672, 29696, 30720, 31744, 17893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 17993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 18093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 18193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 18293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 18393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 18493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 18593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 18693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 18793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 18893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 18993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 19093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 19193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)32768, 32768, 32768, 32768, 32768, 32768, 32768, 32769, 32770, 32772, 32776, 32784, 32800, 32832, 32896, 33024, 19293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)33280, 33792, 34816, 35840, 36864, 37888, 38912, 39936, 40960, 41984, 43008, 44032, 45056, 46080, 47104, 48128, 19393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)49152, 50176, 51200, 52224, 53248, 54272, 55296, 56320, 57344, 58368, 59392, 60416, 61440, 62464, 63488, 64512, 19493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 19593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 19693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 19793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 19893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 19993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 20093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512 20193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 20293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 20393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)unsigned char shiftTable[512] = { 20493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 20593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 20693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 20793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 20893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 20993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 21193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 21293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24, 21393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 21993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13, 22093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 22793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 22893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24, 22993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13 23693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 23793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 23893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)unsigned short convertFloatToHalfFloat(float f) 23993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 24093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned temp = *(reinterpret_cast<unsigned *>(&f)); 24193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned signexp = (temp >> 23) & 0x1ff; 24293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]); 24393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 24493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 24593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/* BEGIN CODE SHARED WITH MOZILLA FIREFOX */ 24693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 24793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// The following packing and unpacking routines are expressed in terms of function templates and inline functions to achieve generality and speedup. 24893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// Explicit template specializations correspond to the cases that would occur. 24993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/WebGLTexelConversions.h 25093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 25193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)//---------------------------------------------------------------------- 25293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// Pixel unpacking routines. 25393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int format, typename SourceType, typename DstType> 25493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)void unpack(const SourceType*, DstType*, unsigned) 25593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 25693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 25793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 25893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 25993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRGB8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 26093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 26193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 26293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 26393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1]; 26493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2]; 26593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 0xFF; 26693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 3; 26793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 26893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 26993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 27093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 27193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatBGR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 27293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 27393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 27493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[2]; 27593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1]; 27693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[0]; 27793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 0xFF; 27893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 3; 27993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 28093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 28193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 28293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 28393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatARGB8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 28493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 28593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 28693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[1]; 28793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[2]; 28893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[3]; 28993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[0]; 29093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 29193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 29293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 29393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 29493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 29593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatABGR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 29693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 29793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 29893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[3]; 29993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[2]; 30093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[1]; 30193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[0]; 30293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 30393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 30493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 30593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 30693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 30793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatBGRA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 30893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 30993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const uint32_t* source32 = reinterpret_cast_ptr<const uint32_t*>(source); 31093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint32_t* destination32 = reinterpret_cast_ptr<uint32_t*>(destination); 31193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 31293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint32_t bgra = source32[i]; 31393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if CPU(BIG_ENDIAN) 31493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint32_t brMask = 0xff00ff00; 31593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint32_t gaMask = 0x00ff00ff; 31693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#else 31793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint32_t brMask = 0x00ff00ff; 31893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint32_t gaMask = 0xff00ff00; 31993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 32093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMask); 32193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination32[i] = rgba; 32293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 32393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 32493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 32593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRGBA5551, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) 32693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 32793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if HAVE(ARM_NEON_INTRINSICS) 32893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SIMD::unpackOneRowOfRGBA5551ToRGBA8(source, destination, pixelsPerRow); 32993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 33093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 33193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint16_t packedValue = source[0]; 33293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t r = packedValue >> 11; 33393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t g = (packedValue >> 6) & 0x1F; 33493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t b = (packedValue >> 1) & 0x1F; 33593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = (r << 3) | (r & 0x7); 33693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = (g << 3) | (g & 0x7); 33793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = (b << 3) | (b & 0x7); 33893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = (packedValue & 0x1) ? 0xFF : 0x0; 33993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 1; 34093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 34193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 34293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 34393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 34493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRGBA4444, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) 34593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 34693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if HAVE(ARM_NEON_INTRINSICS) 34793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SIMD::unpackOneRowOfRGBA4444ToRGBA8(source, destination, pixelsPerRow); 34893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 34993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 35093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint16_t packedValue = source[0]; 35193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t r = packedValue >> 12; 35293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t g = (packedValue >> 8) & 0x0F; 35393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t b = (packedValue >> 4) & 0x0F; 35493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t a = packedValue & 0x0F; 35593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = r << 4 | r; 35693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = g << 4 | g; 35793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = b << 4 | b; 35893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = a << 4 | a; 35993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 1; 36093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 36193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 36293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 36393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 36493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRGB565, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) 36593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 36693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if HAVE(ARM_NEON_INTRINSICS) 36793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SIMD::unpackOneRowOfRGB565ToRGBA8(source, destination, pixelsPerRow); 36893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 36993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 37093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint16_t packedValue = source[0]; 37193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t r = packedValue >> 11; 37293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t g = (packedValue >> 5) & 0x3F; 37393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t b = packedValue & 0x1F; 37493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = (r << 3) | (r & 0x7); 37593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = (g << 2) | (g & 0x3); 37693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = (b << 3) | (b & 0x7); 37793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 0xFF; 37893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 1; 37993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 38093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 38193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 38293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 38393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 38493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 38593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 38693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 38793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[0]; 38893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[0]; 38993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 0xFF; 39093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 1; 39193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 39293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 39393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 39493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 39593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 39693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 39793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 39893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 39993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[0]; 40093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[0]; 40193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[1]; 40293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 2; 40393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 40493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 40593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 40693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 40793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatAR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 40893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 40993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 41093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[1]; 41193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1]; 41293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[1]; 41393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[0]; 41493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 2; 41593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 41693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 41793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 41893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 41993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 42093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 42193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 42293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = 0x0; 42393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = 0x0; 42493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = 0x0; 42593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[0]; 42693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 1; 42793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 42893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 42993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 43093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 43193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRGBA8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow) 43293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 43393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const float scaleFactor = 1.0f / 255.0f; 43493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 43593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 43693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 43793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2] * scaleFactor; 43893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[3] * scaleFactor; 43993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 44093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 44193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 44293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 44393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 44493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatBGRA8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow) 44593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 44693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const float scaleFactor = 1.0f / 255.0f; 44793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 44893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[2] * scaleFactor; 44993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 45093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[0] * scaleFactor; 45193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[3] * scaleFactor; 45293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 45393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 45493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 45593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 45693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 45793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatABGR8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow) 45893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 45993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const float scaleFactor = 1.0f / 255.0f; 46093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 46193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[3] * scaleFactor; 46293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[2] * scaleFactor; 46393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[1] * scaleFactor; 46493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[0] * scaleFactor; 46593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 46693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 46793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 46893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 46993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 47093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatARGB8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow) 47193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 47293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const float scaleFactor = 1.0f / 255.0f; 47393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 47493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[1] * scaleFactor; 47593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[2] * scaleFactor; 47693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[3] * scaleFactor; 47793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[0] * scaleFactor; 47893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 47993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 48093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 48193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 48293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 48393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRGB8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow) 48493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 48593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const float scaleFactor = 1.0f / 255.0f; 48693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 48793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 48893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 48993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2] * scaleFactor; 49093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 1; 49193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 3; 49293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 49393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 49493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 49593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 49693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatBGR8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow) 49793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 49893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const float scaleFactor = 1.0f / 255.0f; 49993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 50093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[2] * scaleFactor; 50193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 50293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[0] * scaleFactor; 50393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 1; 50493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 3; 50593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 50693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 50793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 50893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 50993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRGB32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 51093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 51193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 51293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 51393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1]; 51493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2]; 51593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 1; 51693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 3; 51793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 51893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 51993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 52093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 52193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatR32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 52293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 52393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 52493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 52593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[0]; 52693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[0]; 52793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = 1; 52893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 1; 52993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 53093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 53193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 53293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 53393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatRA32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 53493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 53593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 53693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 53793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[0]; 53893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[0]; 53993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[1]; 54093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 2; 54193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 54293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 54393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 54493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 54593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void unpack<GraphicsContext3D::DataFormatA32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 54693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 54793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 54893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = 0; 54993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = 0; 55093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = 0; 55193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[0]; 55293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 1; 55393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 55493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 55593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 55693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 55793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)//---------------------------------------------------------------------- 55893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// Pixel packing routines. 55993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// 56093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 56193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int format, int alphaOp, typename SourceType, typename DstType> 56293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)void pack(const SourceType*, DstType*, unsigned) 56393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 56493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 56593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 56693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 56793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 56893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 56993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 57093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[3]; 57193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 57293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 57393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 57493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 57593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 57693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 57793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 57893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 57993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 58093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 58193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 58293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 58393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 58493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 58593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 58693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 58793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 58893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] / 255.0f; 58993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 59093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 59193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 59293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 59393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 59493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 59593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 59693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// FIXME: this routine is lossy and must be removed. 59793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 59893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 59993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 60093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; 60193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 60293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 60393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 60493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 60593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 60693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 60793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 60893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 60993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 61093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 61193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 61293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[3]; 61393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 61493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 61593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 61693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 61793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 61893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 61993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 62093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 62193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] / 255.0f; 62293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 62393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 62493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[3]; 62593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 62693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 62793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 62893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 62993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 63093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// FIXME: this routine is lossy and must be removed. 63193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 63293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 63393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 63493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; 63593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 63693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 63793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[3]; 63893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 63993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 64093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 64193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 64293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 64393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 64493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 64593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 64693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 64793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1]; 64893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2]; 64993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 65093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 65193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 65293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 65393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 65493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 65593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 65693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 65793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] / 255.0f; 65893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 65993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 66093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 66193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 66293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = sourceG; 66393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = sourceB; 66493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 66593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 66693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 66793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 66893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 66993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// FIXME: this routine is lossy and must be removed. 67093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 67193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 67293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 67393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; 67493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 67593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 67693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 67793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 67893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = sourceG; 67993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = sourceB; 68093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 68193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 68293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 68393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 68493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 68593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 68693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 68793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 68893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) memcpy(destination, source, pixelsPerRow * 4); 68993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 69093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 69193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 69293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 69393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 69493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] / 255.0f; 69593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 69693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 69793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 69893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 69993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = sourceG; 70093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = sourceB; 70193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[3]; 70293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 70393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 70493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 70593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 70693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 70793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// FIXME: this routine is lossy and must be removed. 70893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) 70993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 71093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 71193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; 71293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 71393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 71493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 71593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = sourceR; 71693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = sourceG; 71793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = sourceB; 71893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[3]; 71993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 72093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 72193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 72293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 72393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 72493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 72593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 72693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if HAVE(ARM_NEON_INTRINSICS) 72793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SIMD::packOneRowOfRGBA8ToUnsignedShort4444(source, destination, pixelsPerRow); 72893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 72993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 73093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((source[0] & 0xF0) << 8) 73193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((source[1] & 0xF0) << 4) 73293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (source[2] & 0xF0) 73393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (source[3] >> 4)); 73493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 73593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 73693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 73793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 73893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 73993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 74093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 74193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 74293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] / 255.0f; 74393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 74493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 74593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 74693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((sourceR & 0xF0) << 8) 74793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceG & 0xF0) << 4) 74893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (sourceB & 0xF0) 74993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (source[3] >> 4)); 75093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 75193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 75293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 75393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 75493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 75593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// FIXME: this routine is lossy and must be removed. 75693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 75793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 75893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 75993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; 76093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 76193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 76293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 76393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((sourceR & 0xF0) << 8) 76493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceG & 0xF0) << 4) 76593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (sourceB & 0xF0) 76693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (source[3] >> 4)); 76793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 76893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 76993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 77093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 77193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 77293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 77393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 77493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if HAVE(ARM_NEON_INTRINSICS) 77593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SIMD::packOneRowOfRGBA8ToUnsignedShort5551(source, destination, pixelsPerRow); 77693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 77793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 77893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((source[0] & 0xF8) << 8) 77993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((source[1] & 0xF8) << 3) 78093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((source[2] & 0xF8) >> 2) 78193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (source[3] >> 7)); 78293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 78393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 78493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 78593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 78693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 78793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 78893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 78993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 79093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] / 255.0f; 79193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 79293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 79393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 79493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((sourceR & 0xF8) << 8) 79593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceG & 0xF8) << 3) 79693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceB & 0xF8) >> 2) 79793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (source[3] >> 7)); 79893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 79993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 80093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 80193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 80293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 80393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// FIXME: this routine is lossy and must be removed. 80493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 80593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 80693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 80793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; 80893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 80993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 81093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 81193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((sourceR & 0xF8) << 8) 81293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceG & 0xF8) << 3) 81393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceB & 0xF8) >> 2) 81493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | (source[3] >> 7)); 81593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 81693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 81793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 81893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 81993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 82093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 82193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 82293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#if HAVE(ARM_NEON_INTRINSICS) 82393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SIMD::packOneRowOfRGBA8ToUnsignedShort565(source, destination, pixelsPerRow); 82493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 82593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 82693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((source[0] & 0xF8) << 8) 82793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((source[1] & 0xFC) << 3) 82893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((source[2] & 0xF8) >> 3)); 82993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 83093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 83193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 83293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 83393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 83493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 83593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 83693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 83793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] / 255.0f; 83893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 83993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 84093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 84193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((sourceR & 0xF8) << 8) 84293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceG & 0xFC) << 3) 84393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceB & 0xF8) >> 3)); 84493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 84593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 84693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 84793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 84893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 84993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// FIXME: this routine is lossy and must be removed. 85093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow) 85193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 85293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 85393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; 85493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor); 85593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor); 85693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor); 85793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *destination = (((sourceR & 0xF8) << 8) 85893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceG & 0xFC) << 3) 85993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) | ((sourceB & 0xF8) >> 3)); 86093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 86193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 86293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 86393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 86493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 86593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 86693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 86793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 86893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 86993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1]; 87093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2]; 87193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 87293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 87393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 87493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 87593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 87693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 87793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 87893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 87993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 88093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 88193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 88293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2] * scaleFactor; 88393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 88493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 88593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 88693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 88793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 88893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 88993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 89093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 89193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 89293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 89393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 89493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2] * scaleFactor; 89593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 89693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 89793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 89893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 89993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 90093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// Used only during RGBA8 or BGRA8 -> floating-point uploads. 90193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 90293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 90393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) memcpy(destination, source, pixelsPerRow * 4 * sizeof(float)); 90493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 90593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 90693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 90793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 90893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 90993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 91093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 91193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 91293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2] * scaleFactor; 91393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[3]; 91493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 91593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 91693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 91793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 91893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 91993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 92093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 92193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 92293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 92393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 92493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[1] * scaleFactor; 92593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = source[2] * scaleFactor; 92693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = source[3]; 92793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 92893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 92993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 93093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 93193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 93293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 93393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 93493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 93593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[3]; 93693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 93793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 93893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 93993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 94093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 94193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 94293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 94393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 94493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 94593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 94693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 94793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 94893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 94993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 95093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 95193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 95293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 95393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 95493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 95593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 95693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 95793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 95893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 95993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 96093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 96193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 96293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 96393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 96493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 96593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 96693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 96793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 96893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 96993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 97093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 97193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 97293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 97393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0]; 97493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[3]; 97593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 97693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 97793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 97893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 97993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 98093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 98193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 98293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 98393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 98493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 98593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[3]; 98693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 98793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 98893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 98993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 99093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 99193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow) 99293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 99393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned int i = 0; i < pixelsPerRow; ++i) { 99493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 99593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = source[0] * scaleFactor; 99693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = source[3]; 99793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 99893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 99993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 100093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 100193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 100293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 100393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 100493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 100593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0]); 100693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[1]); 100793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = convertFloatToHalfFloat(source[2]); 100893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = convertFloatToHalfFloat(source[3]); 100993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 101093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 101193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 101293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 101393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 101493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 101593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 101693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 101793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 101893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 101993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor); 102093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor); 102193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = convertFloatToHalfFloat(source[3]); 102293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 102393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 102493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 102593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 102693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 102793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 102893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 102993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 103093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 103193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 103293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor); 103393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor); 103493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[3] = convertFloatToHalfFloat(source[3]); 103593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 103693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 4; 103793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 103893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 103993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 104093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 104193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 104293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 104393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0]); 104493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[1]); 104593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = convertFloatToHalfFloat(source[2]); 104693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 104793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 104893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 104993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 105093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 105193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 105293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 105393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 105493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 105593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 105693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor); 105793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor); 105893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 105993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 106093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 106193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 106293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 106393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 106493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 106593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 106693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 106793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 106893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor); 106993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor); 107093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 107193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 3; 107293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 107393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 107493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 107593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 107693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 107793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 107893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0]); 107993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[3]); 108093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 108193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 108293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 108393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 108493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 108593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 108693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 108793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 108893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 108993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 109093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[3]); 109193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 109293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 109393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 109493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 109593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 109693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 109793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 109893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 109993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 110093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 110193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[1] = convertFloatToHalfFloat(source[3]); 110293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 110393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 2; 110493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 110593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 110693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 110793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 110893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 110993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 111093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0]); 111193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 111293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 111393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 111493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 111593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 111693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 111793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 111893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 111993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3]; 112093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 112193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 112293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 112393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 112493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 112593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 112693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 112793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 112893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 112993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 113093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor); 113193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 113293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 113393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 113493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 113593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 113693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<> void pack<GraphicsContext3D::DataFormatA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow) 113793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 113893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (unsigned i = 0; i < pixelsPerRow; ++i) { 113993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination[0] = convertFloatToHalfFloat(source[3]); 114093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) source += 4; 114193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destination += 1; 114293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 114393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 114493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 114593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)bool HasAlpha(int format) 114693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 114793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return format == GraphicsContext3D::DataFormatA8 114893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatA16F 114993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatA32F 115093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRA8 115193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatAR8 115293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRA16F 115393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRA32F 115493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA8 115593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatBGRA8 115693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatARGB8 115793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatABGR8 115893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA16F 115993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA32F 116093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA4444 116193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA5551; 116293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 116393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 116493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)bool HasColor(int format) 116593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 116693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return format == GraphicsContext3D::DataFormatRGBA8 116793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA16F 116893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA32F 116993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGB8 117093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGB16F 117193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGB32F 117293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatBGR8 117393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatBGRA8 117493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatARGB8 117593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatABGR8 117693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA5551 117793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGBA4444 117893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRGB565 117993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatR8 118093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatR16F 118193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatR32F 118293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRA8 118393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRA16F 118493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatRA32F 118593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || format == GraphicsContext3D::DataFormatAR8; 118693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 118793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 118893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format> 118993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct IsFloatFormat { 119093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) static const bool Value = 119193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Format == GraphicsContext3D::DataFormatRGBA32F 119293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatRGB32F 119393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatRA32F 119493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatR32F 119593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatA32F; 119693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 119793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 119893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format> 119993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct IsHalfFloatFormat { 120093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) static const bool Value = 120193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Format == GraphicsContext3D::DataFormatRGBA16F 120293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatRGB16F 120393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatRA16F 120493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatR16F 120593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatA16F; 120693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 120793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 120893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format> 120993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct Is16bppFormat { 121093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) static const bool Value = 121193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Format == GraphicsContext3D::DataFormatRGBA5551 121293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatRGBA4444 121393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) || Format == GraphicsContext3D::DataFormatRGB565; 121493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 121593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 121693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format, bool IsFloat = IsFloatFormat<Format>::Value, bool IsHalfFloat = IsHalfFloatFormat<Format>::Value, bool Is16bpp = Is16bppFormat<Format>::Value> 121793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct DataTypeForFormat { 121893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) typedef uint8_t Type; 121993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 122093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 122193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format> 122293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct DataTypeForFormat<Format, true, false, false> { 122393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) typedef float Type; 122493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 122593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 122693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format> 122793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct DataTypeForFormat<Format, false, true, false> { 122893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) typedef uint16_t Type; 122993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 123093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 123193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format> 123293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct DataTypeForFormat<Format, false, false, true> { 123393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) typedef uint16_t Type; 123493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 123593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 123693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<int Format> 123793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)struct IntermediateFormat { 123893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) static const int Value = (IsFloatFormat<Format>::Value || IsHalfFloatFormat<Format>::Value) ? GraphicsContext3D::DataFormatRGBA32F : GraphicsContext3D::DataFormatRGBA8; 123993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 124093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 124193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)unsigned TexelBytesForFormat(GraphicsContext3D::DataFormat format) 124293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 124393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (format) { 124493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatR8: 124593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatA8: 124693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 1; 124793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRA8: 124893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatAR8: 124993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGBA5551: 125093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGBA4444: 125193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGB565: 125293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatA16F: 125393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatR16F: 125493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 2; 125593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGB8: 125693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatBGR8: 125793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 3; 125893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGBA8: 125993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatARGB8: 126093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatABGR8: 126193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatBGRA8: 126293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatR32F: 126393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatA32F: 126493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRA16F: 126593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 4; 126693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGB16F: 126793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 6; 126893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRA32F: 126993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGBA16F: 127093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 8; 127193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGB32F: 127293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 12; 127393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case GraphicsContext3D::DataFormatRGBA32F: 127493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 16; 127593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 127693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return 0; 127793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 127893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 127993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 128093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/* END CODE SHARED WITH MOZILLA FIREFOX */ 128193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 128293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class FormatConverter { 128393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)public: 128493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FormatConverter(unsigned width, unsigned height, 128593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const void* srcStart, void* dstStart, int srcStride, int dstStride) 128693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) : m_width(width), m_height(height), m_srcStart(srcStart), m_dstStart(dstStart), m_srcStride(srcStride), m_dstStride(dstStride), m_success(false) 128793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) { 128893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const unsigned MaxNumberOfComponents = 4; 128993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const unsigned MaxBytesPerComponent = 4; 129093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) m_unpackedIntermediateSrcData = adoptArrayPtr(new uint8_t[m_width * MaxNumberOfComponents *MaxBytesPerComponent]); 129193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT(m_unpackedIntermediateSrcData.get()); 129293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 129393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 129493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void convert(GraphicsContext3D::DataFormat srcFormat, GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp); 129593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool Success() const { return m_success; } 129693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 129793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)private: 129893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) template<GraphicsContext3D::DataFormat SrcFormat> 129993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void convert(GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp); 130093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 130193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat> 130293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void convert(GraphicsContext3D::AlphaOp); 130393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 130493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat, GraphicsContext3D::AlphaOp alphaOp> 130593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void convert(); 130693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 130793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const unsigned m_width, m_height; 130893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const void* const m_srcStart; 130993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void* const m_dstStart; 131093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const int m_srcStride, m_dstStride; 131193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool m_success; 131293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) OwnArrayPtr<uint8_t> m_unpackedIntermediateSrcData; 131393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 131493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 131593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)void FormatConverter::convert(GraphicsContext3D::DataFormat srcFormat, GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp alphaOp) 131693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 131793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define FORMATCONVERTER_CASE_SRCFORMAT(SrcFormat) \ 131893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case SrcFormat: \ 131993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return convert<SrcFormat>(dstFormat, alphaOp); 132093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 132193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (srcFormat) { 132293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatR8) 132393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatA8) 132493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatR32F) 132593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatA32F) 132693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRA8) 132793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRA32F) 132893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB8) 132993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatBGR8) 133093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB565) 133193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB32F) 133293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA8) 133393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatARGB8) 133493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatABGR8) 133593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatAR8) 133693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatBGRA8) 133793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA5551) 133893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA4444) 133993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA32F) 134093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 134193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 134293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 134393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#undef FORMATCONVERTER_CASE_SRCFORMAT 134493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 134593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 134693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<GraphicsContext3D::DataFormat SrcFormat> 134793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)void FormatConverter::convert(GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp alphaOp) 134893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 134993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \ 135093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case DstFormat: \ 135193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return convert<SrcFormat, DstFormat>(alphaOp); 135293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 135393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (dstFormat) { 135493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR8) 135593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR16F) 135693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR32F) 135793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA8) 135893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA16F) 135993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA32F) 136093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA8) 136193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA16F) 136293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA32F) 136393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB8) 136493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB565) 136593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB16F) 136693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB32F) 136793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA8) 136893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA5551) 136993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA4444) 137093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA16F) 137193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA32F) 137293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 137393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 137493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 137593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 137693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#undef FORMATCONVERTER_CASE_DSTFORMAT 137793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 137893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 137993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat> 138093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)void FormatConverter::convert(GraphicsContext3D::AlphaOp alphaOp) 138193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 138293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define FORMATCONVERTER_CASE_ALPHAOP(alphaOp) \ 138393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) case alphaOp: \ 138493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return convert<SrcFormat, DstFormat, alphaOp>(); 138593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 138693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) switch (alphaOp) { 138793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoNothing) 138893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoPremultiply) 138993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoUnmultiply) 139093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) default: 139193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 139293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 139393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#undef FORMATCONVERTER_CASE_ALPHAOP 139493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 139593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 139693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat, GraphicsContext3D::AlphaOp alphaOp> 139793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)void FormatConverter::convert() 139893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 139993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Many instantiations of this template function will never be entered, so we try 140093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // to return immediately in these cases to avoid the compiler to generate useless code. 140193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (SrcFormat == DstFormat && alphaOp == GraphicsContext3D::AlphaDoNothing) { 140293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 140393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return; 140493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 140593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!IsFloatFormat<DstFormat>::Value && IsFloatFormat<SrcFormat>::Value) { 140693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 140793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return; 140893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 140993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 141093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Only textures uploaded from DOM elements or ImageData can allow DstFormat != SrcFormat. 141193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const bool srcFormatComesFromDOMElementOrImageData = GraphicsContext3D::srcFormatComeFromDOMElementOrImageData(SrcFormat); 141293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat) { 141393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 141493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return; 141593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 141693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Likewise, only textures uploaded from DOM elements or ImageData can possibly have to be unpremultiplied. 141793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!srcFormatComesFromDOMElementOrImageData && alphaOp == GraphicsContext3D::AlphaDoUnmultiply) { 141893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 141993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return; 142093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 142193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) && alphaOp != GraphicsContext3D::AlphaDoNothing) { 142293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT_NOT_REACHED(); 142393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return; 142493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 142593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 142693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; 142793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) typedef typename DataTypeForFormat<DstFormat>::Type DstType; 142893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const int IntermediateSrcFormat = IntermediateFormat<DstFormat>::Value; 142993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) typedef typename DataTypeForFormat<IntermediateSrcFormat>::Type IntermediateSrcType; 143093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType); 143193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType); 143293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const bool trivialUnpack = (SrcFormat == GraphicsContext3D::DataFormatRGBA8 && !IsFloatFormat<DstFormat>::Value && !IsHalfFloatFormat<DstFormat>::Value) || SrcFormat == GraphicsContext3D::DataFormatRGBA32F; 143393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const bool trivialPack = (DstFormat == GraphicsContext3D::DataFormatRGBA8 || DstFormat == GraphicsContext3D::DataFormatRGBA32F) && alphaOp == GraphicsContext3D::AlphaDoNothing && m_dstStride > 0; 143493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ASSERT(!trivialUnpack || !trivialPack); 143593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 143693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart); 143793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) DstType* dstRowStart = static_cast<DstType*>(m_dstStart); 143893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!trivialUnpack && trivialPack) { 143993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (size_t i = 0; i < m_height; ++i) { 144093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unpack<SrcFormat>(srcRowStart, dstRowStart, m_width); 144193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) srcRowStart += srcStrideInElements; 144293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstRowStart += dstStrideInElements; 144393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 144493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } else if (!trivialUnpack && !trivialPack) { 144593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (size_t i = 0; i < m_height; ++i) { 144693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unpack<SrcFormat>(srcRowStart, reinterpret_cast<IntermediateSrcType*>(m_unpackedIntermediateSrcData.get()), m_width); 144793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) pack<DstFormat, alphaOp>(reinterpret_cast<IntermediateSrcType*>(m_unpackedIntermediateSrcData.get()), dstRowStart, m_width); 144893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) srcRowStart += srcStrideInElements; 144993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstRowStart += dstStrideInElements; 145093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 145193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } else { 145293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) for (size_t i = 0; i < m_height; ++i) { 145393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) pack<DstFormat, alphaOp>(srcRowStart, dstRowStart, m_width); 145493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) srcRowStart += srcStrideInElements; 145593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstRowStart += dstStrideInElements; 145693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 145793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 145893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) m_success = true; 145993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return; 146093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 146193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 146293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} // anonymous namespace 146393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 146493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)bool GraphicsContext3D::packImageData( 146593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Image* image, 146693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const void* pixels, 146793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) GC3Denum format, 146893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) GC3Denum type, 146993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool flipY, 147093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) AlphaOp alphaOp, 147193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) DataFormat sourceFormat, 147293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned width, 147393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned height, 147493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned sourceUnpackAlignment, 147593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Vector<uint8_t>& data) 147693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 147793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!pixels) 147893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 147993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 148093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned packedSize; 148193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Output data is tightly packed (alignment == 1). 148293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR) 148393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 148493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) data.resize(packedSize); 148593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 148693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, width, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY)) 148793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 148893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (ImageObserver *observer = image->imageObserver()) 148993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) observer->didDraw(image); 149093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return true; 149193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 149293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 149393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)bool GraphicsContext3D::extractImageData( 149493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ImageData* imageData, 149593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) GC3Denum format, 149693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) GC3Denum type, 149793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool flipY, 149893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool premultiplyAlpha, 149993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Vector<uint8_t>& data) 150093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 150193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!imageData) 150293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 150393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int width = imageData->width(); 150493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int height = imageData->height(); 150593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 150693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned packedSize; 150793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Output data is tightly packed (alignment == 1). 150893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (computeImageSizeInBytes(format, type, width, height, 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR) 150993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 151093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) data.resize(packedSize); 151193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 151293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!packPixels(imageData->data()->data(), DataFormatRGBA8, width, height, 0, format, type, premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing, data.data(), flipY)) 151393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 151493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 151593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return true; 151693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 151793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 151893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)bool GraphicsContext3D::extractTextureData( 151993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned width, 152093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned height, 152193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) GC3Denum format, GC3Denum type, 152293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned unpackAlignment, 152393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool flipY, bool premultiplyAlpha, 152493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const void* pixels, 152593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Vector<uint8_t>& data) 152693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 152793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Assumes format, type, etc. have already been validated. 152893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) DataFormat sourceDataFormat = getDataFormat(format, type); 152993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 153093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Resize the output buffer. 153193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned int componentsPerPixel, bytesPerComponent; 153293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent)) 153393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 153493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned bytesPerPixel = componentsPerPixel * bytesPerComponent; 153593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) data.resize(width * height * bytesPerPixel); 153693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 153793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!packPixels(static_cast<const uint8_t*>(pixels), sourceDataFormat, width, height, unpackAlignment, format, type, (premultiplyAlpha ? AlphaDoPremultiply : AlphaDoNothing), data.data(), flipY)) 153893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 153993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 154093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return true; 154193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 154293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 154393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)bool GraphicsContext3D::packPixels( 154493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const uint8_t* sourceData, 154593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) DataFormat sourceDataFormat, 154693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned width, 154793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned height, 154893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned sourceUnpackAlignment, 154993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned destinationFormat, 155093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned destinationType, 155193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) AlphaOp alphaOp, 155293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void* destinationData, 155393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool flipY) 155493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){ 155593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int validSrc = width * TexelBytesForFormat(sourceDataFormat); 155693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int remainder = sourceUnpackAlignment ? (validSrc % sourceUnpackAlignment) : 0; 155793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int srcStride = remainder ? (validSrc + sourceUnpackAlignment - remainder) : validSrc; 155893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 155993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) DataFormat dstDataFormat = getDataFormat(destinationFormat, destinationType); 156093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int dstStride = width * TexelBytesForFormat(dstDataFormat); 156193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (flipY) { 156293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) destinationData = static_cast<uint8_t*>(destinationData) + dstStride*(height - 1); 156393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dstStride = -dstStride; 156493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 156593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!HasAlpha(sourceDataFormat) || !HasColor(sourceDataFormat) || !HasColor(dstDataFormat)) 156693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) alphaOp = AlphaDoNothing; 156793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 156893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (sourceDataFormat == dstDataFormat && alphaOp == AlphaDoNothing) { 156993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const uint8_t* ptr = sourceData; 157093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const uint8_t* ptrEnd = sourceData + srcStride * height; 157193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) unsigned rowSize = (dstStride > 0) ? dstStride: -dstStride; 157293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) uint8_t* dst = static_cast<uint8_t*>(destinationData); 157393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) while (ptr < ptrEnd) { 157493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) memcpy(dst, ptr, rowSize); 157593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ptr += srcStride; 157693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) dst += dstStride; 157793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 157893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return true; 157993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) } 158093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 158193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) FormatConverter converter(width, height, sourceData, destinationData, srcStride, dstStride); 158293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) converter.convert(sourceDataFormat, dstDataFormat, alphaOp); 158393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) if (!converter.Success()) 158493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return false; 158593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) return true; 158693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} 158793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 158893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)} // namespace WebCore 158993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 1590