Skip to content

Commit

Permalink
fix rgb binary representation
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonMiraj committed Jul 1, 2024
1 parent 267b252 commit 1ccd91e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/backends/raster/bitmap_backend.f90
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ subroutine load_from_ppm(this,file_path)
green = ichar(ccode)
read(unit_num) ccode
blue = ichar(ccode)
this%pixels(i, j) = red + shiftl(green, 8) + shiftl(blue, 16)
this%pixels(i, j) = blue + shiftl(green, 8) + shiftl(red, 16)
end do
end do

Expand All @@ -117,9 +117,9 @@ subroutine save_to_ppm(this,file_path)
write(unit_num, '(i0)') 2**rgb_bit_depth-1
do j = 0, int(this%size%height)-1
do i = 0, int(this%size%width)-1
bytes(1) = ibits(this%pixels(i, j), 0, rgb_bit_depth)
bytes(3) = ibits(this%pixels(i, j), 0, rgb_bit_depth)
bytes(2) = ibits(this%pixels(i, j), rgb_bit_depth, rgb_bit_depth)
bytes(3) = ibits(this%pixels(i, j), 2*rgb_bit_depth, rgb_bit_depth)
bytes(1) = ibits(this%pixels(i, j), 2*rgb_bit_depth, rgb_bit_depth)

write(unit_num, '(3a1)', advance='no') bytes
end do
Expand Down
8 changes: 4 additions & 4 deletions src/fig_rgb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ elemental type(integer(pixel)) function rgb_to_int(color) result(rgb_int)
type(RGB), intent(in) :: color

rgb_int = ior(ishft(color%a, rgb_bit_depth*3),&
ior(ishft(color%b, rgb_bit_depth*2),&
ior(ishft(color%g, rgb_bit_depth), color%r)))
ior(ishft(color%r, rgb_bit_depth*2),&
ior(ishft(color%g, rgb_bit_depth), color%b)))

end function rgb_to_int

elemental type(RGB) function int_to_rgb(rgb_int) result(color)
integer(pixel), intent(in):: rgb_int

color%a = ibits(rgb_int, 3*rgb_bit_depth, rgb_bit_depth)
color%b = ibits(rgb_int, 2*rgb_bit_depth, rgb_bit_depth)
color%r = ibits(rgb_int, 2*rgb_bit_depth, rgb_bit_depth)
color%g = ibits(rgb_int, rgb_bit_depth , rgb_bit_depth)
color%r = ibits(rgb_int, 0, rgb_bit_depth)
color%b = ibits(rgb_int, 0, rgb_bit_depth)
end function int_to_rgb

function rgb_to_string(color) result(color_string)
Expand Down

0 comments on commit 1ccd91e

Please sign in to comment.