forked from KolibriOS/kolibrios
82 lines
2.5 KiB
Plaintext
82 lines
2.5 KiB
Plaintext
|
(*
|
||
|
Copyright 2016, 2022 Anton Krotov
|
||
|
|
||
|
This file is part of fb2read.
|
||
|
|
||
|
fb2read is free software: 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
|
||
|
(at your option) any later version.
|
||
|
|
||
|
fb2read is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with fb2read. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*)
|
||
|
|
||
|
MODULE LibImg;
|
||
|
|
||
|
IMPORT sys := SYSTEM, KOSAPI, File, S := Strings;
|
||
|
|
||
|
|
||
|
PROCEDURE [stdcall, "Libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
|
||
|
PROCEDURE [stdcall, "Libimg.obj", ""] img_to_rgb2 (data, data_rgb: INTEGER); END;
|
||
|
PROCEDURE [stdcall, "Libimg.obj", ""] img_scale (src, crop_x, crop_y, crop_width, crop_height, dst, scale, inter, param1, param2: INTEGER): INTEGER; END;
|
||
|
PROCEDURE [stdcall, "Libimg.obj", ""] img_destroy* (img: INTEGER); END;
|
||
|
PROCEDURE [stdcall, "Libimg.obj", ""] img_convert (src, dst, dst_type, flags, param: INTEGER): INTEGER; END;
|
||
|
|
||
|
|
||
|
PROCEDURE GetInf* (img: INTEGER; VAR sizeX, sizeY, data: INTEGER);
|
||
|
BEGIN
|
||
|
sys.GET(img + 4, sizeX);
|
||
|
sys.GET(img + 8, sizeY);
|
||
|
sys.GET(img + 24, data)
|
||
|
END GetInf;
|
||
|
|
||
|
|
||
|
PROCEDURE GetImg* (ptr, size, Width: INTEGER; VAR sizeY: INTEGER): INTEGER;
|
||
|
VAR
|
||
|
image_data, dst, x, y, type: INTEGER;
|
||
|
BEGIN
|
||
|
image_data := img_decode(ptr, size, 0);
|
||
|
IF image_data # 0 THEN
|
||
|
sys.GET(image_data + 4, x);
|
||
|
sys.GET(image_data + 8, y);
|
||
|
sys.GET(image_data + 20, type);
|
||
|
IF type # 3 THEN
|
||
|
dst := img_convert(image_data, 0, 3, 0, 0);
|
||
|
img_destroy(image_data);
|
||
|
image_data := dst
|
||
|
END;
|
||
|
IF (x > Width) & (image_data # 0) THEN
|
||
|
dst := img_scale(image_data, 0, 0, x, y, 0, 3, 1, Width, (y * Width) DIV x);
|
||
|
img_destroy(image_data);
|
||
|
image_data := dst
|
||
|
END;
|
||
|
IF image_data # 0 THEN
|
||
|
sys.GET(image_data + 8, sizeY)
|
||
|
END
|
||
|
END
|
||
|
RETURN image_data
|
||
|
END GetImg;
|
||
|
|
||
|
|
||
|
PROCEDURE LoadFromFile* (fileName: S.STRING; width: INTEGER; VAR height: INTEGER): INTEGER;
|
||
|
VAR
|
||
|
size, res, ptr: INTEGER;
|
||
|
BEGIN
|
||
|
res := 0;
|
||
|
ptr := File.Load(fileName, size);
|
||
|
IF ptr # 0 THEN
|
||
|
res := GetImg(ptr, size, width, height);
|
||
|
ptr := KOSAPI.free(ptr)
|
||
|
END
|
||
|
RETURN res
|
||
|
END LoadFromFile;
|
||
|
|
||
|
|
||
|
END LibImg.
|