This type is designed to store and manipulate PNM (Portable Any Map) image files.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=ik), | public, | dimension(:,:), allocatable | :: | pixels |
Pixel values of the image. |
||
character(len=:), | private, | allocatable | :: | comment |
Optional comment associated with the image. |
||
character(len=6), | private | :: | encoding |
Encoding of the PNM image ( |
|||
character(len=3), | private | :: | file_format |
File format of the PNM image ( |
|||
integer, | private | :: | height |
Height (number of rows) of the image. |
|||
character(len=2), | private | :: | magic_number |
Magic number representing the PNM image type ( |
|||
integer, | private | :: | max_color |
Maximum color value of the image. Used for PGM and PPM images. |
|||
integer, | private | :: | width |
Width (number of columns) of the image. |
Adjust the brightness and darkness of the image.
Brightens or darkens the image. Only supported for PGM and PPM images.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | factor |
Crop the image to a specified region.
Crops the image to a specified region.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | start_row | |||
integer, | intent(in) | :: | end_row | |||
integer, | intent(in) | :: | start_col | |||
integer, | intent(in) | :: | end_col |
Write an image to a file.
Writes the PNM image to a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | file_name | |||
character(len=*), | intent(in), | optional | :: | encoding |
Clean up allocated memory for the PNM image.
Deallocates memory for the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this |
Flip the image horizontally.
Flips the image horizontally.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this |
Flip the image vertically.
Flips the image vertically.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this |
Get the encoding of the PNM image.
Gets the encoding of the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(in) | :: | this |
Convert a color image to greyscale.
Converts a color image to greyscale. Only supported for PPM images.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this |
Read an image from a file.
Reads a PNM image from a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | file_name | |||
character(len=3), | intent(in) | :: | file_format | |||
character(len=*), | intent(in) | :: | encoding |
Invert the colors of the image.
Inverts the colors of the image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this |
Display information about the image (dimensions, aspect ratio, etc.).
Displays information about the image e.g. dimensions, aspect ratio, etc.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(in) | :: | this |
Remove one or more RGB channels from the image.
Removes one or more RGB channels from the image. Only supported for PPM images.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
logical, | intent(in), | optional | :: | remove_r | ||
logical, | intent(in), | optional | :: | remove_g | ||
logical, | intent(in), | optional | :: | remove_b |
Resize the image to a specified size.
Resizes the image to specified dimensions.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | new_height | |||
integer, | intent(in) | :: | new_width |
Rotate the image by a specified angle.
Rotates the image by a specified angle. Supported angles are 90, 180, 270, -90, -180, -270.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | angle |
Set the encoding of the PNM image.
Sets the encoding of the PNM image. Supported values are ascii
or plain
and binary
or raw
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | encoding |
Set the attributes of the PNM image.
Sets the attributes of the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | encoding | |||
character(len=3), | intent(in) | :: | file_format | |||
integer, | intent(in) | :: | width | |||
integer, | intent(in) | :: | height | |||
integer, | intent(in), | optional | :: | max_color | ||
character(len=*), | intent(in) | :: | comment | |||
integer(kind=ik), | intent(in), | dimension(:,:) | :: | pixels |
Swap the RGB channels of the image.
Swaps the RGB channels of the image. Only supported for PPM images.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | swap |
Allocate memory for the pixels of the PNM image.
Allocates memory for the pixels of the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this |
Check if the pixel values are within the valid range.
Checks if the pixel values are within the valid range.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer(kind=ik), | intent(in), | dimension(:,:) | :: | pixels |
Set a comment for the PNM image.
Sets a comment for the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | comment |
Set the file format of the PNM image.
Sets the file format of the PNM image. Supported values are pbm
, pgm
, and ppm
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=3), | intent(in) | :: | file_format |
Set the header of the PNM image.
Sets the header of the PNM image. The header includes the magic number, width, height, comment, and max_color.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | magic_number | |||
integer, | intent(in) | :: | width | |||
integer, | intent(in) | :: | height | |||
character(len=*), | intent(in) | :: | comment | |||
integer, | intent(in), | optional | :: | max_color |
Set the height of the PNM image.
Sets the height of the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | height |
Set the magic number of the PNM image.
Sets the magic number of the PNM image. Supported values are P1
, P2
, P3
, P4
, P5
, and P6
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
character(len=*), | intent(in) | :: | magic_number |
Set the maximum color value of the PNM image.
Sets the maximum color value of the PNM image. Only required for PGM and PPM images
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | max_color |
Set the pixel values of the PNM image.
Sets the pixel values of the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer(kind=ik), | intent(in), | dimension(:,:) | :: | pixels |
Set the width of the PNM image.
Sets the width of the PNM image.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | width |
type format_pnm character(2) , private :: magic_number !! Magic number representing the PNM image type (`P1`, `P2`, `P3`, `P4`, `P5`, `P6`). integer , private :: width !! Width (number of columns) of the image. integer , private :: height !! Height (number of rows) of the image. character(:), allocatable , private :: comment !! Optional comment associated with the image. integer , private :: max_color !! Maximum color value of the image. Used for PGM and PPM images. integer(ik), dimension(:,:), allocatable :: pixels !! Pixel values of the image. character(3) , private :: file_format !! File format of the PNM image (`pbm`, `pgm`, `ppm`). character(6) , private :: encoding !! Encoding of the PNM image (`ascii` or `plain`, `binary` or `raw`). contains ! Procedures for setting individual attributes procedure :: set_format !!> Set the encoding of the PNM image. procedure, private :: set_file_format !!> Set the file format of the PNM image. procedure, private :: set_magicnumber !!> Set the magic number of the PNM image. procedure, private :: set_width !!> Set the width of the PNM image. procedure, private :: set_height !!> Set the height of the PNM image. procedure, private :: set_comment !!> Set a comment for the PNM image. procedure, private :: set_max_color !!> Set the maximum color value of the PNM image. procedure, private :: set_header !!> Set the header of the PNM image. procedure, private :: allocate_pixels !!> Allocate memory for the pixels of the PNM image. procedure, private :: check_pixel_range !!> Check if the pixel values are within the valid range. procedure, private :: set_pixels !!> Set the pixel values of the PNM image. ! Procedures for setting individual attributes procedure :: get_format !!> Get the encoding of the PNM image. ! High-level procedures for working with PNM images procedure :: set_pnm !!> Set the attributes of the PNM image. procedure :: print_info !!> Display information about the image (dimensions, aspect ratio, etc.). procedure :: import_pnm !!> Read an image from a file. procedure :: export_pnm !!> Write an image to a file. procedure :: finalize => deallocate_pnm !!> Clean up allocated memory for the PNM image. ! Image manipulation procedures procedure :: negative !!> Invert the colors of the image. procedure :: brighten !!> Adjust the brightness and darkness of the image. procedure :: swap_channels !!> Swap the RGB channels of the image. procedure :: remove_channels !!> Remove one or more RGB channels from the image. procedure :: greyscale !!> Convert a color image to greyscale. procedure :: rotate !!> Rotate the image by a specified angle. procedure :: flip_horizontal !!> Flip the image horizontally. procedure :: flip_vertical !!> Flip the image vertically. procedure :: crop !!> Crop the image to a specified region. procedure :: resize !!> Resize the image to a specified size. end type format_pnm