Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading palette colors?
#1
how do i read the palette color of a certain color?

eDIT: didn't make sense. Oops.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#2
Eh...I'm assuming you want to read the DAC...technically not the palette, but it's what most people refer to when they say "palette"...

Code:
OUT &H3C7, Colr
Red = INP(&H3C9)
Green = INP(&H3C9)
Blue = INP(&H3C9)
Reply
#3
Erm, my question didn't make sense.

I reworded it.

I'm using OUT &H3C9 to change the colors, but I want to make it so that the current color being drawn is always of the same color. After it's drawn, I want to change it back to what it should be. Easier on the eyes.

You'll see what I mean by running this:

Code:
DEFINT A-Z
SCREEN 13
RANDOMIZE TIMER
FOR i& = 0 TO 255
OUT &H3C9, 0
OUT &H3C9, i&
OUT &H3C9, 0
NEXT i&
i& = 0
mb = -(INT(RND * 16) + 5)
ma = INT(RND * 15) + 3
me = 0
mc = -1
mc2 = -1
md = 255
r1 = INT(RND * 20) - 10

DIM rnd2(1 TO 4)
DO
m4 = (INT(RND * 8) + 2)

FOR i = 1 TO 4
rnd2(i) = INT(RND * r1)
NEXT i
rnd2(INT(RND * 4) + 1) = 1
m3 = 0
m2& = 0
FOR m = ma TO mb STEP mc
FOR i = 1 TO 4
rnd2(i) = INT(RND * r1)
NEXT i
rnd2(INT(RND * 4 + 1)) = 1
m3 = m3 + 1
m2& = m2& + 5000 \ (SQR(ABS(m3) + 1))
IF m2& > 10000 THEN m2& = 10000
FOR i = md TO me STEP mc2
IF me > 128 THEN OUT &H3C9, 0
OUT &H3C9, i
IF me > 128 THEN OUT &H3C9, 0
FOR j& = 1 TO m2& + ABS(256 - i) * 100
NEXT j&: im = i * m \ m4
sqr.i% = SQR(i%)
FOR im2 = im - sqr.i% TO im + sqr.i%
im3 = im2 \ 2
IF rnd2(1) > 0 THEN
LINE (160, 150 - im3)-(0, 100), i: LINE (160, 50 + im3)-(0, 100), i
LINE (160, 150 - im3)-(320, 100), i: LINE (160, 50 + im3)-(320, 100), i
END IF
IF rnd2(2) > 0 THEN
LINE (0, 200 - im2)-(160, 150 - im3), i: LINE (0, im2)-(160, 50 + im3), i
LINE (320, 200 - im2)-(160, 150 - im3), i: LINE (320, im2)-(160, 50 + im3), i
END IF
IF rnd2(3) > 0 THEN
LINE (160, 100 + im3)-(319, 199), i: LINE (160, 100 - im3)-(319, 0), i
LINE (160, 100 + im3)-(1, 199), i: LINE (160, 100 - im3)-(1, 0), i
END IF
IF rnd2(4) > 0 THEN
LINE (0, 200 - im2)-(160, 100 - im3), i: LINE (0, im2)-(160, 100 + im3), i
LINE (320, 200 - im2)-(160, 100 - im3), i: LINE (320, im2)-(160, 100 + im3), i
END IF
NEXT im2
IF INKEY$ <> "" THEN EXIT DO
NEXT i
SWAP me, md
mc2 = -mc2
IF mc2 > 0 THEN
mb = -(INT(RND * 16) + 5)
ma = INT(RND * 15) + 3
END IF
NEXT m
SWAP ma, mb
mc = -mc
LOOP

PS: Any idea on how to make the durn lines shade correctly? :|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#4
You're going to have to exhaustively search to palette for the color with RGB values closest to the ones you're looking for.

It will be somewhat faster if you keep a copy of the palette in memory (keep them in sync whenever you change one or the other), so you can search the copy instead. This will be much, much faster than asking the video card for palette values.

The simplest and easiest way is to compare two sets of RGB values is to subtract the R, G, and B from the other R, G, and B respectively and score by average difference.

You might get better results if you square each difference before averaging them. This heavily penalizes colors for having one value way off, even if the color is closer on average.

Or you could convert to hue, brightness, saturation, before comparing.

Another way to do it is to standardize your palette such that any color's position in it can be calculated, like this:
color = desiredRed*36 + desiredGreen*6 + desiredBlue
' (each value ranging from 0 to 5, 6*6*6 = 216 colors)
Reply
#5
:|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
Code:
for i = 1 to 256
  out &h3c7,i
  red(i) = inp(&h3c9)
  green(i) = inp(&h3c9)
  blue(i) = inp(&h3c9)
next i

This will store the normal colours

Code:
for i = 1 to 256
  out &h3c8,i
  out &h3c9,red(i)
  out &h3c9,green(i)
  out &h3c9,blue(i)
next i

This will put your colours back to normal after you have changed them.
eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)