$screenhide
_screenhide
defint A-Z
declare function e$(b$)
in$ = "data.png"
out$ = "data.dat"
' Load input image into m
screen _loadimage(in$, 32)
sleep 1
dim m as _mem
m = _memimage(0)
indata$ = _deflate$(indata$) ' *** How does indata$ have a value already?
wid = _width
hih = _height
screen 0
open out$ for output as 2
q$ = chr$(34) ' Quotation mark
inFunc$ = left$(in$, len(in$) - 4) ' Input file without extension
' Remove punctuation, except backslash
for i = 32 to 47
if instr(inFunc$, chr$(i)) then
inFunc$ = string.remove(inFunc$, chr$(i))
end if
next i
for i = 58 to 64
if instr(inFunc$, chr$(i)) then
inFunc$ = string.remove(inFunc$, chr$(i))
end if
next i
for i = 91 to 96
if instr(inFunc$, chr$(i)) then
if i <> 92 then
inFunc$ = string.remove(inFunc$, chr$(i))
end if
end if
next i
print #2, "function __" + stripdirectory(inFunc$) + "&"
print #2, "dim v&"
print #2, "dim a$"
print #2, "dim btemp$"
print #2, "dim i&"
print #2, "dim b$"
print #2, "dim c%"
print #2, "dim f$"
print #2, "dim c$"
print #2, "dim j"
print #2, "dim t%"
print #2, "dim b&"
print #2, "dim x$"
print #2, "v& = _newimage("; wid; ", "; hih; ", 32)"
print #2, "dim m as _mem: m = _memimage(v&)"
print #2, "a$ = "; q$; q$
print #2, "a$ = a$ + "; q$;
bc& = 1
do
a$ = mid$(indata$, bc&, 3)
bc& = bc& + 3: ll& = ll& + 4
if ll& = 60 then
ll& = 0
print #2, e$(a$);: print #2, q$
print #2, "a$ = a$ + "; q$;
else
print #2, e$(a$);
end if
if len(indata$) - bc& < 3 then
a$ = mid$(indata$, len(indata$) - bc&, 1): b$ = e$(a$)
select case len(b$)
case 0: a$ = q$
case 1: a$ = "%%%" + b$ + q$
case 2: a$ = "%%" + b$ + q$
case 3: a$ = "%" + b$ + q$
end select: print #2, a$;: exit do
end if
loop: print #2, ""
print #2, "btemp$ = "; q$; q$
print #2, "for i& = 1 to len(a$) step 4: b$ = mid$(a$, i&, 4)"
print #2, "if instr(1, b$, "; q$; "%"; q$; ") then"
print #2, "for c% = 1 to len(b$): f$ = mid$(b$, c%, 1)"
print #2, "if f$ <> "; q$; "%"; q$; " then c$ = c$ + f$"
print #2, "next: b$ = c$: end if: for j = 1 to len(b$)"
print #2, "if mid$(b$, j, 1) = "; q$; "#"; q$; " then"
print #2, "mid$(b$, j) = "; q$; "@"; q$; ": end if: next"
print #2, "for t% = len(b$) to 1 step -1"
print #2, "b& = (b& * 64) + asc(mid$(b$, t%)) - 48"
print #2, "next: x$ = "; q$; q$; ": for t% = 1 to len(b$) - 1"
print #2, "x$ = x$ + chr$(b& and 255): b& = b& \ 256"
print #2, "next: btemp$ = btemp$ + x$: next"
print #2, "btemp$ = _inflate$(btemp$)"
print #2, "_memput m, m.offset, btemp$: _memfree m"
print #2, "__" + inFunc$ + "& = _copyimage(v&): _freeimage v&"
print #2, "end function"
system
function e$(b$)
for t% = len(b$) to 1 step -1
b& = (b& * 256) + asc(mid$(b$, t%))
next t%
a$ = ""
for t% = 1 to len(b$) + 1
g$ = chr$(48 + (b& and 63)): b& = b& \ 64
if g$ = "@" then g$ = "#"
a$ = a$ + g$
next t%: e$ = a$
end function
function stripdirectory$(ofile$)
do
ofile$ = right$(ofile$, len(ofile$) - instr(ofile$, "\"))
loop while instr(ofile$, "\")
stripdirectory$ = ofile$
end function
function string.remove$(a as string, b as string)
dim c as string
c = ""
j = instr(a, b)
if j > 0 then
r$ = left$(a, j - 1) + c + string.remove(right$(a, len(a) - j + 1 - len(b)), b)
else
r$ = a
end if
string.remove = r$
end function