TEXTURES lump: fixed a problem where textures that use textures as patches were too bright when gamma correction was enabled

This commit is contained in:
biwa 2021-05-13 21:36:29 +02:00
parent 0d78a48bd5
commit 898fe21f75
3 changed files with 30 additions and 30 deletions

View file

@ -235,42 +235,44 @@ namespace CodeImp.DoomBuilder.Data
public Image GetBackgroundBitmap()
{
return LocalGetBitmap();
return LocalGetBitmap(usecolorcorrection);
}
public Bitmap GetSkyboxBitmap()
{
return LocalGetBitmap();
return LocalGetBitmap(usecolorcorrection);
}
public Bitmap ExportBitmap()
{
return LocalGetBitmap();
return LocalGetBitmap(usecolorcorrection);
}
public Bitmap GetSpritePreview()
{
if (spritepreviewbitmap == null)
spritepreviewbitmap = LocalGetBitmap();
spritepreviewbitmap = LocalGetBitmap(usecolorcorrection);
return spritepreviewbitmap;
}
// Loads the image directly. This is needed by the background loader for some patches.
public Bitmap LocalGetBitmap()
{
// Note: if this turns out to be too slow, do NOT try to make it use GetBitmap or bitmap.
// Create a cache for the local background loader thread instead.
// biwa. Just setting UseGammeCorrection before LocalGetBitmap was not enough, since its
// state is subject to race conditions at load time when using a texture as a patch
public Bitmap LocalGetBitmap(bool withcolorcorrection)
{
// Note: if this turns out to be too slow, do NOT try to make it use GetBitmap or bitmap.
// Create a cache for the local background loader thread instead.
LocalLoadResult result = LocalLoadImage();
if (result.messages.Any(x => x.Type == ErrorType.Error))
{
return Properties.Resources.Failed;
}
ConvertImageFormat(result);
return result.bitmap;
}
public void LoadImageNow()
LocalLoadResult result = LocalLoadImage();
if (result.messages.Any(x => x.Type == ErrorType.Error))
{
return Properties.Resources.Failed;
}
ConvertImageFormat(result, withcolorcorrection);
return result.bitmap;
}
public void LoadImageNow()
{
if (imagestate != ImageLoadState.Ready)
{
@ -293,7 +295,7 @@ namespace CodeImp.DoomBuilder.Data
// Do the loading
LocalLoadResult loadResult = LocalLoadImage();
ConvertImageFormat(loadResult);
ConvertImageFormat(loadResult, usecolorcorrection);
MakeImagePreview(loadResult);
MakeAlphaTestImage(loadResult);
@ -393,7 +395,7 @@ namespace CodeImp.DoomBuilder.Data
public string Text { get; set; }
}
void ConvertImageFormat(LocalLoadResult loadResult)
void ConvertImageFormat(LocalLoadResult loadResult, bool withcolorcorrection)
{
// Bitmap loaded successfully?
Bitmap bitmap = loadResult.bitmap;
@ -427,7 +429,7 @@ namespace CodeImp.DoomBuilder.Data
}
// This applies brightness correction on the image
if(usecolorcorrection)
if(withcolorcorrection)
{
BitmapData bmpdata = null;

View file

@ -202,9 +202,11 @@ namespace CodeImp.DoomBuilder.Data
ImageData img = General.Map.Data.GetTextureImage(p.LumpName);
if(!(img is UnknownImage) && img != this)
{
//mxd. Apply transformations from TexturePatch. We don't want to modify the original bitmap here, so make a copy
Bitmap bmp = new Bitmap(img.LocalGetBitmap());
Bitmap patchbmp = TransformPatch(bitmap, p, bmp);
//mxd. Apply transformations from TexturePatch. We don't want to modify the original bitmap here, so make a copy
// biwa. Make sure to get the image without color correction, as the final texture would be too bright if the patch
// is also a texture
Bitmap bmp = new Bitmap(img.LocalGetBitmap(false));
Bitmap patchbmp = TransformPatch(bitmap, p, bmp);
// Draw the patch on the texture image
Rectangle tgtrect = new Rectangle(p.X, p.Y, patchbmp.Size.Width, patchbmp.Size.Height);

View file

@ -260,9 +260,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
// The image might have a color correction applied, but we need it without. So we use LocalGetBitmap, because it reloads the image,
// but doesn't applie the color correction if we set UseColorCorrection to false first
ImageData imagedata = General.Map.Data.GetFlatImage(s.FloorTexture);
imagedata.UseColorCorrection = false;
brushtexture = new Bitmap(imagedata.LocalGetBitmap());
imagedata.UseColorCorrection = true;
brushtexture = new Bitmap(imagedata.LocalGetBitmap(false));
textureoffset.x = s.Fields.GetValue("xpanningfloor", 0.0) * scale;
textureoffset.y = s.Fields.GetValue("ypanningfloor", 0.0) * scale;
@ -276,9 +274,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
// The image might have a color correction applied, but we need it without. So we use LocalGetBitmap, because it reloads the image,
// but doesn't applie the color correction if we set UseColorCorrection to false first
ImageData imagedata = General.Map.Data.GetFlatImage(s.CeilTexture);
imagedata.UseColorCorrection = false;
brushtexture = new Bitmap(imagedata.LocalGetBitmap());
imagedata.UseColorCorrection = true;
brushtexture = new Bitmap(imagedata.LocalGetBitmap(false));
textureoffset.x = s.Fields.GetValue("xpanningceiling", 0.0) * scale;
textureoffset.y = s.Fields.GetValue("ypanningceiling", 0.0) * scale;