Bitmap/Write a PPM file: Difference between revisions

→‎{{header|Fortran}}: rewrote rgbimage module
(+Stata)
(→‎{{header|Fortran}}: rewrote rgbimage module)
Line 427:
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
It loads <code>RCImageBasicrgbimage_m</code> module, which is defined [[Basic bitmap storage#Fortran|here]].
<lang fortran>moduleprogram RCImageIOmain
 
use RCImageBasic
use rgbimage_m
 
implicit none
 
integer :: nx, ny, i, j, k
contains
 
type(rgbimage), intent(in) :: imgim
subroutine output_ppm(u, img)
integer, intent(in) :: u
type(rgbimage), intent(in) :: img
integer :: i, j
 
! init image of height nx, width ny
write(u, '(A2)') 'P6'
nx = 400
write(u, '(I0,'' '',I0)') img%width, img%height
ny = 300
write(u, '(A)') '255'
call im%init(nx, ny)
 
do j=1, img%height
! set some random pixel data
do i=1, img%width
do i = 1, nx
write(u, '(3A1)', advance='no') achar(img%red(i,j)), achar(img%green(i,j)), &
do j = 1, img%heightny
achar(img%blue(i,j))
call im%set_pixel(i, j, [(nint(rand()*255), k=1,3)])
end do
end do
end do
 
! output image into file
call im%write('fig.ppm')
 
end module RCImageIOprogram</lang>
end subroutine output_ppm
 
end module RCImageIO</lang>
=={{header|GAP}}==
<lang gap># Dirty implementation
Anonymous user