mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 14:06:23 +01:00
importer
This commit is contained in:
parent
d91d7e10ba
commit
974a7e858f
9 changed files with 264 additions and 42 deletions
|
@ -1299,6 +1299,7 @@
|
||||||
{"name":"pcx_parse","order":3,"path":"scripts/pcx_parse/pcx_parse.yy",},
|
{"name":"pcx_parse","order":3,"path":"scripts/pcx_parse/pcx_parse.yy",},
|
||||||
{"name":"pcx_server","order":2,"path":"scripts/pcx_server/pcx_server.yy",},
|
{"name":"pcx_server","order":2,"path":"scripts/pcx_server/pcx_server.yy",},
|
||||||
{"name":"perlin_noise","order":5,"path":"scripts/perlin_noise/perlin_noise.yy",},
|
{"name":"perlin_noise","order":5,"path":"scripts/perlin_noise/perlin_noise.yy",},
|
||||||
|
{"name":"png_reader","order":9,"path":"scripts/png_reader/png_reader.yy",},
|
||||||
{"name":"point_direction_positive","order":4,"path":"scripts/point_direction_positive/point_direction_positive.yy",},
|
{"name":"point_direction_positive","order":4,"path":"scripts/point_direction_positive/point_direction_positive.yy",},
|
||||||
{"name":"point_rect_overlap","order":2,"path":"scripts/point_rect_overlap/point_rect_overlap.yy",},
|
{"name":"point_rect_overlap","order":2,"path":"scripts/point_rect_overlap/point_rect_overlap.yy",},
|
||||||
{"name":"point_rotate","order":1,"path":"scripts/point_rotate/point_rotate.yy",},
|
{"name":"point_rotate","order":1,"path":"scripts/point_rotate/point_rotate.yy",},
|
||||||
|
|
|
@ -1922,6 +1922,7 @@
|
||||||
{"id":{"name":"pcx_parse","path":"scripts/pcx_parse/pcx_parse.yy",},},
|
{"id":{"name":"pcx_parse","path":"scripts/pcx_parse/pcx_parse.yy",},},
|
||||||
{"id":{"name":"pcx_server","path":"scripts/pcx_server/pcx_server.yy",},},
|
{"id":{"name":"pcx_server","path":"scripts/pcx_server/pcx_server.yy",},},
|
||||||
{"id":{"name":"perlin_noise","path":"scripts/perlin_noise/perlin_noise.yy",},},
|
{"id":{"name":"perlin_noise","path":"scripts/perlin_noise/perlin_noise.yy",},},
|
||||||
|
{"id":{"name":"png_reader","path":"scripts/png_reader/png_reader.yy",},},
|
||||||
{"id":{"name":"point_direction_positive","path":"scripts/point_direction_positive/point_direction_positive.yy",},},
|
{"id":{"name":"point_direction_positive","path":"scripts/point_direction_positive/point_direction_positive.yy",},},
|
||||||
{"id":{"name":"point_rect_overlap","path":"scripts/point_rect_overlap/point_rect_overlap.yy",},},
|
{"id":{"name":"point_rect_overlap","path":"scripts/point_rect_overlap/point_rect_overlap.yy",},},
|
||||||
{"id":{"name":"point_rotate","path":"scripts/point_rotate/point_rotate.yy",},},
|
{"id":{"name":"point_rotate","path":"scripts/point_rotate/point_rotate.yy",},},
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/////============= LITTLE ENDIEN =============
|
||||||
|
|
||||||
function bin_read_byte(_bin) {
|
function bin_read_byte(_bin) {
|
||||||
return file_bin_read_byte(_bin);
|
return file_bin_read_byte(_bin);
|
||||||
}
|
}
|
||||||
|
@ -111,6 +113,15 @@ function bin_read_long64(_bin) {
|
||||||
return sig? -lng : lng;
|
return sig? -lng : lng;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bin_read_chars(_bin, _len) {
|
||||||
|
var ss = "";
|
||||||
|
repeat(_len) {
|
||||||
|
var utf = bin_read_byte(_bin);
|
||||||
|
ss += chr(utf);
|
||||||
|
}
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
|
||||||
function bin_read_string(_bin) {
|
function bin_read_string(_bin) {
|
||||||
var len = bin_read_word(_bin);
|
var len = bin_read_word(_bin);
|
||||||
var ss = "";
|
var ss = "";
|
||||||
|
@ -140,4 +151,159 @@ function bin_read_pixel(_bin, type) {
|
||||||
case 2 : return [ bin_read_byte(_bin) ];
|
case 2 : return [ bin_read_byte(_bin) ];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////=========== BIG ENDIEN ===========
|
||||||
|
|
||||||
|
function Bin_read_byte(_bin) {
|
||||||
|
return file_bin_read_byte(_bin);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_word(_bin) {
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
return b0 + (b1 << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_short(_bin) {
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
|
||||||
|
var sht = b0 + (b1 << 8);
|
||||||
|
var sig = sht >> 15;
|
||||||
|
sht = sht & ~(1 << 15);
|
||||||
|
return sig? sht - power(2, 15) : sht;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_dword(_bin) {
|
||||||
|
var b3 = file_bin_read_byte(_bin);
|
||||||
|
var b2 = file_bin_read_byte(_bin);
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
var dw = b0 + (b1 << 8) + (b2 << 16) + (b3 << 24);
|
||||||
|
return dw;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_long(_bin) {
|
||||||
|
var b3 = file_bin_read_byte(_bin);
|
||||||
|
var b2 = file_bin_read_byte(_bin);
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
var lng = b0 + (b1 << 8) + (b2 << 16) + (b3 << 24);
|
||||||
|
|
||||||
|
var sig = lng >> 31;
|
||||||
|
lng = lng & ~(1 << 31);
|
||||||
|
return sig? lng - power(2, 31) : lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_fixed(_bin) {
|
||||||
|
var b3 = file_bin_read_byte(_bin);
|
||||||
|
var b2 = file_bin_read_byte(_bin);
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
|
||||||
|
var fixInt = b0 + (b1 << 8);
|
||||||
|
var fixFrc = b2 + (b3 << 8);
|
||||||
|
return fixInt + bin_fraction(fixFrc, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_float(_bin) {
|
||||||
|
var b3 = file_bin_read_byte(_bin);
|
||||||
|
var b2 = file_bin_read_byte(_bin);
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
var flt = b0 + (b1 << 8) + (b2 << 16) + (b3 << 24);
|
||||||
|
|
||||||
|
var sig = flt >> 31;
|
||||||
|
var expo = (flt & ~(1 << 31)) >> 23;
|
||||||
|
var mant = flt & 0b00000000_01111111_11111111_11111111;
|
||||||
|
|
||||||
|
var val = (1 + mant) * power(2, expo - 127);
|
||||||
|
return sig? -val : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_double(_bin) {
|
||||||
|
var b7 = file_bin_read_byte(_bin);
|
||||||
|
var b6 = file_bin_read_byte(_bin);
|
||||||
|
var b5 = file_bin_read_byte(_bin);
|
||||||
|
var b4 = file_bin_read_byte(_bin);
|
||||||
|
var b3 = file_bin_read_byte(_bin);
|
||||||
|
var b2 = file_bin_read_byte(_bin);
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
var dub = int64(b0 + (b1 << 8) + (b2 << 16) + (b3 << 24) + (b2 << 32) + (b3 << 40) + (b2 << 48) + (b3 << 56));
|
||||||
|
|
||||||
|
var sig = dub >> 63;
|
||||||
|
var expo = (dub & ~(1 << 63)) >> 52;
|
||||||
|
var mant = dub & 0b00000000_00001111_11111111_11111111_11111111_11111111_11111111_11111111;
|
||||||
|
|
||||||
|
var val = (1 + mant) * power(2, expo - 1023);
|
||||||
|
return sig? -val : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_qword(_bin) {
|
||||||
|
var b7 = file_bin_read_byte(_bin);
|
||||||
|
var b6 = file_bin_read_byte(_bin);
|
||||||
|
var b5 = file_bin_read_byte(_bin);
|
||||||
|
var b4 = file_bin_read_byte(_bin);
|
||||||
|
var b3 = file_bin_read_byte(_bin);
|
||||||
|
var b2 = file_bin_read_byte(_bin);
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
return int64(b0 + (b1 << 8) + (b2 << 16) + (b3 << 24) + (b2 << 32) + (b3 << 40) + (b2 << 48) + (b3 << 56));
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_long64(_bin) {
|
||||||
|
var b7 = file_bin_read_byte(_bin);
|
||||||
|
var b6 = file_bin_read_byte(_bin);
|
||||||
|
var b5 = file_bin_read_byte(_bin);
|
||||||
|
var b4 = file_bin_read_byte(_bin);
|
||||||
|
var b3 = file_bin_read_byte(_bin);
|
||||||
|
var b2 = file_bin_read_byte(_bin);
|
||||||
|
var b1 = file_bin_read_byte(_bin);
|
||||||
|
var b0 = file_bin_read_byte(_bin);
|
||||||
|
var lng = int64(b0 + (b1 << 8) + (b2 << 16) + (b3 << 24) + (b2 << 32) + (b3 << 40) + (b2 << 48) + (b3 << 56));
|
||||||
|
var sig = lng >> 63;
|
||||||
|
lng = lng & ~(1 << 63);
|
||||||
|
return sig? -lng : lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_chars(_bin, _len) {
|
||||||
|
var ss = "";
|
||||||
|
repeat(_len) {
|
||||||
|
var utf = Bin_read_byte(_bin);
|
||||||
|
ss += chr(utf);
|
||||||
|
}
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_string(_bin) {
|
||||||
|
var len = Bin_read_word(_bin);
|
||||||
|
var ss = "";
|
||||||
|
repeat(len) {
|
||||||
|
var utf = Bin_read_byte(_bin);
|
||||||
|
ss += chr(utf);
|
||||||
|
}
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_point(_bin) { return [ Bin_read_long(_bin), Bin_read_long(_bin) ]; }
|
||||||
|
function Bin_read_size(_bin) { return [ Bin_read_long(_bin), Bin_read_long(_bin) ]; }
|
||||||
|
function Bin_read_rect(_bin) { return [ Bin_read_point(_bin), Bin_read_size(_bin) ]; }
|
||||||
|
|
||||||
|
function Bin_read_color(_bin) {
|
||||||
|
var r = Bin_read_byte(_bin);
|
||||||
|
var g = Bin_read_byte(_bin);
|
||||||
|
var b = Bin_read_byte(_bin);
|
||||||
|
|
||||||
|
return make_color_rgb(r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bin_read_pixel(_bin, type) {
|
||||||
|
switch(type) {
|
||||||
|
case 0 : return [ Bin_read_byte(_bin), Bin_read_byte(_bin), Bin_read_byte(_bin), Bin_read_byte(_bin) ];
|
||||||
|
case 1 : return [ Bin_read_byte(_bin), Bin_read_byte(_bin) ];
|
||||||
|
case 2 : return [ Bin_read_byte(_bin) ];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
|
@ -1161,7 +1161,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
|
||||||
static loadImagePath = function(path, live = false) {
|
static loadImagePath = function(path, live = false) {
|
||||||
if(!file_exists_empty(path)) return noone;
|
if(!file_exists_empty(path)) return noone;
|
||||||
|
|
||||||
var _spr = sprite_add(path, 0, 0, 0, 0, 0);
|
var _spr = sprite_add(sprite_path_check_depth(path), 0, 0, 0, 0, 0);
|
||||||
if(_spr == -1) return noone;
|
if(_spr == -1) return noone;
|
||||||
|
|
||||||
var _sw = sprite_get_width(_spr);
|
var _sw = sprite_get_width(_spr);
|
||||||
|
@ -1194,7 +1194,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
|
||||||
if(tool_selection.is_selected)
|
if(tool_selection.is_selected)
|
||||||
tool_selection.apply();
|
tool_selection.apply();
|
||||||
|
|
||||||
var _spr = sprite_add(path, 0, 0, 0, 0, 0);
|
var _spr = sprite_add(sprite_path_check_depth(path), 0, 0, 0, 0, 0);
|
||||||
if(_spr == -1) return noone;
|
if(_spr == -1) return noone;
|
||||||
|
|
||||||
var _sw = sprite_get_width(_spr);
|
var _sw = sprite_get_width(_spr);
|
||||||
|
|
|
@ -45,18 +45,14 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; },
|
array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; },
|
||||||
new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]);
|
new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]);
|
||||||
|
|
||||||
on_drop_file = function(path) {
|
static on_drop_file = function(path) {
|
||||||
inputs[0].setValue(path);
|
inputs[0].setValue(path);
|
||||||
|
|
||||||
if(updatePaths(path)) {
|
if(updatePaths(path)) { doUpdate(); return true; }
|
||||||
doUpdate();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSprite(path) {
|
static createSprite = function(path) {
|
||||||
if(!file_exists(path))
|
if(!file_exists(path))
|
||||||
return noone;
|
return noone;
|
||||||
|
|
||||||
|
@ -69,7 +65,9 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
case ".jpeg":
|
case ".jpeg":
|
||||||
case ".gif":
|
case ".gif":
|
||||||
setDisplayName(_name);
|
setDisplayName(_name);
|
||||||
var _spr = sprite_add(path, 1, false, false, 0, 0);
|
|
||||||
|
var _real_path = sprite_path_check_depth(path);
|
||||||
|
var _spr = sprite_add(_real_path, 1, false, false, 0, 0);
|
||||||
|
|
||||||
if(_spr == -1) {
|
if(_spr == -1) {
|
||||||
var _txt = $"Image node: File not a valid image.";
|
var _txt = $"Image node: File not a valid image.";
|
||||||
|
@ -84,11 +82,8 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
return noone;
|
return noone;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePaths(path) {
|
static updatePaths = function(path) {
|
||||||
|
if(sprite_exists(spr)) sprite_delete(spr);
|
||||||
if(sprite_exists(spr))
|
|
||||||
sprite_delete(spr);
|
|
||||||
|
|
||||||
spr = createSprite(path);
|
spr = createSprite(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,29 +129,28 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||||
|
|
||||||
outputs[0].setValue(_outsurf);
|
outputs[0].setValue(_outsurf);
|
||||||
|
|
||||||
#region splice
|
if(!attributes.check_splice) return;
|
||||||
if(!attributes.check_splice) return;
|
attributes.check_splice = false;
|
||||||
attributes.check_splice = false;
|
|
||||||
|
//////////////////////////////////////////////// SPLICE ////////////////////////////////////////////////
|
||||||
|
|
||||||
|
if(LOADING || APPENDING) return;
|
||||||
|
if(string_pos("strip", display_name) == 0) return;
|
||||||
|
|
||||||
if(LOADING || APPENDING) return;
|
var sep_pos = string_pos("strip", display_name) + 5;
|
||||||
if(string_pos("strip", display_name) == 0) return;
|
var sep = string_copy(display_name, sep_pos, string_length(display_name) - sep_pos + 1);
|
||||||
|
var amo = toNumber(string_digits(sep));
|
||||||
|
|
||||||
|
if(amo == 0) return;
|
||||||
|
|
||||||
var sep_pos = string_pos("strip", display_name) + 5;
|
var ww = sprite_get_width(spr) / amo;
|
||||||
var sep = string_copy(display_name, sep_pos, string_length(display_name) - sep_pos + 1);
|
var hh = sprite_get_height(spr);
|
||||||
var amo = toNumber(string_digits(sep));
|
|
||||||
|
var _splice = nodeBuild("Node_Image_Sheet", x + w + 64, y);
|
||||||
if(amo == 0) return;
|
_splice.inputs[0].setFrom(outputs[0], false);
|
||||||
|
_splice.inputs[1].setValue([ ww, hh ]);
|
||||||
var ww = sprite_get_width(spr) / amo;
|
_splice.inputs[2].setValue(amo);
|
||||||
var hh = sprite_get_height(spr);
|
_splice.inputs[3].setValue([ amo, 1 ]);
|
||||||
|
|
||||||
var _splice = nodeBuild("Node_Image_Sheet", x + w + 64, y);
|
|
||||||
_splice.inputs[0].setFrom(outputs[0], false);
|
|
||||||
_splice.inputs[1].setValue([ ww, hh ]);
|
|
||||||
_splice.inputs[2].setValue(amo);
|
|
||||||
_splice.inputs[3].setValue([ amo, 1 ]);
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static dropPath = function(path) {
|
static dropPath = function(path) {
|
||||||
|
|
|
@ -83,7 +83,7 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
||||||
array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; },
|
array_push(attributeEditors, [ "File Watcher", function() { return attributes.file_checker; },
|
||||||
new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]);
|
new checkBox(function() { attributes.file_checker = !attributes.file_checker; }) ]);
|
||||||
|
|
||||||
on_drop_file = function(path) { #region
|
on_drop_file = function(path) {
|
||||||
if(directory_exists(path)) {
|
if(directory_exists(path)) {
|
||||||
with(dialogCall(o_dialog_drag_folder, WIN_W / 2, WIN_H / 2)) {
|
with(dialogCall(o_dialog_drag_folder, WIN_W / 2, WIN_H / 2)) {
|
||||||
dir_paths = path;
|
dir_paths = path;
|
||||||
|
@ -101,9 +101,9 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} #endregion
|
}
|
||||||
|
|
||||||
function updatePaths(paths = path_current) { #region
|
function updatePaths(paths = path_current) {
|
||||||
if(!is_array(paths) && ds_exists(paths, ds_type_list))
|
if(!is_array(paths) && ds_exists(paths, ds_type_list))
|
||||||
paths = ds_list_to_array(paths);
|
paths = ds_list_to_array(paths);
|
||||||
|
|
||||||
|
@ -128,7 +128,8 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
||||||
case ".png" :
|
case ".png" :
|
||||||
case ".jpg" :
|
case ".jpg" :
|
||||||
case ".jpeg" :
|
case ".jpeg" :
|
||||||
var _spr = sprite_add(_path, 1, false, false, 0, 0);
|
var _real_path = sprite_path_check_depth(path);
|
||||||
|
var _spr = sprite_add(_real_path, 1, false, false, 0, 0);
|
||||||
|
|
||||||
if(_spr == -1) {
|
if(_spr == -1) {
|
||||||
var _txt = $"Image node: File not a valid image.";
|
var _txt = $"Image node: File not a valid image.";
|
||||||
|
@ -143,7 +144,7 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} #endregion
|
}
|
||||||
|
|
||||||
insp1UpdateTooltip = __txt("Refresh");
|
insp1UpdateTooltip = __txt("Refresh");
|
||||||
insp1UpdateIcon = [ THEME.refresh_icon, 1, COLORS._main_value_positive ];
|
insp1UpdateIcon = [ THEME.refresh_icon, 1, COLORS._main_value_positive ];
|
||||||
|
|
28
scripts/png_reader/png_reader.gml
Normal file
28
scripts/png_reader/png_reader.gml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#macro ___PNG_READ_ERROR { if(noti) noti_warning($"PNG header read error."); return noone; }
|
||||||
|
|
||||||
|
function read_png_header(path, noti = true) {
|
||||||
|
static png_header = [ 137, 80, 78, 71, 13, 10, 26, 10 ];
|
||||||
|
|
||||||
|
var f = file_bin_open(path, 0);
|
||||||
|
if(f < 0) ___PNG_READ_ERROR
|
||||||
|
|
||||||
|
var b;
|
||||||
|
|
||||||
|
for (var i = 0, n = array_length(png_header); i < n; i++) {
|
||||||
|
b = file_bin_read_byte(f);
|
||||||
|
if(b != png_header[i]) { file_bin_close(f); ___PNG_READ_ERROR }
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat(4) b = file_bin_read_byte(f); // chunk size
|
||||||
|
|
||||||
|
b = bin_read_chars(f, 4);
|
||||||
|
if(b != "IHDR") { file_bin_close(f); ___PNG_READ_ERROR }
|
||||||
|
|
||||||
|
var _width = Bin_read_dword(f);
|
||||||
|
var _height = Bin_read_dword(f);
|
||||||
|
var _depth = Bin_read_byte(f);
|
||||||
|
|
||||||
|
file_bin_close(f);
|
||||||
|
|
||||||
|
return { width: _width, height: _height, depth: _depth };
|
||||||
|
}
|
13
scripts/png_reader/png_reader.yy
Normal file
13
scripts/png_reader/png_reader.yy
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"$GMScript":"v1",
|
||||||
|
"%Name":"png_reader",
|
||||||
|
"isCompatibility":false,
|
||||||
|
"isDnD":false,
|
||||||
|
"name":"png_reader",
|
||||||
|
"parent":{
|
||||||
|
"name":"importers",
|
||||||
|
"path":"folders/functions/importers.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMScript",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
}
|
|
@ -2,7 +2,8 @@ globalvar SPRITE_PATH_MAP;
|
||||||
SPRITE_PATH_MAP = {};
|
SPRITE_PATH_MAP = {};
|
||||||
|
|
||||||
function sprite_add_map(path) {
|
function sprite_add_map(path) {
|
||||||
var _s = sprite_add(path, 1, 0, 0, 0, 0);
|
var _real_path = sprite_path_check_depth(path);
|
||||||
|
var _s = sprite_add(_real_path, 1, 0, 0, 0, 0);
|
||||||
SPRITE_PATH_MAP[$ path] = _s;
|
SPRITE_PATH_MAP[$ path] = _s;
|
||||||
return _s;
|
return _s;
|
||||||
}
|
}
|
||||||
|
@ -17,4 +18,21 @@ function sprite_add_center(path) {
|
||||||
sprite_set_offset(_s, _sw / 2, _sh / 2);
|
sprite_set_offset(_s, _sw / 2, _sh / 2);
|
||||||
|
|
||||||
return _s;
|
return _s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sprite_path_check_depth(path, noti = true) {
|
||||||
|
if(filename_ext(path) != ".png") return path;
|
||||||
|
|
||||||
|
var _data = read_png_header(path, noti);
|
||||||
|
if(_data == noone) return path;
|
||||||
|
if(_data.depth == 8) return path;
|
||||||
|
|
||||||
|
if(noti) noti_warning($"{_data.depth} bits image is not supported. Proxy will be used.");
|
||||||
|
|
||||||
|
var path_magick = filepath_resolve(PREFERENCES.ImageMagick_path) + "magick.exe";
|
||||||
|
var proxy_path = $"{TEMPDIR}{filename_name_only(path)}_{seed_random(6)}.png";
|
||||||
|
var shell_cmd = $"convert \"{path}\" -depth 8 \"{proxy_path}\"";
|
||||||
|
shell_execute(path_magick, shell_cmd, self);
|
||||||
|
|
||||||
|
return proxy_path;
|
||||||
}
|
}
|
Loading…
Reference in a new issue