我正在尝试创建一个从PNG提取颜色并将其放入查找纹理的应用程序,然后保存使用颜色通道存储LUT位置的原始PNG的副本。这对于一维LUT来说效果很好,但不会为二维LUT保留额外的通道。
输出图像后,我将其加载到Photoshop中以检查通道,红色通道已正确保存,但绿色通道未正确保存。
哪个通道似乎无关紧要,由于某种原因,它不会为foundRow
保存0,即使在调试器中逐步执行时,我仍然可以验证foundRow
是否上升至少要为该特定图片添加3个。
private static bool ProcessImage(string filePath, string newPath, Color[,] colors, ref int colorsColumnIndex, ref int colorsRowIndex)
{
Console.WriteLine($"Processing file: {filePath}");
var bmp = new Bitmap(filePath);
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
var pixel = bmp.GetPixel(x, y);
var lutPixel = Color.FromArgb(pixel.R, pixel.G, pixel.B);
int foundColumn;
int foundRow;
GetColorIndexes(colors, lutPixel, out foundColumn, out foundRow);
if (foundColumn < 0 || foundRow < 0)
{
foundColumn = colorsColumnIndex;
foundRow = colorsRowIndex;
colors[foundColumn, foundRow] = lutPixel;
colorsColumnIndex++;
if (colorsColumnIndex >= 256)
{
colorsColumnIndex = 0;
colorsRowIndex++;
}
}
if (colorsColumnIndex >= 256 || colorsRowIndex >= 256)
{
Console.WriteLine($"ERROR: More than {256 * 256} colors found!");
return false;
}
//if (foundRow != 0)
//Console.Write($"Setting pixel at {x}, {y} to R: {foundColumn}, G: {foundRow}");
var newPixel = Color.FromArgb(255, foundColumn, foundRow, 0);
bmp.SetPixel(x, y, newPixel);
}
}
bmp.Save(newPath, ImageFormat.Png);
bmp.Dispose();
Console.WriteLine($"Saved {newPath}");
return true;
}
在这些行:
var newPixel = Color.FromArgb(255, foundColumn, foundRow, 0);
bmp.SetPixel(x, y, newPixel);
如果newPixel
为ARGB(255,1,1,0),则由于某些原因,实际保存的文件将导致ARGB(255,1,0,0)