Bitmap/Fortran: Difference between revisions
m
Fixed syntax highlighting.
(rewrote everything. just one type using type-bound procedures) |
m (Fixed syntax highlighting.) |
||
(One intermediate revision by one other user not shown) | |||
Line 2:
{{works with|Fortran|90 and later}}
<
implicit none
Line 27:
!! k=1: red, k=2: green, k=3: blue
integer ::
!! image dimensions: [height, width]
Line 51:
integer, intent(in) :: height, width
this%
allocate (this%rgb(height,width,3), source=0)
end subroutine
Line 64:
! always check that dimensions match
rgbimage_valid = ( all(this%
& (size(this%rgb, dim=1) == this%
& (size(this%rgb, dim=2) == this%
& (size(this%rgb, dim=3) == 3)
! optionally: check if rgb values are in allowed range
Line 85:
integer, intent(in) :: x, y
rgbimage_inside = ((x > 0) .and. (x <= this%
end function
Line 162:
! write header
write (iounit, '(A)') 'P6'
write (iounit, '(I0, A, I0)') this%
write (iounit, '(A)') '255'
do i = 1, this%
do j = 1, this%
write (iounit, '(3A1)', advance='no') [(achar(this%rgb(i,j,k)), k=1,3)]
end do
Line 175:
end subroutine
end module</
|