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

namespace Oddlib
{
    static Uint8 NextNibble(IStream& stream, bool& readLo, Uint8& srcByte)
    {
        if (readLo)
        {
            readLo = !readLo;
            return srcByte >> 4;
        }
        else
        {
            srcByte = ReadUInt8(stream);
            readLo = !readLo;
            return srcByte & 0xF;
        }
    }

    // Function 0x0040A8A0 in AE
    std::vector<Uint8> CompressionType6Ae::Decompress(IStream& stream, Uint32 finalW, Uint32 w, Uint32 h, Uint32 /*dataSize*/)
    {
        std::vector<Uint8> out(finalW*h);


        union intUni
        {
            Uint8 b[4];
            int i;
        } dstByte;


        bool bNibbleToRead = false; // ebp@5
        bool bBitsWriten = false;
        
        Uint32 dstPos = 0;

        if (h > 0)
        {
            Uint8 srcByte = 0;
            Sint32 heightCounter = h;
            do
            {
                Uint32 byteCounter = 0;
                while (byteCounter < w)
                {
                    Uint8 nibble = NextNibble(stream, bNibbleToRead, srcByte);
                    byteCounter += nibble;

                    if (nibble > 0)
                    {
                        do
                        {
                            if (bBitsWriten)
                            {
                                dstPos++;
                            }
                            else
                            {
                                out[dstPos] = 0;
                            }
                            bBitsWriten = !bBitsWriten;
                            --nibble;
                        } while (nibble);
                    }

                    nibble = NextNibble(stream, bNibbleToRead, srcByte);
                    byteCounter += nibble;

                    if (nibble > 0)
                    {
                        do
                        {
                            dstByte.b[0] = NextNibble(stream, bNibbleToRead, srcByte);
                         

                            if (bBitsWriten)
                            {
                                out[dstPos++] |= 16 * dstByte.b[0];
                                bBitsWriten = 0;
                            }
                            else
                            {
                                out[dstPos] = dstByte.b[0];
                                bBitsWriten = 1;
                            }
                        } while (--nibble);
                    }
                }

                for (; byteCounter & 7; ++byteCounter)
                {
                    if (bBitsWriten)
                    {
                        dstPos++;
                    }
                    else
                    {
                        out[dstPos] = 0;
                    }
                    bBitsWriten = !bBitsWriten;
                }

            } while (heightCounter-- != 1);
        }
        return out;
    }
}<commit_msg>remove need for union<commit_after>#include "oddlib/compressiontype6ae.hpp"
#include "oddlib/stream.hpp"
#include "logger.hpp"
#include <vector>
#include <cassert>

namespace Oddlib
{
    static Uint8 NextNibble(IStream& stream, bool& readLo, Uint8& srcByte)
    {
        if (readLo)
        {
            readLo = !readLo;
            return srcByte >> 4;
        }
        else
        {
            srcByte = ReadUInt8(stream);
            readLo = !readLo;
            return srcByte & 0xF;
        }
    }

    // Function 0x0040A8A0 in AE
    std::vector<Uint8> CompressionType6Ae::Decompress(IStream& stream, Uint32 finalW, Uint32 w, Uint32 h, Uint32 /*dataSize*/)
    {
        std::vector<Uint8> out(finalW*h);

        bool bNibbleToRead = false;
        bool bSkip = false;
        Uint32 dstPos = 0;

        if (h > 0)
        {
            Uint8 srcByte = 0;
            Sint32 heightCounter = h;
            do
            {
                Uint32 widthCounter = 0;
                while (widthCounter < w)
                {
                    Uint8 nibble = NextNibble(stream, bNibbleToRead, srcByte);
                    widthCounter += nibble;

                    if (nibble > 0)
                    {
                        do
                        {
                            if (bSkip)
                            {
                                dstPos++;
                            }
                            else
                            {
                                out[dstPos] = 0;
                            }
                            bSkip = !bSkip;
                            --nibble;
                        } while (nibble);
                    }

                    nibble = NextNibble(stream, bNibbleToRead, srcByte);
                    widthCounter += nibble;

                    if (nibble > 0)
                    {
                        do
                        {
                            const Uint8 data = NextNibble(stream, bNibbleToRead, srcByte);
                            if (bSkip)
                            {
                                out[dstPos++] |= 16 * data;
                                bSkip = 0;
                            }
                            else
                            {
                                out[dstPos] = data;
                                bSkip = 1;
                            }
                        } while (--nibble);
                    }
                }

                for (; widthCounter & 7; ++widthCounter)
                {
                    if (bSkip)
                    {
                        dstPos++;
                    }
                    else
                    {
                        out[dstPos] = 0;
                    }
                    bSkip = !bSkip;
                }

            } while (heightCounter-- != 1);
        }
        return out;
    }
}
{'fraction_non_alphanumeric': 0.07836990595611286, 'fraction_numerical': 0.016333938294010888, 'mean_word_length': 0.6759745645562621, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '6867570', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1479, 'n_words': 301}