Author Topic: Question about conversion Palette  (Read 2872 times)

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Question about conversion Palette
« on: 2014-Oct-30 »
Hi,
when I read one pixel of a sprite with this system:
Code: GLBasic [Select]
        LOADSPRITEMEM("1.png", w2%, h2%, pixels[])
        FOREACH pix IN pixels[]
                FOR x% = 0 TO value_palette
                        IF pix = memo[x][0]
                                pix =  memo[x][1]
                                BREAK
                        ENDIF
                NEXT
        NEXT
 

the var pix return this value: -5462343
I have to convert in Hex (Exmple: #000301), it's possible?

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4186
    • View Profile
    • Portfolio
Re: Question about conversion Palette
« Reply #2 on: 2014-Oct-31 »
exactly! I havenĀ“t implemented it yet though. :-[

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Question about conversion Palette
« Reply #3 on: 2014-Oct-31 »
This is one way of doing it:
http://www.glbasic.com/forum/index.php?topic=9975.msg87520#msg87520

I have to use the command GETPIXEL/SETPIXEL or it's possible with this system?
Code: GLBasic [Select]
LOADSPRITEMEM("1.png", w2%, h2%, pixels[])
        FOREACH pix IN pixels[]
                FOR x% = 0 TO value_palette
 

-------------------------

I tried some tests, but I could not get anybody can help me?

First i read from a txt file a sequence of color value:
Code: GLBasic [Select]
#000301
#160000
#0e0300
#270000
 
after I compare with those in sprite on memory, and I have to replace them if they are equal, but when i read the pixel of the sprite in memory, he gives me these values:

Code: GLBasic [Select]
9474192
-5462343
-4605498
-3158058
 
« Last Edit: 2014-Oct-31 by Kyo »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: Question about conversion Palette
« Reply #4 on: 2014-Oct-31 »
The commands I posted above helps you convert the

9474192
-5462343
-4605498
-3158058

to rgb components

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Question about conversion Palette
« Reply #5 on: 2014-Oct-31 »
The commands I posted above helps you convert the

9474192
-5462343
-4605498
-3158058

to rgb components

ok and for this?

Code: GLBasic [Select]
#000301
#160000
#0e0300
#270000
 

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: Question about conversion Palette
« Reply #6 on: 2014-Oct-31 »
How should we know how you created/calculated that values? If you got them from someone else, ask him whats his formula.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Question about conversion Palette
« Reply #7 on: 2014-Oct-31 »
I export this value:
Code: GLBasic [Select]
#000301
#160000
#0e0300
#270000
 
with gimp (Export Palette .TXT)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: Question about conversion Palette
« Reply #8 on: 2014-Nov-01 »
Since this are 6 digits, I guess its simply a hex number so 0x0e0300 = RGB(0x0e,0x03,0x00) = 918272 = RGB(14,3,0). But thats just a guess, I would recommend that you simply try it yourself. Of cause this would work perfectly together with SPRITE2MEM: 9474192 = 0x909090 = RGB(0x90,0x90,0x90) = RGB(144,144,144).
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Question about conversion Palette
« Reply #9 on: 2014-Nov-01 »
Since this are 6 digits, I guess its simply a hex number so 0x0e0300 = RGB(0x0e,0x03,0x00) = 918272 = RGB(14,3,0). But thats just a guess, I would recommend that you simply try it yourself. Of cause this would work perfectly together with SPRITE2MEM: 9474192 = 0x909090 = RGB(0x90,0x90,0x90) = RGB(144,144,144).

OK Thanks  :good: