| |
| /pliant/graphic/image/pixmap.pli |
| |
| 1 |
abstract | |
| 2 |
[The basic, uncompressed image implementation.] | |
| 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 |
submodule "prototype.pli" | |
| 22 |
module "/pliant/language/compiler/type/inherit.pli" | |
| 23 |
| |
| 24 |
constant default_tile_size 2^16 | |
| 25 |
| |
| 26 |
| |
| 27 |
type ImagePixmap | |
| 28 |
inherit ImagePrototype | |
| 29 |
field Address data | |
| 30 |
field Int tile_y | |
| 31 |
| |
| 32 |
ImagePrototype maybe ImagePixmap | |
| 33 |
| |
| 34 |
| |
| 35 |
method p line y -> adr | |
| 36 |
arg ImagePixmap p ; arg Int y ; arg Address adr | |
| 37 |
check y>=0 and y<p:size_y | |
| 38 |
adr := p:data map Address y | |
| 39 |
| |
| 40 |
method p pixel x y -> adr | |
| 41 |
arg ImagePixmap p ; arg Int x y ; arg Address adr | |
| 42 |
check x>=0 and x<p:size_x | |
| 43 |
check y>=0 and y<p:size_y | |
| 44 |
adr := (p:data map Address y) translate Byte x*p:pixel_size | |
| 45 |
| |
| 46 |
| |
| 47 |
function build p | |
| 48 |
arg_w ImagePixmap p | |
| 49 |
p data := null | |
| 50 |
p size_x := 0 | |
| 51 |
p size_y := 0 | |
| 52 |
p tile_y := 1 | |
| 53 |
| |
| 54 |
function destroy p | |
| 55 |
arg_w ImagePixmap p | |
| 56 |
for (var Int y) 0 p:size_y-1 step p:tile_y | |
| 57 |
memory_free (p line y) | |
| 58 |
memory_free p:data | |
| 59 |
| |
| 60 |
| |
| 61 |
method p setup proto options -> status | |
| 62 |
oarg_rw ImagePixmap p ; arg ImagePrototype proto ; arg Str options ; arg ExtendedStatus status | |
| 63 |
check proto:size_x>0 and proto:size_y>0 and proto:line_size>0 | |
| 64 |
for (var Int y) 0 p:size_y-1 step p:tile_y | |
| 65 |
memory_free (p line y) | |
| 66 |
memory_free p:data | |
| 67 |
addressof:p map ImagePrototype := proto | |
| 68 |
p data := memory_allocate p:size_y*Address:size null | |
| 69 |
p tile_y := max (options option "tile_y" Int (options option "tile_size" Int default_tile_size)\p:line_size) 1 | |
| 70 |
check p:tile_y>0 | |
| 71 |
for (var Int y) 0 p:size_y-1 | |
| 72 |
if y%p:tile_y=0 | |
| 73 |
p:data map Address y := memory_allocate p:line_size*(min p:tile_y p:size_y-y) addressof:p | |
| 74 |
else | |
| 75 |
p:data map Address y := (p:data map Address y-1) translate Byte p:line_size | |
| 76 |
status := success | |
| 77 |
| |
| 78 |
| |
| 79 |
method p read x y count adr | |
| 80 |
oarg_rw ImagePixmap p ; arg Int x y count ; arg Address adr | |
| 81 |
check x>=0 and count>=0 and x+count<=p:size_x and y>=0 and y<p:size_y | |
| 82 |
memory_copy (p pixel x y) adr count*p:pixel_size | |
| 83 |
| |
| 84 |
method p write x y count adr | |
| 85 |
oarg_rw ImagePixmap p ; arg Int x y count ; arg Address adr | |
| 86 |
check x>=0 and count>=0 and x+count<=p:size_x and y>=0 and y<p:size_y | |
| 87 |
memory_copy adr (p pixel x y) count*p:pixel_size | |
| 88 |
| |
| 89 |
| |
| 90 |
method p read_map x y mini maxi count -> adr | |
| 91 |
oarg_rw ImagePixmap p ; arg Int x y mini maxi ; arg_w Int count ; arg Address adr | |
| 92 |
check mini>0 and maxi>=mini and x>=0 and x+maxi<=p:size_x and y>=0 and y<p:size_y | |
| 93 |
adr := p pixel x y ; count := maxi | |
| 94 |
| |
| 95 |
method p write_map x y mini maxi count -> adr | |
| 96 |
oarg_rw ImagePixmap p ; arg Int x y mini maxi ; arg_w Int count ; arg Address adr | |
| 97 |
check mini>0 and maxi>=mini and x>=0 and x+maxi<=p:size_x and y>=0 and y<p:size_y | |
| 98 |
adr := p pixel x y ; count := maxi | |
| 99 |
| |
| 100 |
| |
| 101 |
method p rectangle_read_map x y x0 y0 x1 y1 step_x step_y -> adr | |
| 102 |
oarg_rw ImagePixmap p ; arg Int x y ; arg_w Int x0 y0 x1 y1 step_x step_y ; arg Address adr | |
| 103 |
x0 := 0 ; y0 := y-(y%p:tile_y) ; x1 := p size_x ; y1 := min y0+p:tile_y p:size_y | |
| 104 |
step_x := p pixel_size ; step_y := p line_size | |
| 105 |
adr := p line y0 | |
| 106 |
| |
| 107 |
| |
| 108 |
export ImagePixmap '. setup' '. line' '. pixel' | |
| |