Thanks to you all for the pointers, that was a big help, was losing my mind for a minute there. Got it working using callocate now and everything is sweet. OK here is the code to load and display a 32bit Uncompressed tga file with per pixel alpha information..... Also please note it doesn't check if something is drawn off the edges of the screen so dont do it as that will be an issue.
Other than that if its of any use to you please free to use it. And of course any comments / critique are welcome....
I've also included the source and an image to use in a zip file at the end.......
'TGA image file loader (Supports Alpha)
#include once "tinyptc.bi"
screenres 640, 480, 32
if(ptc_open("TGA Test", 640, 480)) = 0 then end
dim shared as integer scr_buffer(640 * 480)
declare function load_image(f_name as string)
declare function draw_image(src_buffer as integer ptr, x_pos, y_pos)
declare function clear_screen()
dim my_img as integer ptr
my_img = load_image("test.tga")
dim angle as single
dim offset as single
angle = 250
while inkey$ = ""
clear_screen()
offset = 0
for i = 0 to 14
sprite_x = (320 - 32) + sin((angle - offset) / 1.7) * 200
sprite_y = (240 - 32) + cos(angle - offset) * 160
draw_image(my_img, sprite_x, sprite_y)
offset -= .3
next i
angle += .03
screensync
ptc_update @scr_buffer(0)
wend
deallocate(my_img)
ptc_close()
end
function clear_screen()
counter = 0
for i = 0 to 640 * 480 - 1
scr_buffer(i) = rgb(0, 0, 200)
next i
end function
function draw_image(src_buffer as integer ptr, x_pos, y_pos)
i = 2
for y = src_buffer[0] to 0 step -1
for x = 0 to src_buffer[1]
buffer_pos = (x_pos + x) + (y_pos + y) * 640
sr = scr_buffer(buffer_pos) shr 16 and &hff
sg = scr_buffer(buffer_pos) shr 8 and &hff
sb = scr_buffer(buffer_pos) and &hff
ir = src_buffer[i] shr 24 and &hff
ig = src_buffer[i] shr 16 and &hff
ib = src_buffer[i] shr 8 and &hff
ia = src_buffer[i + 1] and &hff
dr = (ia * (ir - sr)) shr 8 + sr and &hff
dg = (ia * (ig - sg)) shr 8 + sg and &hff
db = (ia * (ib - sb)) shr 8 + sb and &hff
scr_buffer(buffer_pos) = rgb(dr, dg, db)
i += 1
next x
next y
end function
function load_image(f_name as string)
dim img_width_lo_byte as byte
dim img_width_hi_byte as byte
dim img_height_lo_byte as byte
dim img_height_hi_byte as byte
dim img_width as short
dim img_height as short
dim img_bit as integer
#f = freefile
open f_name for binary as #f
get #f, 12, img_width_hi_byte 'and &hff
get #f, 13, img_width_lo_byte 'and &hff
get #f, 14, img_height_hi_byte' and &hff
get #f, 15, img_height_lo_byte 'and &hff
img_width = img_width_hi_byte shl 1 or img_width_lo_byte
img_height = img_height_hi_byte shl 1 or img_height_lo_byte
dim img_array as integer ptr
img_array = callocate(len(integer) * (img_width * img_height) + 3)
img_array[0] = img_width - 1
img_array[1] = img_height - 1
for i = 0 to img_width * img_height
get #f, 18 + i shl 2, img_array[i + 2]
next i
close #f
return img_array
end function