Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-09

BLOCKWRITE-restrictions in writing .bmp-file?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Arjan van Dijk

Hi!

About 1 year ago, I had this excellently working UNIT of bitmap-picture handling routines.
Today I wanted to use them again, but the result is crappy. I was wondering if this can have something to do with BLOCKWRITE-restrictions in the new version of FPC.

I have 2 routines for writing gridded variables to bitmap picture files:

- one that uses 1 byte per pixel (=256 colours)
Here the definition of the colours is written first, then all pixels are written as index to the defined palette.
This routine still works.

- and one that takes 3 bytes per colour. Each byte gives R, G or B. No palette is written.
This is the type of bmp that I want to use for combining pictures. This is the one that refuses to give anything decent today!

The relevant part of code is:

.........write the header .......

FOR j := 1 TO NGridY DO
BEGIN
      FOR i := 1 TO NGridX DO
      BEGIN

........relate the gridded variable in this point to R, G and B values........

        BLOCKWRITE(OutFile,PixelB,SIZEOF(PixelB));
        BLOCKWRITE(OutFile,PixelG,SIZEOF(PixelG));
        BLOCKWRITE(OutFile,PixelR,SIZEOF(PixelR));
      END;

{ Fill line with dummy-data, since .bmp requires N-bytes divisible by 4 points on 1 line }

      NDum := 3*NGridX;
      IF (((NDum    ) MOD 4)0) THEN
BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel));
      IF (((NDum + 1) MOD 4)0) THEN
BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel));
      IF (((NDum + 2) MOD 4)0) THEN
BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel));
END;

Could it be that with the new compiler (like I found out with FORTRAN...) BLOCKWRITE requires
a MINIMUM set of bytes to write for it to work? In my code each BLOCKWRITE writes only 1 byte.

I am using Version 1.0.10 2008/08/03 of the IDE on Windows XP (SP2) Compiler version 2.2.2, precompiled binary.

Suggestions welcome!

Thanks!

Arjan

____________________________________________________________________________

DISCLAIMER: http://www.rivm.nl/disclaimer.htm

Reply by email

Пётр Косаревский
to Arjan van Dijk
Show quoted text 6 lines
IF (((NDum ) MOD 4)0) THEN BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel)); IF (((NDum + 1) MOD 4)0) THEN BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel)); IF (((NDum + 2) MOD 4)0) THEN BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel));

1. If NDum = 4k (e.g. 12=4*3), you write two times; if NDum = 4k + 3 (e.g. 15=5*3), you write two times. It's not right.

2. Check sizeof-s. Are you sure they are one byte each?

3. Are you sure the code worked good before?

Reply by email

Arjan van Dijk
to Пётр Косаревский
Show quoted text 13 lines
> IF (((NDum ) MOD 4)0) THEN > BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel)); > IF (((NDum + 1) MOD 4)0) THEN > BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel)); > IF (((NDum + 2) MOD 4)0) THEN > BLOCKWRITE(OutFile,Pixel,SIZEOF(Pixel)); 1. If NDum = 4k (e.g. 12=4*3), you write two times; if NDum = 4k + 3 (e.g. 15=5*3), you write two times. It's not right. 2. Check sizeof-s. Are you sure they are one byte each? 3. Are you sure the code worked good before?

I modified the code a bit to make it better readable, but, as you remarked, with an error
in the padding of the line! I'll recheck my original code and come back. Thanks!

A.

Reply by email