OneCypher
Anmeldungsdatum: 23.09.2007 Beiträge: 802
|
Verfasst am: 25.09.2008, 17:35 Titel: |
|
|
Hier mein bisheriger Quälcode (jpeg62.dll vorrausgesetzt):
Code: |
#include "fbgfx.bi"
#include "jpeglib.bi"
function red(col AS UINTEGER) as ubyte
red = col SHR 16
END function
function green(col AS UINTEGER) as ubyte
green = col SHR 8
END function
function blue(col AS UINTEGER) as ubyte
blue = col
end function
type _image
buffer as fb.image ptr
thumb as any ptr
w as integer
h as integer
tw as integer
th as integer
end type
const SCR_W = 640
const SCR_H = 480
const SCR_BPP = 32
declare sub imageread_jpg( byval filename as zstring ptr, byval bpp as integer, byref img_object as _image)
screenres SCR_W, SCR_H, SCR_BPP
dim as FB.IMAGE ptr img
dim i1 as _image
dim w as integer
dim h as integer
dim cmd as string = "C:\Dokumente und Einstellungen\User\Desktop\IMG_2950.JPG"
imageread_jpg( cmd, SCR_BPP, i1)
if( i1.buffer = 0 ) then
end 1
end if
'put (0,0), i1.buffer, pset
put (0,0), i1.thumb, pset
sleep
imagedestroy( i1.buffer )
'':::::
sub imageread_jpg( byval filename as zstring ptr, byval bpp as integer, byref img_object as _image)
dim as FILE ptr fp = fopen( filename, "rb" )
if( fp = NULL ) then
img_object.buffer = NULL
exit sub
end if
dim jinfo as jpeg_decompress_struct
jpeg_create_decompress( @jinfo )
dim jerr as jpeg_error_mgr
jinfo.err = jpeg_std_error( @jerr )
jpeg_stdio_src( @jinfo, fp )
jpeg_read_header( @jinfo, TRUE )
jpeg_start_decompress( @jinfo )
dim row as JSAMPARRAY
row = jinfo.mem->alloc_sarray( cast( j_common_ptr, @jinfo ), _
JPOOL_IMAGE, _
jinfo.output_width * jinfo.output_components, _
1 )
'dim img as FB.IMAGE ptr
img_object.buffer = imagecreate( jinfo.output_width, jinfo.output_height )
img_object.w = jinfo.output_width
img_object.h = jinfo.output_height
dim as byte ptr dst = cast( byte ptr, img_object.buffer + 1 )
do while jinfo.output_scanline < jinfo.output_height
jpeg_read_scanlines( @jinfo, row, 1 )
'' !!!FIXME!!! no grayscale support
imageconvertrow( *row, 24, dst, bpp, jinfo.output_width )
dst += img_object.buffer->pitch
loop
jinfo.mem->free_pool( cast( j_common_ptr, @jinfo ), JPOOL_IMAGE )
jpeg_finish_decompress( @jinfo )
jpeg_destroy_decompress( @jinfo )
fclose( fp )
'function = img
dim tx as double
dim ty as double
with img_object
if .w > .h then
.tw = 400
.th = (.tw / .w) * .h
else
.th = 400
.tw = (.th / .h) * .w
end if
.tw = 640
.th = 480
'dim tx as integer
dim t as double
dim s as double
dim sc as double
dim tp as double
dim spx as double = .w / .tw
dim spy as double = .h / .th
dim rx as any ptr = imagecreate(.tw,.h)
dim cr as double
dim cg as double
dim cb as double
.thumb = imagecreate(.tw,.th)
for ty = 0 to .h
s = -1
for tx = 0 to .w step spx
s += 1
cr = 0: cg = 0: cb = 0:sc = 0
for tp = tx to tx + spx
sc +=1
t = point(tp,ty,.buffer)
cr += red(t)
cg += green(t)
cb += blue(t)
next
pset rx,(s,ty), RGB(cr /sc,cg / sc,cb / sc)
next
next
for tx = 0 to .tw
s = -1
for ty = 0 to .h step spy
s += 1
cr = 0: cg = 0: cb = 0:sc = 0
for tp = ty to ty + spy
sc +=1
t = point(tx,tp,rx)
cr += red(t)
cg += green(t)
cb += blue(t)
next
pset .thumb,(tx,s), RGB(cr /sc,cg / sc,cb / sc)
next
next
end with
end sub
|
.thumb enthält noch NICHT die Briefmarke vom bild sondern skaliert es einfach auf Screen-größe. Soll auch erstmal zu testzwecken so sein... |
|