Skip to content

Commit 84b90a7

Browse files
committed
fixup! refactor: Move FreeImage into separate project
1 parent dc03ef2 commit 84b90a7

File tree

3 files changed

+162
-165
lines changed

3 files changed

+162
-165
lines changed

sources/tools/Stride.FreeImage/FreeImageWrapper.cs

Lines changed: 0 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
using FreeImageAPI.IO;
4646
using FreeImageAPI.Metadata;
4747
using Stride.Core;
48-
using StridePixelFormat = Stride.Graphics.PixelFormat;
4948

5049
namespace FreeImageAPI
5150
{
@@ -2423,165 +2422,6 @@ public static bool GetFormatParameters(
24232422
return result;
24242423
}
24252424

2426-
/// <summary>
2427-
/// Retrieves all parameters needed to create a new FreeImage bitmap from the pixel format.
2428-
/// </summary>
2429-
/// <param name="format">The <see cref="Stride.Graphics.PixelFormat"/> of the image.</param>
2430-
/// <param name="type">Returns the type used for the new bitmap.</param>
2431-
/// <param name="bpp">Returns the color depth for the new bitmap.</param>
2432-
/// <param name="redMask">Returns the red_mask for the new bitmap.</param>
2433-
/// <param name="greenMask">Returns the green_mask for the new bitmap.</param>
2434-
/// <param name="blueMask">Returns the blue_mask for the new bitmap.</param>
2435-
/// <returns>True in case a matching conversion exists; else false.
2436-
/// </returns>
2437-
public static bool GetFormatParameters(
2438-
StridePixelFormat format,
2439-
out FREE_IMAGE_TYPE type,
2440-
out uint bpp,
2441-
out uint redMask,
2442-
out uint greenMask,
2443-
out uint blueMask)
2444-
{
2445-
var result = true;
2446-
type = FREE_IMAGE_TYPE.FIT_UNKNOWN;
2447-
bpp = 0;
2448-
redMask = 0;
2449-
greenMask = 0;
2450-
blueMask = 0;
2451-
2452-
switch (format)
2453-
{
2454-
case StridePixelFormat.R32G32B32A32_Float:
2455-
type = FREE_IMAGE_TYPE.FIT_RGBAF;
2456-
bpp = 128;
2457-
break;
2458-
case StridePixelFormat.R32G32B32_Float:
2459-
type = FREE_IMAGE_TYPE.FIT_RGBF;
2460-
bpp = 96;
2461-
break;
2462-
case StridePixelFormat.R16G16B16A16_Typeless:
2463-
case StridePixelFormat.R16G16B16A16_Float:
2464-
case StridePixelFormat.R16G16B16A16_UNorm:
2465-
case StridePixelFormat.R16G16B16A16_UInt:
2466-
case StridePixelFormat.R16G16B16A16_SNorm:
2467-
case StridePixelFormat.R16G16B16A16_SInt:
2468-
type = FREE_IMAGE_TYPE.FIT_RGBA16;
2469-
bpp = 64;
2470-
break;
2471-
case StridePixelFormat.D32_Float:
2472-
case StridePixelFormat.R32_Float:
2473-
type = FREE_IMAGE_TYPE.FIT_FLOAT;
2474-
bpp = 32;
2475-
break;
2476-
case StridePixelFormat.R32_SInt:
2477-
type = FREE_IMAGE_TYPE.FIT_INT32;
2478-
bpp = 32;
2479-
break;
2480-
case StridePixelFormat.R32_UInt:
2481-
type = FREE_IMAGE_TYPE.FIT_UINT32;
2482-
bpp = 32;
2483-
break;
2484-
case StridePixelFormat.R16_SInt:
2485-
type = FREE_IMAGE_TYPE.FIT_INT16;
2486-
bpp = 16;
2487-
break;
2488-
case StridePixelFormat.R16_UInt:
2489-
type = FREE_IMAGE_TYPE.FIT_UINT16;
2490-
bpp = 16;
2491-
break;
2492-
case StridePixelFormat.R32_Typeless:
2493-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2494-
bpp = 32;
2495-
break;
2496-
case StridePixelFormat.R8G8B8A8_Typeless:
2497-
case StridePixelFormat.R8G8B8A8_UNorm:
2498-
case StridePixelFormat.R8G8B8A8_UNorm_SRgb:
2499-
case StridePixelFormat.R8G8B8A8_UInt:
2500-
case StridePixelFormat.R8G8B8A8_SNorm:
2501-
case StridePixelFormat.R8G8B8A8_SInt:
2502-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2503-
bpp = 32;
2504-
redMask = FI_RGBA_RED_MASK;
2505-
greenMask = FI_RGBA_GREEN_MASK;
2506-
blueMask = FI_RGBA_BLUE_MASK;
2507-
break;
2508-
case StridePixelFormat.R16G16_Typeless:
2509-
case StridePixelFormat.R16G16_Float:
2510-
case StridePixelFormat.R16G16_UNorm:
2511-
case StridePixelFormat.R16G16_UInt:
2512-
case StridePixelFormat.R16G16_SNorm:
2513-
case StridePixelFormat.R16G16_SInt:
2514-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2515-
bpp = 32;
2516-
redMask = 0xFFFF0000;
2517-
greenMask = 0x0000FFFF;
2518-
break;
2519-
case StridePixelFormat.B8G8R8A8_Typeless:
2520-
case StridePixelFormat.B8G8R8A8_UNorm_SRgb:
2521-
case StridePixelFormat.B8G8R8X8_Typeless:
2522-
case StridePixelFormat.B8G8R8X8_UNorm_SRgb:
2523-
case StridePixelFormat.B8G8R8A8_UNorm:
2524-
case StridePixelFormat.B8G8R8X8_UNorm:
2525-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2526-
bpp = 32;
2527-
redMask = FI_RGBA_BLUE_MASK;
2528-
greenMask = FI_RGBA_GREEN_MASK;
2529-
blueMask = FI_RGBA_RED_MASK;
2530-
break;
2531-
2532-
case StridePixelFormat.B5G6R5_UNorm:
2533-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2534-
bpp = 16;
2535-
redMask = FI16_565_RED_MASK;
2536-
greenMask = FI16_565_GREEN_MASK;
2537-
blueMask = FI16_565_BLUE_MASK;
2538-
break;
2539-
case StridePixelFormat.B5G5R5A1_UNorm:
2540-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2541-
bpp = 16;
2542-
redMask = FI16_555_RED_MASK;
2543-
greenMask = FI16_555_GREEN_MASK;
2544-
blueMask = FI16_555_BLUE_MASK;
2545-
break;
2546-
case StridePixelFormat.R16_Typeless:
2547-
case StridePixelFormat.R16_Float:
2548-
case StridePixelFormat.D16_UNorm:
2549-
case StridePixelFormat.R16_UNorm:
2550-
case StridePixelFormat.R16_SNorm:
2551-
type = FREE_IMAGE_TYPE.FIT_UINT16;
2552-
bpp = 16;
2553-
break;
2554-
case StridePixelFormat.R8G8_Typeless:
2555-
case StridePixelFormat.R8G8_UNorm:
2556-
case StridePixelFormat.R8G8_UInt:
2557-
case StridePixelFormat.R8G8_SNorm:
2558-
case StridePixelFormat.R8G8_SInt:
2559-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2560-
bpp = 16;
2561-
redMask = 0xFF00;
2562-
greenMask= 0x00FF;
2563-
break;
2564-
case StridePixelFormat.R8_Typeless:
2565-
case StridePixelFormat.R8_UNorm:
2566-
case StridePixelFormat.R8_UInt:
2567-
case StridePixelFormat.R8_SNorm:
2568-
case StridePixelFormat.R8_SInt:
2569-
case StridePixelFormat.A8_UNorm:
2570-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2571-
bpp = 8;
2572-
break;
2573-
case StridePixelFormat.R1_UNorm:
2574-
type = FREE_IMAGE_TYPE.FIT_BITMAP;
2575-
bpp = 1;
2576-
break;
2577-
default:
2578-
result = false;
2579-
break;
2580-
}
2581-
2582-
return result;
2583-
}
2584-
25852425
/// <summary>
25862426
/// Retrieves all parameters needed to create a new FreeImage bitmap from
25872427
/// raw bits <see cref="System.Drawing.Image"/>.

sources/tools/Stride.FreeImage/Stride.FreeImage.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
</ItemGroup>
1616
<ItemGroup>
1717
<ProjectReference Include="..\..\core\Stride.Core\Stride.Core.csproj" />
18-
<ProjectReference Include="..\..\engine\Stride.Graphics\Stride.Graphics.csproj" />
1918
</ItemGroup>
2019
<Import Project="$(StrideSdkTargets)" />
2120
</Project>

sources/tools/Stride.TextureConverter/Backend/TexLibraries/FITexLib.cs

Lines changed: 162 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
using Stride.Graphics;
1111
using Stride.TextureConverter.Requests;
1212
using FreeImageAPI;
13-
using FreeImageAPI.Plugins;
14-
using System.Runtime.CompilerServices;
13+
using StridePixelFormat = Stride.Graphics.PixelFormat;
1514

1615
namespace Stride.TextureConverter.TexLibraries
1716
{
@@ -69,7 +68,7 @@ public void StartLibrary(TexImage image)
6968

7069
FREE_IMAGE_TYPE type;
7170
uint bpp, redMask, greenMask, blueMask;
72-
if (!FreeImage.GetFormatParameters(image.Format, out type, out bpp, out redMask, out greenMask, out blueMask))
71+
if (!GetFormatParameters(image.Format, out type, out bpp, out redMask, out greenMask, out blueMask))
7372
{
7473
throw new ArgumentException("The pixel format '{0}' is not supported by FreeImage".ToFormat(image.Format));
7574
}
@@ -611,6 +610,165 @@ private static int GetAlphaDepth(FREE_IMAGE_FORMAT fileFormat, FIBITMAP bitmap)
611610
}
612611
return 0;
613612
}
614-
613+
614+
615+
/// <summary>
616+
/// Retrieves all parameters needed to create a new FreeImage bitmap from the pixel format.
617+
/// </summary>
618+
/// <param name="format">The <see cref="Stride.Graphics.PixelFormat"/> of the image.</param>
619+
/// <param name="type">Returns the type used for the new bitmap.</param>
620+
/// <param name="bpp">Returns the color depth for the new bitmap.</param>
621+
/// <param name="redMask">Returns the red_mask for the new bitmap.</param>
622+
/// <param name="greenMask">Returns the green_mask for the new bitmap.</param>
623+
/// <param name="blueMask">Returns the blue_mask for the new bitmap.</param>
624+
/// <returns>True in case a matching conversion exists; else false.
625+
/// </returns>
626+
private static bool GetFormatParameters(
627+
StridePixelFormat format,
628+
out FREE_IMAGE_TYPE type,
629+
out uint bpp,
630+
out uint redMask,
631+
out uint greenMask,
632+
out uint blueMask)
633+
{
634+
var result = true;
635+
type = FREE_IMAGE_TYPE.FIT_UNKNOWN;
636+
bpp = 0;
637+
redMask = 0;
638+
greenMask = 0;
639+
blueMask = 0;
640+
641+
switch (format)
642+
{
643+
case StridePixelFormat.R32G32B32A32_Float:
644+
type = FREE_IMAGE_TYPE.FIT_RGBAF;
645+
bpp = 128;
646+
break;
647+
case StridePixelFormat.R32G32B32_Float:
648+
type = FREE_IMAGE_TYPE.FIT_RGBF;
649+
bpp = 96;
650+
break;
651+
case StridePixelFormat.R16G16B16A16_Typeless:
652+
case StridePixelFormat.R16G16B16A16_Float:
653+
case StridePixelFormat.R16G16B16A16_UNorm:
654+
case StridePixelFormat.R16G16B16A16_UInt:
655+
case StridePixelFormat.R16G16B16A16_SNorm:
656+
case StridePixelFormat.R16G16B16A16_SInt:
657+
type = FREE_IMAGE_TYPE.FIT_RGBA16;
658+
bpp = 64;
659+
break;
660+
case StridePixelFormat.D32_Float:
661+
case StridePixelFormat.R32_Float:
662+
type = FREE_IMAGE_TYPE.FIT_FLOAT;
663+
bpp = 32;
664+
break;
665+
case StridePixelFormat.R32_SInt:
666+
type = FREE_IMAGE_TYPE.FIT_INT32;
667+
bpp = 32;
668+
break;
669+
case StridePixelFormat.R32_UInt:
670+
type = FREE_IMAGE_TYPE.FIT_UINT32;
671+
bpp = 32;
672+
break;
673+
case StridePixelFormat.R16_SInt:
674+
type = FREE_IMAGE_TYPE.FIT_INT16;
675+
bpp = 16;
676+
break;
677+
case StridePixelFormat.R16_UInt:
678+
type = FREE_IMAGE_TYPE.FIT_UINT16;
679+
bpp = 16;
680+
break;
681+
case StridePixelFormat.R32_Typeless:
682+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
683+
bpp = 32;
684+
break;
685+
case StridePixelFormat.R8G8B8A8_Typeless:
686+
case StridePixelFormat.R8G8B8A8_UNorm:
687+
case StridePixelFormat.R8G8B8A8_UNorm_SRgb:
688+
case StridePixelFormat.R8G8B8A8_UInt:
689+
case StridePixelFormat.R8G8B8A8_SNorm:
690+
case StridePixelFormat.R8G8B8A8_SInt:
691+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
692+
bpp = 32;
693+
redMask = FreeImage.FI_RGBA_RED_MASK;
694+
greenMask = FreeImage.FI_RGBA_GREEN_MASK;
695+
blueMask = FreeImage.FI_RGBA_BLUE_MASK;
696+
break;
697+
case StridePixelFormat.R16G16_Typeless:
698+
case StridePixelFormat.R16G16_Float:
699+
case StridePixelFormat.R16G16_UNorm:
700+
case StridePixelFormat.R16G16_UInt:
701+
case StridePixelFormat.R16G16_SNorm:
702+
case StridePixelFormat.R16G16_SInt:
703+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
704+
bpp = 32;
705+
redMask = 0xFFFF0000;
706+
greenMask = 0x0000FFFF;
707+
break;
708+
case StridePixelFormat.B8G8R8A8_Typeless:
709+
case StridePixelFormat.B8G8R8A8_UNorm_SRgb:
710+
case StridePixelFormat.B8G8R8X8_Typeless:
711+
case StridePixelFormat.B8G8R8X8_UNorm_SRgb:
712+
case StridePixelFormat.B8G8R8A8_UNorm:
713+
case StridePixelFormat.B8G8R8X8_UNorm:
714+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
715+
bpp = 32;
716+
redMask = FreeImage.FI_RGBA_BLUE_MASK;
717+
greenMask = FreeImage.FI_RGBA_GREEN_MASK;
718+
blueMask = FreeImage.FI_RGBA_RED_MASK;
719+
break;
720+
721+
case StridePixelFormat.B5G6R5_UNorm:
722+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
723+
bpp = 16;
724+
redMask = FreeImage.FI16_565_RED_MASK;
725+
greenMask = FreeImage.FI16_565_GREEN_MASK;
726+
blueMask = FreeImage.FI16_565_BLUE_MASK;
727+
break;
728+
case StridePixelFormat.B5G5R5A1_UNorm:
729+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
730+
bpp = 16;
731+
redMask = FreeImage.FI16_555_RED_MASK;
732+
greenMask = FreeImage.FI16_555_GREEN_MASK;
733+
blueMask = FreeImage.FI16_555_BLUE_MASK;
734+
break;
735+
case StridePixelFormat.R16_Typeless:
736+
case StridePixelFormat.R16_Float:
737+
case StridePixelFormat.D16_UNorm:
738+
case StridePixelFormat.R16_UNorm:
739+
case StridePixelFormat.R16_SNorm:
740+
type = FREE_IMAGE_TYPE.FIT_UINT16;
741+
bpp = 16;
742+
break;
743+
case StridePixelFormat.R8G8_Typeless:
744+
case StridePixelFormat.R8G8_UNorm:
745+
case StridePixelFormat.R8G8_UInt:
746+
case StridePixelFormat.R8G8_SNorm:
747+
case StridePixelFormat.R8G8_SInt:
748+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
749+
bpp = 16;
750+
redMask = 0xFF00;
751+
greenMask= 0x00FF;
752+
break;
753+
case StridePixelFormat.R8_Typeless:
754+
case StridePixelFormat.R8_UNorm:
755+
case StridePixelFormat.R8_UInt:
756+
case StridePixelFormat.R8_SNorm:
757+
case StridePixelFormat.R8_SInt:
758+
case StridePixelFormat.A8_UNorm:
759+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
760+
bpp = 8;
761+
break;
762+
case StridePixelFormat.R1_UNorm:
763+
type = FREE_IMAGE_TYPE.FIT_BITMAP;
764+
bpp = 1;
765+
break;
766+
default:
767+
result = false;
768+
break;
769+
}
770+
771+
return result;
772+
}
615773
}
616774
}

0 commit comments

Comments
 (0)