add pixrgb support

This commit is contained in:
tTh
2022-12-16 19:26:54 +01:00
parent c55a7460e0
commit fc03c70454
7 changed files with 93 additions and 264 deletions

2
Modules/.gitignore vendored
View File

@@ -2,4 +2,6 @@
chkpixels
*.pgm
*.pnm
*.png

View File

@@ -4,21 +4,26 @@
# Makefile for the general purpose moduls
#
GFOPT = -Wall -Wextra -time -g
GFOPT = -Wall -Wextra -time -g
all: chkpixels
# -----------------------------------------------
spitpgm.o: spitpgm.f90 Makefile
gfortran $(GFOPT) -c $< -o $@
pixrgb.o: pixrgb.f90 Makefile
gfortran $(GFOPT) -c $< -o $@
trials.o: trials.f90 Makefile
gfortran $(GFOPT) -c $< -o $@
#
# programmes de testouille
#
OBJS = trials.o spitpgm.o pixrgb.o
chkpixels: chkpixels.f90 Makefile trials.o spitpgm.o
gfortran $(GFOPT) $< spitpgm.o trials.o -o $@
chkpixels: chkpixels.f90 Makefile $(OBJS)
gfortran $(GFOPT) $< $(OBJS) -o $@

View File

@@ -3,20 +3,50 @@
program chkpixels
use spitpgm ! main module
use trials ! experiments, ymmv.
use spitpgm
use pixrgb
use trials ! experiments, ymmv.
implicit none
write(0, *) "------ CHKPIXELS ------"
call test_alpha(3)
! call test_spit_as(3)
call test_spit_rgb(256)
STOP 'BECAUSE NO CPU AVAILABLE'
contains
!-------------------------------------------------------------------
!-
subroutine test_alpha(increment)
subroutine test_spit_rgb(sz)
integer, intent(in) :: sz
type(t_pixrgb), allocatable :: pixrgb(:,:)
integer :: ix, iy
print *, "test spit rgb", sz
allocate(pixrgb(sz, sz))
! pixrgb = 0
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(pixrgb, "rgb.pnm")
deallocate(pixrgb)
end subroutine
!-------------------------------------------------------------------
!-
subroutine test_spit_as(increment)
integer, intent(in) :: increment
integer, parameter :: SZ = 40

42
Modules/pixrgb.f90 Normal file
View File

@@ -0,0 +1,42 @@
!-
! This module try to write PGM complient gray level files
!-
module pixrgb
implicit none
!-----------------------------------------------------------------------
!-
! definition of structures
!-
type t_pixrgb
integer :: r, g, b
integer :: alpha = 0
end type
!-------------------------------------------------------------------
contains
!-------------------------------------------------------------------
!-
subroutine rgbpix_spit_as_pnm(pic, fname)
type(t_pixrgb), intent(in) :: pic(:,:)
character (len=*), intent(in) :: fname
integer :: io, ix, iy
open(newunit=io, file=fname)
write (io, '(a2)') "P3"
write (io, '("# spit_rgb_pnm")')
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, "(3I7)") pic(ix, iy)%r, pic(ix, iy)%g, pic(ix, iy)%b
enddo
enddo
close(unit=io)
end subroutine
!-------------------------------------------------------------------
end module

View File

@@ -1,5 +1,5 @@
!-
! This module try to write PNM complient files - ymmv
! This module try to write PGM complient gray level files
!-
module spitpgm

View File

@@ -4,7 +4,13 @@
module trials
implicit none
!-----------------------------------------------------------------------
!-------------------------------------------------------------------
contains
!-----------------------------------------------------------------------
!-
!-------------------------------------------------------------------
subroutine new_spit_a(pic, fname)