From 8ea11d110b0a89ae3a876ecebac990468ef3d27a Mon Sep 17 00:00:00 2001 From: tTh Date: Sat, 24 Dec 2022 22:13:17 +0100 Subject: [PATCH] cleanup + add a 0 func --- Modules/chkpixels.f90 | 11 +++-------- Modules/pixrgb.f90 | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Modules/chkpixels.f90 b/Modules/chkpixels.f90 index 525a944..f2df981 100644 --- a/Modules/chkpixels.f90 +++ b/Modules/chkpixels.f90 @@ -18,6 +18,8 @@ program chkpixels contains !------------------------------------------------------------------- +!- +! exerciser for the 'pixrgb' module !- subroutine test_spit_rgb(sz) integer, intent(in) :: sz @@ -27,20 +29,15 @@ contains print *, "test spit rgb", sz allocate(pixrgb(sz, sz)) - ! pixrgb = 0 - + call rgbpix_set_to_zero(pixrgb) do ix=1, sz do iy=1, sz - pixrgb(ix, iy)%r = ix pixrgb(ix, iy)%g = 0 pixrgb(ix, iy)%b = iy - end do end do - call rgbpix_spit_as_pnm_8(pixrgb, "rgb.pnm") - deallocate(pixrgb) end subroutine @@ -60,12 +57,10 @@ contains value = value + increment enddo enddo - call spit_as_pgm_16 (greymap, 'a.pgm') call spit_as_pgm_eq (greymap, 'b.pgm') call spit_as_pgm_8 (greymap, 'c.pgm') call new_spit_a (greymap, 'x.pgm') - end subroutine end program diff --git a/Modules/pixrgb.f90 b/Modules/pixrgb.f90 index 719977f..499fb9c 100644 --- a/Modules/pixrgb.f90 +++ b/Modules/pixrgb.f90 @@ -15,8 +15,20 @@ end type contains !------------------------------------------------------------------- !- +subroutine rgbpix_set_to_zero(pic) + type(t_pixrgb), intent(out) :: pic(:,:) + integer :: ix, iy + do iy=1, ubound(pic, 2) + do ix=1, ubound(pic, 1) + pic(ix, iy)%r = 0 + pic(ix, iy)%g = 0 + pic(ix, iy)%b = 0 + enddo + enddo +end subroutine +!------------------------------------------------------------------- +!- subroutine rgbpix_spit_as_pnm_8(pic, fname) - type(t_pixrgb), intent(in) :: pic(:,:) character (len=*), intent(in) :: fname @@ -25,14 +37,12 @@ subroutine rgbpix_spit_as_pnm_8(pic, fname) open(newunit=io, file=fname) write (io, '(a2)') "P3" write (io, '("# rgbpix_spit_as_pnm_8")') - write (io, '(i0," ",i0)') size(pic, 1), size(pic, 2) + write (io, '(i0," ",i0)') size(pic, 1), size(pic, 2) write (io, '(i0)') 255 do iy=1, ubound(pic, 2) do ix=1, ubound(pic, 1) - - write(io, "(3I4)") pic(ix, iy)%r, pic(ix, iy)%g, pic(ix, iy)%b - + write(io, "(3I12)") pic(ix, iy)%r, pic(ix, iy)%g, pic(ix, iy)%b enddo enddo close(unit=io) @@ -55,9 +65,7 @@ subroutine rgbpix_spit_as_pnm_16(pic, fname) do iy=1, ubound(pic, 2) do ix=1, ubound(pic, 1) - - write(io, "(3I6)") pic(ix, iy)%r, pic(ix, iy)%g, pic(ix, iy)%b - + write(io, "(3I6)") pic(ix, iy)%r, pic(ix, iy)%g, pic(ix, iy)%b enddo enddo close(unit=io)