Image exporter: sector colors are now taken into account

This commit is contained in:
biwa 2021-06-24 19:58:26 +02:00
parent a86a596e00
commit 98321b6f40

View file

@ -298,6 +298,12 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
AdjustBrightness(ref brushtexture, brightness > 0 ? brightness / 255.0f : 0.0f);
}
// Take sector colors into account
int lightcolor = s.Fields.GetValue("lightcolor", 0xffffff);
int surfacecolor = settings.Floor ? s.Fields.GetValue("color_floor", 0xffffff) : s.Fields.GetValue("color_ceiling", 0xffffff);
Rendering.Color4 color = Rendering.PixelColor.Modulate(Rendering.PixelColor.FromInt(lightcolor), Rendering.PixelColor.FromInt(surfacecolor)).ToColorValue();
Colorize(ref brushtexture, color.Red, color.Green, color.Blue);
if (scale > 1.0f)
ResizeImage(ref brushtexture, brushtexture.Width * (int)scale, brushtexture.Height * (int)scale);
@ -506,6 +512,41 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
image = bm;
}
private void Colorize(ref Bitmap image, float r, float g, float b)
{
// Make the ColorMatrix.
ColorMatrix cm = new ColorMatrix(new float[][] {
new float[] {r, 0, 0, 0, 0},
new float[] {0, g, 0, 0, 0},
new float[] {0, 0, b, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1},
});
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(cm);
// Draw the image onto the new bitmap while applying the new ColorMatrix.
Point[] points = {
new Point(0, 0),
new Point(image.Width, 0),
new Point(0, image.Height),
};
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
// Make the result bitmap.
Bitmap bm = new Bitmap(image.Width, image.Height);
using (Graphics gr = Graphics.FromImage(bm))
{
gr.DrawImage(image, points, rect, GraphicsUnit.Pixel, attributes);
}
// Dispose the original...
image.Dispose();
// ... and set it as the adjusted image
image = bm;
}
/// <summary>
/// Resize the image to the specified width and height. Taken from https://stackoverflow.com/a/24199315 (with some modifications)
/// </summary>