For Programmers: Free Programming Magazines  


Home > Archive > Fortran > April 2007 > Read a .BMP into Fortran?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Read a .BMP into Fortran?
David.Paterson@csiro.au

2007-03-26, 7:05 pm

I'm using a new Microsoft visual fortran at work and a really old
Compaq Visual Fortran Professional Edition 6.1.0 at home. I'd like to
do this on the Compaq fortran if possible.

I need to read a .BMP or other bitmap file into Fortran to do image
manipulation on it eg. conversion to and from LAB or HSV,
autocorrelation, convolution & deconvolution, edge detection, fft,
discrete and continuous optimisation.

How can I read a bitmap file into Fortran?

>From "USE DFLIB",

LOADIMAGE will read a .bmp and display it to screen
SAVEIMAGE will screendump to a .bmp
but neither will allow the image to be saved and manipulated within
the program.

GETIMAGE will screendump to a buffer but I've no idea what format the
buffer is in or whether it can be used. Can I use the buffer?

Perhaps I can use "USE DFOPNGL", but how?

gary.l.scott@lmco.com

2007-03-26, 7:05 pm

On Mar 26, 5:32 pm, David.Pater...@csiro.au wrote:
> I'm using a new Microsoft visual fortran at work and a really old
> Compaq Visual Fortran Professional Edition 6.1.0 at home. I'd like to
> do this on the Compaq fortran if possible.
>
> I need to read a .BMP or other bitmap file into Fortran to do image
> manipulation on it eg. conversion to and from LAB or HSV,
> autocorrelation, convolution & deconvolution, edge detection, fft,
> discrete and continuous optimisation.
>
> How can I read a bitmap file into Fortran?
>
>
> LOADIMAGE will read a .bmp and display it to screen
> SAVEIMAGE will screendump to a .bmp
> but neither will allow the image to be saved and manipulated within
> the program.
>
> GETIMAGE will screendump to a buffer but I've no idea what format the
> buffer is in or whether it can be used. Can I use the buffer?
>
> Perhaps I can use "USE DFOPNGL", but how?


You need to locate the bmp file format and craft derived types
suitable for reading the bmp file content. You'll probably want to
use the "binary" file I/O capability. Method is (or can be) the same
whether MS FPS (there was no MS Visual Fortran) or CVF (or IVF). You
don't technically need any OS APIs to read in the raw data (assuming
you want to perform the above transformations yourself).

e p chandler

2007-03-26, 7:05 pm

On Mar 26, 6:38 pm, gary.l.sc...@lmco.com wrote:
> On Mar 26, 5:32 pm, David.Pater...@csiro.au wrote:
>
>
>
>
>
>
>
>
>
>
>
>
> You need to locate the bmp file format and craft derived types
> suitable for reading the bmp file content. You'll probably want to
> use the "binary" file I/O capability. Method is (or can be) the same
> whether MS FPS (there was no MS Visual Fortran) or CVF (or IVF). You
> don't technically need any OS APIs to read in the raw data (assuming
> you want to perform the above transformations yourself).- Hide quoted text -
>
> - Show quoted text -


A newsgroup search seems to indicate the DISLIN has facilities to R/
W .bmp files and interconvert to RGB. HTH


David.Paterson@csiro.au

2007-03-26, 10:07 pm

> locate the bmp file format

Code for reading .bmp files in C use a "struct" containing "unsigned
short" and "unsigned int" data types. How do these translate into
Fortran? If the .bmp is compressed then it becomes more difficult.

> DISLIN


I've downloaded it now. I'll unzip it in a minute.

Gary Scott

2007-03-26, 10:07 pm

David.Paterson@csiro.au wrote:

>
>
> Code for reading .bmp files in C use a "struct" containing "unsigned
> short" and "unsigned int" data types. How do these translate into
> Fortran? If the .bmp is compressed then it becomes more difficult.


read them into signed integers of the same length (same number of bytes
or bits). works just fine. do it all the time. With CVF/IVF a derived
type can be made interoperable with a c struct.

>
>
>
>
> I've downloaded it now. I'll unzip it in a minute.
>



--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
Edward N Bromhead

2007-03-31, 7:03 pm


<David.Paterson@csiro.au> wrote in message
news:1174948368.428119.172170@e65g2000hsc.googlegroups.com...
> I'm using a new Microsoft visual fortran at work and a really old
> Compaq Visual Fortran Professional Edition 6.1.0 at home. I'd like to
> do this on the Compaq fortran if possible.
>
> I need to read a .BMP or other bitmap file into Fortran to do image
> manipulation on it eg. conversion to and from LAB or HSV,
> autocorrelation, convolution & deconvolution, edge detection, fft,
> discrete and continuous optimisation.


You seem to be using a Windows platform. Both MS visual fortran and the
compaq fortran are now rather old.
You can download a free personal edition version of the salford/silverfrost
FTN95 from www.silverfrost.com.
It appears that various graphics file formats (not just BMP, but JPEG and
possibly others) can be read into
a "device independent bitmap" format (essentially an array) and processed
from there. You can at least try it
(for free) and see if it works for you. I suspect that the advantage of
importing and converting to the DIB format
is that you can import various other graphics formats and process them all
using the same code.
I'd be prepared to bet that other up-to-date fortrans offer similar
facilities, although I only know this one, and can
vouch that it will do what you want without any add-ons. The DIB and BMP
formats are written up on the
MSDN website.

EB


cup

2007-03-31, 7:10 pm

A bmp is just a binary file. Just open it as an unformatted file and read it normally. The structure of the bmp is specified in Microsoft documentation - keeps on shifting so you'll have to look on the MS site.

The things that you need to note are

1) There are about 5 bmp formats
2) Not all packages will handle the 32-bit format
3) bmps are stored upside down. The bottom most line appears first
4) each line of the bmp may be padded to some multiple of 2. If when printing, you find your image drifting, go up to the next multiple of 2.
rrr7rrr@gmail.com

2007-04-01, 4:07 am

On Mar 31, 4:55 am, "Edward N Bromhead"
> I only know this one, and can
> vouch that it will do what you want without any add-ons.
>


Yes, I also confirm, this works fine. The compiler has help file and
very effective examples how to read, write, covert, manipulate in
fortran and display bitmaps

Lane Straatman

2007-04-01, 7:04 pm


<rrr7rrr@gmail.com> wrote in message
news:1175417087.381162.35440@b75g2000hsg.googlegroups.com...
> On Mar 31, 4:55 am, "Edward N Bromhead"
>
> Yes, I also confirm, this works fine. The compiler has help file and
> very effective examples how to read, write, [convert], manipulate in
> fortran and display bitmaps

Can you give more detail on this? I use silverfrost's IDE and have not
found any of the visual knink-knacks that I used to have with MS Visual
Studio.
--
LS


rrr7rrr@gmail.com

2007-04-04, 8:05 am

On Apr 1, 1:09 pm, "Lane Straatman" <inva...@invalid.net> wrote:
> <rrr7...@gmail.com> wrote in message
>
> news:1175417087.381162.35440@b75g2000hsg.googlegroups.com...> On Mar 31, 4:55 am, "Edward N Bromhead"
>
>
> Can you give more detail on this? I use silverfrost's IDE and have not
> found any of the visual knink-knacks that I used to have with MS Visual
> Studio.
> --
> LS


Send me message with your email and I will try to prepare some
relatively small programs as a prototypes.

Some things like image scalings, comparison, distortions, animations,
highlighting part of screen with mouse, cut, paste and save in
several
graphics formats etc are hard already to extract out of my code...
I am very happy with that my application-oriented little personal
"Photoshop" and find this very convenient

David.Paterson@csiro.au

2007-04-23, 10:04 pm

> How can I read a bitmap file into Fortran?

The following Fortran code fragment will read a 24 bit .bmp file. On
my compiler I also need the switch "/assume:byterecl"

integer Maxwidth,Maxheight,irec,iwidth,iheight,i
,j,ipad
parameter(Maxwidth=3220,Maxheight=2415)
character header(54),ch
integer image(Maxheight,Maxwidth,3)

open(1,file='..\..
\cow_small. bmp',form='unformatted',access='direct',
recl=1)

do irec=1,54
read(1,rec=irec) header(irec)
end do

if(ichar(header(11)).ne.54.or.ichar(header(29)).ne.
24.or.ichar(header(31)).ne.0) then
print*,'sorry, can not handle this file'
end if

! get image height and width
iheight=ichar(header(23))+256*(ichar(hea
der(24))
+256*(ichar(header(25))+256*ichar(header
(26))))
iwidth=ichar(header(19))+256*(ichar(head
er(20))
+256*(ichar(header(21))+256*ichar(header
(22))))
print*,'iheight,iwidth=',iheight,iwidth

ipad=(Maxwidth-iwidth)-((Maxwidth-iwidth)/4)*4
irec=54
do i=1,iheight
do j=1,iwidth
irec=irec+1
read(1,rec=irec) ch
image(i,j,3)=ichar(ch)
irec=irec+1
read(1,rec=irec) ch
image(i,j,2)=ichar(ch)
irec=irec+1
read(1,rec=irec) ch
image(i,j,1)=ichar(ch)
end do
irec=irec+ipad
end do

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com