aboutsummaryrefslogtreecommitdiff
path: root/xormat.h
blob: 59cf66d8e570d5d4efd13699bf9d399182633f92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
///                                 _
/// __  _____  _ __ _ __ ___   __ _| |_
/// \ \/ / _ \| '__| '_ ` _ \ / _` | __|
///  >  < (_) | |  | | | | | | (_| | |_
/// /_/\_\___/|_|  |_| |_| |_|\__,_|\__|
///
/// Copyright (c) 1997 - Ognjen 'xolatile' Milan Robovic
///
/// xolatile@chud.cyou - xormat - Very simple file format wrapper for things I hate but have to use anyway...
///
/// This program is free software, free as in freedom and as in free beer, you can redistribute it and/or modify it under the terms of the GNU
/// General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version if you wish...
///
/// This program is distributed in the hope that it will be useful, but it is probably not, and without any warranty, without even the implied
/// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License
/// for more details, if you dare, it is a lot of text that nobody wants to read...

#ifdef use_png_library
#include "xormat/png.h"
#endif

#ifdef use_jxl_library
#include "xormat/jxl.h"
#endif

#ifdef use_jpg_library
#include "xormat/jpg.h"
#endif

#ifdef use_tga_library
#include "xormat/tga.h"
#endif

static generic * format_image_import (character * path, natural * width, natural * height) {
	natural * data = null;

#ifdef use_png_library
	if (data == null) {
		character buffer [256] = "";

		if (file_exists (string_concatenate (string_copy (buffer, path), ".png")) == true) {
			data = png_image_import (buffer, width, height);
		}
	}
#endif

#ifdef use_jxl_library
	if (data == null) {
		character buffer [256] = "";

		if (file_exists (string_concatenate (string_copy (buffer, path), ".jxl")) == true) {
			data = jxl_image_import (buffer, width, height);
		}
	}
#endif

#ifdef use_jpg_library
	if (data == null) {
		character buffer [256] = "";

		if (file_exists (string_concatenate (string_copy (buffer, path), ".jpg")) == true) {
			data = jpg_image_import (buffer, width, height);
		}
	}
#endif

#ifdef use_tga_library
	if (data == null) {
		character buffer [256] = "";

		if (file_exists (string_concatenate (string_copy (buffer, path), ".tga")) == true) {
			data = tga_image_import (buffer, width, height);
		}
	}
#endif

	if (data == null) {
		switch (file_type (path)) {
#ifdef use_png_library
			case (file_type_png_image): {
				if (file_exists (path) == true) {
					data = png_image_import (path, width, height);
				} else {
					print ("/w File '/3%s/-' doesn't exist.\n", path);
				}
			} break;
#endif
#ifdef use_jxl_library
			case (file_type_jxl_image): {
				if (file_exists (path) == true) {
					data = jxl_image_import (path, width, height);
				} else {
					print ("/w File '/3%s/-' doesn't exist.\n", path);
				}
			} break;
#endif
#ifdef use_jpg_library
			case (file_type_jpg_image): {
				if (file_exists (path) == true) {
					data = jpg_image_import (path, width, height);
				} else {
					print ("/w File '/3%s/-' doesn't exist.\n", path);
				}
			} break;
#endif
#ifdef use_tga_library
			case (file_type_tga_image): {
				if (file_exists (path) == true) {
					data = tga_image_import (path, width, height);
				} else {
					print ("/w File '/3%s/-' doesn't exist.\n", path);
				}
			} break;
#endif
			default: {
				print ("/w File '/3%s/-' doesn't exist or file type isn't supported.\n", path);
			} break;
		}
	}

	return (data);
}