Packs pixel bits into characters to create the binary representation for PBM images.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(format_pnm), | intent(in) | :: | this |
pure function encode_binary_pbm_pixels(this) result(packed_data) class(format_pnm), intent(in) :: this character(len=1), allocatable :: packed_data(:) integer, allocatable :: temp(:) integer :: row, col, nbytes nbytes = (this%width+7)/8 allocate(packed_data(this%height*nbytes)) allocate(temp(nbytes)) do row = 1, this%height temp = 0 do col = 0, this%width-1 temp(col/8+1) = temp(col/8+1) + this%pixels(row, col+1) * 2**(7-mod(col, 8)) end do packed_data((row-1)*nbytes+1 : row*nbytes) = achar(temp) end do end function encode_binary_pbm_pixels