4 protected static string s_sImageFilePath;
6 protected static const string DEFAULT_FILE_PATH =
"image.png";
7 protected static const string PNG_DOTTED_EXTENSION =
".png";
8 protected static const string DDS_DOTTED_EXTENSION =
".dds";
9 protected static const string EDDS_DOTTED_EXTENSION =
".edds";
10 protected static const string META_DOTTED_EXTENSION =
".meta";
19 static bool TEMP_SaveImageDataWrapper(
string filePath,
int width,
int height, notnull array<int>
data)
21 int dataCount =
data.Count();
24 Print(
"[SCR_ImageHelper.TEMP_SaveImageDataWrapper] provided data is empty",
LogLevel.ERROR);
28 if (dataCount != width * height)
30 Print(
"[SCR_ImageHelper.TEMP_SaveImageDataWrapper] data / width × height mismatch",
LogLevel.ERROR);
34 array<int> dataCopy = {};
35 dataCopy.Resize(dataCount);
37 foreach (
int i,
int argb :
data)
39 int a = argb & 0xFF000000;
40 int b = (argb & 0x000000FF) * 0x10000;
41 int g = argb & 0x0000FF00;
42 int r = (argb & 0x00FF0000) / 0x10000;
44 dataCopy[i] = a | b | g | r;
47 return TexTools.SaveImageData(filePath, width, height, dataCopy);
53 static array<int> GetImageDataBlackAndWhite(notnull array<float> greyscaleValues01)
55 array<int> result = {};
56 result.Reserve(greyscaleValues01.Count());
58 foreach (
float greyscaleValue01 : greyscaleValues01)
60 if (greyscaleValue01 > 1)
63 if (greyscaleValue01 < 0)
66 int greyscaleValue0255 = greyscaleValue01 * 255;
67 result.Insert((greyscaleValue0255 * 0x10000 + greyscaleValue0255 * 0x100 + greyscaleValue0255) | 0xFF000000);
77 static array<int> GetImageDataAlphaColour(notnull array<float> greyscaleValues01, Color colour = null)
79 array<int> result = {};
80 result.Reserve(greyscaleValues01.Count());
84 colourMask = colour.PackToInt() & 0x00FFFFFF;
86 colourMask = 0x00FFFFFF;
88 foreach (
float greyscaleValue01 : greyscaleValues01)
90 if (greyscaleValue01 > 1)
93 if (greyscaleValue01 < 0)
96 result.Insert(((
int)(greyscaleValue01 * 255) * 0x1000000) | colourMask);
107 static bool IncreaseResolution(notnull inout array<int> imageData,
int width,
int height,
int factor)
109 if (factor < 1 || width < 1 || height < 1)
115 int imageDataCount = imageData.Count();
116 if (imageDataCount != width * height)
118 Print(
"[SCR_ImageHelper.IncreaseResolution] imageData array size does not match width × height",
LogLevel.WARNING);
122 array<int> enhancedData = {};
123 enhancedData.Reserve(imageDataCount * factor * factor);
125 for (
int rowId; rowId < height; ++rowId)
127 for (
int rowRepeat; rowRepeat < factor; ++rowRepeat)
129 for (
int colId; colId < width; ++colId)
131 int value = imageData[rowId * width + colId];
132 for (
int colRepeat; colRepeat < factor; ++colRepeat)
134 enhancedData.Insert(value);
140 imageData.Copy(enhancedData);
152 static bool SaveImageDataToPNG(
string filePath,
int width,
int height, notnull array<int> imageData)
154 if (imageData.Count() != width * height)
156 Print(
"[SCR_ImageHelper.SaveImageDataToPNG] imageData array size does not match width × height",
LogLevel.WARNING);
160 filePath.TrimInPlace();
162 filePath = DEFAULT_FILE_PATH;
164 if (!filePath.EndsWith(PNG_DOTTED_EXTENSION))
165 filePath += PNG_DOTTED_EXTENSION;
167 string fileWithoutExtension = FilePath.StripExtension(filePath);
170 string absoluteDDSFilePath;
171 if (!Workbench.GetAbsolutePath(fileWithoutExtension + DDS_DOTTED_EXTENSION, absoluteDDSFilePath,
false))
174 string absoluteEDDSFilePath;
175 if (!Workbench.GetAbsolutePath(fileWithoutExtension + EDDS_DOTTED_EXTENSION, absoluteEDDSFilePath,
false))
178 if (!TexTools.SaveImageData(absoluteDDSFilePath, width, height, imageData))
182 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
183 if (!resourceManager)
186 resourceManager.RegisterResourceFile(absoluteDDSFilePath,
true);
188 MetaFile eddsMetaFile = resourceManager.GetMetaFile(absoluteEDDSFilePath);
195 Print(
"[SCR_ImageHelper.SaveImageDataToPNG] No Game!",
LogLevel.WARNING);
199 WorkspaceWidget workspaceWidget =
game.GetWorkspace();
200 if (!workspaceWidget)
202 Print(
"[SCR_ImageHelper.SaveImageDataToPNG] No WorkspaceWidget!",
LogLevel.WARNING);
207 ImageWidget imageWidget = ImageWidget.Cast(workspaceWidget.CreateWidget(
WidgetType.ImageWidgetTypeID,
WidgetFlags.CENTER, Color.White, 0, null));
211 if (!imageWidget.LoadImageTexture(0, eddsMetaFile.GetResourceID(),
false,
true))
215 s_sImageFilePath = filePath;
216 if (!imageWidget.GetTextureRawData(0, GetTextureRawDataCallbackMethod))
218 Print(
"[SCR_ImageHelper.SaveImageDataToPNG] Cannot get texture raw data",
LogLevel.WARNING);
222 FileIO.DeleteFile(absoluteDDSFilePath);
223 FileIO.DeleteFile(absoluteDDSFilePath + META_DOTTED_EXTENSION);
224 FileIO.DeleteFile(absoluteEDDSFilePath);
225 FileIO.DeleteFile(absoluteEDDSFilePath + META_DOTTED_EXTENSION);
231 protected static void GetTextureRawDataCallbackMethod(PixelRawData
data,
int imageWidth,
int imageHeight,
int stride)
234 Workbench.SavePixelRawData(s_sImageFilePath,
data, imageWidth, imageHeight, stride);
ArmaReforgerScripted GetGame()
Get all prefabs that have the spawner data
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
WidgetFlags
Widget flags. See enf::Widget::SetFlags().