1 // dimage is actually stripped out part of dlib - just to support reading PNG and JPEG
2 module dimage.image;
3 
4 //import dimage.color;
5 
6 class ImageLoadException : Exception
7 {
8     this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
9     {
10         super(msg, file, line, next);
11     }
12 }
13 
14 
15 class SuperImageFactory {
16     SuperImage createImage(int width, int height, int components, int bitsPerComponent) {
17         return new SuperImage(width, height, components, bitsPerComponent);
18     }
19 }
20 
21 class SuperImage {
22     immutable int width;
23     immutable int height;
24     uint[] data;
25     immutable int channels;
26     immutable int bitDepth;
27     immutable int length;
28 
29     void opIndexAssign(uint color, int x, int y) {
30         data[x + y * width] = color;
31     }
32 
33     uint opIndex(int x, int y) {
34         return data[x + y * width];
35     }
36 
37     this(int w, int h, int chan, int depth) {
38         width = w;
39         height = h;
40         channels = chan;
41         bitDepth = depth;
42         length = width * height;
43         data.length = width * height;
44     }
45     void free() {
46         data = null;
47     }
48 }
49 
50 __gshared SuperImageFactory defaultImageFactory = new SuperImageFactory();
51 
52 
53 /*
54  * Byte operations
55  */
56 version (BigEndian)
57 {
58     uint bigEndian(uint value) nothrow
59     {
60         return value;
61     }
62 
63     uint networkByteOrder(uint value) nothrow
64     {
65         return value;
66     }
67 }
68 
69 version (LittleEndian)
70 {
71     uint bigEndian(uint value) nothrow
72     {
73         return value << 24
74             | (value & 0x0000FF00) << 8
75             | (value & 0x00FF0000) >> 8
76             |  value >> 24;
77     }
78 
79     uint networkByteOrder(uint value) nothrow
80     {
81         return bigEndian(value);
82     }
83 }