average_colors Subroutine

private pure elemental subroutine average_colors(this, avg, avg_red, avg_green, avg_blue)

Calculates the average color values of the image. Required for print_info method.

Arguments

Type IntentOptional 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

Called by

proc~~average_colors~~CalledByGraph proc~average_colors average_colors proc~print_info format_pnm%print_info proc~print_info->proc~average_colors program~demo_ppm demo_ppm program~demo_ppm->proc~print_info program~test test program~test->proc~print_info program~test1 test1 program~test1->proc~print_info program~test10 test10 program~test10->proc~print_info program~test11 test11 program~test11->proc~print_info program~test12 test12 program~test12->proc~print_info program~test13 test13 program~test13->proc~print_info program~test14 test14 program~test14->proc~print_info program~test17 test17 program~test17->proc~print_info program~test18 test18 program~test18->proc~print_info program~test19 test19 program~test19->proc~print_info program~test2 test2 program~test2->proc~print_info program~test20 test20 program~test20->proc~print_info program~test21 test21 program~test21->proc~print_info program~test22 test22 program~test22->proc~print_info program~test23 test23 program~test23->proc~print_info program~test24 test24 program~test24->proc~print_info program~test25 test25 program~test25->proc~print_info program~test3 test3 program~test3->proc~print_info program~test4 test4 program~test4->proc~print_info program~test6 test6 program~test6->proc~print_info program~test7 test7 program~test7->proc~print_info program~test8 test8 program~test8->proc~print_info program~test9 test9 program~test9->proc~print_info

Source Code

   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