Bitmap/Fortran: Difference between revisions

overwrote dim. now uses variable name: n
(rewrote everything. just one type using type-bound procedures)
(overwrote dim. now uses variable name: n)
Line 27:
!! k=1: red, k=2: green, k=3: blue
 
integer :: dimn(2) = 0
!! image dimensions: [height, width]
 
Line 51:
integer, intent(in) :: height, width
 
this%dimn = [height, width]
allocate (this%rgb(height,width,3), source=0)
end subroutine
Line 64:
 
! always check that dimensions match
rgbimage_valid = ( all(this%dimn > 0) .and. &
& (size(this%rgb, dim=1) == this%dimn(1)) .and. &
& (size(this%rgb, dim=2) == this%dimn(2)) .and. &
& (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%dimn(1)) .and. (y > 0) .and. (y <= this%dimn(2)))
end function
 
Line 162:
! write header
write (iounit, '(A)') 'P6'
write (iounit, '(I0, A, I0)') this%dimn(1), " ", this%dimn(2)
write (iounit, '(A)') '255'
 
do i = 1, this%dimn(1)
do j = 1, this%dimn(2)
write (iounit, '(3A1)', advance='no') [(achar(this%rgb(i,j,k)), k=1,3)]
end do
Anonymous user