Subversion Repositories Kolibri OS

Rev

Rev 9896 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9896 akron1 1
(*
9898 akron1 2
    Copyright 2016, 2022, 2023 Anton Krotov
9896 akron1 3
 
4
    This file is part of fb2read.
5
 
6
    fb2read is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
 
11
    fb2read is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with fb2read. If not, see .
18
*)
19
 
20
MODULE LibImg;
21
 
9898 akron1 22
IMPORT SYSTEM, KOSAPI, File, S := Strings;
9896 akron1 23
 
24
 
25
PROCEDURE [stdcall, "Libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
26
PROCEDURE [stdcall, "Libimg.obj", ""] img_scale (src, crop_x, crop_y, crop_width, crop_height, dst, scale, inter, param1, param2: INTEGER): INTEGER; END;
9898 akron1 27
PROCEDURE [stdcall, "Libimg.obj", ""] img_destroy (img: INTEGER); END;
9896 akron1 28
PROCEDURE [stdcall, "Libimg.obj", ""] img_convert (src, dst, dst_type, flags, param: INTEGER): INTEGER; END;
29
 
30
 
9898 akron1 31
PROCEDURE Destroy* (VAR img: INTEGER);
32
BEGIN
33
	IF img # 0 THEN
34
		img_destroy(img);
35
		img := 0
36
	END
37
END Destroy;
38
 
39
 
9896 akron1 40
PROCEDURE GetInf* (img: INTEGER; VAR sizeX, sizeY, data: INTEGER);
41
BEGIN
9898 akron1 42
	SYSTEM.GET(img +  4, sizeX);
43
	SYSTEM.GET(img +  8, sizeY);
44
	SYSTEM.GET(img + 24, data)
9896 akron1 45
END GetInf;
46
 
47
 
48
PROCEDURE GetImg* (ptr, size, Width: INTEGER; VAR sizeY: INTEGER): INTEGER;
49
VAR
50
	image_data, dst, x, y, type: INTEGER;
51
BEGIN
52
	image_data := img_decode(ptr, size, 0);
53
	IF image_data # 0 THEN
9898 akron1 54
		SYSTEM.GET(image_data + 4, x);
55
		SYSTEM.GET(image_data + 8, y);
56
		SYSTEM.GET(image_data + 20, type);
9896 akron1 57
		IF type # 3 THEN
58
			dst := img_convert(image_data, 0, 3, 0, 0);
59
			img_destroy(image_data);
60
			image_data := dst
61
		END;
62
		IF (x > Width) & (image_data # 0) THEN
63
			dst := img_scale(image_data, 0, 0, x, y, 0, 3, 1, Width, (y * Width) DIV x);
64
			img_destroy(image_data);
65
			image_data := dst
66
		END;
67
		IF image_data # 0 THEN
9898 akron1 68
			SYSTEM.GET(image_data +  8, sizeY)
9896 akron1 69
		END
70
	END
71
	RETURN image_data
72
END GetImg;
73
 
74
 
75
PROCEDURE LoadFromFile* (fileName: S.STRING; width: INTEGER; VAR height: INTEGER): INTEGER;
76
VAR
77
	size, res, ptr: INTEGER;
78
BEGIN
79
	res := 0;
80
	ptr := File.Load(fileName, size);
81
	IF ptr # 0 THEN
82
		res := GetImg(ptr, size, width, height);
83
		ptr := KOSAPI.free(ptr)
84
	END
85
	RETURN res
86
END LoadFromFile;
87
 
88
 
89
END LibImg.