1 /*
2 Copyright (c) 2019 Ferhat Kurtulmuş
3 Boost Software License - Version 1.0 - August 17th, 2003
4 Permission is hereby granted, free of charge, to any person or organization
5 obtaining a copy of the software and accompanying documentation covered by
6 this license (the "Software") to use, reproduce, display, distribute,
7 execute, and transmit the Software, and to prepare derivative works of the
8 Software, and to permit third-parties to whom the Software is furnished to
9 do so, all subject to the following:
10 The copyright notices in the Software and this entire statement, including
11 the above license grant, this restriction and the following disclaimer,
12 must be included in all copies of the Software, in whole or in part, and
13 all derivative works of the Software, unless such copies or derivative
14 works are solely in the form of machine-executable object code generated by
15 a source language processor.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
19 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
20 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24 
25 module opencvd.imgcodecs;
26 
27 import std.string;
28 
29 import opencvd.cvcore;
30 
31 private {
32     extern (C){
33         Mat Image_IMRead(const char* filename, int flags);
34         bool Image_IMWrite(const char* filename, Mat img);
35         bool Image_IMWrite_WithParams(const char* filename, Mat img, IntVector params);
36         ByteArray Image_IMEncode(const char* fileExt, Mat img);
37         ByteArray Image_IMEncode_WithParams(const char* fileExt, Mat img, IntVector params);
38         Mat Image_IMDecode(ByteArray buf, int flags);
39     }
40 }
41 
42 enum: int { // cv::ImreadModes
43     IMREAD_UNCHANGED = -1, 
44     IMREAD_GRAYSCALE = 0, 
45     IMREAD_COLOR = 1, 
46     IMREAD_ANYDEPTH = 2, 
47     IMREAD_ANYCOLOR = 4, 
48     IMREAD_LOAD_GDAL = 8, 
49     IMREAD_REDUCED_GRAYSCALE_2 = 16, 
50     IMREAD_REDUCED_COLOR_2 = 17, 
51     IMREAD_REDUCED_GRAYSCALE_4 = 32, 
52     IMREAD_REDUCED_COLOR_4 = 33, 
53     IMREAD_REDUCED_GRAYSCALE_8 = 64, 
54     IMREAD_REDUCED_COLOR_8 = 65, 
55     IMREAD_IGNORE_ORIENTATION = 128 
56 }
57 
58 Mat imread(string filename, int flags = 0){
59     return Image_IMRead(toStringz(filename), flags);
60 }
61 
62 bool imwrite(string filename, Mat img){
63     return Image_IMWrite(toStringz(filename), img);
64 }
65 
66 bool imwriteWithParams(string filename, Mat img, IntVector params){
67     return Image_IMWrite_WithParams(toStringz(filename), img, params);
68 }
69 
70 ByteArray imencode(string fileExt, Mat img){
71     return Image_IMEncode(toStringz(fileExt), img);
72 }
73 
74 ByteArray imencodeWithParams(string fileExt, Mat img, IntVector params){
75     return Image_IMEncode_WithParams(toStringz(fileExt), img, params);
76 }
77 
78 Mat imdecode(ByteArray buf, int flags){
79     return Image_IMDecode(buf, flags);
80 }
81