mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-07 08:21:59 +00:00
DOES NOT COMPILE - working on resource management
This commit is contained in:
parent
4d67cc7dd4
commit
996a56dafc
7 changed files with 228 additions and 192 deletions
|
@ -77,6 +77,7 @@
|
||||||
<Compile Include="Data\DirectoryReader.cs" />
|
<Compile Include="Data\DirectoryReader.cs" />
|
||||||
<Compile Include="Data\FileImage.cs" />
|
<Compile Include="Data\FileImage.cs" />
|
||||||
<Compile Include="Data\FlatImage.cs" />
|
<Compile Include="Data\FlatImage.cs" />
|
||||||
|
<Compile Include="Data\ImageLoadState.cs" />
|
||||||
<Compile Include="Data\NullImage.cs" />
|
<Compile Include="Data\NullImage.cs" />
|
||||||
<Compile Include="Data\PatchNames.cs" />
|
<Compile Include="Data\PatchNames.cs" />
|
||||||
<Compile Include="Data\PK3Reader.cs" />
|
<Compile Include="Data\PK3Reader.cs" />
|
||||||
|
|
|
@ -55,12 +55,12 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
// Flats
|
// Flats
|
||||||
private Dictionary<long, ImageData> flats;
|
private Dictionary<long, ImageData> flats;
|
||||||
private List<string> flatnames;
|
private List<string> flatnames;
|
||||||
|
|
||||||
// Sprites
|
// Sprites
|
||||||
private Dictionary<long, ImageData> sprites;
|
private Dictionary<long, ImageData> sprites;
|
||||||
|
|
||||||
// Background loading
|
// Background loading
|
||||||
private LinkedList<ImageData> loadlist;
|
private Queue<ImageData> imageque;
|
||||||
private Thread backgroundloader;
|
private Thread backgroundloader;
|
||||||
|
|
||||||
// Image previews
|
// Image previews
|
||||||
|
@ -77,6 +77,7 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
#region ================== Properties
|
#region ================== Properties
|
||||||
|
|
||||||
public Playpal Palette { get { return palette; } }
|
public Playpal Palette { get { return palette; } }
|
||||||
|
internal PreviewManager Previews { get { return previews; } }
|
||||||
public ICollection<ImageData> Textures { get { return textures.Values; } }
|
public ICollection<ImageData> Textures { get { return textures.Values; } }
|
||||||
public ICollection<ImageData> Flats { get { return flats.Values; } }
|
public ICollection<ImageData> Flats { get { return flats.Values; } }
|
||||||
public List<string> TextureNames { get { return texturenames; } }
|
public List<string> TextureNames { get { return texturenames; } }
|
||||||
|
@ -341,7 +342,7 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
General.MainWindow.UpdateStatusIcon();
|
General.MainWindow.UpdateStatusIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The background loader
|
// The background loader
|
||||||
private void BackgroundLoad()
|
private void BackgroundLoad()
|
||||||
{
|
{
|
||||||
|
@ -351,34 +352,37 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
{
|
{
|
||||||
// Get next item
|
// Get next item
|
||||||
ImageData image = null;
|
ImageData image = null;
|
||||||
lock(loadlist)
|
lock(imageque)
|
||||||
{
|
{
|
||||||
// Anything to do?
|
// Fethc next image to process
|
||||||
if(loadlist.Count > 0)
|
if(imageque.Count > 0) image = imageque.Dequeue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Any image to process?
|
||||||
|
if(image != null)
|
||||||
|
{
|
||||||
|
// Load this image?
|
||||||
|
if(image.ImageState == ImageLoadState.Loading)
|
||||||
{
|
{
|
||||||
// Fetch image
|
// Still referenced?
|
||||||
image = loadlist.First.Value;
|
if(image.IsReferenced)
|
||||||
image.LoadingTicket = null;
|
image.LoadImage();
|
||||||
loadlist.RemoveFirst();
|
else
|
||||||
|
image.ImageState = ImageLoadState.None;
|
||||||
// Load or unload this image?
|
}
|
||||||
switch(image.LoadState)
|
|
||||||
{
|
// Unload this image?
|
||||||
// Load image
|
if(image.ImageState == ImageLoadState.Unloading)
|
||||||
case ImageData.LOADSTATE_LOAD:
|
{
|
||||||
image.LoadImage();
|
// Still unreferenced?
|
||||||
//image.CreateTexture(); // Impossible from different thread
|
if(!image.IsReferenced)
|
||||||
break;
|
image.UnloadImage();
|
||||||
|
else
|
||||||
// Unload image
|
image.ImageState = ImageLoadState.Ready;
|
||||||
case ImageData.LOADSTATE_TRASH:
|
|
||||||
image.UnloadImage();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Did we do something?
|
// Doing something?
|
||||||
if(image != null)
|
if(image != null)
|
||||||
{
|
{
|
||||||
// Wait a bit and update icon
|
// Wait a bit and update icon
|
||||||
|
@ -387,9 +391,23 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Wait longer to release CPU resources
|
// Process previews only when we don't have images to process
|
||||||
Thread.Sleep(50);
|
// because these are lower priority than the actual images
|
||||||
|
if(previews.BackgroundLoad())
|
||||||
|
{
|
||||||
|
// Wait a bit and update icon
|
||||||
|
General.MainWindow.UpdateStatusIcon();
|
||||||
|
Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Wait longer to release CPU resources
|
||||||
|
Thread.Sleep(50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Done
|
||||||
|
image = null;
|
||||||
}
|
}
|
||||||
while(true);
|
while(true);
|
||||||
}
|
}
|
||||||
|
@ -398,55 +416,29 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This adds an image for background loading or unloading
|
// This adds an image for background loading or unloading
|
||||||
public void BackgroundLoadImage(ImageData img, bool load)
|
internal void ProcessImage(ImageData img)
|
||||||
{
|
{
|
||||||
int loadstate = load ? ImageData.LOADSTATE_LOAD : ImageData.LOADSTATE_TRASH;
|
// Load this image?
|
||||||
|
if((img.ImageState == ImageLoadState.None) && img.IsReferenced)
|
||||||
lock(loadlist)
|
|
||||||
{
|
{
|
||||||
// Already in the list?
|
// Add for loading
|
||||||
if(img.LoadingTicket != null)
|
img.ImageState = ImageLoadState.Loading;
|
||||||
{
|
lock(imageque) { imageque.Enqueue(img); }
|
||||||
// Just change the state
|
}
|
||||||
img.LoadState = loadstate;
|
|
||||||
}
|
// Unload this image?
|
||||||
else
|
if((img.ImageState == ImageLoadState.Ready) && !img.IsReferenced)
|
||||||
{
|
{
|
||||||
// Set load state and add to list
|
// Add for unloading
|
||||||
img.LoadState = loadstate;
|
img.ImageState = ImageLoadState.Unloading;
|
||||||
img.LoadingTicket = loadlist.AddLast(img);
|
lock(imageque) { imageque.Enqueue(img); }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update icon
|
// Update icon
|
||||||
General.MainWindow.UpdateStatusIcon();
|
General.MainWindow.UpdateStatusIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This removes an image from background loading
|
|
||||||
// This does not work for images that are being unloaded!
|
|
||||||
public void BackgroundCancelImage(ImageData img)
|
|
||||||
{
|
|
||||||
// Queued?
|
|
||||||
if(img.LoadingTicket != null)
|
|
||||||
{
|
|
||||||
// Not being trashed?
|
|
||||||
if(img.LoadState != ImageData.LOADSTATE_TRASH)
|
|
||||||
{
|
|
||||||
lock(loadlist)
|
|
||||||
{
|
|
||||||
// Remove it from queue
|
|
||||||
LinkedListNode<ImageData> ticket = img.LoadingTicket;
|
|
||||||
img.LoadingTicket = null;
|
|
||||||
loadlist.Remove(ticket);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update icon
|
|
||||||
General.MainWindow.UpdateStatusIcon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,9 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
public abstract unsafe class ImageData
|
public abstract unsafe class ImageData
|
||||||
{
|
{
|
||||||
#region ================== Constants
|
#region ================== Constants
|
||||||
|
|
||||||
internal const int LOADSTATE_NONE = 0;
|
|
||||||
internal const int LOADSTATE_LOAD = 1;
|
|
||||||
internal const int LOADSTATE_TRASH = 2;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Variables
|
#region ================== Variables
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
@ -54,45 +50,48 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
protected float scaledheight;
|
protected float scaledheight;
|
||||||
protected bool usecolorcorrection;
|
protected bool usecolorcorrection;
|
||||||
|
|
||||||
// Background loading
|
// Loading
|
||||||
private LinkedListNode<ImageData> loadingticket;
|
private LinkedListNode<ImageData> processticket;
|
||||||
private int loadstate;
|
private ImageLoadState previewstate;
|
||||||
private bool temporary;
|
private ImageLoadState imagestate;
|
||||||
|
|
||||||
|
// References
|
||||||
|
private bool usedinmap;
|
||||||
|
private int references;
|
||||||
|
|
||||||
// GDI bitmap
|
// GDI bitmap
|
||||||
protected Bitmap bitmap;
|
protected Bitmap bitmap;
|
||||||
|
|
||||||
// 2D rendering data
|
|
||||||
private PixelColorBlock pixeldata;
|
|
||||||
|
|
||||||
// Direct3D texture
|
// Direct3D texture
|
||||||
private int mipmaplevels = 0; // 0 creates the full chain
|
private int mipmaplevels = 0; // 0 = all mipmaps
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
|
|
||||||
// Disposing
|
// Disposing
|
||||||
protected bool isdisposed = false;
|
protected bool isdisposed = false;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Properties
|
#region ================== Properties
|
||||||
|
|
||||||
public string Name { get { return name; } }
|
public string Name { get { return name; } }
|
||||||
public long LongName { get { return longname; } }
|
public long LongName { get { return longname; } }
|
||||||
public bool UseColorCorrection { get { return usecolorcorrection; } set { usecolorcorrection = value; } }
|
public bool UseColorCorrection { get { return usecolorcorrection; } set { usecolorcorrection = value; } }
|
||||||
public PixelColorBlock PixelData { get { lock(this) { return pixeldata; } } }
|
|
||||||
public Bitmap Bitmap { get { lock(this) { if(bitmap != null) return new Bitmap(bitmap); else return CodeImp.DoomBuilder.Properties.Resources.Hourglass; } } }
|
public Bitmap Bitmap { get { lock(this) { if(bitmap != null) return new Bitmap(bitmap); else return CodeImp.DoomBuilder.Properties.Resources.Hourglass; } } }
|
||||||
public Texture Texture { get { lock(this) { return texture; } } }
|
public Texture Texture { get { lock(this) { return texture; } } }
|
||||||
public bool IsLoaded { get { return (bitmap != null) && (loadstate != ImageData.LOADSTATE_LOAD); } }
|
public bool IsPreviewLoaded { get { lock(this) { return (previewstate == ImageLoadState.Ready); } } }
|
||||||
|
public bool IsImageLoaded { get { lock(this) { return (imagestate == ImageLoadState.Ready); } } }
|
||||||
public bool IsDisposed { get { return isdisposed; } }
|
public bool IsDisposed { get { return isdisposed; } }
|
||||||
internal bool Temporary { get { return temporary; } set { temporary = value; } }
|
internal ImageLoadState ImageState { get { return imagestate; } set { imagestate = value; } }
|
||||||
internal int LoadState { get { return loadstate; } set { loadstate = value; } }
|
internal ImageLoadState PreviewState { get { return previewstate; } set { previewstate = value; } }
|
||||||
internal LinkedListNode<ImageData> LoadingTicket { get { return loadingticket; } set { loadingticket = value; } }
|
internal LinkedListNode<ImageData> ProcessTicket { get { return processticket; } set { processticket = value; } }
|
||||||
|
internal bool IsReferenced { get { return (references > 0) || usedinmap; } }
|
||||||
|
internal bool UsedInMap { get { return usedinmap; } set { usedinmap = value; } }
|
||||||
public int MipMapLevels { get { return mipmaplevels; } set { mipmaplevels = value; } }
|
public int MipMapLevels { get { return mipmaplevels; } set { mipmaplevels = value; } }
|
||||||
public int Width { get { return width; } }
|
public int Width { get { return width; } }
|
||||||
public int Height { get { return height; } }
|
public int Height { get { return height; } }
|
||||||
public float ScaledWidth { get { return scaledwidth; } }
|
public float ScaledWidth { get { return scaledwidth; } }
|
||||||
public float ScaledHeight { get { return scaledheight; } }
|
public float ScaledHeight { get { return scaledheight; } }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Constructor / Disposer
|
#region ================== Constructor / Disposer
|
||||||
|
@ -120,18 +119,34 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
if(texture != null) texture.Dispose();
|
if(texture != null) texture.Dispose();
|
||||||
bitmap = null;
|
bitmap = null;
|
||||||
texture = null;
|
texture = null;
|
||||||
pixeldata = null;
|
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
|
usedinmap = false;
|
||||||
|
references = 0;
|
||||||
|
imagestate = ImageLoadState.None;
|
||||||
|
previewstate = ImageLoadState.None;
|
||||||
isdisposed = true;
|
isdisposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Management
|
#region ================== Management
|
||||||
|
|
||||||
|
// This adds a reference
|
||||||
|
public void AddReference()
|
||||||
|
{
|
||||||
|
references++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This removes a reference
|
||||||
|
public void RemoveReference()
|
||||||
|
{
|
||||||
|
references--;
|
||||||
|
if(references < 0) General.Fail("FAIL! (references < 0)", "Somewhere this image is dereferenced more than it was referenced.");
|
||||||
|
}
|
||||||
|
|
||||||
// This sets the name
|
// This sets the name
|
||||||
protected void SetName(string name)
|
protected void SetName(string name)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +161,7 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
{
|
{
|
||||||
if(bitmap != null) bitmap.Dispose();
|
if(bitmap != null) bitmap.Dispose();
|
||||||
bitmap = null;
|
bitmap = null;
|
||||||
loadstate = ImageData.LOADSTATE_NONE;
|
imagestate = ImageLoadState.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,67 +169,34 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
public virtual void LoadImage()
|
public virtual void LoadImage()
|
||||||
{
|
{
|
||||||
BitmapData bmpdata = null;
|
BitmapData bmpdata = null;
|
||||||
|
|
||||||
// Determine amounts
|
|
||||||
float gamma = (float)(General.Settings.ImageBrightness + 10) * 0.1f;
|
|
||||||
float bright = (float)General.Settings.ImageBrightness * 5f;
|
|
||||||
|
|
||||||
// This applies brightness correction on the image
|
|
||||||
if((bitmap != null) && usecolorcorrection)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Try locking the bitmap
|
|
||||||
bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
General.WriteLogLine("ERROR: Cannot lock image '" + name + "' for color correction. " + e.GetType().Name + ": " + e.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bitmap locked?
|
|
||||||
if(bmpdata != null)
|
|
||||||
{
|
|
||||||
// Apply color correction
|
|
||||||
byte* pixels = (byte*)(bmpdata.Scan0.ToPointer());
|
|
||||||
for(int p = 0; p < bmpdata.Stride * bmpdata.Height; p += 4)
|
|
||||||
{
|
|
||||||
// Apply color correction for individual colors
|
|
||||||
float r = (float)pixels[p + 0] * gamma + bright;
|
|
||||||
float g = (float)pixels[p + 1] * gamma + bright;
|
|
||||||
float b = (float)pixels[p + 2] * gamma + bright;
|
|
||||||
|
|
||||||
// Clamp to 0..255 range
|
|
||||||
if(r < 0f) pixels[p + 0] = 0; else if(r > 255f) pixels[p + 0] = 255; else pixels[p + 0] = (byte)r;
|
|
||||||
if(g < 0f) pixels[p + 1] = 0; else if(g > 255f) pixels[p + 1] = 255; else pixels[p + 1] = (byte)g;
|
|
||||||
if(b < 0f) pixels[p + 2] = 0; else if(b > 255f) pixels[p + 2] = 255; else pixels[p + 2] = (byte)b;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Done with the lock
|
|
||||||
bitmap.UnlockBits(bmpdata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Done, reset load state
|
|
||||||
loadstate = ImageData.LOADSTATE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This creates the 2D pixel data
|
|
||||||
internal virtual void CreatePixelData()
|
|
||||||
{
|
|
||||||
BitmapData bmpdata;
|
|
||||||
|
|
||||||
lock(this)
|
lock(this)
|
||||||
{
|
{
|
||||||
// Only do this when data is not created yet
|
// This applies brightness correction on the image
|
||||||
if((pixeldata == null) && IsLoaded)
|
if((bitmap != null) && usecolorcorrection)
|
||||||
{
|
{
|
||||||
// Make a data copy of the bits for the 2D renderer
|
try
|
||||||
bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
{
|
||||||
pixeldata = new PixelColorBlock(bitmap.Size.Width, bitmap.Size.Height);
|
// Try locking the bitmap
|
||||||
General.CopyMemory((void*)pixeldata.Pointer, bmpdata.Scan0.ToPointer(), new UIntPtr(pixeldata.Length));
|
bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||||
bitmap.UnlockBits(bmpdata);
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
General.WriteLogLine("ERROR: Cannot lock image '" + name + "' for color correction. " + e.GetType().Name + ": " + e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bitmap locked?
|
||||||
|
if(bmpdata != null)
|
||||||
|
{
|
||||||
|
// Apply color correction
|
||||||
|
PixelColor* pixels = (PixelColor*)(bmpdata.Scan0.ToPointer());
|
||||||
|
General.Colors.ApplColorCorrection(pixels, bmpdata.Width * bmpdata.Height);
|
||||||
|
bitmap.UnlockBits(bmpdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Image is ready
|
||||||
|
imagestate = ImageLoadState.Ready;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +208,7 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
lock(this)
|
lock(this)
|
||||||
{
|
{
|
||||||
// Only do this when texture is not created yet
|
// Only do this when texture is not created yet
|
||||||
if(((texture == null) || (texture.Disposed)) && IsLoaded)
|
if(((texture == null) || (texture.Disposed)) && this.IsLoaded)
|
||||||
{
|
{
|
||||||
// Write to memory stream and read from memory
|
// Write to memory stream and read from memory
|
||||||
memstream = new MemoryStream();
|
memstream = new MemoryStream();
|
||||||
|
|
43
Source/Data/ImageLoadState.cs
Normal file
43
Source/Data/ImageLoadState.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
||||||
|
* This program is released under GNU General Public License
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Namespaces
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using SlimDX.Direct3D9;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using CodeImp.DoomBuilder.Rendering;
|
||||||
|
using CodeImp.DoomBuilder.IO;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace CodeImp.DoomBuilder.Data
|
||||||
|
{
|
||||||
|
internal enum ImageLoadState : int
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Loading,
|
||||||
|
Ready,
|
||||||
|
Unloading
|
||||||
|
}
|
||||||
|
}
|
|
@ -123,7 +123,7 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Loading
|
#region ================== Loading
|
||||||
|
|
||||||
// This makes a new atlas
|
// This makes a new atlas
|
||||||
private void MakeNewAtlas()
|
private void MakeNewAtlas()
|
||||||
{
|
{
|
||||||
|
@ -139,7 +139,15 @@ namespace CodeImp.DoomBuilder.Data
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Background loading
|
||||||
|
// Return true when we have more work to do, so that the
|
||||||
|
// thread will not wait too long before calling again
|
||||||
|
internal bool BackgroundLoad()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,10 +99,13 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
private PixelColor[] brightcolors;
|
private PixelColor[] brightcolors;
|
||||||
private PixelColor[] darkcolors;
|
private PixelColor[] darkcolors;
|
||||||
|
|
||||||
|
// Color-correction table
|
||||||
|
private byte[] correctiontable;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Properties
|
#region ================== Properties
|
||||||
|
|
||||||
public PixelColor[] Colors { get { return colors; } }
|
public PixelColor[] Colors { get { return colors; } }
|
||||||
public PixelColor[] BrightColors { get { return brightcolors; } }
|
public PixelColor[] BrightColors { get { return brightcolors; } }
|
||||||
public PixelColor[] DarkColors { get { return darkcolors; } }
|
public PixelColor[] DarkColors { get { return darkcolors; } }
|
||||||
|
@ -117,11 +120,11 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
public PixelColor Indication { get { return colors[INDICATION]; } internal set { colors[INDICATION] = value; } }
|
public PixelColor Indication { get { return colors[INDICATION]; } internal set { colors[INDICATION] = value; } }
|
||||||
public PixelColor Grid { get { return colors[GRID]; } internal set { colors[GRID] = value; } }
|
public PixelColor Grid { get { return colors[GRID]; } internal set { colors[GRID] = value; } }
|
||||||
public PixelColor Grid64 { get { return colors[GRID64]; } internal set { colors[GRID64] = value; } }
|
public PixelColor Grid64 { get { return colors[GRID64]; } internal set { colors[GRID64] = value; } }
|
||||||
|
|
||||||
public PixelColor Crosshair3D { get { return colors[CROSSHAIR3D]; } internal set { colors[CROSSHAIR3D] = value; } }
|
public PixelColor Crosshair3D { get { return colors[CROSSHAIR3D]; } internal set { colors[CROSSHAIR3D] = value; } }
|
||||||
public PixelColor Highlight3D { get { return colors[HIGHLIGHT3D]; } internal set { colors[HIGHLIGHT3D] = value; } }
|
public PixelColor Highlight3D { get { return colors[HIGHLIGHT3D]; } internal set { colors[HIGHLIGHT3D] = value; } }
|
||||||
public PixelColor Selection3D { get { return colors[SELECTION3D]; } internal set { colors[SELECTION3D] = value; } }
|
public PixelColor Selection3D { get { return colors[SELECTION3D]; } internal set { colors[SELECTION3D] = value; } }
|
||||||
|
|
||||||
public PixelColor ScriptBackground { get { return colors[SCRIPTBACKGROUND]; } internal set { colors[SCRIPTBACKGROUND] = value; } }
|
public PixelColor ScriptBackground { get { return colors[SCRIPTBACKGROUND]; } internal set { colors[SCRIPTBACKGROUND] = value; } }
|
||||||
public PixelColor LineNumbers { get { return colors[LINENUMBERS]; } internal set { colors[LINENUMBERS] = value; } }
|
public PixelColor LineNumbers { get { return colors[LINENUMBERS]; } internal set { colors[LINENUMBERS] = value; } }
|
||||||
public PixelColor PlainText { get { return colors[PLAINTEXT]; } internal set { colors[PLAINTEXT] = value; } }
|
public PixelColor PlainText { get { return colors[PLAINTEXT]; } internal set { colors[PLAINTEXT] = value; } }
|
||||||
|
@ -129,7 +132,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
public PixelColor Keywords { get { return colors[KEYWORDS]; } internal set { colors[KEYWORDS] = value; } }
|
public PixelColor Keywords { get { return colors[KEYWORDS]; } internal set { colors[KEYWORDS] = value; } }
|
||||||
public PixelColor Literals { get { return colors[LITERALS]; } internal set { colors[LITERALS] = value; } }
|
public PixelColor Literals { get { return colors[LITERALS]; } internal set { colors[LITERALS] = value; } }
|
||||||
public PixelColor Constants { get { return colors[CONSTANTS]; } internal set { colors[CONSTANTS] = value; } }
|
public PixelColor Constants { get { return colors[CONSTANTS]; } internal set { colors[CONSTANTS] = value; } }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Constructor / Disposer
|
#region ================== Constructor / Disposer
|
||||||
|
@ -174,24 +177,8 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
// Create assist colors
|
// Create assist colors
|
||||||
CreateAssistColors();
|
CreateAssistColors();
|
||||||
|
|
||||||
// We have no destructor
|
// Create color correction table
|
||||||
GC.SuppressFinalize(this);
|
General.Colors.CreateCorrectionTable();
|
||||||
}
|
|
||||||
|
|
||||||
// Copy constructor
|
|
||||||
internal ColorCollection(ColorCollection collection)
|
|
||||||
{
|
|
||||||
// Initialize
|
|
||||||
colors = new PixelColor[NUM_COLORS];
|
|
||||||
brightcolors = new PixelColor[NUM_COLORS];
|
|
||||||
darkcolors = new PixelColor[NUM_COLORS];
|
|
||||||
|
|
||||||
// Copy all colors
|
|
||||||
for(int i = 0; i < NUM_COLORS; i++)
|
|
||||||
colors[i] = collection.colors[i];
|
|
||||||
|
|
||||||
// Create assist colors
|
|
||||||
CreateAssistColors();
|
|
||||||
|
|
||||||
// We have no destructor
|
// We have no destructor
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
@ -201,6 +188,37 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
|
|
||||||
#region ================== Methods
|
#region ================== Methods
|
||||||
|
|
||||||
|
// This generates a color-correction table
|
||||||
|
internal void CreateCorrectionTable()
|
||||||
|
{
|
||||||
|
// Determine amounts
|
||||||
|
float gamma = (float)(General.Settings.ImageBrightness + 10) * 0.1f;
|
||||||
|
float bright = (float)General.Settings.ImageBrightness * 5f;
|
||||||
|
|
||||||
|
// Make table
|
||||||
|
correctiontable = new byte[256];
|
||||||
|
|
||||||
|
// Fill table
|
||||||
|
for(int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
byte b;
|
||||||
|
float a = (float)i * gamma + bright;
|
||||||
|
if(a < 0f) b = 0; else if(a > 255f) b = 255; else b = (byte)a;
|
||||||
|
correctiontable[i] = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This applies color-correction over a block of pixel data
|
||||||
|
internal unsafe void ApplColorCorrection(PixelColor* pixels, int numpixels)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < numpixels; i++)
|
||||||
|
{
|
||||||
|
pixels[i].r = correctiontable[pixels[i].r];
|
||||||
|
pixels[i].g = correctiontable[pixels[i].g];
|
||||||
|
pixels[i].b = correctiontable[pixels[i].b];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This clamps a value between 0 and 1
|
// This clamps a value between 0 and 1
|
||||||
private float Saturate(float v)
|
private float Saturate(float v)
|
||||||
{
|
{
|
||||||
|
@ -233,17 +251,6 @@ namespace CodeImp.DoomBuilder.Rendering
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This applies colors to this collection
|
|
||||||
internal void Apply(ColorCollection collection)
|
|
||||||
{
|
|
||||||
// Copy all colors
|
|
||||||
for(int i = 0; i < NUM_COLORS; i++)
|
|
||||||
colors[i] = collection.colors[i];
|
|
||||||
|
|
||||||
// Rebuild assist colors
|
|
||||||
CreateAssistColors();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This saves colors to configuration
|
// This saves colors to configuration
|
||||||
internal void SaveColors(Configuration cfg)
|
internal void SaveColors(Configuration cfg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1695,6 +1695,9 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
// Update shortcut keys in menus
|
// Update shortcut keys in menus
|
||||||
ApplyShortcutKeys();
|
ApplyShortcutKeys();
|
||||||
|
|
||||||
|
// Generate new color correction table
|
||||||
|
General.Colors.CreateCorrectionTable();
|
||||||
|
|
||||||
// Let the plugins know
|
// Let the plugins know
|
||||||
General.Plugins.ProgramReconfigure();
|
General.Plugins.ProgramReconfigure();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue