add TIM2 alpha setting

This commit is contained in:
ManicSteiner
2025-01-18 22:14:49 +08:00
parent 700084a820
commit 5eaf4391d8
10 changed files with 77 additions and 7 deletions

View File

@@ -23,6 +23,7 @@
// IN THE SOFTWARE.
//
using GameRes.Formats.Strings;
using System;
using System.ComponentModel.Composition;
using System.IO;
@@ -36,7 +37,7 @@ namespace GameRes.Formats.DigitalWorks
public int PaletteSize;
public int HeaderSize;
public int Colors;
public bool X_A = false;
public byte X_A;
}
[Export(typeof(ImageFormat))]
@@ -49,8 +50,16 @@ namespace GameRes.Formats.DigitalWorks
public Tim2Format ()
{
Extensions = new string[] { "tm2", "ext" };
Settings = new[] { AlphaFormat };
}
FixedSetSetting AlphaFormat = new FixedSetSetting(Properties.Settings.Default)
{
Name = "TIM2AlphaFormat",
Text = arcStrings.Tim2AlphaFormat,
ValuesSet = new[] { "No Alpha", "RGBX", "RGBA" },
};
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
var header = file.ReadHeader (0x40);
@@ -63,6 +72,14 @@ namespace GameRes.Formats.DigitalWorks
case 5: bpp = 8; break;
default: return null;
}
byte alpha;
switch (AlphaFormat.Get<String>())
{
case "No Alpha": alpha = 0; break;
case "RGBX": alpha = 7; break;
case "RGBA":
default: alpha = 8; break;
}
return new Tim2MetaData {
Width = header.ToUInt16 (0x24),
Height = header.ToUInt16 (0x26),
@@ -70,7 +87,7 @@ namespace GameRes.Formats.DigitalWorks
PaletteSize = header.ToInt32 (0x14),
HeaderSize = header.ToUInt16 (0x1C),
Colors = header.ToUInt16 (0x1E),
X_A = header.ToUInt16(0x30) == 0, // not so sure, there will be omissions
X_A = alpha, //header.ToUInt16(0x30) == 0?// not so sure, there will be omissions
};
}
@@ -117,7 +134,7 @@ namespace GameRes.Formats.DigitalWorks
if (pixel_size <= 8 && m_info.Colors > 0)
Palette = ReadPalette (m_info.Colors, m_info.X_A);
if (pixel_size == 3 || pixel_size == 4 && !m_info.X_A)
if (pixel_size == 3 || pixel_size == 4 && m_info.X_A == 8)
{
for (int i = 0; i < image_size; i += pixel_size)
{
@@ -126,7 +143,7 @@ namespace GameRes.Formats.DigitalWorks
output[i+2] = r;
}
}
if (pixel_size == 4 && m_info.X_A)
if (pixel_size == 4 && m_info.X_A == 7)
{
for (int i = 0; i < image_size; i += 4)
{
@@ -139,12 +156,23 @@ namespace GameRes.Formats.DigitalWorks
output[i + 3] = (byte)(output[i + 3] << 1);
}
}
if (pixel_size == 4 && m_info.X_A == 0)
{
for (int i = 0; i < image_size; i += 4)
{
byte r = output[i];
output[i] = output[i + 2];
output[i + 2] = r;
output[i + 3] = byte.MaxValue;
}
}
return output;
}
BitmapPalette ReadPalette (int color_num, bool X_A = false)
BitmapPalette ReadPalette (int color_num, byte X_A = 8)
{
var source = ImageFormat.ReadColorMap (m_input.AsStream, color_num, X_A ? PaletteFormat.RgbX : PaletteFormat.RgbA);
var source = ImageFormat.ReadColorMap (m_input.AsStream,
color_num, X_A == 7 ? PaletteFormat.RgbX : X_A == 0 ? PaletteFormat.RgbX_Disposed : PaletteFormat.RgbA);
var color_map = new Color[color_num];
int parts = color_num / 32;

View File

@@ -15,7 +15,9 @@ namespace GameRes.Formats.DigitalWorks
public TM2ArkFormat()
{
Extensions = new string[] { "tm2" };
Settings = null;
}
public override ImageMetaData ReadMetaData(IBinaryStream stream)
{
stream.Position = 9;

View File

@@ -11,7 +11,7 @@ namespace GameRes.Formats.MAGES
public override string Tag { get { return "ARC/Princess Soft ARC20"; } }
public override string Description { get { return "Princess Soft PS2 resource archive"; } }
public override uint Signature { get { return 0x20435241; } } // 'ARC\x20'
public override bool IsHierarchic { get { return false; } }
public override bool IsHierarchic { get { return true; } }
public override bool CanWrite { get { return false; } }
public override ArcFile TryOpen(ArcView file)

View File

@@ -837,5 +837,17 @@ namespace GameRes.Formats.Properties {
this["NexasEncodingCP"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("RGBA")]
public string TIM2AlphaFormat {
get {
return ((string)(this["TIM2AlphaFormat"]));
}
set {
this["TIM2AlphaFormat"] = value;
}
}
}
}

View File

@@ -206,5 +206,8 @@
<Setting Name="NexasEncodingCP" Type="System.Int32" Scope="User">
<Value Profile="(Default)">932</Value>
</Setting>
<Setting Name="TIM2AlphaFormat" Type="System.String" Scope="User">
<Value Profile="(Default)">RGBA</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -752,6 +752,16 @@ namespace GameRes.Formats.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Choose Tim2 image alpha format.
/// It can&apos;t be read correctly from the file.
/// </summary>
public static string Tim2AlphaFormat {
get {
return ResourceManager.GetString("Tim2AlphaFormat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Hex number.
/// </summary>

View File

@@ -501,4 +501,8 @@ Choose encryption scheme or enter a passphrase.</comment>
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>Default audio sampling rate</value>
</data>
<data name="Tim2AlphaFormat" xml:space="preserve">
<value>Tim2画像のAlpha形式を選択してください。
ファイルから正しく読み取ることができません。</value>
</data>
</root>

View File

@@ -401,4 +401,8 @@ Choose encryption scheme or enter a passphrase.</value>
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>Default audio sampling rate</value>
</data>
<data name="Tim2AlphaFormat" xml:space="preserve">
<value>Choose Tim2 image alpha format.
It can't be read correctly from the file.</value>
</data>
</root>

View File

@@ -399,4 +399,8 @@
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>默认音频采样率</value>
</data>
<data name="Tim2AlphaFormat" xml:space="preserve">
<value>选择Tim2图片透明度格式。
这无法从文件中正确获取。</value>
</data>
</root>

View File

@@ -208,6 +208,9 @@
<setting name="NexasEncodingCP" serializeAs="String">
<value>932</value>
</setting>
<setting name="TIM2AlphaFormat" serializeAs="String">
<value>RGBA</value>
</setting>
</GameRes.Formats.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup>