1 module dtiv.main;
2 
3 import dtiv.lib;
4 
5 void main(string[] args)
6 {
7     import dtiv.ansi;
8     import std.getopt;
9 
10     bool noBlocks;
11     bool colors256;
12     bool disableShapes;
13     bool disableBraille;
14 
15     auto opts = getopt(
16         args,
17         "noblocks|0", "No block character adjustment, always use top half block char.", &noBlocks,
18         "256", "Use 256 color mode.", &colors256,
19         "noshapes", "Disable usage of triangle shapes.", &disableShapes,
20         "nobraille", "Disable usage of triangle shapes.", &disableBraille,
21     );
22 
23     if(opts.helpWanted)
24     {
25         defaultGetoptPrinter("Options:", opts.options);
26         return;
27     }
28 
29     int flags;
30 
31     if(noBlocks) flags |= FLAG_NOOPT;
32     if(colors256) flags |= FLAG_MODE_256;
33     if(disableShapes) flags |= FLAG_NOT_USE_SKEW;
34     if(disableBraille) flags |= FLAG_NOT_USE_BRAILLE;
35 
36     auto img = IFImgWrapper(args[$-1]);
37 
38     emit_image(img, flags);
39 }
40 
41 struct IFImgWrapper
42 {
43     import imageformats;
44 
45     IFImage img;
46     alias img this;
47 
48     this(string filename)
49     {
50         img = read_image(filename, ColFmt.RGB);
51     }
52 
53     Pixel getPixel(int x, int y) const
54     {
55         assert (x >= 0);
56         assert (y >= 0);
57 
58         const idx = (y * img.w + x) * Pixel.arr.length;
59 
60         assert(idx >= 0);
61         assert(idx < img.pixels.length);
62 
63         Pixel ret;
64         ret.arr = img.pixels[idx .. idx + Pixel.arr.length];
65 
66         return ret;
67     }
68 }
69 
70 /// Represents raw bytes picture
71 /// Useful for testing purposes
72 struct RawImgWrapper
73 {
74     int w = 32;
75     int h = 32;
76     private ubyte[] pixels;
77 
78     this(string filename)
79     {
80         import std.file;
81         pixels = cast(ubyte[]) read(filename);
82     }
83 
84     Pixel getPixel(int x, int y) const
85     {
86         assert (x >= 0);
87         assert (y >= 0);
88 
89         const idx = (y * w + x) * Pixel.arr.length;
90 
91         assert(idx >= 0);
92         assert(idx < pixels.length);
93 
94         Pixel ret;
95         ret.arr = pixels[idx .. idx + Pixel.arr.length];
96 
97         return ret;
98     }
99 }