Count used colors
Posted: Thu Jan 09, 2014 6:34 pm
Two simple procedures that maybe someone could use.
CountColors(image.i) - Counts the amount of colors the image contains (alpha channel is ignored).
HasOverMaxColors(image.i, max = 256) - Returns #True when the image contains more than max colors.
CountColors(image.i) - Counts the amount of colors the image contains (alpha channel is ignored).
HasOverMaxColors(image.i, max = 256) - Returns #True when the image contains more than max colors.
Code: Select all
Procedure CountColors(image.i); count colors (24 bit)
Protected.i x, y, max_x, max_y, c, count
Dim m.a(2097151)
StartDrawing(ImageOutput(image))
max_x = ImageWidth(image) - 1
max_y = ImageHeight(image) - 1
For y = 0 To max_y
For x = 0 To max_x
c = Point(x, y) & $ffffff
If m(c >> 3) & 1 << (c & 7) = 0
m(c >> 3) | 1 << (c & 7)
count + 1
EndIf
Next
Next
StopDrawing()
ProcedureReturn count
EndProcedure
Procedure.i HasOverMaxColors(image.i, max = 256); checks color limit (24 bit)
Protected.i x, y, max_x, max_y, c, count
Dim m.a(2097151)
StartDrawing(ImageOutput(image))
max_x = ImageWidth(image) - 1
max_y = ImageHeight(image) - 1
For y = 0 To max_y
For x = 0 To max_x
c = Point(x, y) & $ffffff
If m(c >> 3) & 1 << (c & 7) = 0
m(c >> 3) | 1 << (c & 7)
count + 1
If count > max
StopDrawing()
ProcedureReturn #True
EndIf
EndIf
Next
Next
StopDrawing()
ProcedureReturn #False
EndProcedure