Yeah I was just looking into this last night. I haven't done any timing on it though, or know the frequency of negative numbers being right shifted.
function rdRightShift(num as integer, count = 1 as integer) as integer
if Sgn(num) then
mult = 2 ^ count
summand = 1
total = 0
for i = count to 31
if (num and summand * mult)
total = total + summand
end if
summand = summand * 2
end for
else
total=num/(2^count)
end if
return total
end function
A couple other changes was looking into.
in the createDataChunk instead of looping through the whole bitmap to add the png scanline filter(0) to the start of each scanline, not sure if this is faster or not.
hxstr=pixels.toHexString()
regfind="(.{"+(width*8).toStr()+"})"
r = CreateObject("roRegex",regfind , "")
hxstr=r.ReplaceAll(hxstr, "\100")
hxstr="00"+hxstr.left(hxstr.len()-2)
raw.FromHexString(hxstr)
and in the rdByteArray.brs was experimented with different ways to copy a subset of a bytearray to a new bytearray.
Copy via using a substring
sraw=source.toHexString()
strraw=sraw.Mid( (index_start*2), (index_end-index_start)*2)
dest.FromHexString(strraw)
Copy via a temp file
tmp = rdTempFile(".byt")
print "Byte File "+tmp
source.writefile(tmp,index_start,(index_end-index_start))
dest.readfile(tmp)
DeleteFile(tmp)
Another possibility is to create a palette chunk from the bitmap data if the # of colors is less the 256 and then the actually IDAT chunk would only need to be palette indexes which would reduce the amount of data that is processed by the crc32/adler32/zlib deflate . Also looking into breaking the pixel data up into multiple IDAT chunks section to see if that is any faster but would make the png even larger with some additional book keeping data.
Thanks,
Troy