module "common.pli" module "/pliant/graphic/image/pixmap.pli" module "/pliant/graphic/image/resampling.pli" module "/pliant/graphic/image/convert.pli" module "/pliant/graphic/filter/io.pli" module "/pliant/graphic/color/gamut.pli"
type D2Image inherit D2Box field Link:ImagePrototype image field Str url
D2Box maybe D2Image
method i configure attribute value options oarg_rw D2Image i ; arg Str attribute value options if attribute="src" i image :> new ImagePixmap i url := url_concat (options option "url" Str) value var ExtendedStatus status := i:image load i:url "" if status=failure console "failed to load image " i:url ": " status:message eol i image :> null map ImagePrototype
method i position c oarg_rw D2Image i ; arg_rw D2Context c i position_undefined c var Pointer:ImagePrototype image :> i image if exists:image i x0 := 0 i y0 := (c:line_y0-c:line_y)+((c:y0-c:line_y0)-(image:y1-image:y0))/2 i x1 := image:x1-image:x0 i y1 := i:y0+image:y1-image:y0 c addtoline i
method i draw img c oarg_rw D2Image i ; oarg_rw ImagePrototype img ; arg_rw D2Context c if not (exists i:image) return var Int jx0 := img index_x i:x0 var Int jy0 := img index_y i:y0 var Int jx1 := img index_x i:x1 var Int jy1 := img index_y i:y1 var Int ix0 := max jx0 0 var Int iy0 := max jy0 0 var Int ix1 := min jx1 img:size_x var Int iy1 := min jy1 img:size_y if ix1>ix0 and iy1>iy0 var Link:ImageResampling rs :> new ImageResampling rs bind i:image i:image:x0 i:image:y0 i:image:x1 i:image:y1 jx1-jx0 jy1-jy0 var Link:ImageConvert conv :> new ImageConvert conv bind rs img:gamut "" var Address buf := memory_allocate conv:line_size null if rs:gamut:transparency=1 var Address tbuf := memory_allocate rs:line_size null for (var Int iy) iy0 iy1-1 conv read ix0-jx0 iy-jy0 ix1-ix0 buf rs read ix0-jx0 iy-jy0 ix1-ix0 tbuf for (var Int ix) ix0 ix1-1 if ((tbuf translate Byte (ix-ix0)*rs:pixel_size+rs:gamut:dimension) map uInt8)>128 img write ix iy 1 (buf translate Byte (ix-ix0)*conv:pixel_size) memory_free tbuf else for (var Int iy) iy0 iy1-1 conv read ix0-jx0 iy-jy0 ix1-ix0 buf img write ix0 iy ix1-ix0 buf memory_free buf
method i event e oarg_rw D2Image i ; arg_rw D2Event e if e:status:mouse_button_1_pressed if e:potencial_url<>"" and i:x0=defined and e:x>=i:x0 and e:x<=i:x1 and e:y>=i:y0 and e:y<=i:y1 e url := e potencial_url
html_tags insert "img" true addressof:D2Image
|