XeNTaX Forum Index
Forum MultiEx Commander Tools Tools Home
It is currently Thu Dec 13, 2018 9:10 am

All times are UTC + 1 hour


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: DXT1 Issues
PostPosted: Fri Jun 13, 2014 5:40 am 
Offline
beginner

Joined: Fri Apr 02, 2010 4:37 pm
Posts: 21
Has thanked: 0 time
Have thanks: 4 times

I've been trying to write my own png2txtr converter for Metroid Prime, and I have most image formats supported, however DXT1 is giving me some odd swizzling issues,
This is my code so far:
Code:
    unsigned w = input.get_width();
    unsigned h = input.get_height();
    unsigned paddedW = (w + 3) & ~3;
    unsigned paddedH = (h + 3) & ~3;
    char*  rgbaBuffer = new char[(w*h)<<2];
    memset(rgbaBuffer, 0, (w*h)<<2);

    int iv =0;
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            png::rgba_pixel pixel = input.get_pixel(x, y);
            rgbaBuffer[(y*(w<<2))+(x<<2) + 0] = pixel.red;
            rgbaBuffer[(y*(w<<2))+(x<<2) + 1] = pixel.green;
            rgbaBuffer[(y*(w<<2))+(x<<2) + 2] = pixel.blue;
            rgbaBuffer[(y*(w<<2))+(x<<2) + 3] = pixel.alpha;
        }
    }

    short* compressedData = new short[(w*h) >> 2];
    tx_compress_dxtn(4, w, h, (const GLubyte*)rgbaBuffer, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, (GLubyte*)compressedData);
    int stride = input.get_width();
    #define OFFSET(x,y) (((y)/4)*stride+((x)/4)*4)
    Athena::io::BinaryWriter writer(new Uint8[w*h/2], w*h/2);
    writer.setEndian(Athena::Endian::BigEndian);
    writer.writeUint32((int)TXTRFile::DXT1);
    writer.writeUint16(w);
    writer.writeUint16(h);
    writer.writeUint32(1);
    for (int y = 0; y < h; y += 8)
    {
        for (int x = 0; x < w; x += 8)
        {
            for (int t = 0; t < 4; ++t)
            {
                short color;
                int mx = x+(t&1)*4;
                int my = y+(!!(t&2))*4;

                color = compressedData[OFFSET(mx, my)+0];
                writer.writeUint16(color);
                color = compressedData[OFFSET(mx, my)+1];
                writer.writeUint16(color);
                color = compressedData[OFFSET(mx, my)+2];
                writer.writeUint16(color);
                color = compressedData[OFFSET(mx, my)+3];
                writer.writeUint16(color);
            }
        }
    }
    delete[] rgbaBuffer;
    delete[] compressedData;
    writer.save("test.txtr");


Here is the image before compression:
Image
And here is the result:
Image

Athena is my IO library I wrote to aid my hacking endeavors for those curious.

You can make the ads go away by registering





Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group