У меня долго ничего не происходит, далее таймаут. Потом буду разбираться.
Библиотека PPM ридера
Код программы:
Библиотека PPM ридера
Код: Выделить всё
// PPM reader
// To Yabasic by Galileo, 04/2018
export sub readPPM(f$)
local ff, x, y, t$, dcol$, wid, hei
if f$ = "" print "No PPM file name indicate." : return false
ff = open (f$, "rb")
if not ff print "File ", f$, " not found." : return false
input #ff t$, wid, hei, dcol$
if t$ = "P6" then
open window wid, hei
for x = 0 to hei - 1
for y = 0 to wid - 1
color peek(#ff), peek(#ff), peek(#ff)
dot y, x
next y
next x
close #ff
else
print "File is NOT PPM P6 type." : return false
end if
return true
end sub
Код: Выделить всё
// Bitmap Histogram
// Ported from Phix to Yabasic by Galileo, 04/2018
import ReadFromPPM2
sub to_bw()
local lum, hist(256), li, ri, ltot, rtot, wid, hei, i, j, r, g, b, p$, image(1, 1)
li = 1 : ri = 256
wid = peek("winwidth") : hei = peek("winheight")
redim image(wid, hei)
print "Wait a moment, please ..."
for i = 1 to wid
for j = 1 to hei
p$ = getbit$(i, j, i, j) : p$ = right$(p$, 6)
r = and(dec(left$(p$, 2)), 255)
g = and(dec(mid$(p$, 3, 2)), 255)
b = and(dec(right$(p$, 2)), 255)
lum = int(0.2126 * r + 0.7152 * g + 0.0722 * b)
image(i, j) = lum
hist(lum + 1) = hist(lum + 1) + 1
next j
next i
ltot = hist(li)
rtot = hist(ri)
while(li <> ri)
if ltot < rtot then
li = li + 1
ltot = ltot + hist(li)
else
ri = ri - 1
rtot = rtot + hist(ri)
end if
wend
lum = li
for i = 1 to wid
for j = 1 to hei
if image(i, j) < lum then
color 0, 0, 0
else
color 255, 255, 255
end if
dot i, j
next j
next i
end sub
readPPM("lena.ppm")
to_bw()