Skip to content
Snippets Groups Projects
Commit 7fc81785 authored by Per Hedbor's avatar Per Hedbor
Browse files

Added load_layers and decode_layers

Rev: lib/modules/_Image.pmod/module.pmod:1.5
parent 0bda168d
Branches
Tags
No related merge requests found
//! module Image //! module Image
//! $Id: module.pmod,v 1.4 1999/12/21 23:47:31 per Exp $ //! $Id: module.pmod,v 1.5 2000/02/08 03:39:46 per Exp $
//! method object(Image.Image) load() //! method object(Image.Image) load()
//! method object(Image.Image) load(object file) //! method object(Image.Image) load(object file)
...@@ -89,9 +89,39 @@ mapping _decode( string data, mixed|void tocolor ) ...@@ -89,9 +89,39 @@ mapping _decode( string data, mixed|void tocolor )
"img":i, "img":i,
"image":i, "image":i,
]); ]);
}
array(Image.Layer) decode_layers( string data, mixed|void tocolor )
{
array i;
if(!data)
return 0;
foreach( ({ "GIF", "JPEG", "XWD", "PNM",
"XCF", "PSD", "PNG", "BMP", "TGA", "PCX",
"XBM", "XPM", "TIFF", "ILBM", "PS",
"HRZ", "AVS", "WBF",
}), string fmt )
if( !catch(i = Image[fmt]->decode_layers( data )) && i )
break;
if(!i) // No image could be decoded at all.
catch
{
mapping q = _decode( data, tocolor );
i = ({
Image.Layer( ([
"image":q->img,
"alpha":q->alpha
]) )
});
};
return i;
} }
string read_file(string file) string read_file(string file)
{ {
string ext=""; string ext="";
...@@ -121,7 +151,7 @@ string read_file(string file) ...@@ -121,7 +151,7 @@ string read_file(string file)
return Stdio.read_file( file ); return Stdio.read_file( file );
} }
mapping _load(void|object|string file, mixed|void opts) local string load_file( void|object|string file )
{ {
string data; string data;
if (!file) file=Stdio.stdin; if (!file) file=Stdio.stdin;
...@@ -132,6 +162,12 @@ mapping _load(void|object|string file, mixed|void opts) ...@@ -132,6 +162,12 @@ mapping _load(void|object|string file, mixed|void opts)
if( catch( data = read_file( file ) ) || !data || !strlen(data) ) if( catch( data = read_file( file ) ) || !data || !strlen(data) )
catch( data = Protocols.HTTP.get_url_nice( file )[ 1 ] ); catch( data = Protocols.HTTP.get_url_nice( file )[ 1 ] );
} }
return data;
}
mapping _load(void|object|string file, mixed|void opts)
{
string data = load_file( file, opts );
if( !data ) if( !data )
error("Image._load: Can't open %O for input.\n",file); error("Image._load: Can't open %O for input.\n",file);
return _decode( data,opts ); return _decode( data,opts );
...@@ -146,6 +182,12 @@ object(Image.Layer) load_layer(void|object|string file) ...@@ -146,6 +182,12 @@ object(Image.Layer) load_layer(void|object|string file)
return Image.Layer( (["image":m->image]) ); return Image.Layer( (["image":m->image]) );
} }
array(Image.Layer) load_layers(void|object|string file, mixed|void opts)
{
string d = load_file( file );
return decode_layers( file, opts );
}
object(Image.Image) load(void|object|string file) object(Image.Image) load(void|object|string file)
{ {
return _load(file)->image; return _load(file)->image;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment