<commit_before>#include "oddlib/compressiontype3ae.hpp"
#include "oddlib/stream.hpp"
#include "logger.hpp"
#include <vector>
#include <cassert>

static Uint16 ReadUint16(Oddlib::IStream& stream)
{
    Uint16 ret = 0;
    stream.ReadUInt16(ret);
    return ret;
}

static Uint32 ReadUint32(Oddlib::IStream& stream)
{
    Uint32 ret = 0;
    stream.ReadUInt32(ret);
    return ret;
}

template<typename T>
static void ReadNextSource(Oddlib::IStream& stream, int& control_byte, T& dstIndex)
{
    if (control_byte)
    {
        if (control_byte == 0xE)
        {
            control_byte = 0x1Eu;
            dstIndex |= ReadUint16(stream) << 14;
        }
    }
    else
    {
        dstIndex = ReadUint32(stream);
        control_byte = 0x20u;
    }
}


namespace Oddlib
{
    std::vector<Uint8> CompressionType3Ae::Decompress(IStream& stream, Uint32 size, Uint32 w, Uint32 h)
    {
        LOG_INFO("Data size is " << size);


        // TODO: Shouldn't need to be * 4
        std::vector< unsigned char > buffer(w*h * 4);

        unsigned char *aDbufPtr = &buffer[0];

        int control_byte; // esi@1
        int dstIndex; // edx@2
        unsigned char *dstPtr; // edi@2
        int count; // ebx@3
        unsigned char blackBytes; // al@8
        unsigned int srcByte; // edx@8
        int bytesToWrite; // ebx@8
        int i; // ecx@9
        unsigned char *dstBlackBytesPtr; // edi@9
        unsigned int doubleBBytes; // ecx@9
        int byteCount; // ecx@18
        char dstByte; // al@23

        int width; // [sp+10h] [bp-Ch]@1
        int height; // [sp+14h] [bp-8h]@2
        unsigned char bytes; // [sp+20h] [bp+4h]@17

        control_byte = 0;
        width = ReadUint16(stream);

        height = ReadUint16(stream);
        if (height > 0)
        {
            dstIndex = 0;// (int)aDbufPtr;
            dstPtr = aDbufPtr;
            do
            {
                count = 0;
                while (count < width)
                {
                    ReadNextSource(stream, control_byte, dstIndex);

                    blackBytes = dstIndex & 0x3F;
                    control_byte = control_byte - 6;
                    srcByte = (unsigned int)dstIndex >> 6;


                    bytesToWrite = blackBytes + count;
                    if (blackBytes > 0)
                    {
                        doubleBBytes = (unsigned int)blackBytes >> 2;
                        memset(dstPtr, 0, 4 * doubleBBytes);
                        dstBlackBytesPtr = &dstPtr[4 * doubleBBytes];
                        for (i = blackBytes & 3; i; --i)
                        {
                            *dstBlackBytesPtr++ = 0;
                        }
                        dstPtr = &aDbufPtr[blackBytes];
                        aDbufPtr += blackBytes;
                    }

                    ReadNextSource(stream, control_byte, srcByte);

                    control_byte = control_byte - 6;
                    bytes = srcByte & 0x3F;
                    dstIndex = srcByte >> 6;

                    count = bytes + bytesToWrite;
                    if ((signed int)bytes > 0)
                    {
                        byteCount = bytes;
    
                        do
                        {
                            ReadNextSource(stream, control_byte, dstIndex);

                            control_byte -= 6;
                            dstByte = dstIndex & 0x3F;
                            dstIndex = (unsigned int)dstIndex >> 6;

                            *dstPtr++ = dstByte;
                            --byteCount;
                        } while (byteCount);
                        aDbufPtr = dstPtr;
                    }
                }
                if (count & 3)
                {
                    do
                    {
                        ++dstPtr;
                        ++count;<commit_msg>clean up<commit_after>#include "oddlib/compressiontype3ae.hpp"
#include "oddlib/stream.hpp"
#include "logger.hpp"
#include <vector>
#include <cassert>

static Uint16 ReadUint16(Oddlib::IStream& stream)
{
    Uint16 ret = 0;
    stream.ReadUInt16(ret);
    return ret;
}

static Uint32 ReadUint32(Oddlib::IStream& stream)
{
    Uint32 ret = 0;
    stream.ReadUInt32(ret);
    return ret;
}

template<typename T>
static void ReadNextSource(Oddlib::IStream& stream, int& control_byte, T& dstIndex)
{
    if (control_byte)
    {
        if (control_byte == 0xE)
        {
            control_byte = 0x1Eu;
            dstIndex |= ReadUint16(stream) << 14;
        }
    }
    else
    {
        dstIndex = ReadUint32(stream);
        control_byte = 0x20u;
    }
    control_byte -= 6;
}


namespace Oddlib
{
    std::vector<Uint8> CompressionType3Ae::Decompress(IStream& stream, Uint32 size, Uint32 w, Uint32 h)
    {
        LOG_INFO("Data size is " << size);

        // TODO: Shouldn't need to be * 4
        std::vector< unsigned char > buffer(w*h * 4);

        unsigned char *aDbufPtr = &buffer[0];
        int dstIndex; // edx@2
        unsigned char *dstPtr; // edi@2
   
        int control_byte = 0;
        int width = ReadUint16(stream);
        int height = ReadUint16(stream);
        if (height > 0)
        {
            dstIndex = 0;// (int)aDbufPtr;
            dstPtr = aDbufPtr;
            do
            {
                int count = 0;
                while (count < width)
                {
                    ReadNextSource(stream, control_byte, dstIndex);

                    const unsigned char blackBytes = dstIndex & 0x3F;
                   
                     unsigned int srcByte = (unsigned int)dstIndex >> 6;


                    const int bytesToWrite = blackBytes + count;
                    if (blackBytes > 0)
                    {
                        const unsigned int doubleBBytes = (unsigned int)blackBytes >> 2;
                        memset(dstPtr, 0, 4 * doubleBBytes);
                        unsigned char* dstBlackBytesPtr = &dstPtr[4 * doubleBBytes];
                        for (int i = blackBytes & 3; i; --i)
                        {
                            *dstBlackBytesPtr++ = 0;
                        }
                        dstPtr = &aDbufPtr[blackBytes];
                        aDbufPtr += blackBytes;
                    }

                    ReadNextSource(stream, control_byte, srcByte);

                    const unsigned char bytes = srcByte & 0x3F;
                    dstIndex = srcByte >> 6;

                    count = bytes + bytesToWrite;
                    if (bytes > 0)
                    {
                        int byteCount = bytes;
                        do
                        {
                            ReadNextSource(stream, control_byte, dstIndex);
                          
                            const char dstByte = dstIndex & 0x3F;
                            dstIndex = (unsigned int)dstIndex >> 6;

                            *dstPtr++ = dstByte;
                            --byteCount;
                        } while (byteCount);
                        aDbufPtr = dstPtr;
                    }
                }
                if (count & 3)
                {
                    do
                    {
                        ++dstPtr;
                        ++count;
{'fraction_non_alphanumeric': 0.09350935093509351, 'fraction_numerical': 0.0231023102310231, 'mean_word_length': 1.1447950457092304, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3810632', 'n_tokens_mistral': 2164, 'n_tokens_neox': 1953, 'n_words': 465}