Skip to content

Commit

Permalink
Fix palette display for 32bpp (was getting the wrong value due to sig…
Browse files Browse the repository at this point in the history
…ned 32-bit instead of unsigned)
  • Loading branch information
bbbradsmith committed Oct 11, 2024
1 parent 4851a7a commit 9b86eae
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions BinxelviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ unsafe int getPaletteRaw(long x)
return autoPaletteRaw(x);
}

Color getPalette(int x)
Color getPalette(long x)
{
if (preset.bpp <= PALETTE_BITS) return palette[x];
int p = autoPaletteRaw(x);
Expand Down Expand Up @@ -1149,8 +1149,8 @@ void redrawPalette()
{
for (int x = 0; x < PALETTE_DIM; ++x)
{
int px = (x * (1 << bx)) / PALETTE_DIM;
int py = (y * (1 << by)) / PALETTE_DIM;
long px = ((long)x * (1 << bx)) / PALETTE_DIM;
long py = ((long)y * (1 << by)) / PALETTE_DIM;
Color c = getPalette(px + (py * (1 << bx)));
palette_bmp.SetPixel(x, y, c);
}
Expand Down Expand Up @@ -1465,9 +1465,9 @@ private void paletteBox_MouseMove(object sender, MouseEventArgs e)
{
int bx = preset.bpp / 2;
int by = preset.bpp - bx;
int px = (e.X * (1 << bx)) / PALETTE_DIM;
int py = (e.Y * (1 << by)) / PALETTE_DIM;
int index = px + (py * (1 << bx));
long px = ((long)e.X * (1 << bx)) / PALETTE_DIM;
long py = ((long)e.Y * (1 << by)) / PALETTE_DIM;
long index = px + (py * (1 << bx));
Color c = getPalette(index);
int ch = (c.R << 16) | (c.G << 8) | c.B;
labelInfoPal.Text = String.Format("{0:D} = {1:D},{2:D},{3:D}\n{4:X2} = {5:X6}",(uint)index,c.R,c.G,c.B,(uint)index,ch);
Expand All @@ -1479,9 +1479,9 @@ private void paletteBox_MouseClick(object sender, MouseEventArgs e)

int bx = preset.bpp / 2;
int by = preset.bpp - bx;
int px = (e.X * (1 << bx)) / PALETTE_DIM;
int py = (e.Y * (1 << by)) / PALETTE_DIM;
int index = px + (py * (1 << bx));
long px = ((long)e.X * (1 << bx)) / PALETTE_DIM;
long py = ((long)e.Y * (1 << by)) / PALETTE_DIM;
long index = px + (py * (1 << bx));
Color c = getPalette(index);

ColorDialog d = new ColorDialog();
Expand All @@ -1491,7 +1491,7 @@ private void paletteBox_MouseClick(object sender, MouseEventArgs e)
if (d.ShowDialog() == DialogResult.OK)
{
palette_mode = PaletteMode.PALETTE_CUSTOM;
setPalette(index, d.Color.R, d.Color.G, d.Color.B);
setPalette((int)index, d.Color.R, d.Color.G, d.Color.B);
redrawPixels();
}
refreshPalette();
Expand Down Expand Up @@ -1707,7 +1707,7 @@ private void pixelsToPaletteToolStripMenuItem_Click(object sender, EventArgs e)
{
long p = readPixel(read_pos);
if (p < 0) break;
Color c = getPalette((int)p); // can't modify the new palette because we read it here
Color c = getPalette(p); // can't modify the new palette because we read it here
new_pal[i] = c;
++count;
read_pos += preset.pixel_stride_bit;
Expand Down

0 comments on commit 9b86eae

Please sign in to comment.