Changeset 84441 in webkit


Ignore:
Timestamp:
Apr 20, 2011 5:28:17 PM (13 years ago)
Author:
kbr@google.com
Message:

2011-04-20 Kenneth Russell <kbr@google.com>

Reviewed by James Robinson.

Reduce size of GraphicsContext3D's compiled code
https://bugs.webkit.org/show_bug.cgi?id=59029

Changed format conversion operations to work line-by-line instead
of pixel-by-pixel, and passed them as function pointers rather
than template parameters. Simplified computation of source
increment, since elements per row is now all that is needed.

These changes reduce the size of GraphicsContext3D.o in release
mode on Linux from 299 KB to 53 KB.

No new tests. Existing layout tests cover these format conversions
well, and caught one typo in the restructuring. Also ran WebGL
conformance suite and other demos.

  • platform/graphics/GraphicsContext3D.cpp: (WebCore::doUnpackingAndPacking): (WebCore::computeSourceElementsPerRow): (WebCore::doPacking): (WebCore::doFloatingPointPacking): (WebCore::GraphicsContext3D::packPixels):
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r84440 r84441  
     12011-04-20  Kenneth Russell  <kbr@google.com>
     2
     3        Reviewed by James Robinson.
     4
     5        Reduce size of GraphicsContext3D's compiled code
     6        https://bugs.webkit.org/show_bug.cgi?id=59029
     7
     8        Changed format conversion operations to work line-by-line instead
     9        of pixel-by-pixel, and passed them as function pointers rather
     10        than template parameters. Simplified computation of source
     11        increment, since elements per row is now all that is needed.
     12
     13        These changes reduce the size of GraphicsContext3D.o in release
     14        mode on Linux from 299 KB to 53 KB.
     15
     16        No new tests. Existing layout tests cover these format conversions
     17        well, and caught one typo in the restructuring. Also ran WebGL
     18        conformance suite and other demos.
     19
     20        * platform/graphics/GraphicsContext3D.cpp:
     21        (WebCore::doUnpackingAndPacking):
     22        (WebCore::computeSourceElementsPerRow):
     23        (WebCore::doPacking):
     24        (WebCore::doFloatingPointPacking):
     25        (WebCore::GraphicsContext3D::packPixels):
     26
    1272011-04-20  Dimitri Glazkov  <dglazkov@chromium.org>
    228
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp

    r76600 r84441  
    343343}
    344344
    345 // These functions can not be static, or gcc will not allow them to be
    346 // used as template parameters. Use an anonymous namespace to prevent
    347 // the need to declare prototypes for them.
     345// The following packing and unpacking routines are expressed in terms
     346// of line-by-line operations, and passed by function pointer rather
     347// than template parameter, to achieve the majority of the speedups of
     348// having them inlined while reducing code size.
     349
    348350namespace {
    349351
     
    351353// Pixel unpacking routines.
    352354
    353 void unpackRGBA8ToRGBA8(const uint8_t* source, uint8_t* destination)
    354 {
    355     destination[0] = source[0];
    356     destination[1] = source[1];
    357     destination[2] = source[2];
    358     destination[3] = source[3];
    359 }
    360 
    361 void unpackRGBA16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    362 {
    363     destination[0] = convertColor16LittleTo8(source[0]);
    364     destination[1] = convertColor16LittleTo8(source[1]);
    365     destination[2] = convertColor16LittleTo8(source[2]);
    366     destination[3] = convertColor16LittleTo8(source[3]);
    367 }
    368 
    369 void unpackRGBA16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    370 {
    371     destination[0] = convertColor16BigTo8(source[0]);
    372     destination[1] = convertColor16BigTo8(source[1]);
    373     destination[2] = convertColor16BigTo8(source[2]);
    374     destination[3] = convertColor16BigTo8(source[3]);
    375 }
    376 
    377 void unpackRGB8ToRGBA8(const uint8_t* source, uint8_t* destination)
    378 {
    379     destination[0] = source[0];
    380     destination[1] = source[1];
    381     destination[2] = source[2];
    382     destination[3] = 0xFF;
    383 }
    384 
    385 void unpackRGB16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    386 {
    387     destination[0] = convertColor16LittleTo8(source[0]);
    388     destination[1] = convertColor16LittleTo8(source[1]);
    389     destination[2] = convertColor16LittleTo8(source[2]);
    390     destination[3] = 0xFF;
    391 }
    392 
    393 void unpackRGB16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    394 {
    395     destination[0] = convertColor16BigTo8(source[0]);
    396     destination[1] = convertColor16BigTo8(source[1]);
    397     destination[2] = convertColor16BigTo8(source[2]);
    398     destination[3] = 0xFF;
    399 }
    400 
    401 void unpackBGR8ToRGBA8(const uint8_t* source, uint8_t* destination)
    402 {
    403     destination[0] = source[2];
    404     destination[1] = source[1];
    405     destination[2] = source[0];
    406     destination[3] = 0xFF;
    407 }
    408 
    409 void unpackARGB8ToRGBA8(const uint8_t* source, uint8_t* destination)
    410 {
    411     destination[0] = source[1];
    412     destination[1] = source[2];
    413     destination[2] = source[3];
    414     destination[3] = source[0];
    415 }
    416 
    417 void unpackARGB16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    418 {
    419     destination[0] = convertColor16LittleTo8(source[1]);
    420     destination[1] = convertColor16LittleTo8(source[2]);
    421     destination[2] = convertColor16LittleTo8(source[3]);
    422     destination[3] = convertColor16LittleTo8(source[0]);
    423 }
    424 
    425 void unpackARGB16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    426 {
    427     destination[0] = convertColor16BigTo8(source[1]);
    428     destination[1] = convertColor16BigTo8(source[2]);
    429     destination[2] = convertColor16BigTo8(source[3]);
    430     destination[3] = convertColor16BigTo8(source[0]);
    431 }
    432 
    433 void unpackABGR8ToRGBA8(const uint8_t* source, uint8_t* destination)
    434 {
    435     destination[0] = source[3];
    436     destination[1] = source[2];
    437     destination[2] = source[1];
    438     destination[3] = source[0];
    439 }
    440 
    441 void unpackBGRA8ToRGBA8(const uint8_t* source, uint8_t* destination)
    442 {
    443     destination[0] = source[2];
    444     destination[1] = source[1];
    445     destination[2] = source[0];
    446     destination[3] = source[3];
    447 }
    448 
    449 void unpackBGRA16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    450 {
    451     destination[0] = convertColor16LittleTo8(source[2]);
    452     destination[1] = convertColor16LittleTo8(source[1]);
    453     destination[2] = convertColor16LittleTo8(source[0]);
    454     destination[3] = convertColor16LittleTo8(source[3]);
    455 }
    456 
    457 void unpackBGRA16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    458 {
    459     destination[0] = convertColor16BigTo8(source[2]);
    460     destination[1] = convertColor16BigTo8(source[1]);
    461     destination[2] = convertColor16BigTo8(source[0]);
    462     destination[3] = convertColor16BigTo8(source[3]);
    463 }
    464 
    465 void unpackRGBA5551ToRGBA8(const uint16_t* source, uint8_t* destination)
    466 {
    467     uint16_t packedValue = source[0];
    468     uint8_t r = packedValue >> 11;
    469     uint8_t g = (packedValue >> 6) & 0x1F;
    470     uint8_t b = (packedValue >> 1) & 0x1F;
    471     destination[0] = (r << 3) | (r & 0x7);
    472     destination[1] = (g << 3) | (g & 0x7);
    473     destination[2] = (b << 3) | (b & 0x7);
    474     destination[3] = (packedValue & 0x1) ? 0xFF : 0x0;
    475 }
    476 
    477 void unpackRGBA4444ToRGBA8(const uint16_t* source, uint8_t* destination)
    478 {
    479     uint16_t packedValue = source[0];
    480     uint8_t r = packedValue >> 12;
    481     uint8_t g = (packedValue >> 8) & 0x0F;
    482     uint8_t b = (packedValue >> 4) & 0x0F;
    483     uint8_t a = packedValue & 0x0F;
    484     destination[0] = r << 4 | r;
    485     destination[1] = g << 4 | g;
    486     destination[2] = b << 4 | b;
    487     destination[3] = a << 4 | a;
    488 }
    489 
    490 void unpackRGB565ToRGBA8(const uint16_t* source, uint8_t* destination)
    491 {
    492     uint16_t packedValue = source[0];
    493     uint8_t r = packedValue >> 11;
    494     uint8_t g = (packedValue >> 5) & 0x3F;
    495     uint8_t b = packedValue & 0x1F;
    496     destination[0] = (r << 3) | (r & 0x7);
    497     destination[1] = (g << 2) | (g & 0x3);
    498     destination[2] = (b << 3) | (b & 0x7);
    499     destination[3] = 0xFF;
    500 }
    501 
    502 void unpackR8ToRGBA8(const uint8_t* source, uint8_t* destination)
    503 {
    504     destination[0] = source[0];
    505     destination[1] = source[0];
    506     destination[2] = source[0];
    507     destination[3] = 0xFF;
    508 }
    509 
    510 void unpackR16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    511 {
    512     destination[0] = convertColor16LittleTo8(source[0]);
    513     destination[1] = convertColor16LittleTo8(source[0]);
    514     destination[2] = convertColor16LittleTo8(source[0]);
    515     destination[3] = 0xFF;
    516 }
    517 
    518 void unpackR16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    519 {
    520     destination[0] = convertColor16BigTo8(source[0]);
    521     destination[1] = convertColor16BigTo8(source[0]);
    522     destination[2] = convertColor16BigTo8(source[0]);
    523     destination[3] = 0xFF;
    524 }
    525 
    526 void unpackRA8ToRGBA8(const uint8_t* source, uint8_t* destination)
    527 {
    528     destination[0] = source[0];
    529     destination[1] = source[0];
    530     destination[2] = source[0];
    531     destination[3] = source[1];
    532 }
    533 
    534 void unpackRA16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    535 {
    536     destination[0] = convertColor16LittleTo8(source[0]);
    537     destination[1] = convertColor16LittleTo8(source[0]);
    538     destination[2] = convertColor16LittleTo8(source[0]);
    539     destination[3] = convertColor16LittleTo8(source[1]);
    540 }
    541 
    542 void unpackRA16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    543 {
    544     destination[0] = convertColor16BigTo8(source[0]);
    545     destination[1] = convertColor16BigTo8(source[0]);
    546     destination[2] = convertColor16BigTo8(source[0]);
    547     destination[3] = convertColor16BigTo8(source[1]);
    548 }
    549 
    550 void unpackAR8ToRGBA8(const uint8_t* source, uint8_t* destination)
    551 {
    552     destination[0] = source[1];
    553     destination[1] = source[1];
    554     destination[2] = source[1];
    555     destination[3] = source[0];
    556 }
    557 
    558 void unpackAR16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    559 {
    560     destination[0] = convertColor16LittleTo8(source[1]);
    561     destination[1] = convertColor16LittleTo8(source[1]);
    562     destination[2] = convertColor16LittleTo8(source[1]);
    563     destination[3] = convertColor16LittleTo8(source[0]);
    564 }
    565 
    566 void unpackAR16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    567 {
    568     destination[0] = convertColor16BigTo8(source[1]);
    569     destination[1] = convertColor16BigTo8(source[1]);
    570     destination[2] = convertColor16BigTo8(source[1]);
    571     destination[3] = convertColor16BigTo8(source[0]);
    572 }
    573 
    574 void unpackA8ToRGBA8(const uint8_t* source, uint8_t* destination)
    575 {
    576     destination[0] = 0x0;
    577     destination[1] = 0x0;
    578     destination[2] = 0x0;
    579     destination[3] = source[0];
    580 }
    581 
    582 void unpackA16LittleToRGBA8(const uint16_t* source, uint8_t* destination)
    583 {
    584     destination[0] = 0x0;
    585     destination[1] = 0x0;
    586     destination[2] = 0x0;
    587     destination[3] = convertColor16LittleTo8(source[0]);
    588 }
    589 
    590 void unpackA16BigToRGBA8(const uint16_t* source, uint8_t* destination)
    591 {
    592     destination[0] = 0x0;
    593     destination[1] = 0x0;
    594     destination[2] = 0x0;
    595     destination[3] = convertColor16BigTo8(source[0]);
    596 }
    597 
    598 void unpackRGB32FToRGBA32F(const float* source, float* destination)
    599 {
    600     destination[0] = source[0];
    601     destination[1] = source[1];
    602     destination[2] = source[2];
    603     destination[3] = 1;
    604 }
    605 
    606 void unpackR32FToRGBA32F(const float* source, float* destination)
    607 {
    608     destination[0] = source[0];
    609     destination[1] = source[0];
    610     destination[2] = source[0];
    611     destination[3] = 1;
    612 }
    613 
    614 void unpackRA32FToRGBA32F(const float* source, float* destination)
    615 {
    616     destination[0] = source[0];
    617     destination[1] = source[0];
    618     destination[2] = source[0];
    619     destination[3] = source[1];
    620 }
    621 
    622 void unpackA32FToRGBA32F(const float* source, float* destination)
    623 {
    624     destination[0] = 0;
    625     destination[1] = 0;
    626     destination[2] = 0;
    627     destination[3] = source[0];
     355void unpackOneRowOfRGBA8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     356{
     357    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     358        destination[0] = source[0];
     359        destination[1] = source[1];
     360        destination[2] = source[2];
     361        destination[3] = source[3];
     362        source += 4;
     363        destination += 4;
     364    }
     365}
     366
     367void unpackOneRowOfRGBA16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     368{
     369    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     370        destination[0] = convertColor16LittleTo8(source[0]);
     371        destination[1] = convertColor16LittleTo8(source[1]);
     372        destination[2] = convertColor16LittleTo8(source[2]);
     373        destination[3] = convertColor16LittleTo8(source[3]);
     374        source += 4;
     375        destination += 4;
     376    }
     377}
     378
     379void unpackOneRowOfRGBA16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     380{
     381    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     382        destination[0] = convertColor16BigTo8(source[0]);
     383        destination[1] = convertColor16BigTo8(source[1]);
     384        destination[2] = convertColor16BigTo8(source[2]);
     385        destination[3] = convertColor16BigTo8(source[3]);
     386        source += 4;
     387        destination += 4;
     388    }
     389}
     390
     391void unpackOneRowOfRGB8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     392{
     393    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     394        destination[0] = source[0];
     395        destination[1] = source[1];
     396        destination[2] = source[2];
     397        destination[3] = 0xFF;
     398        source += 3;
     399        destination += 4;
     400    }
     401}
     402
     403void unpackOneRowOfRGB16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     404{
     405    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     406        destination[0] = convertColor16LittleTo8(source[0]);
     407        destination[1] = convertColor16LittleTo8(source[1]);
     408        destination[2] = convertColor16LittleTo8(source[2]);
     409        destination[3] = 0xFF;
     410        source += 3;
     411        destination += 4;
     412    }
     413}
     414
     415void unpackOneRowOfRGB16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     416{
     417    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     418        destination[0] = convertColor16BigTo8(source[0]);
     419        destination[1] = convertColor16BigTo8(source[1]);
     420        destination[2] = convertColor16BigTo8(source[2]);
     421        destination[3] = 0xFF;
     422        source += 3;
     423        destination += 4;
     424    }
     425}
     426
     427void unpackOneRowOfBGR8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     428{
     429    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     430        destination[0] = source[2];
     431        destination[1] = source[1];
     432        destination[2] = source[0];
     433        destination[3] = 0xFF;
     434        source += 3;
     435        destination += 4;
     436    }
     437}
     438
     439void unpackOneRowOfARGB8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     440{
     441    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     442        destination[0] = source[1];
     443        destination[1] = source[2];
     444        destination[2] = source[3];
     445        destination[3] = source[0];
     446        source += 4;
     447        destination += 4;
     448    }
     449}
     450
     451void unpackOneRowOfARGB16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     452{
     453    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     454        destination[0] = convertColor16LittleTo8(source[1]);
     455        destination[1] = convertColor16LittleTo8(source[2]);
     456        destination[2] = convertColor16LittleTo8(source[3]);
     457        destination[3] = convertColor16LittleTo8(source[0]);
     458        source += 4;
     459        destination += 4;
     460    }
     461}
     462
     463void unpackOneRowOfARGB16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     464{
     465    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     466        destination[0] = convertColor16BigTo8(source[1]);
     467        destination[1] = convertColor16BigTo8(source[2]);
     468        destination[2] = convertColor16BigTo8(source[3]);
     469        destination[3] = convertColor16BigTo8(source[0]);
     470        source += 4;
     471        destination += 4;
     472    }
     473}
     474
     475void unpackOneRowOfABGR8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     476{
     477    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     478        destination[0] = source[3];
     479        destination[1] = source[2];
     480        destination[2] = source[1];
     481        destination[3] = source[0];
     482        source += 4;
     483        destination += 4;
     484    }
     485}
     486
     487void unpackOneRowOfBGRA8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     488{
     489    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     490        destination[0] = source[2];
     491        destination[1] = source[1];
     492        destination[2] = source[0];
     493        destination[3] = source[3];
     494        source += 4;
     495        destination += 4;
     496    }
     497}
     498
     499void unpackOneRowOfBGRA16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     500{
     501    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     502        destination[0] = convertColor16LittleTo8(source[2]);
     503        destination[1] = convertColor16LittleTo8(source[1]);
     504        destination[2] = convertColor16LittleTo8(source[0]);
     505        destination[3] = convertColor16LittleTo8(source[3]);
     506        source += 4;
     507        destination += 4;
     508    }
     509}
     510
     511void unpackOneRowOfBGRA16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     512{
     513    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     514        destination[0] = convertColor16BigTo8(source[2]);
     515        destination[1] = convertColor16BigTo8(source[1]);
     516        destination[2] = convertColor16BigTo8(source[0]);
     517        destination[3] = convertColor16BigTo8(source[3]);
     518        source += 4;
     519        destination += 4;
     520    }
     521}
     522
     523void unpackOneRowOfRGBA5551ToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     524{
     525    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     526        uint16_t packedValue = source[0];
     527        uint8_t r = packedValue >> 11;
     528        uint8_t g = (packedValue >> 6) & 0x1F;
     529        uint8_t b = (packedValue >> 1) & 0x1F;
     530        destination[0] = (r << 3) | (r & 0x7);
     531        destination[1] = (g << 3) | (g & 0x7);
     532        destination[2] = (b << 3) | (b & 0x7);
     533        destination[3] = (packedValue & 0x1) ? 0xFF : 0x0;
     534        source += 1;
     535        destination += 4;
     536    }
     537}
     538
     539void unpackOneRowOfRGBA4444ToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     540{
     541    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     542        uint16_t packedValue = source[0];
     543        uint8_t r = packedValue >> 12;
     544        uint8_t g = (packedValue >> 8) & 0x0F;
     545        uint8_t b = (packedValue >> 4) & 0x0F;
     546        uint8_t a = packedValue & 0x0F;
     547        destination[0] = r << 4 | r;
     548        destination[1] = g << 4 | g;
     549        destination[2] = b << 4 | b;
     550        destination[3] = a << 4 | a;
     551        source += 1;
     552        destination += 4;
     553    }
     554}
     555
     556void unpackOneRowOfRGB565ToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     557{
     558    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     559        uint16_t packedValue = source[0];
     560        uint8_t r = packedValue >> 11;
     561        uint8_t g = (packedValue >> 5) & 0x3F;
     562        uint8_t b = packedValue & 0x1F;
     563        destination[0] = (r << 3) | (r & 0x7);
     564        destination[1] = (g << 2) | (g & 0x3);
     565        destination[2] = (b << 3) | (b & 0x7);
     566        destination[3] = 0xFF;
     567        source += 1;
     568        destination += 4;
     569    }
     570}
     571
     572void unpackOneRowOfR8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     573{
     574    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     575        destination[0] = source[0];
     576        destination[1] = source[0];
     577        destination[2] = source[0];
     578        destination[3] = 0xFF;
     579        source += 1;
     580        destination += 4;
     581    }
     582}
     583
     584void unpackOneRowOfR16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     585{
     586    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     587        destination[0] = convertColor16LittleTo8(source[0]);
     588        destination[1] = convertColor16LittleTo8(source[0]);
     589        destination[2] = convertColor16LittleTo8(source[0]);
     590        destination[3] = 0xFF;
     591        source += 1;
     592        destination += 4;
     593    }
     594}
     595
     596void unpackOneRowOfR16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     597{
     598    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     599        destination[0] = convertColor16BigTo8(source[0]);
     600        destination[1] = convertColor16BigTo8(source[0]);
     601        destination[2] = convertColor16BigTo8(source[0]);
     602        destination[3] = 0xFF;
     603        source += 1;
     604        destination += 4;
     605    }
     606}
     607
     608void unpackOneRowOfRA8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     609{
     610    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     611        destination[0] = source[0];
     612        destination[1] = source[0];
     613        destination[2] = source[0];
     614        destination[3] = source[1];
     615        source += 2;
     616        destination += 4;
     617    }
     618}
     619
     620void unpackOneRowOfRA16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     621{
     622    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     623        destination[0] = convertColor16LittleTo8(source[0]);
     624        destination[1] = convertColor16LittleTo8(source[0]);
     625        destination[2] = convertColor16LittleTo8(source[0]);
     626        destination[3] = convertColor16LittleTo8(source[1]);
     627        source += 2;
     628        destination += 4;
     629    }
     630}
     631
     632void unpackOneRowOfRA16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     633{
     634    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     635        destination[0] = convertColor16BigTo8(source[0]);
     636        destination[1] = convertColor16BigTo8(source[0]);
     637        destination[2] = convertColor16BigTo8(source[0]);
     638        destination[3] = convertColor16BigTo8(source[1]);
     639        source += 2;
     640        destination += 4;
     641    }
     642}
     643
     644void unpackOneRowOfAR8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     645{
     646    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     647        destination[0] = source[1];
     648        destination[1] = source[1];
     649        destination[2] = source[1];
     650        destination[3] = source[0];
     651        source += 2;
     652        destination += 4;
     653    }
     654}
     655
     656void unpackOneRowOfAR16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     657{
     658    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     659        destination[0] = convertColor16LittleTo8(source[1]);
     660        destination[1] = convertColor16LittleTo8(source[1]);
     661        destination[2] = convertColor16LittleTo8(source[1]);
     662        destination[3] = convertColor16LittleTo8(source[0]);
     663        source += 2;
     664        destination += 4;
     665    }
     666}
     667
     668void unpackOneRowOfAR16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     669{
     670    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     671        destination[0] = convertColor16BigTo8(source[1]);
     672        destination[1] = convertColor16BigTo8(source[1]);
     673        destination[2] = convertColor16BigTo8(source[1]);
     674        destination[3] = convertColor16BigTo8(source[0]);
     675        source += 2;
     676        destination += 4;
     677    }
     678}
     679
     680void unpackOneRowOfA8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     681{
     682    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     683        destination[0] = 0x0;
     684        destination[1] = 0x0;
     685        destination[2] = 0x0;
     686        destination[3] = source[0];
     687        source += 1;
     688        destination += 4;
     689    }
     690}
     691
     692void unpackOneRowOfA16LittleToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     693{
     694    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     695        destination[0] = 0x0;
     696        destination[1] = 0x0;
     697        destination[2] = 0x0;
     698        destination[3] = convertColor16LittleTo8(source[0]);
     699        source += 1;
     700        destination += 4;
     701    }
     702}
     703
     704void unpackOneRowOfA16BigToRGBA8(const uint16_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     705{
     706    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     707        destination[0] = 0x0;
     708        destination[1] = 0x0;
     709        destination[2] = 0x0;
     710        destination[3] = convertColor16BigTo8(source[0]);
     711        source += 1;
     712        destination += 4;
     713    }
     714}
     715
     716void unpackOneRowOfRGB32FToRGBA32F(const float* source, float* destination, unsigned int pixelsPerRow)
     717{
     718    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     719        destination[0] = source[0];
     720        destination[1] = source[1];
     721        destination[2] = source[2];
     722        destination[3] = 1;
     723        source += 3;
     724        destination += 4;
     725    }
     726}
     727
     728void unpackOneRowOfR32FToRGBA32F(const float* source, float* destination, unsigned int pixelsPerRow)
     729{
     730    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     731        destination[0] = source[0];
     732        destination[1] = source[0];
     733        destination[2] = source[0];
     734        destination[3] = 1;
     735        source += 1;
     736        destination += 4;
     737    }
     738}
     739
     740void unpackOneRowOfRA32FToRGBA32F(const float* source, float* destination, unsigned int pixelsPerRow)
     741{
     742    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     743        destination[0] = source[0];
     744        destination[1] = source[0];
     745        destination[2] = source[0];
     746        destination[3] = source[1];
     747        source += 2;
     748        destination += 4;
     749    }
     750}
     751
     752void unpackOneRowOfA32FToRGBA32F(const float* source, float* destination, unsigned int pixelsPerRow)
     753{
     754    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     755        destination[0] = 0;
     756        destination[1] = 0;
     757        destination[2] = 0;
     758        destination[3] = source[0];
     759        source += 1;
     760        destination += 4;
     761    }
    628762}
    629763
     
    632766//
    633767
    634 void packRGBA8ToA8(const uint8_t* source, uint8_t* destination)
    635 {
    636     destination[0] = source[3];
    637 }
    638 
    639 void packRGBA8ToR8(const uint8_t* source, uint8_t* destination)
    640 {
    641     destination[0] = source[0];
    642 }
    643 
    644 void packRGBA8ToR8Premultiply(const uint8_t* source, uint8_t* destination)
    645 {
    646     float scaleFactor = source[3] / 255.0f;
    647     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    648     destination[0] = sourceR;
     768void packOneRowOfRGBA8ToA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     769{
     770    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     771        destination[0] = source[3];
     772        source += 4;
     773        destination += 1;
     774    }
     775}
     776
     777void packOneRowOfRGBA8ToR8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     778{
     779    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     780        destination[0] = source[0];
     781        source += 4;
     782        destination += 1;
     783    }
     784}
     785
     786void packOneRowOfRGBA8ToR8Premultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     787{
     788    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     789        float scaleFactor = source[3] / 255.0f;
     790        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     791        destination[0] = sourceR;
     792        source += 4;
     793        destination += 1;
     794    }
    649795}
    650796
    651797// FIXME: this routine is lossy and must be removed.
    652 void packRGBA8ToR8Unmultiply(const uint8_t* source, uint8_t* destination)
    653 {
    654     float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
    655     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    656     destination[0] = sourceR;
    657 }
    658 
    659 void packRGBA8ToRA8(const uint8_t* source, uint8_t* destination)
    660 {
    661     destination[0] = source[0];
    662     destination[1] = source[3];
    663 }
    664 
    665 void packRGBA8ToRA8Premultiply(const uint8_t* source, uint8_t* destination)
    666 {
    667     float scaleFactor = source[3] / 255.0f;
    668     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    669     destination[0] = sourceR;
    670     destination[1] = source[3];
     798void packOneRowOfRGBA8ToR8Unmultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     799{
     800    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     801        float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
     802        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     803        destination[0] = sourceR;
     804        source += 4;
     805        destination += 1;
     806    }
     807}
     808
     809void packOneRowOfRGBA8ToRA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     810{
     811    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     812        destination[0] = source[0];
     813        destination[1] = source[3];
     814        source += 4;
     815        destination += 2;
     816    }
     817}
     818
     819void packOneRowOfRGBA8ToRA8Premultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     820{
     821    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     822        float scaleFactor = source[3] / 255.0f;
     823        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     824        destination[0] = sourceR;
     825        destination[1] = source[3];
     826        source += 4;
     827        destination += 2;
     828    }
    671829}
    672830
    673831// FIXME: this routine is lossy and must be removed.
    674 void packRGBA8ToRA8Unmultiply(const uint8_t* source, uint8_t* destination)
    675 {
    676     float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
    677     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    678     destination[0] = sourceR;
    679     destination[1] = source[3];
    680 }
    681 
    682 void packRGBA8ToRGB8(const uint8_t* source, uint8_t* destination)
    683 {
    684     destination[0] = source[0];
    685     destination[1] = source[1];
    686     destination[2] = source[2];
    687 }
    688 
    689 void packRGBA8ToRGB8Premultiply(const uint8_t* source, uint8_t* destination)
    690 {
    691     float scaleFactor = source[3] / 255.0f;
    692     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    693     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    694     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    695     destination[0] = sourceR;
    696     destination[1] = sourceG;
    697     destination[2] = sourceB;
     832void packOneRowOfRGBA8ToRA8Unmultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     833{
     834    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     835        float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
     836        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     837        destination[0] = sourceR;
     838        destination[1] = source[3];
     839        source += 4;
     840        destination += 2;
     841    }
     842}
     843
     844void packOneRowOfRGBA8ToRGB8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     845{
     846    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     847        destination[0] = source[0];
     848        destination[1] = source[1];
     849        destination[2] = source[2];
     850        source += 4;
     851        destination += 3;
     852    }
     853}
     854
     855void packOneRowOfRGBA8ToRGB8Premultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     856{
     857    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     858        float scaleFactor = source[3] / 255.0f;
     859        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     860        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     861        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     862        destination[0] = sourceR;
     863        destination[1] = sourceG;
     864        destination[2] = sourceB;
     865        source += 4;
     866        destination += 3;
     867    }
    698868}
    699869
    700870// FIXME: this routine is lossy and must be removed.
    701 void packRGBA8ToRGB8Unmultiply(const uint8_t* source, uint8_t* destination)
    702 {
    703     float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
    704     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    705     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    706     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    707     destination[0] = sourceR;
    708     destination[1] = sourceG;
    709     destination[2] = sourceB;
     871void packOneRowOfRGBA8ToRGB8Unmultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     872{
     873    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     874        float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
     875        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     876        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     877        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     878        destination[0] = sourceR;
     879        destination[1] = sourceG;
     880        destination[2] = sourceB;
     881        source += 4;
     882        destination += 3;
     883    }
    710884}
    711885
    712886// This is only used when the source format is different than SourceFormatRGBA8.
    713 void packRGBA8ToRGBA8(const uint8_t* source, uint8_t* destination)
    714 {
    715     destination[0] = source[0];
    716     destination[1] = source[1];
    717     destination[2] = source[2];
    718     destination[3] = source[3];
    719 }
    720 
    721 void packRGBA8ToRGBA8Premultiply(const uint8_t* source, uint8_t* destination)
    722 {
    723     float scaleFactor = source[3] / 255.0f;
    724     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    725     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    726     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    727     destination[0] = sourceR;
    728     destination[1] = sourceG;
    729     destination[2] = sourceB;
    730     destination[3] = source[3];
     887void packOneRowOfRGBA8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     888{
     889    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     890        destination[0] = source[0];
     891        destination[1] = source[1];
     892        destination[2] = source[2];
     893        destination[3] = source[3];
     894        source += 4;
     895        destination += 4;
     896    }
     897}
     898
     899void packOneRowOfRGBA8ToRGBA8Premultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     900{
     901    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     902        float scaleFactor = source[3] / 255.0f;
     903        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     904        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     905        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     906        destination[0] = sourceR;
     907        destination[1] = sourceG;
     908        destination[2] = sourceB;
     909        destination[3] = source[3];
     910        source += 4;
     911        destination += 4;
     912    }
    731913}
    732914
    733915// FIXME: this routine is lossy and must be removed.
    734 void packRGBA8ToRGBA8Unmultiply(const uint8_t* source, uint8_t* destination)
    735 {
    736     float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
    737     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    738     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    739     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    740     destination[0] = sourceR;
    741     destination[1] = sourceG;
    742     destination[2] = sourceB;
    743     destination[3] = source[3];
    744 }
    745 
    746 void packRGBA8ToUnsignedShort4444(const uint8_t* source, uint16_t* destination)
    747 {
    748     *destination = (((source[0] & 0xF0) << 8)
    749                     | ((source[1] & 0xF0) << 4)
    750                     | (source[2] & 0xF0)
    751                     | (source[3] >> 4));
    752 }
    753 
    754 void packRGBA8ToUnsignedShort4444Premultiply(const uint8_t* source, uint16_t* destination)
    755 {
    756     float scaleFactor = source[3] / 255.0f;
    757     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    758     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    759     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    760     *destination = (((sourceR & 0xF0) << 8)
    761                     | ((sourceG & 0xF0) << 4)
    762                     | (sourceB & 0xF0)
    763                     | (source[3] >> 4));
     916void packOneRowOfRGBA8ToRGBA8Unmultiply(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
     917{
     918    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     919        float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
     920        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     921        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     922        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     923        destination[0] = sourceR;
     924        destination[1] = sourceG;
     925        destination[2] = sourceB;
     926        destination[3] = source[3];
     927        source += 4;
     928        destination += 4;
     929    }
     930}
     931
     932void packOneRowOfRGBA8ToUnsignedShort4444(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     933{
     934    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     935        *destination = (((source[0] & 0xF0) << 8)
     936                        | ((source[1] & 0xF0) << 4)
     937                        | (source[2] & 0xF0)
     938                        | (source[3] >> 4));
     939        source += 4;
     940        destination += 1;
     941    }
     942}
     943
     944void packOneRowOfRGBA8ToUnsignedShort4444Premultiply(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     945{
     946    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     947        float scaleFactor = source[3] / 255.0f;
     948        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     949        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     950        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     951        *destination = (((sourceR & 0xF0) << 8)
     952                        | ((sourceG & 0xF0) << 4)
     953                        | (sourceB & 0xF0)
     954                        | (source[3] >> 4));
     955        source += 4;
     956        destination += 1;
     957    }
    764958}
    765959
    766960// FIXME: this routine is lossy and must be removed.
    767 void packRGBA8ToUnsignedShort4444Unmultiply(const uint8_t* source, uint16_t* destination)
    768 {
    769     float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
    770     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    771     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    772     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    773     *destination = (((sourceR & 0xF0) << 8)
    774                     | ((sourceG & 0xF0) << 4)
    775                     | (sourceB & 0xF0)
    776                     | (source[3] >> 4));
    777 }
    778 
    779 void packRGBA8ToUnsignedShort5551(const uint8_t* source, uint16_t* destination)
    780 {
    781     *destination = (((source[0] & 0xF8) << 8)
    782                     | ((source[1] & 0xF8) << 3)
    783                     | ((source[2] & 0xF8) >> 2)
    784                     | (source[3] >> 7));
    785 }
    786 
    787 void packRGBA8ToUnsignedShort5551Premultiply(const uint8_t* source, uint16_t* destination)
    788 {
    789     float scaleFactor = source[3] / 255.0f;
    790     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    791     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    792     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    793     *destination = (((sourceR & 0xF8) << 8)
    794                     | ((sourceG & 0xF8) << 3)
    795                     | ((sourceB & 0xF8) >> 2)
    796                     | (source[3] >> 7));
     961void packOneRowOfRGBA8ToUnsignedShort4444Unmultiply(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     962{
     963    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     964        float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
     965        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     966        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     967        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     968        *destination = (((sourceR & 0xF0) << 8)
     969                        | ((sourceG & 0xF0) << 4)
     970                        | (sourceB & 0xF0)
     971                        | (source[3] >> 4));
     972        source += 4;
     973        destination += 1;
     974    }
     975}
     976
     977void packOneRowOfRGBA8ToUnsignedShort5551(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     978{
     979    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     980        *destination = (((source[0] & 0xF8) << 8)
     981                        | ((source[1] & 0xF8) << 3)
     982                        | ((source[2] & 0xF8) >> 2)
     983                        | (source[3] >> 7));
     984        source += 4;
     985        destination += 1;
     986    }
     987}
     988
     989void packOneRowOfRGBA8ToUnsignedShort5551Premultiply(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     990{
     991    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     992        float scaleFactor = source[3] / 255.0f;
     993        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     994        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     995        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     996        *destination = (((sourceR & 0xF8) << 8)
     997                        | ((sourceG & 0xF8) << 3)
     998                        | ((sourceB & 0xF8) >> 2)
     999                        | (source[3] >> 7));
     1000        source += 4;
     1001        destination += 1;
     1002    }
    7971003}
    7981004
    7991005// FIXME: this routine is lossy and must be removed.
    800 void packRGBA8ToUnsignedShort5551Unmultiply(const uint8_t* source, uint16_t* destination)
    801 {
    802     float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
    803     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    804     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    805     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    806     *destination = (((sourceR & 0xF8) << 8)
    807                     | ((sourceG & 0xF8) << 3)
    808                     | ((sourceB & 0xF8) >> 2)
    809                     | (source[3] >> 7));
    810 }
    811 
    812 void packRGBA8ToUnsignedShort565(const uint8_t* source, uint16_t* destination)
    813 {
    814     *destination = (((source[0] & 0xF8) << 8)
    815                     | ((source[1] & 0xFC) << 3)
    816                     | ((source[2] & 0xF8) >> 3));
    817 }
    818 
    819 void packRGBA8ToUnsignedShort565Premultiply(const uint8_t* source, uint16_t* destination)
    820 {
    821     float scaleFactor = source[3] / 255.0f;
    822     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    823     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    824     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    825     *destination = (((sourceR & 0xF8) << 8)
    826                     | ((sourceG & 0xFC) << 3)
    827                     | ((sourceB & 0xF8) >> 3));
     1006void packOneRowOfRGBA8ToUnsignedShort5551Unmultiply(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     1007{
     1008    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1009        float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
     1010        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     1011        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     1012        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     1013        *destination = (((sourceR & 0xF8) << 8)
     1014                        | ((sourceG & 0xF8) << 3)
     1015                        | ((sourceB & 0xF8) >> 2)
     1016                        | (source[3] >> 7));
     1017        source += 4;
     1018        destination += 1;
     1019    }
     1020}
     1021
     1022void packOneRowOfRGBA8ToUnsignedShort565(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     1023{
     1024    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1025        *destination = (((source[0] & 0xF8) << 8)
     1026                        | ((source[1] & 0xFC) << 3)
     1027                        | ((source[2] & 0xF8) >> 3));
     1028        source += 4;
     1029        destination += 1;
     1030    }
     1031}
     1032
     1033void packOneRowOfRGBA8ToUnsignedShort565Premultiply(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     1034{
     1035    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1036        float scaleFactor = source[3] / 255.0f;
     1037        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     1038        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     1039        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     1040        *destination = (((sourceR & 0xF8) << 8)
     1041                        | ((sourceG & 0xFC) << 3)
     1042                        | ((sourceB & 0xF8) >> 3));
     1043        source += 4;
     1044        destination += 1;
     1045    }
    8281046}
    8291047
    8301048// FIXME: this routine is lossy and must be removed.
    831 void packRGBA8ToUnsignedShort565Unmultiply(const uint8_t* source, uint16_t* destination)
    832 {
    833     float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
    834     uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
    835     uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
    836     uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
    837     *destination = (((sourceR & 0xF8) << 8)
    838                     | ((sourceG & 0xFC) << 3)
    839                     | ((sourceB & 0xF8) >> 3));
    840 }
    841 
    842 void packRGBA32FToRGB32F(const float* source, float* destination)
    843 {
    844     destination[0] = source[0];
    845     destination[1] = source[1];
    846     destination[2] = source[2];
    847 }
    848 
    849 void packRGBA32FToRGB32FPremultiply(const float* source, float* destination)
    850 {
    851     float scaleFactor = source[3];
    852     destination[0] = source[0] * scaleFactor;
    853     destination[1] = source[1] * scaleFactor;
    854     destination[2] = source[2] * scaleFactor;
    855 }
    856 
    857 void packRGBA32FToRGBA32FPremultiply(const float* source, float* destination)
    858 {
    859     float scaleFactor = source[3];
    860     destination[0] = source[0] * scaleFactor;
    861     destination[1] = source[1] * scaleFactor;
    862     destination[2] = source[2] * scaleFactor;
    863     destination[3] = source[3];
    864 }
    865 
    866 void packRGBA32FToA32F(const float* source, float* destination)
    867 {
    868     destination[0] = source[3];
    869 }
    870 
    871 void packRGBA32FToR32F(const float* source, float* destination)
    872 {
    873     destination[0] = source[0];
    874 }
    875 
    876 void packRGBA32FToR32FPremultiply(const float* source, float* destination)
    877 {
    878     float scaleFactor = source[3];
    879     destination[0] = source[0] * scaleFactor;
    880 }
    881 
    882 
    883 void packRGBA32FToRA32F(const float* source, float* destination)
    884 {
    885     destination[0] = source[0];
    886     destination[1] = source[3];
    887 }
    888 
    889 void packRGBA32FToRA32FPremultiply(const float* source, float* destination)
    890 {
    891     float scaleFactor = source[3];
    892     destination[0] = source[0] * scaleFactor;
    893     destination[1] = scaleFactor;
     1049void packOneRowOfRGBA8ToUnsignedShort565Unmultiply(const uint8_t* source, uint16_t* destination, unsigned int pixelsPerRow)
     1050{
     1051    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1052        float scaleFactor = 1.0f / (source[3] ? source[3] / 255.0f : 1.0f);
     1053        uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
     1054        uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
     1055        uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
     1056        *destination = (((sourceR & 0xF8) << 8)
     1057                        | ((sourceG & 0xFC) << 3)
     1058                        | ((sourceB & 0xF8) >> 3));
     1059        source += 4;
     1060        destination += 1;
     1061    }
     1062}
     1063
     1064void packOneRowOfRGBA32FToRGB32F(const float* source, float* destination, unsigned int pixelsPerRow)
     1065{
     1066    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1067        destination[0] = source[0];
     1068        destination[1] = source[1];
     1069        destination[2] = source[2];
     1070        source += 4;
     1071        destination += 3;
     1072    }
     1073}
     1074
     1075void packOneRowOfRGBA32FToRGB32FPremultiply(const float* source, float* destination, unsigned int pixelsPerRow)
     1076{
     1077    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1078        float scaleFactor = source[3];
     1079        destination[0] = source[0] * scaleFactor;
     1080        destination[1] = source[1] * scaleFactor;
     1081        destination[2] = source[2] * scaleFactor;
     1082        source += 4;
     1083        destination += 3;
     1084    }
     1085}
     1086
     1087void packOneRowOfRGBA32FToRGBA32FPremultiply(const float* source, float* destination, unsigned int pixelsPerRow)
     1088{
     1089    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1090        float scaleFactor = source[3];
     1091        destination[0] = source[0] * scaleFactor;
     1092        destination[1] = source[1] * scaleFactor;
     1093        destination[2] = source[2] * scaleFactor;
     1094        destination[3] = source[3];
     1095        source += 4;
     1096        destination += 4;
     1097    }
     1098}
     1099
     1100void packOneRowOfRGBA32FToA32F(const float* source, float* destination, unsigned int pixelsPerRow)
     1101{
     1102    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1103        destination[0] = source[3];
     1104        source += 4;
     1105        destination += 1;
     1106    }
     1107}
     1108
     1109void packOneRowOfRGBA32FToR32F(const float* source, float* destination, unsigned int pixelsPerRow)
     1110{
     1111    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1112        destination[0] = source[0];
     1113        source += 4;
     1114        destination += 1;
     1115    }
     1116}
     1117
     1118void packOneRowOfRGBA32FToR32FPremultiply(const float* source, float* destination, unsigned int pixelsPerRow)
     1119{
     1120    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1121        float scaleFactor = source[3];
     1122        destination[0] = source[0] * scaleFactor;
     1123        source += 4;
     1124        destination += 1;
     1125    }
     1126}
     1127
     1128
     1129void packOneRowOfRGBA32FToRA32F(const float* source, float* destination, unsigned int pixelsPerRow)
     1130{
     1131    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1132        destination[0] = source[0];
     1133        destination[1] = source[3];
     1134        source += 4;
     1135        destination += 2;
     1136    }
     1137}
     1138
     1139void packOneRowOfRGBA32FToRA32FPremultiply(const float* source, float* destination, unsigned int pixelsPerRow)
     1140{
     1141    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     1142        float scaleFactor = source[3];
     1143        destination[0] = source[0] * scaleFactor;
     1144        destination[1] = scaleFactor;
     1145        source += 4;
     1146        destination += 2;
     1147    }
    8941148}
    8951149
     
    8991153// is not in RGBA8/RGBA32F format, or the unpack alignment specifies
    9001154// that rows are not tightly packed.
    901 template<typename SourceType, typename IntermediateType, typename DestType,
    902          void unpackingFunc(const SourceType*, IntermediateType*),
    903          void packingFunc(const IntermediateType*, DestType*)>
     1155template<typename SourceType, typename IntermediateType, typename DestType>
    9041156static void doUnpackingAndPacking(const SourceType* sourceData,
     1157                                  void (*rowUnpackingFunc)(const SourceType*, IntermediateType*, unsigned int),
    9051158                                  unsigned int width,
    9061159                                  unsigned int height,
    907                                   unsigned int sourceElementsPerPixel,
    9081160                                  unsigned int sourceElementsPerRow,
    9091161                                  DestType* destinationData,
     1162                                  void (*rowPackingFunc)(const IntermediateType*, DestType*, unsigned int),
    9101163                                  unsigned int destinationElementsPerPixel)
    9111164{
    912     if (!sourceElementsPerRow) {
    913         unsigned int numElements = width * height * sourceElementsPerPixel;
    914         const SourceType* endPointer = sourceData + numElements;
    915         IntermediateType temporaryRGBAData[4];
    916         while (sourceData < endPointer) {
    917             unpackingFunc(sourceData, temporaryRGBAData);
    918             packingFunc(temporaryRGBAData, destinationData);
    919             sourceData += sourceElementsPerPixel;
    920             destinationData += destinationElementsPerPixel;
    921         }
    922     } else {
    923         IntermediateType temporaryRGBAData[4];
    924         for (unsigned int y = 0; y < height; ++y) {
    925             const SourceType* currentSource = sourceData;
    926             for (unsigned int x = 0; x < width; ++x) {
    927                 unpackingFunc(currentSource, temporaryRGBAData);
    928                 packingFunc(temporaryRGBAData, destinationData);
    929                 currentSource += sourceElementsPerPixel;
    930                 destinationData += destinationElementsPerPixel;
    931             }
    932             sourceData += sourceElementsPerRow;
    933         }
     1165    OwnArrayPtr<IntermediateType> temporaryRGBAData = adoptArrayPtr(new IntermediateType[width * 4]);
     1166    const SourceType* endPointer = sourceData + height * sourceElementsPerRow;
     1167    unsigned int destinationElementsPerRow = width * destinationElementsPerPixel;
     1168    while (sourceData < endPointer) {
     1169        rowUnpackingFunc(sourceData, temporaryRGBAData.get(), width);
     1170        rowPackingFunc(temporaryRGBAData.get(), destinationData, width);
     1171        sourceData += sourceElementsPerRow;
     1172        destinationData += destinationElementsPerRow;
    9341173    }
    9351174}
    9361175
    9371176template<typename SourceType>
    938 static void computeIncrementParameters(unsigned int width,
    939                                        unsigned int bytesPerPixel,
    940                                        unsigned int unpackAlignment,
    941                                        unsigned int* sourceElementsPerPixel,
    942                                        unsigned int* sourceElementsPerRow)
     1177static unsigned int computeSourceElementsPerRow(unsigned int width,
     1178                                                unsigned int bytesPerPixel,
     1179                                                unsigned int unpackAlignment)
    9431180{
    9441181    unsigned int elementSizeInBytes = sizeof(SourceType);
     
    9521189            totalRowBytes += (unpackAlignment - remainder);
    9531190    }
    954     *sourceElementsPerPixel = bytesPerPixel / elementSizeInBytes;
    955     if (validRowBytes == totalRowBytes)
    956         *sourceElementsPerRow = 0;
    957     else
    958         *sourceElementsPerRow = totalRowBytes / elementSizeInBytes;
     1191    return totalRowBytes / elementSizeInBytes;
    9591192}
    9601193
    9611194// This handles all conversions with a faster path for tightly packed RGBA8 source data.
    962 template<typename DestType, void packingFunc(const uint8_t*, DestType*)>
     1195template<typename DestType>
    9631196static void doPacking(const void* sourceData,
    9641197                      GraphicsContext3D::SourceDataFormat sourceDataFormat,
     
    9671200                      unsigned int sourceUnpackAlignment,
    9681201                      DestType* destinationData,
     1202                      void (*rowPackingFunc)(const uint8_t*, DestType*, unsigned int),
    9691203                      unsigned int destinationElementsPerPixel)
    9701204{
    9711205    switch (sourceDataFormat) {
    9721206    case GraphicsContext3D::SourceFormatRGBA8: {
    973         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    974         computeIncrementParameters<uint8_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    975         if (!sourceElementsPerRow) {
    976             const uint8_t* source = static_cast<const uint8_t*>(sourceData);
    977             unsigned int numElements = width * height * 4;
    978             const uint8_t* endPointer = source + numElements;
    979             while (source < endPointer) {
    980                 packingFunc(source, destinationData);
    981                 source += sourceElementsPerPixel;
    982                 destinationData += destinationElementsPerPixel;
    983             }
    984         } else {
    985             doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackRGBA8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1207        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 4, sourceUnpackAlignment);
     1208        const uint8_t* source = static_cast<const uint8_t*>(sourceData);
     1209        const uint8_t* endPointer = source + height * sourceElementsPerRow;
     1210        unsigned int destinationElementsPerRow = width * destinationElementsPerPixel;
     1211        while (source < endPointer) {
     1212            rowPackingFunc(source, destinationData, width);
     1213            source += sourceElementsPerRow;
     1214            destinationData += destinationElementsPerRow;
    9861215        }
    9871216        break;
    9881217    }
    9891218    case GraphicsContext3D::SourceFormatRGBA16Little: {
    990         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    991         computeIncrementParameters<uint16_t>(width, 8, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    992         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRGBA16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1219        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 8, sourceUnpackAlignment);
     1220        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRGBA16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    9931221        break;
    9941222    }
    9951223    case GraphicsContext3D::SourceFormatRGBA16Big: {
    996         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    997         computeIncrementParameters<uint16_t>(width, 8, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    998         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRGBA16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1224        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 8, sourceUnpackAlignment);
     1225        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRGBA16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    9991226        break;
    10001227    }
    10011228    case GraphicsContext3D::SourceFormatRGB8: {
    1002         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1003         computeIncrementParameters<uint8_t>(width, 3, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1004         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackRGB8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1229        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 3, sourceUnpackAlignment);
     1230        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfRGB8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10051231        break;
    10061232    }
    10071233    case GraphicsContext3D::SourceFormatRGB16Little: {
    1008         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1009         computeIncrementParameters<uint16_t>(width, 6, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1010         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRGB16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1234        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 6, sourceUnpackAlignment);
     1235        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRGB16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10111236        break;
    10121237    }
    10131238    case GraphicsContext3D::SourceFormatRGB16Big: {
    1014         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1015         computeIncrementParameters<uint16_t>(width, 6, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1016         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRGB16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1239        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 6, sourceUnpackAlignment);
     1240        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRGB16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10171241        break;
    10181242    }
    10191243    case GraphicsContext3D::SourceFormatBGR8: {
    1020         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1021         computeIncrementParameters<uint8_t>(width, 3, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1022         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackBGR8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1244        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 3, sourceUnpackAlignment);
     1245        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfBGR8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10231246        break;
    10241247    }
    10251248    case GraphicsContext3D::SourceFormatARGB8: {
    1026         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1027         computeIncrementParameters<uint8_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1028         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackARGB8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1249        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 4, sourceUnpackAlignment);
     1250        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfARGB8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10291251        break;
    10301252    }
    10311253    case GraphicsContext3D::SourceFormatARGB16Little: {
    1032         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1033         computeIncrementParameters<uint16_t>(width, 8, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1034         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackARGB16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1254        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 8, sourceUnpackAlignment);
     1255        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfARGB16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10351256        break;
    10361257    }
    10371258    case GraphicsContext3D::SourceFormatARGB16Big: {
    1038         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1039         computeIncrementParameters<uint16_t>(width, 8, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1040         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackARGB16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1259        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 8, sourceUnpackAlignment);
     1260        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfARGB16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10411261        break;
    10421262    }
    10431263    case GraphicsContext3D::SourceFormatABGR8: {
    1044         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1045         computeIncrementParameters<uint8_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1046         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackABGR8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1264        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 4, sourceUnpackAlignment);
     1265        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfABGR8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10471266        break;
    10481267    }
    10491268    case GraphicsContext3D::SourceFormatBGRA8: {
    1050         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1051         computeIncrementParameters<uint8_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1052         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackBGRA8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1269        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 4, sourceUnpackAlignment);
     1270        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfBGRA8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10531271        break;
    10541272    }
    10551273    case GraphicsContext3D::SourceFormatBGRA16Little: {
    1056         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1057         computeIncrementParameters<uint16_t>(width, 8, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1058         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackBGRA16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1274        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 8, sourceUnpackAlignment);
     1275        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfBGRA16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10591276        break;
    10601277    }
    10611278    case GraphicsContext3D::SourceFormatBGRA16Big: {
    1062         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1063         computeIncrementParameters<uint16_t>(width, 8, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1064         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackBGRA16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1279        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 8, sourceUnpackAlignment);
     1280        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfBGRA16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10651281        break;
    10661282    }
    10671283    case GraphicsContext3D::SourceFormatRGBA5551: {
    1068         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1069         computeIncrementParameters<uint16_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1070         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRGBA5551ToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1284        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 2, sourceUnpackAlignment);
     1285        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRGBA5551ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10711286        break;
    10721287    }
    10731288    case GraphicsContext3D::SourceFormatRGBA4444: {
    1074         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1075         computeIncrementParameters<uint16_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1076         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRGBA4444ToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1289        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 2, sourceUnpackAlignment);
     1290        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRGBA4444ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10771291        break;
    10781292    }
    10791293    case GraphicsContext3D::SourceFormatRGB565: {
    1080         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1081         computeIncrementParameters<uint16_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1082         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRGB565ToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1294        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 2, sourceUnpackAlignment);
     1295        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRGB565ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10831296        break;
    10841297    }
    10851298    case GraphicsContext3D::SourceFormatR8: {
    1086         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1087         computeIncrementParameters<uint8_t>(width, 1, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1088         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackR8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1299        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 1, sourceUnpackAlignment);
     1300        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfR8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10891301        break;
    10901302    }
    10911303    case GraphicsContext3D::SourceFormatR16Little: {
    1092         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1093         computeIncrementParameters<uint16_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1094         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackR16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1304        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 2, sourceUnpackAlignment);
     1305        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfR16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    10951306        break;
    10961307    }
    10971308    case GraphicsContext3D::SourceFormatR16Big: {
    1098         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1099         computeIncrementParameters<uint16_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1100         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackR16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1309        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 2, sourceUnpackAlignment);
     1310        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfR16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11011311        break;
    11021312    }
    11031313    case GraphicsContext3D::SourceFormatRA8: {
    1104         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1105         computeIncrementParameters<uint8_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1106         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackRA8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1314        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 2, sourceUnpackAlignment);
     1315        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfRA8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11071316        break;
    11081317    }
    11091318    case GraphicsContext3D::SourceFormatRA16Little: {
    1110         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1111         computeIncrementParameters<uint16_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1112         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRA16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1319        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 4, sourceUnpackAlignment);
     1320        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRA16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11131321        break;
    11141322    }
    11151323    case GraphicsContext3D::SourceFormatRA16Big: {
    1116         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1117         computeIncrementParameters<uint16_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1118         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackRA16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1324        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 4, sourceUnpackAlignment);
     1325        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfRA16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11191326        break;
    11201327    }
    11211328    case GraphicsContext3D::SourceFormatAR8: {
    1122         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1123         computeIncrementParameters<uint8_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1124         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackAR8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1329        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 2, sourceUnpackAlignment);
     1330        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfAR8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11251331        break;
    11261332    }
    11271333    case GraphicsContext3D::SourceFormatAR16Little: {
    1128         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1129         computeIncrementParameters<uint16_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1130         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackAR16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1334        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 4, sourceUnpackAlignment);
     1335        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfAR16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11311336        break;
    11321337    }
    11331338    case GraphicsContext3D::SourceFormatAR16Big: {
    1134         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1135         computeIncrementParameters<uint16_t>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1136         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackAR16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1339        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 4, sourceUnpackAlignment);
     1340        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfAR16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11371341        break;
    11381342    }
    11391343    case GraphicsContext3D::SourceFormatA8: {
    1140         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1141         computeIncrementParameters<uint8_t>(width, 1, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1142         doUnpackingAndPacking<uint8_t, uint8_t, DestType, unpackA8ToRGBA8, packingFunc>(static_cast<const uint8_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1344        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint8_t>(width, 1, sourceUnpackAlignment);
     1345        doUnpackingAndPacking<uint8_t, uint8_t, DestType>(static_cast<const uint8_t*>(sourceData), unpackOneRowOfA8ToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11431346        break;
    11441347    }
    11451348    case GraphicsContext3D::SourceFormatA16Little: {
    1146         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1147         computeIncrementParameters<uint16_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1148         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackA16LittleToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1349        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 2, sourceUnpackAlignment);
     1350        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfA16LittleToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11491351        break;
    11501352    }
    11511353    case GraphicsContext3D::SourceFormatA16Big: {
    1152         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1153         computeIncrementParameters<uint16_t>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1154         doUnpackingAndPacking<uint16_t, uint8_t, DestType, unpackA16BigToRGBA8, packingFunc>(static_cast<const uint16_t*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1354        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<uint16_t>(width, 2, sourceUnpackAlignment);
     1355        doUnpackingAndPacking<uint16_t, uint8_t, DestType>(static_cast<const uint16_t*>(sourceData), unpackOneRowOfA16BigToRGBA8, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11551356        break;
    11561357    }
     
    11641365// currently no native floating-point image formats in WebKit, there are only a
    11651366// few upload paths.
    1166 template<void packingFunc(const float*, float*)>
    11671367static void doFloatingPointPacking(const void* sourceData,
    11681368                                   GraphicsContext3D::SourceDataFormat sourceDataFormat,
     
    11711371                                   unsigned int sourceUnpackAlignment,
    11721372                                   float* destinationData,
     1373                                   void rowPackingFunc(const float*, float*, unsigned int),
    11731374                                   unsigned int destinationElementsPerPixel)
    11741375{
    11751376    switch (sourceDataFormat) {
    11761377    case GraphicsContext3D::SourceFormatRGBA8: {
    1177         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1178         computeIncrementParameters<float>(width, 4, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1179         ASSERT(!sourceElementsPerRow); // Guaranteed because each color channel is sizeof(float) bytes.
     1378        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(width, 4, sourceUnpackAlignment);
    11801379        const float* source = static_cast<const float*>(sourceData);
    1181         unsigned int numElements = width * height * 4;
    1182         const float* endPointer = source + numElements;
     1380        const float* endPointer = source + height * sourceElementsPerRow;
     1381        unsigned int destinationElementsPerRow = width * destinationElementsPerPixel;
    11831382        while (source < endPointer) {
    1184             packingFunc(source, destinationData);
    1185             source += sourceElementsPerPixel;
    1186             destinationData += destinationElementsPerPixel;
     1383            rowPackingFunc(source, destinationData, width);
     1384            source += sourceElementsPerRow;
     1385            destinationData += destinationElementsPerRow;
    11871386        }
    11881387        break;
    11891388    }
    11901389    case GraphicsContext3D::SourceFormatRGB32F: {
    1191         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1192         computeIncrementParameters<float>(width, 3, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1193         doUnpackingAndPacking<float, float, float, unpackRGB32FToRGBA32F, packingFunc>(static_cast<const float*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1390        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(width, 3, sourceUnpackAlignment);
     1391        doUnpackingAndPacking<float, float, float>(static_cast<const float*>(sourceData), unpackOneRowOfRGB32FToRGBA32F, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    11941392        break;
    11951393    }
    11961394    case GraphicsContext3D::SourceFormatR32F: {
    1197         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1198         computeIncrementParameters<float>(width, 1, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1199         doUnpackingAndPacking<float, float, float, unpackR32FToRGBA32F, packingFunc>(static_cast<const float*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1395        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(width, 1, sourceUnpackAlignment);
     1396        doUnpackingAndPacking<float, float, float>(static_cast<const float*>(sourceData), unpackOneRowOfR32FToRGBA32F, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    12001397        break;
    12011398    }
    12021399    case GraphicsContext3D::SourceFormatRA32F: {
    1203         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1204         computeIncrementParameters<float>(width, 2, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1205         doUnpackingAndPacking<float, float, float, unpackRA32FToRGBA32F, packingFunc>(static_cast<const float*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1400        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(width, 2, sourceUnpackAlignment);
     1401        doUnpackingAndPacking<float, float, float>(static_cast<const float*>(sourceData), unpackOneRowOfRA32FToRGBA32F, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    12061402        break;
    12071403    }
    12081404    case GraphicsContext3D::SourceFormatA32F: {
    1209         unsigned int sourceElementsPerPixel, sourceElementsPerRow;
    1210         computeIncrementParameters<float>(width, 1, sourceUnpackAlignment, &sourceElementsPerPixel, &sourceElementsPerRow);
    1211         doUnpackingAndPacking<float, float, float, unpackA32FToRGBA32F, packingFunc>(static_cast<const float*>(sourceData), width, height, sourceElementsPerPixel, sourceElementsPerRow, destinationData, destinationElementsPerPixel);
     1405        unsigned int sourceElementsPerRow = computeSourceElementsPerRow<float>(width, 1, sourceUnpackAlignment);
     1406        doUnpackingAndPacking<float, float, float>(static_cast<const float*>(sourceData), unpackOneRowOfA32FToRGBA32F, width, height, sourceElementsPerRow, destinationData, rowPackingFunc, destinationElementsPerPixel);
    12121407        break;
    12131408    }
     
    12391434            switch (alphaOp) {
    12401435            case AlphaDoNothing:
    1241                 doPacking<uint8_t, packRGBA8ToRGB8>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 3);
     1436                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRGB8, 3);
    12421437                break;
    12431438            case AlphaDoPremultiply:
    1244                 doPacking<uint8_t, packRGBA8ToRGB8Premultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 3);
     1439                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRGB8Premultiply, 3);
    12451440                break;
    12461441            case AlphaDoUnmultiply:
    1247                 doPacking<uint8_t, packRGBA8ToRGB8Unmultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 3);
     1442                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRGB8Unmultiply, 3);
    12481443                break;
    12491444            }
     
    12531448            case AlphaDoNothing:
    12541449                ASSERT(sourceDataFormat != SourceFormatRGBA8 || sourceUnpackAlignment > 4); // Handled above with fast case.
    1255                 doPacking<uint8_t, packRGBA8ToRGBA8>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 4);
     1450                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRGBA8, 4);
    12561451                break;
    12571452            case AlphaDoPremultiply:
    1258                 doPacking<uint8_t, packRGBA8ToRGBA8Premultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 4);
     1453                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRGBA8Premultiply, 4);
    12591454                break;
    12601455            case AlphaDoUnmultiply:
    1261                 doPacking<uint8_t, packRGBA8ToRGBA8Unmultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 4);
     1456                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRGBA8Unmultiply, 4);
    12621457                break;
    12631458            default:
     
    12691464            // specification, Table 3.15), the alpha channel is chosen
    12701465            // from the RGBA data.
    1271             doPacking<uint8_t, packRGBA8ToA8>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1466            doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToA8, 1);
    12721467            break;
    12731468        case LUMINANCE:
     
    12771472            switch (alphaOp) {
    12781473            case AlphaDoNothing:
    1279                 doPacking<uint8_t, packRGBA8ToR8>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1474                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToR8, 1);
    12801475                break;
    12811476            case AlphaDoPremultiply:
    1282                 doPacking<uint8_t, packRGBA8ToR8Premultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1477                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToR8Premultiply, 1);
    12831478                break;
    12841479            case AlphaDoUnmultiply:
    1285                 doPacking<uint8_t, packRGBA8ToR8Unmultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1480                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToR8Unmultiply, 1);
    12861481                break;
    12871482            }
     
    12931488            switch (alphaOp) {
    12941489            case AlphaDoNothing:
    1295                 doPacking<uint8_t, packRGBA8ToRA8>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 2);
     1490                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRA8, 2);
    12961491                break;
    12971492            case AlphaDoPremultiply:
    1298                 doPacking<uint8_t, packRGBA8ToRA8Premultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 2);
     1493                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRA8Premultiply, 2);
    12991494                break;
    13001495            case AlphaDoUnmultiply:
    1301                 doPacking<uint8_t, packRGBA8ToRA8Unmultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 2);
     1496                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRA8Unmultiply, 2);
    13021497                break;
    13031498            }
     
    13101505        switch (alphaOp) {
    13111506        case AlphaDoNothing:
    1312             doPacking<uint16_t, packRGBA8ToUnsignedShort4444>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1507            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort4444, 1);
    13131508            break;
    13141509        case AlphaDoPremultiply:
    1315             doPacking<uint16_t, packRGBA8ToUnsignedShort4444Premultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1510            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort4444Premultiply, 1);
    13161511            break;
    13171512        case AlphaDoUnmultiply:
    1318             doPacking<uint16_t, packRGBA8ToUnsignedShort4444Unmultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1513            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort4444Unmultiply, 1);
    13191514            break;
    13201515        }
     
    13251520        switch (alphaOp) {
    13261521        case AlphaDoNothing:
    1327             doPacking<uint16_t, packRGBA8ToUnsignedShort5551>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1522            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort5551, 1);
    13281523            break;
    13291524        case AlphaDoPremultiply:
    1330             doPacking<uint16_t, packRGBA8ToUnsignedShort5551Premultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1525            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort5551Premultiply, 1);
    13311526            break;
    13321527        case AlphaDoUnmultiply:
    1333             doPacking<uint16_t, packRGBA8ToUnsignedShort5551Unmultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1528            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort5551Unmultiply, 1);
    13341529            break;
    13351530        }
     
    13401535        switch (alphaOp) {
    13411536        case AlphaDoNothing:
    1342             doPacking<uint16_t, packRGBA8ToUnsignedShort565>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1537            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort565, 1);
    13431538            break;
    13441539        case AlphaDoPremultiply:
    1345             doPacking<uint16_t, packRGBA8ToUnsignedShort565Premultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1540            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort565Premultiply, 1);
    13461541            break;
    13471542        case AlphaDoUnmultiply:
    1348             doPacking<uint16_t, packRGBA8ToUnsignedShort565Unmultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1543            doPacking<uint16_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToUnsignedShort565Unmultiply, 1);
    13491544            break;
    13501545        }
     
    13791574            switch (alphaOp) {
    13801575            case AlphaDoNothing:
    1381                 doFloatingPointPacking<packRGBA32FToRGB32F>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 3);
     1576                doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGB32F, 3);
    13821577                break;
    13831578            case AlphaDoPremultiply:
    1384                 doFloatingPointPacking<packRGBA32FToRGB32FPremultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 3);
     1579                doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGB32FPremultiply, 3);
    13851580                break;
    13861581            default:
     
    13911586            // AlphaDoNothing is handled above with fast path.
    13921587            ASSERT(alphaOp == AlphaDoPremultiply);
    1393             doFloatingPointPacking<packRGBA32FToRGBA32FPremultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 4);
     1588            doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRGBA32FPremultiply, 4);
    13941589            break;
    13951590        case ALPHA:
     
    13971592            // specification, Table 3.15), the alpha channel is chosen
    13981593            // from the RGBA data.
    1399             doFloatingPointPacking<packRGBA32FToA32F>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1594            doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToA32F, 1);
    14001595            break;
    14011596        case LUMINANCE:
     
    14051600            switch (alphaOp) {
    14061601            case AlphaDoNothing:
    1407                 doFloatingPointPacking<packRGBA32FToR32F>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1602                doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToR32F, 1);
    14081603                break;
    14091604            case AlphaDoPremultiply:
    1410                 doFloatingPointPacking<packRGBA32FToR32FPremultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 1);
     1605                doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToR32FPremultiply, 1);
    14111606                break;
    14121607            default:
     
    14201615            switch (alphaOp) {
    14211616            case AlphaDoNothing:
    1422                 doFloatingPointPacking<packRGBA32FToRA32F>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 2);
     1617                doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRA32F, 2);
    14231618                break;
    14241619            case AlphaDoPremultiply:
    1425                 doFloatingPointPacking<packRGBA32FToRA32FPremultiply>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 2);
     1620                doFloatingPointPacking(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA32FToRA32FPremultiply, 2);
    14261621                break;
    14271622            default:
Note: See TracChangeset for help on using the changeset viewer.