Skip to content

added -ga and -gA #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libgrit/grit_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void grit_init(GritRec *gr)
gr->gfxAlphaColor= clr2rgb(RGB(255, 0, 255));
gr->gfxBpp= 8;
gr->gfxOffset= 0;
gr->gfxIsOffsetOnZero= false;
gr->gfxIsShared= false;

// Map options.
Expand Down Expand Up @@ -231,6 +232,7 @@ void grit_copy_options(GritRec *dst, const GritRec *src)
dst->gfxAlphaColor= src->gfxAlphaColor;
dst->gfxBpp= src->gfxBpp;
dst->gfxOffset= src->gfxOffset;
dst->gfxIsOffsetOnZero= src->gfxIsOffsetOnZero;
dst->gfxIsShared= src->gfxIsShared;

// Map options.
Expand Down
1 change: 1 addition & 0 deletions libgrit/grit_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ struct GritRec
bool gfxHasAlpha; //!< Input image has transparent color.
RGBQUAD gfxAlphaColor; //!< Transparent color (-gT {num} ).
u32 gfxOffset; //!< Pixel value offset (-ga {num}).
bool gfxIsOffsetOnZero; //!< Pixel value offset for zero pixel as well. (-gA {num}).
bool gfxIsShared; //!< Graphics are shared (-gS).

// Map:
Expand Down
22 changes: 18 additions & 4 deletions libgrit/grit_prep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ bool grit_prep_gfx(GritRec *gr)
{
lprintf(LOG_STATUS, "Graphics preparation.\n");

int ii;
int srcB= dib_get_bpp(gr->_dib); // should be 8 or 16 by now
int srcP= dib_get_pitch(gr->_dib);
int srcS= dib_get_size_img(gr->_dib);
Expand Down Expand Up @@ -575,14 +576,27 @@ bool grit_prep_gfx(GritRec *gr)
// problems with padding
// NOTE: we're already at 8 or 16 bpp here, with 16 bpp already
// accounted for. Only have to do 8->1,2,4
// TODO: offset
// TODO: base eBUP big-endian
if(srcB == 8 && srcB != dstB)
{
lprintf(LOG_STATUS, " Bitpacking: %d -> %d.\n", srcB, dstB);
data_bit_pack(dstD, srcD, srcS, srcB, dstB, 0);
DWORD base = gr->gfxOffset;
if (gr->gfxIsOffsetOnZero)
base |= BUP_BASE0;
data_bit_pack(dstD, srcD, srcS, srcB, dstB, base);
}
else
memcpy(dstD, srcD, dstS);
else {
for (ii=0;ii<dstS;ii++) {
BYTE bsrcD = srcD[ii];
if (bsrcD)
dstD[ii] = bsrcD + gr->gfxOffset;
else
dstD[ii] =
gr->gfxIsOffsetOnZero
? bsrcD + gr->gfxOffset
: bsrcD;
}
}

//add alpha data for texture formats
if((gr->gfxTexMode == GRIT_TEXFMT_A5I3 || gr->gfxTexMode == GRIT_TEXFMT_A3I5))
Expand Down
10 changes: 7 additions & 3 deletions srcgrit/grit_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ const char appHelpText[]=
"-g | -g! Include or exclude gfx data [inc]\n"
"-gu(8|16|32) Gfx data type: u8, u16, u32 [u32]\n"
"-gz[!lhr0] Gfx compression: off, lz77, huff, RLE, off+header [off]\n"
//"-ga{n} Gfx pixel offset (non-zero pixels) [0]\n"
//"-gA{n} Gfx pixel offset n (all pixels) [0]\n"
"-ga{n} Gfx pixel offset (non-zero pixels) [0]\n"
"-gA{n} Gfx pixel offset n (all pixels) [0]\n"
"-gb | -gt Gfx format, bitmap or tile [tile]\n"
"-gB{fmt} Gfx format / bit depth (1, 2, 4, 8, 16, a5i3, a3i5) [img bpp]\n"
"-gx Enable texture operations\n"
Expand Down Expand Up @@ -332,7 +332,11 @@ bool grit_parse_gfx(GritRec *gr, const strvec &args)
gr->gfxCompression= val;

// pixel offset
gr->gfxOffset= CLI_INT("-ga", 0);
gr->gfxOffset= CLI_INT("-gA", 0);
gr->gfxIsOffsetOnZero= (bool)gr->gfxOffset;
if (!gr->gfxOffset) {
gr->gfxOffset= CLI_INT("-ga", 0);
}
}
else
//# PONDER: can img really be excluded from processing?
Expand Down