/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include <eCxx/eCxx_ColorSpace.h>

#include "TestUtility.h"


//
// Helper functions
//
template <typename ColorFX2D_T>
static void dumpBufferRaw3Packed(const ColorFX2D_T& cfx)
{
    typename ColorFX2D_T::ConstIterator it = cfx.colorBufferData();

    for(typename ColorFX2D_T::BufferSizeType y = 0; y < ColorFX2D_T::YElementCount; ++y) {
        for(typename ColorFX2D_T::BufferSizeType x = 0; x < ColorFX2D_T::XElementCount; ++x) {
            printf( "%d%d%d ", (int) *(it + 0), (int) *(it + 1), (int) *(it + 2) );
            it += ColorFX2D_T::ColorByteSize;
        }
        printf("\n");
    }
}


//
// Test application
//
int main()
{
#if 0
    #define S_PROGMEM_D PROGMEM_FAR
    #define S_PGM_PTR_T eCxx::PGMCharPointerFar
    #define S_PGM_PTR_F eCxx::PGM_PTR_FAR
#else
    #define S_PROGMEM_D PROGMEM
    #define S_PGM_PTR_T eCxx::PGMCharPointer
    #define S_PGM_PTR_F eCxx::PGM_PTR
#endif

    #define R   0
    #define G 120
    #define B 240

    #define S 200
    #define V   6

    static const eCxx::uint8_t S_PROGMEM_D pgmSpriteData[eCxx::HSVColor::RawByteSize * 3 * 2 * 5 * 3] = {
        // Sprite (0, 0)
        0,0,0,0, R,0,S,V, R,0,S,V, R,0,S,V, 0,0,0,0,
        0,0,S,V, R,0,S,V, R,0,S,V, R,0,S,V, R,0,S,V,
        0,0,0,0, R,0,S,V, R,0,S,V, R,0,S,V, 0,0,0,0,
        // Sprite (1, 0)
        0,0,0,0, G,0,S,V, G,0,S,V, G,0,S,V, 0,0,0,0,
        G,0,S,V, G,0,S,V, G,0,S,V, G,0,S,V, G,0,S,V,
        0,0,0,0, G,0,S,V, G,0,S,V, G,0,S,V, 0,0,0,0,
        // Sprite (2, 0)
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        // Sprite (0, 1)
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        // Sprite (1, 1)
        0,0,0,0, B,0,S,V, B,0,S,V, B,0,S,V, 0,0,0,0,
        B,0,S,V, B,0,S,V, B,0,S,V, B,0,S,V, B,0,S,V,
        0,0,0,0, B,0,S,V, B,0,S,V, B,0,S,V, 0,0,0,0,
        // Sprite (2, 1)
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
    };

    eCxx::SpriteSheet2D<eCxx::HSVColor, 3, 2, 5, 3, S_PGM_PTR_T> ss2d( S_PGM_PTR_F(pgmSpriteData) );

    #undef R
    #undef G
    #undef B

    #undef S
    #undef V



    const eCxx::HSVColor transCol(0, 0, 0);
    eCxx::ColorFX2D<eCxx::RGBColor, 32, 32, eCxx::CBP::DefaultLayout, eCxx::CBP::RawBuffer> cfx;
    printf("\n");



    cfx.set( eCxx::RGBColor(8, 8, 8) );
    cfx.putSpriteXY( 10, 10, ss2d, 0, 0          );
    cfx.putSpriteXY( 20, 20, ss2d, 0, 0, transCol);
    dumpBufferRaw3Packed(cfx);
    printf("\n");

    cfx.set( eCxx::RGBColor(8, 8, 8) );
    cfx.putSpriteXY( 5,  5, ss2d, 0, 0, transCol);
    cfx.putSpriteXY(10, 10, ss2d, 1, 0, transCol);
    cfx.putSpriteXY(15, 15, ss2d, 1, 1, transCol);
    dumpBufferRaw3Packed(cfx);
    printf("\n");



    return 0;
}
