Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. (*
  2.     Copyright 2016, 2022 Anton Krotov
  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 <http://www.gnu.org/licenses/>.
  18. *)
  19.  
  20. MODULE LibImg;
  21.  
  22. IMPORT sys := SYSTEM, KOSAPI, File, S := Strings;
  23.  
  24.  
  25. PROCEDURE [stdcall, "Libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
  26. PROCEDURE [stdcall, "Libimg.obj", ""] img_to_rgb2 (data, data_rgb: INTEGER); END;
  27. PROCEDURE [stdcall, "Libimg.obj", ""] img_scale (src, crop_x, crop_y, crop_width, crop_height, dst, scale, inter, param1, param2: INTEGER): INTEGER; END;
  28. PROCEDURE [stdcall, "Libimg.obj", ""] img_destroy* (img: INTEGER); END;
  29. PROCEDURE [stdcall, "Libimg.obj", ""] img_convert (src, dst, dst_type, flags, param: INTEGER): INTEGER; END;
  30.  
  31.  
  32. PROCEDURE GetInf* (img: INTEGER; VAR sizeX, sizeY, data: INTEGER);
  33. BEGIN
  34.         sys.GET(img +  4, sizeX);
  35.         sys.GET(img +  8, sizeY);
  36.         sys.GET(img + 24, data)
  37. END GetInf;
  38.  
  39.  
  40. PROCEDURE GetImg* (ptr, size, Width: INTEGER; VAR sizeY: INTEGER): INTEGER;
  41. VAR
  42.         image_data, dst, x, y, type: INTEGER;
  43. BEGIN
  44.         image_data := img_decode(ptr, size, 0);
  45.         IF image_data # 0 THEN
  46.                 sys.GET(image_data + 4, x);
  47.                 sys.GET(image_data + 8, y);
  48.                 sys.GET(image_data + 20, type);
  49.                 IF type # 3 THEN
  50.                         dst := img_convert(image_data, 0, 3, 0, 0);
  51.                         img_destroy(image_data);
  52.                         image_data := dst
  53.                 END;
  54.                 IF (x > Width) & (image_data # 0) THEN
  55.                         dst := img_scale(image_data, 0, 0, x, y, 0, 3, 1, Width, (y * Width) DIV x);
  56.                         img_destroy(image_data);
  57.                         image_data := dst
  58.                 END;
  59.                 IF image_data # 0 THEN
  60.                         sys.GET(image_data +  8, sizeY)
  61.                 END
  62.         END
  63.         RETURN image_data
  64. END GetImg;
  65.  
  66.  
  67. PROCEDURE LoadFromFile* (fileName: S.STRING; width: INTEGER; VAR height: INTEGER): INTEGER;
  68. VAR
  69.         size, res, ptr: INTEGER;
  70. BEGIN
  71.         res := 0;
  72.         ptr := File.Load(fileName, size);
  73.         IF ptr # 0 THEN
  74.                 res := GetImg(ptr, size, width, height);
  75.                 ptr := KOSAPI.free(ptr)
  76.         END
  77.         RETURN res
  78. END LoadFromFile;
  79.  
  80.  
  81. END LibImg.
  82.