1. Reading and writing files

Dear Euphorians:

Apologies for the spelling of Thermometer. Now I know the "h" is in front of
the first "e".
(In my discharge, I have to say that in  Catalan and Spanish is "Termňmetre"
and "Termómetro", and I cannot remember how is spelled in French, but I
would spell it "Termomętre" as well, without any "h"..).
It will be fixed in the next version of (now) WinTher...

I also promise to get a decent english-speller interfaced to my e-mail
program... (I knew "bound", but I put "binded" -the wrong regular form-
because when thinking on technical issues, the right  side of the brain
takes control over...). Apologies for any unintended misuse of your (for me)
foreign languages.

Going technical: ( grammatical mistakes allowed blink

As a matter of progress, I'm trying to implement a basic bitmap resource
toolkit, based on the crunching routines of Graeme, just to save/recover
crunched bitmaps (to save disk and executable space).

Everything looks fine, but when I save a compressed bitmap and I try to read
it back,  I get a shorter sequence. I'm sure I misunderstand file access, so
I would appreciate some help.

What I do is:

sequence iBmp, oBmp, path

outfile = open("test.gcb", "wb")

path=input("\n\nEnter .BMP path:")
iBmp=read_bitmap(path)
l=length(iBmp[2])*length(iBmp[2][1])
pal=iBmp[1]

oBmp=crunch(iBmp[2])

puts(outfile,oBmp)
close(outfile)

-- and afterwards I try to read it back to iBmp, a differenet sequence to be
able to compare

infile = open("test.gcb", "rb")
iBmp = {}
line = gets(infile)
while  (atom(line)) do
         iBmp = append(iBmp, line)
         line = gets(infile)
end while

-- at this point I've been forced to add the following line, to get the
sequence in the same format:

iBmp = iBmp[1]  -- why?

-- but iBmp is shorter than oBmp. iBmp is at most 99 bytes...
-- What i'm doing wrong?.

Thanks.
Jesus.

new topic     » topic index » view message » categorize

2. Re: Reading and writing files

At 05:04 PM 6/9/98 +0200, Jesus Consuegra wrote:

>Dear Euphorians:
>
>Apologies for the spelling ....

Your English is better than my Spanish (none).


--- LOADING AND SAVING BINARY DATA.

I think you are running into trouble using
puts() and gets() to try to read and write
the whole sequence at once.

puts() also works with integers (fast), and
teams up well with getc()

Try this;


--- code begins ---

sequence bm,data
integer fn,char

bm=read_bitmap("some.BMP")
data=crunch(bm[2])

-- Write
fn=open("test.gcb","wb")
for x = 1 to length(data) do
    puts(fn,data[x])
end for
close(fn)

-- Read
data={}
fn=open("test.gcb","rb")
char=getc(fn)
while char != -1 do
    data=data&char
    char=getc(fn)
end while
close(fn)

display_image({0,0},decrunch(data))

--- code ends ---



If you're still not having any joy,
let me know. The crunch/decrunch
routines are still pretty new, there
could be a bug lurking somewhere, but
I *think* they're OK.

Graeme.

----------------------------------------------------

new topic     » goto parent     » topic index » view message » categorize

3. Re: Reading and writing files

Graeme:
Thanks for the clues.
> fn=open("test.gcb","rb")
(BTW, .gcb means "Graeme Compressed Bitmap").

> I *think* they're OK.
They look fine. I'm getting nice compression ratios for the bitmaps. I'm
also trying the resources from David, so eventually I'll end with
compressed image resources...

Jesús.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu