4 using System.Runtime.InteropServices;
5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Serialization;
7 using SiliconStudio.Core.Serialization.Contents;
9 namespace SiliconStudio.
Paradox.Graphics.Data
11 [ContentSerializerExtension(
"tga")]
17 throw new NotSupportedException(
"Texture needs to be in package to be saved.");
20 var headerBytes = stream.ReadBytes(Utilities.SizeOf<
Header>());
21 fixed (byte* p = &headerBytes[0])
23 Utilities.ReadOut((IntPtr)p, out header);
28 throw new NotSupportedException(
"Only RGB 24 or 32 bits TGA are currently supported.");
31 var pixelData =
new byte[header.Width * header.Height * 4];
33 for (
int y = 0;
y < header.Height; ++
y)
35 var scanlineData = stream.ReadBytes(header.Width * (header.Bits / 8));
38 if (header.
Bits == 24)
40 var expandedScanlineData =
new byte[header.Width * 4];
41 for (
int i = 0; i < header.Width; ++i)
43 expandedScanlineData[i * 4 + 0] = scanlineData[i * 3 + 0];
44 expandedScanlineData[i * 4 + 1] = scanlineData[i * 3 + 1];
45 expandedScanlineData[i * 4 + 2] = scanlineData[i * 3 + 2];
46 expandedScanlineData[i * 4 + 3] = 255;
48 scanlineData = expandedScanlineData;
50 int targetY = ((header.Descriptor & 0x10) == 0x10) ?
y : header.Height - 1 -
y;
51 fixed (byte*
dest = &pixelData[header.
Width * 4 * targetY])
52 fixed (byte* src = &scanlineData[0])
53 Utilities.CopyMemory((IntPtr)
dest, (IntPtr)src, header.Width * 4);
64 [StructLayout(LayoutKind.Sequential, Pack = 1)]
Provides method to instantiate an image 1D/2D/3D supporting TextureArray and mipmaps on the CPU or to...
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
override unsafe void Serialize(ContentSerializerContext context, SerializationStream stream, ref Image textureData)
Base class for implementation of SerializationStream.
ArchiveMode
Enumerates the different mode of serialization (either serialization or deserialization).