What is the best way to go about converting a uint8 into a normal int I want to do some work with an rgb histogram, but I can't find a correct approach to the final piece here (updated to rm stbi lib)
proc obc*(image1, image2: string) =
type IntArray = array[24,int]
var
r24: IntArray
let f:float = 24/256
var
data1: seq[uint8]
#data1 = stbi.load(image1,w,h,c,stbi.Default) #uint8
for i in countUp(0, data1.len - 3, step = 4):
let
r1: uint8 = data1[i]
r24[ (int)(r1*f) ] = r24[(int)(r1*f)] + 1
I thought of doing something like converting the r1 to a string and then doing parseInt(), but that just seems perverse. Is there a cleaner way?
Here is the compiler error
Error: type mismatch: got <uint8, float>
but expected one of:
proc `*`(x, y: uint): uint
first type mismatch at position: 2
required type for y: uint
but expression 'f' is of type: float
proc `*`(x, y: uint16): uint16
first type mismatch at position: 2
required type for y: uint16
but expression 'f' is of type: float
proc `*`(x, y: uint32): uint32
first type mismatch at position: 2
required type for y: uint32
but expression 'f' is of type: float
proc `*`(x, y: uint64): uint64
first type mismatch at position: 2
required type for y: uint64
but expression 'f' is of type: float
proc `*`(x, y: uint8): uint8
first type mismatch at position: 2
required type for y: uint8
but expression 'f' is of type: float
8 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
expression: r1 * f