Calculates the average color values of the image. Required for print_info
method.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(in) | :: | this | |||
real(kind=rk), | intent(out), | optional | :: | avg | ||
real(kind=rk), | intent(out), | optional | :: | avg_red | ||
real(kind=rk), | intent(out), | optional | :: | avg_green | ||
real(kind=rk), | intent(out), | optional | :: | avg_blue |
elemental pure subroutine average_colors(this, avg, avg_red, avg_green, avg_blue) class(format_pnm), intent(in) :: this real(rk), intent(out), optional :: avg_red, avg_green, avg_blue, avg select case (this%file_format) case ('pbm', 'pgm') avg = sum(this%pixels) / real(this%width*this%height, kind=rk) case ('ppm') avg_red = sum(this%pixels(:, 1:this%width:3)) / real(this%width*this%height, kind=rk) avg_green = sum(this%pixels(:, 2:this%width:3)) / real(this%width*this%height, kind=rk) avg_blue = sum(this%pixels(:, 3:this%width:3)) / real(this%width*this%height, kind=rk) end select end subroutine average_colors