trying to restore transparency handling fix.

probably missed some bitflag in a header that's responsible for this
behavior.
This commit is contained in:
morkt 2016-10-14 01:51:46 +04:00
parent 44deae320c
commit 8c6b44bb3f
2 changed files with 36 additions and 39 deletions

View File

@ -152,7 +152,7 @@ namespace GameRes.Formats.Circus
Palette = new BitmapPalette (palette); Palette = new BitmapPalette (palette);
} }
public void Unpack () public void Unpack (bool is_diff = false)
{ {
if (m_compression >= 3) if (m_compression >= 3)
{ {
@ -184,8 +184,7 @@ namespace GameRes.Formats.Circus
int g = m_output[pixel+2]; int g = m_output[pixel+2];
int r = m_output[pixel+3]; int r = m_output[pixel+3];
/* if (!is_diff && alpha != alpha_flip)
if (alpha != alpha_flip)
{ {
b += (w & 1) + shift; b += (w & 1) + shift;
if (b < 0) if (b < 0)
@ -205,7 +204,7 @@ namespace GameRes.Formats.Circus
else if (r > 0xff) else if (r > 0xff)
r = 0xff; r = 0xff;
} }
*/
m_output[pixel] = (byte)b; m_output[pixel] = (byte)b;
m_output[pixel+1] = (byte)g; m_output[pixel+1] = (byte)g;
m_output[pixel+2] = (byte)r; m_output[pixel+2] = (byte)r;

View File

@ -136,46 +136,44 @@ namespace GameRes.Formats.Circus
if (null == base_info || base_info.BPP != info.BPP) if (null == base_info || base_info.BPP != info.BPP)
throw new InvalidFormatException ("Invalid base image"); throw new InvalidFormatException ("Invalid base image");
using (var reader = new Reader (base_file, base_info)) using (var reader = new Reader (base_file, base_info))
using (var crx = OpenDiffStream (stream, meta))
using (var diff_reader = new Reader (crx, meta.DiffInfo))
{ {
reader.Unpack(); reader.Unpack (true);
using (var crx = OpenDiffStream (stream, meta)) diff_reader.Unpack (true);
using (var diff_reader = new Reader (crx, meta.DiffInfo)) var diff_rect = new Rectangle (meta.OffsetX, meta.OffsetY, (int)meta.Width, (int)meta.Height);
var base_rect = new Rectangle (base_info.OffsetX, base_info.OffsetY,
(int)base_info.Width, (int)base_info.Height);
diff_rect = Rectangle.Intersect (diff_rect, base_rect);
if (diff_rect.IsEmpty)
throw new InvalidFormatException ("Empty diff region");
int pixel_size = base_info.BPP / 8;
int x = diff_rect.X - base_rect.X;
int y = diff_rect.Y - base_rect.Y;
int dst = y * reader.Stride + pixel_size * x;
var image = reader.Data;
int dx = diff_rect.X - meta.OffsetX;
int dy = diff_rect.Y - meta.OffsetY;
int src = dy * diff_reader.Stride + pixel_size * dx;
var diff = diff_reader.Data;
int blend_stride = diff_rect.Width * pixel_size;
for (int row = 0; row < diff_rect.Height; ++row)
{ {
diff_reader.Unpack(); for (int i = 0; i < blend_stride; i += pixel_size)
var diff_rect = new Rectangle (meta.OffsetX, meta.OffsetY, (int)meta.Width, (int)meta.Height);
var base_rect = new Rectangle (base_info.OffsetX, base_info.OffsetY,
(int)base_info.Width, (int)base_info.Height);
diff_rect = Rectangle.Intersect (diff_rect, base_rect);
if (diff_rect.IsEmpty)
throw new InvalidFormatException ("Empty diff region");
int pixel_size = base_info.BPP / 8;
int x = diff_rect.X - base_rect.X;
int y = diff_rect.Y - base_rect.Y;
int dst = y * reader.Stride + pixel_size * x;
var image = reader.Data;
int dx = diff_rect.X - meta.OffsetX;
int dy = diff_rect.Y - meta.OffsetY;
int src = dy * diff_reader.Stride + pixel_size * dx;
var diff = diff_reader.Data;
int blend_stride = diff_rect.Width * pixel_size;
for (int row = 0; row < diff_rect.Height; ++row)
{ {
for (int i = 0; i < blend_stride; i += pixel_size) image[dst+i ] += diff[src+i];
{ image[dst+i+1] += diff[src+i+1];
image[dst+i ] += diff[src+i]; image[dst+i+2] += diff[src+i+2];
image[dst+i+1] += diff[src+i+1]; if (4 == pixel_size)
image[dst+i+2] += diff[src+i+2]; image[dst+i+3] -= diff[src+i+3];
if (4 == pixel_size)
image[dst+i+3] -= diff[src+i+3];
}
dst += reader.Stride;
src += diff_reader.Stride;
} }
return ImageData.Create (base_info, reader.Format, reader.Palette, image, reader.Stride); dst += reader.Stride;
src += diff_reader.Stride;
} }
return ImageData.Create (base_info, reader.Format, reader.Palette, image, reader.Stride);
} }
} }
} }