Ooops
March 05, 2021, 07:53:32 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
BlitzPlus Gui
»
[bb] Unique Colour Counter by Snarty [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Unique Colour Counter by Snarty [ 1+ years ago ] (Read 598 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[bb] Unique Colour Counter by Snarty [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:40 AM »
Title :
Unique Colour Counter
Author :
Snarty
Posted :
1+ years ago
Description :
This function will step through a 24bit image (Created with Flag 4) and return the amount of colours in the image. This will be useful for building palette lists for colour operations.. etc.
Code :
Code: BlitzBasic
Dim
RG
(
255
,
255
)
Function
CountColours
(
Parent,Image
)
UpWin=CreateWindow
(
"Analysing Image..."
,GadgetX
(
Parent
)
+
(
(
GadgetWidth
(
Parent
)
-
240
)
/
2
)
,GadgetY
(
Parent
)
+
(
(
GadgetHeight
(
Parent
)
-
60
)
/
2
)
,
240
,
60
,Parent,
17
)
Progbar=CreateProgBar
(
4
,
4
,ClientWidth
(
UpWin
)
-
8
,ClientHeight
(
UpWin
)
-
8
,UpWin,
1
)
Buffer=
ImageBuffer
(
Image
)
LockBuffer
Buffer
BBank=LockedPixels
(
Buffer
)
BPitch=LockedPitch
(
Buffer
)
SH#=
ImageBuffer
(
Image
)
For
y=
0
To
ImageHeight
(
Image
)
-
1
yoff=y*BPitch
For
x=
0
To
ImageWidth
(
Image
)
-
1
pyxoff=yoff+
(
x*
3
)
Rd=
PeekByte
(
BBank,pyxoff+
2
)
Gr=
PeekByte
(
BBank,pyxoff+
1
)
Bl=
PeekByte
(
BBank,pyxoff
)
If
RG
(
Rd,Gr
)
If
Not
PeekByte
(
RG
(
Rd,Gr
)
,Bl
)
PokeByte
RG
(
Rd,Gr
)
,Bl,
1
NumCols=NumCols+
1
EndIf
Else
RG
(
Rd,Gr
)
=
CreateBank
(
256
)
PokeByte
RG
(
Rd,Gr
)
,Bl,
1
NumCols=NumCols+
1
EndIf
Next
UpdateProgBar ProgBar,y/SH
Next
UnlockBuffer
Buffer
For
r=
0
To
255
For
g=
0
To
255
If
RG
(
r,g
)
FreeBank
RG
(
r,g
)
RG
(
r,g
)
=
0
EndIf
Next
Next
FreeGadget UpWin
Return
NumCols
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
BlitzPlus Gui
»
[bb] Unique Colour Counter by Snarty [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal