Skip to content

Commit afd599a

Browse files
committed
1、添加调整温度色度条功能;2、添加根据温度设置颜色功能。
1 parent dea4b5f commit afd599a

23 files changed

+415
-66
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dji_thermal_sdk_v1.7_20241205.zip
3333
##### 3、使用例子
3434

3535
```c#
36-
byte[] data = System.IO.File.ReadAllBytes("3_M3TD.JPG");
36+
byte[] data = System.IO.File.ReadAllBytes("img/H30T.JPG");
3737

3838
using (var rjpg = RJPEG.TryParse(data))
3939
{
@@ -47,14 +47,15 @@ using (var rjpg = RJPEG.TryParse(data))
4747
Console.WriteLine($"rect:MinTemp={rect.MinTemp} ,MaxTemp={rect.MaxTemp} ,AvgTemp={rect.AvgTemp}");
4848

4949
//设置调色板风格
50-
rjpg.SetPseudoColor(PseudoColor.DIRP_PSEUDO_COLOR_HOTIRON);
50+
rjpg.SetPseudoColor(PseudoColor.DIRP_PSEUDO_COLOR_IRONRED);
51+
5152
//设置亮度
5253
rjpg.SetBrightness(60);
5354

54-
//保存设置后的伪彩色照片
55-
using (var fs = System.IO.File.OpenWrite("3_M3TD_HOTIRON.JPG"))
55+
//保存设置温宽后的伪彩色照片
56+
using (var fs = System.IO.File.OpenWrite("H30T_adjust.JPG"))
5657
{
57-
rjpg.SaveTo(fs);
58+
rjpg.SaveTo(fs, rjpg.MaxTemp - 2, rjpg.MaxTemp);
5859
fs.Flush();
5960
}
6061
}

SDKs.DjiImage.Net45/Package.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>SDKs.DjiImage.Net45</id>
5-
<version>1.5.1</version>
5+
<version>1.7.0</version>
66
<authors>jazous</authors>
77
<requireLicenseAcceptance>true</requireLicenseAcceptance>
88
<license type="expression">MIT</license>
99
<projectUrl>https://github.com/Jazous</projectUrl>
1010
<description>Dji TSDK for .NET4.5.2</description>
11-
<releaseNotes>1、添加设置调色板风格 SetPseudoColor 方法;2、添加设置亮度 SetBrightness 方法;3、添加 SaveTo 保存设置后的伪彩色照片;4、适配DJI TSDK 1.5版本的环境温度获取。</releaseNotes>
12-
<copyright>Copyright (c) 2022-2024 Jazous</copyright>
11+
<releaseNotes>1、添加调整温度色度条功能;2、添加根据温度设置颜色功能。</releaseNotes>
12+
<copyright>Copyright (c) 2022-2025 Jazous</copyright>
1313
<tags>dji,thermal,r-jpeg</tags>
1414
<language>zh</language>
1515
<dependencies>

SDKs.DjiImage.Net45/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
3333
//通过使用 "*",如下所示:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.5.1.0")]
36-
[assembly: AssemblyFileVersion("1.5.1.0")]
35+
[assembly: AssemblyVersion("1.7.0.0")]
36+
[assembly: AssemblyFileVersion("1.7.0.0")]

SDKs.DjiImage.Net45/SDKs.DjiImage.Net45.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Thermals\LTEntry.cs" />
6363
<Compile Include="Thermals\MeasureParam.cs" />
6464
<Compile Include="Thermals\PseudoColor.cs" />
65+
<Compile Include="Thermals\PseudoColorLUT.cs" />
6566
<Compile Include="Thermals\RJPEG.cs" />
6667
<Compile Include="Thermals\RTEntry.cs" />
6768
<Compile Include="Thermals\_tsdk.cs" />

SDKs.DjiImage.Net45/Thermals/PseudoColor.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace SDKs.DjiImage.Thermals
55
/// <summary>
66
/// 伪彩色调色板枚举
77
/// </summary>
8-
public enum PseudoColor
8+
public enum PseudoColor : byte
99
{
1010
/// <summary>
1111
/// White Hot
@@ -56,10 +56,6 @@ public enum PseudoColor
5656
/// Black Hot
5757
/// </summary>
5858
[Description("黑热")]
59-
DIRP_PSEUDO_COLOR_BLACKHOT,
60-
/// <summary>
61-
/// Total number
62-
/// </summary>
63-
DIRP_PSEUDO_COLOR_NUM
59+
DIRP_PSEUDO_COLOR_BLACKHOT
6460
}
6561
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace SDKs.DjiImage.Thermals
4+
{
5+
/// <summary>
6+
/// 8 bit伪彩色 LUT 结构
7+
/// </summary>
8+
public struct PseudoColorLUT
9+
{
10+
/// <summary>
11+
/// 红色 LUT
12+
/// </summary>
13+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2560, ArraySubType = UnmanagedType.U1)]
14+
internal byte[] red;
15+
/// <summary>
16+
/// 绿色 LUT
17+
/// </summary>
18+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2560, ArraySubType = UnmanagedType.U1)]
19+
internal byte[] green;
20+
/// <summary>
21+
/// 蓝色 LUT
22+
/// </summary>
23+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2560, ArraySubType = UnmanagedType.U1)]
24+
internal byte[] blue;
25+
26+
/// <summary>
27+
/// 获取指定伪彩色映射的 Red 颜色值
28+
/// </summary>
29+
/// <param name="color"></param>
30+
/// <param name="value"></param>
31+
/// <returns></returns>
32+
public byte GetRed(PseudoColor color, byte value)
33+
{
34+
return red[(byte)color * 256 + value];
35+
}
36+
/// <summary>
37+
/// 获取指定伪彩色映射的 Green 颜色值
38+
/// </summary>
39+
/// <param name="color"></param>
40+
/// <param name="value"></param>
41+
/// <returns></returns>
42+
43+
public byte GetGreen(PseudoColor color, int value)
44+
{
45+
return green[(byte)color * 256 + value];
46+
}
47+
/// <summary>
48+
/// 获取指定伪彩色映射的 Blue 颜色值
49+
/// </summary>
50+
/// <param name="color"></param>
51+
/// <param name="value"></param>
52+
/// <returns></returns>
53+
54+
public byte GetBlue(PseudoColor color, int value)
55+
{
56+
return blue[(byte)color * 256 + value];
57+
}
58+
59+
}
60+
}

SDKs.DjiImage.Net45/Thermals/RJPEG.cs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,16 @@ public bool SetPseudoColor(PseudoColor color)
829829
return _tsdk.dirp_set_pseudo_color(_ph, color) == 0;
830830
}
831831
/// <summary>
832+
/// 获取调色板风格
833+
/// </summary>
834+
/// <returns></returns>
835+
public PseudoColor GetPseudoColor()
836+
{
837+
PseudoColor color = default;
838+
_tsdk.dirp_get_pseudo_color(_ph, ref color);
839+
return color;
840+
}
841+
/// <summary>
832842
/// 设置等温线
833843
/// </summary>
834844
/// <param name="low">最低温度</param>
@@ -881,7 +891,7 @@ public void SaveTo(Stream stream)
881891
/// <summary>
882892
/// 保存 RGB 伪彩色 Jpeg 图片到指定的流,可以设定指定温度的颜色。
883893
/// </summary>
884-
/// <param name="stream"></param>
894+
/// <param name="stream">需要保存到流</param>
885895
/// <param name="setter">根据温度设置对应的颜色,若返回 null 则保留原来的颜色</param>
886896
public void SaveTo(Stream stream, Func<float, System.Drawing.Color?> setter)
887897
{
@@ -914,6 +924,53 @@ public void SaveTo(Stream stream, Func<float, System.Drawing.Color?> setter)
914924
}
915925
}
916926
/// <summary>
927+
/// 保存 RGB 伪彩色 Jpeg 图片到指定的流,可以设定指定温度区间。
928+
/// </summary>
929+
/// <param name="stream">需要保存到流</param>
930+
/// <param name="minTemp">最低温度</param>
931+
/// <param name="maxTemp">最高我呢度</param>
932+
public void SaveTo(Stream stream, float minTemp, float maxTemp)
933+
{
934+
if (maxTemp < minTemp)
935+
throw new ArgumentException("maxTemp must larger‌ than minTemp.", nameof(minTemp));
936+
937+
if (minTemp < _mintemp) minTemp = _mintemp;
938+
if (maxTemp > _maxtemp) maxTemp = _maxtemp;
939+
float range = maxTemp - minTemp;
940+
941+
PseudoColor color = default;
942+
_tsdk.dirp_get_pseudo_color(_ph, ref color);
943+
944+
PseudoColorLUT lut = default;
945+
_tsdk.dirp_get_pseudo_color_lut(_ph, ref lut);
946+
947+
using (var bitmap = new Bitmap(_width, _height))
948+
{
949+
byte r, g, b, val;
950+
float temp;
951+
for (int y = 0; y < _height; y++)
952+
{
953+
for (int x = 0; x < _width; x++)
954+
{
955+
//归一化
956+
temp = _mData[x, y];
957+
if (temp < minTemp)
958+
temp = minTemp;
959+
else if (temp > maxTemp)
960+
temp = maxTemp;
961+
val = Convert.ToByte((((temp - minTemp) / range) * 255));
962+
963+
r = lut.GetRed(color, val);
964+
g = lut.GetGreen(color, val);
965+
b = lut.GetBlue(color, val);
966+
967+
bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(r, g, b));
968+
}
969+
}
970+
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
971+
}
972+
}
973+
/// <summary>
917974
/// Get original RAW binary data from R-JPEG.
918975
/// </summary>
919976
/// <returns></returns>

SDKs.DjiImage.Net45/Thermals/_tsdk.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ static class _tsdk
2222
[System.Runtime.InteropServices.DllImport(dllName, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
2323
public extern static int dirp_set_pseudo_color(System.IntPtr h, PseudoColor color);
2424
[System.Runtime.InteropServices.DllImport(dllName, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
25+
public extern static int dirp_get_pseudo_color_lut(System.IntPtr h, ref PseudoColorLUT lut);
26+
[System.Runtime.InteropServices.DllImport(dllName, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
2527
public extern static int dirp_get_isotherm(System.IntPtr h, ref dirp_isotherm_t isotherm);
2628
[System.Runtime.InteropServices.DllImport(dllName, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
2729
public extern static int dirp_set_isotherm(System.IntPtr h, dirp_isotherm_t isotherm);

SDKs.DjiImage.Net48/Package.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>SDKs.DjiImage.Net48</id>
5-
<version>1.5.1</version>
5+
<version>1.7.0</version>
66
<authors>jazous</authors>
77
<requireLicenseAcceptance>true</requireLicenseAcceptance>
88
<license type="expression">MIT</license>
99
<projectUrl>https://github.com/Jazous</projectUrl>
1010
<description>Dji TSDK for .NET4.8</description>
11-
<releaseNotes>1、添加设置调色板风格 SetPseudoColor 方法;2、添加设置亮度 SetBrightness 方法;3、添加 SaveTo 保存设置后的伪彩色照片;4、适配DJI TSDK 1.5版本的环境温度获取。</releaseNotes>
12-
<copyright>Copyright (c) 2022-2024 Jazous</copyright>
11+
<releaseNotes>1、添加调整温度色度条功能;2、添加根据温度设置颜色功能。</releaseNotes>
12+
<copyright>Copyright (c) 2022-2025 Jazous</copyright>
1313
<tags>dji,thermal,r-jpeg</tags>
1414
<language>zh</language>
1515
<dependencies>

SDKs.DjiImage.Net48/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
3434
//通过使用 "*",如下所示:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("1.5.1.0")]
37-
[assembly: AssemblyFileVersion("1.5.1.0")]
36+
[assembly: AssemblyVersion("1.7.0.0")]
37+
[assembly: AssemblyFileVersion("1.7.0.0")]
3838
[assembly: NeutralResourcesLanguage("zh")]

0 commit comments

Comments
 (0)