| |
| /pliant/graphic/filter/prototype.pli |
| |
| 1 |
abstract | |
| 2 |
[Prototypes for various files format drivers] | |
| 3 |
| |
| 4 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 5 |
# | |
| 6 |
# This program is free software; you can redistribute it and/or | |
| 7 |
# modify it under the terms of the GNU General Public License version 2 | |
| 8 |
# as published by the Free Software Foundation. | |
| 9 |
# | |
| 10 |
# This program is distributed in the hope that it will be useful, | |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 |
# GNU General Public License for more details. | |
| 14 |
# | |
| 15 |
# You should have received a copy of the GNU General Public License | |
| 16 |
# version 2 along with this program; if not, write to the Free Software | |
| 17 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 18 |
| |
| 19 |
| |
| 20 |
module "/pliant/language/compiler.pli" | |
| 21 |
module "/pliant/language/stream.pli" | |
| 22 |
module "/pliant/language/stream/openmode.pli" | |
| 23 |
submodule "/pliant/graphic/image/prototype.pli" | |
| 24 |
| |
| 25 |
public | |
| 26 |
| |
| 27 |
| |
| 28 |
type ImageReadFilter | |
| 29 |
void | |
| 30 |
| |
| 31 |
method f open stream options p -> status | |
| 32 |
oarg_rw ImageReadFilter f ; arg_rw Stream stream ; arg Str options ; arg_w ImagePrototype p ; arg ExtendedStatus status | |
| 33 |
generic | |
| 34 |
status := failure "Generic image read open filter called" | |
| 35 |
| |
| 36 |
method f readline adr -> status | |
| 37 |
oarg_rw ImageReadFilter f ; arg Address adr ; arg Status status | |
| 38 |
generic | |
| 39 |
status := failure | |
| 40 |
| |
| 41 |
method f close -> status | |
| 42 |
oarg_rw ImageReadFilter f ; arg ExtendedStatus status | |
| 43 |
generic | |
| 44 |
status := failure "Generic image read close filter called" | |
| 45 |
| |
| 46 |
method f query filename options h -> status | |
| 47 |
oarg_rw ImageReadFilter f ; arg Str filename options ; arg_w ImagePrototype h ; arg ExtendedStatus status | |
| 48 |
generic | |
| 49 |
status := (var Stream s) open filename options in+safe | |
| 50 |
if status=success | |
| 51 |
status := f open s options h | |
| 52 |
if status=success | |
| 53 |
f close | |
| 54 |
| |
| 55 |
| |
| 56 |
type ImageWriteFilter | |
| 57 |
void | |
| 58 |
| |
| 59 |
method f open stream options h -> status | |
| 60 |
oarg_rw ImageWriteFilter f ; arg_rw Stream stream ; arg Str options ; arg ImagePrototype h ; arg ExtendedStatus status | |
| 61 |
generic | |
| 62 |
status := failure "Generic image write open filter called" | |
| 63 |
| |
| 64 |
method f writeline adr -> status | |
| 65 |
oarg_rw ImageWriteFilter f ; arg Address adr ; arg Status status | |
| 66 |
generic | |
| 67 |
status := failure | |
| 68 |
| |
| 69 |
method f close -> status | |
| 70 |
oarg_rw ImageWriteFilter f ; arg ExtendedStatus status | |
| 71 |
generic | |
| 72 |
status := failure "Generic image write close filter called" | |
| 73 |
| |
| 74 |
| |
| 75 |
private | |
| 76 |
| |
| 77 |
gvar Dictionary image_read_filters # extension -> type | |
| 78 |
gvar Dictionary image_read_seek | |
| 79 |
gvar Dictionary image_write_filters # extension -> type | |
| 80 |
gvar Dictionary image_write_seek | |
| 81 |
| |
| 82 |
function image_record_filters ext read_filter read_seek write_filter write_seek | |
| 83 |
arg Str ext ; arg Type read_filter write_filter ; arg CBool read_seek write_seek | |
| 84 |
if read_filter<>Void | |
| 85 |
image_read_filters insert ext true addressof:read_filter | |
| 86 |
if read_seek | |
| 87 |
image_read_seek insert ext true addressof:void | |
| 88 |
if write_filter<>Void | |
| 89 |
image_write_filters insert ext true addressof:write_filter | |
| 90 |
if write_seek | |
| 91 |
image_write_seek insert ext true addressof:void | |
| 92 |
| |
| 93 |
function image_read_filter filename -> f | |
| 94 |
arg Str filename ; arg Link:ImageReadFilter f | |
| 95 |
var Str ext := filename | |
| 96 |
ext := ext (ext search_last "/" -1)+1 ext:len | |
| 97 |
ext := ext (ext search "." ext:len) ext:len | |
| 98 |
var Pointer:Arrow c :> image_read_filters first ext | |
| 99 |
if c=null | |
| 100 |
f :> null map ImageReadFilter | |
| 101 |
return | |
| 102 |
f :> entry_new:(c map Type) map ImageReadFilter | |
| 103 |
| |
| 104 |
function image_read_flags filename -> flags | |
| 105 |
arg Str filename ; arg Int flags | |
| 106 |
var Str ext := filename | |
| 107 |
ext := ext (ext search_last "/" -1)+1 ext:len | |
| 108 |
ext := ext (ext search "." ext:len) ext:len | |
| 109 |
flags := shunt (image_read_seek first ext)<>null seek 0 | |
| 110 |
| |
| 111 |
function image_write_filter filename -> f | |
| 112 |
arg Str filename ; arg Link:ImageWriteFilter f | |
| 113 |
var Str ext := filename | |
| 114 |
ext := ext (ext search_last "/" -1)+1 ext:len | |
| 115 |
ext := ext (ext search "." ext:len) ext:len | |
| 116 |
var Pointer:Arrow c :> image_write_filters first ext | |
| 117 |
if c=null | |
| 118 |
f :> null map ImageWriteFilter | |
| 119 |
return | |
| 120 |
f :> entry_new:(c map Type) map ImageWriteFilter | |
| 121 |
| |
| 122 |
function image_write_flags filename -> flags | |
| 123 |
arg Str filename ; arg Int flags | |
| 124 |
var Str ext := filename | |
| 125 |
ext := ext (ext search_last "/" -1)+1 ext:len | |
| 126 |
ext := ext (ext search "." ext:len) ext:len | |
| 127 |
flags := shunt (image_write_seek first ext)<>null seek 0 | |
| 128 |
| |
| 129 |
export image_record_filters | |
| 130 |
export image_read_filter image_read_flags | |
| 131 |
export image_write_filter image_write_flags | |
| 132 |
| |
| |