1. new Win32Lib-version + Win32Dib
Derek, when can we expect the new Win32Lib? I want to know, because I want
Win32Dib 0.5.1 (next version) to be fully compatible with the new Win32Lib, and
to use the new subClassControl.
One thing I've implemented in the next version of Win32Dib is the function
saveDibReduced, which saves a bitmap as a 8-bit color BMP-file. For those who
already want to use that function in Win32Dib 0.5.0: add the following code to
w32dcore.ew (preferably after saveDibGray: line 350).
global function saveDibReduced(sequence dib, sequence fileName, integer x1,
integer y1, integer x2, integer y2)
-- Saves a portion ((x1, y1) -> (x2, y2)) of the bitmap to an 8-bit BMP-file
(uses websafe palette).
integer fn, cx, cy, width, height, bytes, index, padding
atom memory
sequence line, color
width = dib[DibWidth]
height = dib[DibHeight]
if x1 < 0 then x1 = 0 elsif x1 >= width then x1 = width - 1 end if -- make sure
x1 is within boundaries
if x2 < 0 then x2 = 0 elsif x2 >= width then x2 = width - 1 end if -- make sure
x2 is within boundaries
if x2 < x1 then -- swap x1 and x2 if x2 < x1
cx = x2
x2 = x1
x1 = cx
elsif x1 = x2 then -- empty region
return 1
end if
cx = x2 - x1 + 1 -- the width of the region
if y1 < 0 then y1 = 0 elsif y1 >= height then y1 = height - 1 end if -- make
sure y1 is within boundaries
if y2 < 0 then y2 = 0 elsif y2 >= height then y2 = height - 1 end if -- make
sure y2 is within boundaries
if y2 < y1 then -- swap y1 and y2 if y2 < y1
cy = y2
y2 = y1
y1 = cy
elsif y1 = y2 then -- empty region
return 1
end if
cy = y2 - y1 + 1 -- the height of the region
fn = open(fileName, "wb") -- open the file for writing
if fn = -1 then return 1 end if
padding = floor((cx + 3)/4) * 4 - cx
puts(fn, "BM" & int_to_bytes(54 + cy * (cx + padding))
& {0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, 0}
& int_to_bytes(cx) & int_to_bytes(cy)
& {1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 11, 0, 0, 64, 11, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0})
-- write the bitmap-header
for i = 0 to 255 by 51 do
for j = 0 to 255 by 51 do
for k = 0 to 255 by 51 do
puts(fn, {i, j, k, 0})
end for
end for
end for
puts(fn, repeat(0, 156))
bytes = dib[DibBytesPerLine]
line = repeat(0, cx + padding)
cx *= 3
memory = dib[DibMemory] + 3 * x1 + y2 * bytes -- reading starts at (x1, y2):
bottom to top
for i = 1 to cy do
index = 1
for j = memory to memory + cx - 3 by 3 do
color = peek({j, 3})
line[index] = (floor(color[1] / 51 + 0.5) * 6 + floor(color[2] / 51 + 0.5)) *
6 + floor(color[3] / 51 + 0.5)
index += 1
end for
puts(fn, line)
memory -= bytes
end for
close(fn) -- close the file
return 0
end function
--
tommy online: http://users.pandora.be/tommycarlier
2. Re: new Win32Lib-version + Win32Dib
The first line of code should have been:
global function saveDibReduced(sequence dib, sequence fileName, integer x1,
integer y1, integer x2, integer y2)
instead of
global function saveDibReduced(sequence dib, sequence fileName, integer x1,
integer
Didn't come through right.
--
tommy online: http://users.pandora.be/tommycarlier