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 |
elemental pure subroutine swap_channels(this, swap) class(format_pnm), intent(inout) :: this character(*), intent(in) :: swap integer(ik) :: temp integer :: i, j ! Check if the file is ppm if (this%file_format /= 'ppm') error stop 'swap_channels: This function is only for ppm files.' ! Swap R and G channels if (swap=='rg' .or. swap=='gr' .or. swap=='RG' .or. swap=='GR') then do i = 1, this%height do j = 1, this%width temp = this%pixels(i, 3*j-2) this%pixels(i, 3*j-2) = this%pixels(i, 3*j-1) this%pixels(i, 3*j-1) = temp end do end do end if ! Swap G and B channels if (swap=='gb' .or. swap=='bg' .or. swap=='GB' .or. swap=='BG') then do i = 1, this%height do j = 1, this%width temp = this%pixels(i, 3*j-1) this%pixels(i, 3*j-1) = this%pixels(i, 3*j-0) this%pixels(i, 3*j-0) = temp end do end do end if ! Swap R and B channels if (swap=='rb' .or. swap=='br' .or. swap=='RB' .or. swap=='BR') then do i = 1, this%height do j = 1, this%width temp = this%pixels(i, 3*j-2) this%pixels(i, 3*j-2) = this%pixels(i, 3*j-0) this%pixels(i, 3*j-0) = temp end do end do end if call this%check_pixel_range(this%pixels) end subroutine swap_channels