Skip to content

Commit

Permalink
Merge pull request #38 from trapexit/dump
Browse files Browse the repository at this point in the history
Fix packing edgecase + add dump instr cmd
  • Loading branch information
trapexit committed May 15, 2024
2 parents a3c2280 + 0869d24 commit 7514bb4
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 106 deletions.
34 changes: 34 additions & 0 deletions src/bitmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,40 @@ struct Bitmap
set("rotation","0");
}

bool
has_transparent() const
{
for(size_t y = 0; y < h; y++)
{
for(size_t x = 0; x < w; x++)
{
const RGBA8888 *c = xy(x,y);

if(c->a == 0)
return true;
}
}

return false;
}

bool
has_black() const
{
for(size_t y = 0; y < h; y++)
{
for(size_t x = 0; x < w; x++)
{
const RGBA8888 *c = xy(x,y);

if((c->r == 0) && (c->g == 0) && (c->b == 0) && (c->a > 0))
return true;
}
}

return false;
}

public:
std::size_t w;
std::size_t h;
Expand Down
5 changes: 5 additions & 0 deletions src/bits_and_bytes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#define BITS_PER_BYTE 8
#define BYTES_PER_WORD 4
#define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
28 changes: 28 additions & 0 deletions src/bitstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,55 @@ class BitStreamWriter
skip(0x8 - (_idx & 0x7));
}

void
zero_till_8bit_boundary()
{
if(_idx & 0x7)
write((0x8 - (_idx & 0x7)),0);
}

void
skip_to_16bit_boundary()
{
if(_idx & 0x0F)
skip(0x10 - (_idx & 0x0F));
}

void
zero_till_16bit_boundary()
{
if(_idx & 0x0F)
write((0x10 - (_idx & 0x0F)),0);
}

void
skip_to_32bit_boundary()
{
if(_idx & 0x1F)
skip(0x20 - (_idx & 0x1F));
}

void
zero_till_32bit_boundary()
{
if(_idx & 0x1F)
write((0x20 - (_idx & 0x1F)),0);
}

void
skip_to_64bit_boundary()
{
if(_idx & 0x3F)
skip(0x40 - (_idx & 0x3F));
}

void
zero_till_64bit_boundary()
{
if(_idx & 0x3F)
write((0x40 - (_idx & 0x3F)),0);
}

size_t
tell() const
{
Expand Down
9 changes: 6 additions & 3 deletions src/cel_control_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ CelControlChunk::packed() const
return (ccb_Flags & CCB_PACKED);
}

bool
CelControlChunk::unpacked() const
{
return !packed();
}

bool
CelControlChunk::lrform() const
{
Expand Down Expand Up @@ -398,9 +404,6 @@ CelControlChunk::type() const
return CEL_TYPE(coded(),packed(),lrform(),bpp());
}




void
CelControlChunk::byteswap_if_little_endian()
{
Expand Down
1 change: 1 addition & 0 deletions src/cel_control_chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CelControlChunk
public:
bool coded() const;
bool packed() const;
bool unpacked() const;
bool lrform() const;
int bpp() const;
bool rep8() const;
Expand Down
Loading

0 comments on commit 7514bb4

Please sign in to comment.