1 module d2dgfx
is aliced
;
12 // ////////////////////////////////////////////////////////////////////////// //
13 public __gshared Color
[256] d2dpal
;
16 public void loadPalette () {
17 auto fl
= openFile("playpal.pal");
18 foreach (immutable idx
; 0..256) {
19 ubyte r
= cast(ubyte)(fl
.readNum
!ubyte()*4);
20 ubyte g
= cast(ubyte)(fl
.readNum
!ubyte()*4);
21 ubyte b
= cast(ubyte)(fl
.readNum
!ubyte()*4);
27 // color 0 is transparent
32 // ////////////////////////////////////////////////////////////////////////// //
33 public class D2DImage
{
34 private import std
.stdio
: File
;
45 auto fl
= openFile(name
);
48 } catch (Exception
) {}
49 import std
.algorithm
: endsWith
;
50 if (name
.endsWith("_mirrored.vga")) {
51 auto fl
= openFile(name
[0..$-13]~".vga");
55 auto fl
= openFile(name
); // throw error message
58 @property bool valid () const pure nothrow @safe @nogc { /*pragma(inline, true);*/ return (data
!is null && width
> 0 && height
> 0); }
60 Color
opIndex (usize y
, usize x
) { pragma(inline
, true); return (x
< width
&& y
< height ? d2dpal
.ptr
[data
.ptr
[y
*width
+x
]] : Color(0, 0, 0, 0)); }
63 if (tex
!is null) tex
.clear
;
64 //if (img !is null) img.clear;
72 @property TrueColorImage
asTCImage () {
73 if (img
is null && valid
) {
74 img
= new TrueColorImage(width
, height
);
75 auto cols
= img
.imageData
.colors
.ptr
;
76 foreach (int y
; 0..height
) {
77 foreach (int x
; 0..width
) {
78 ubyte c
= data
.ptr
[y
*width
+x
];
80 *cols
= Color(0, 0, 0, 0); // transparent
91 @property Texture
asGLTex () {
92 if (tex
is null && valid
) tex
= new Texture(asTCImage
, Texture
.Option
.Nearest
);
97 void drawAtXY (int x
, int y
) {
101 glutils
.drawAtXY(tex
, x
-sx
, y
);
106 void load (File fi
, bool mirrored
) {
107 width
= fi
.readNum
!ushort();
108 height
= fi
.readNum
!ushort();
109 if (width
< 1) assert(0);
110 if (height
< 1) assert(0);
111 sx
= fi
.readNum
!short();
112 sy
= fi
.readNum
!short();
113 data
= new ubyte[width
*height
];
114 fi
.rawReadExact(data
[]);
115 if (mirrored
) mirrorVga();
119 auto nd
= new ubyte[](data
.length
);
120 foreach (int y
; 0..height
) {
121 int npos
= y
*width
+width
-1;
122 foreach (int x
; 0..width
) {
123 nd
[npos
--] = data
[y
*width
+x
];