Jibble

Author Topic: Retrieving RGB values  (Read 603 times)

Chrille

  • Posts: 726
    • Chrille worked on a game that was nominated for an AGS Award!
      Chrille worked on a game that won an AGS Award!
Retrieving RGB values
« on: 13 Jul 2010, 18:20 »
Is it possible to retrieve a color value from the screen? Like, what's the value of Red, Green or Blue at X & Y?
GASPOP software
http://www.gaspop.com

Calin Leafshade

  • Posts: 3,514
  • Long live King Cat!
    • I can help with making music
    • I can help with voice acting
    • Calin Leafshade worked on a game that was nominated for an AGS Award!
      Calin Leafshade worked on a game that won an AGS Award!
Re: Retrieving RGB values
« Reply #1 on: 13 Jul 2010, 18:22 »
Yea the latest version of my utility module contains functions to convert AGS colour values to RGB and HSL and back again but its not uploaded at the moment..

in the mean time GG posted a routine in my sprite deformation thread in the Tech forum which does it

Chrille

  • Posts: 726
    • Chrille worked on a game that was nominated for an AGS Award!
      Chrille worked on a game that won an AGS Award!
Re: Retrieving RGB values
« Reply #2 on: 13 Jul 2010, 18:36 »
Thanks! I'll have a look at it
GASPOP software
http://www.gaspop.com

Dualnames

  • AGS Baker
  • Posts: 7,166
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
Re: Retrieving RGB values
« Reply #3 on: 13 Jul 2010, 18:47 »
Or you can additionally go and SEARCH the forums Chrille and find it being already there. (from May 2006!)

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=26432.0

And since the link doesn't work. Shame.
Oh, dawg, I have that one too.

http://www.xenogiagames.com/dngames/RawGetRGB.rar
No more military army stuff. I'm alive and back.

Khris

  • Posts: 10,648
  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on a game that was nominated for an AGS Award!
Re: Retrieving RGB values
« Reply #4 on: 13 Jul 2010, 18:50 »
This should work:

Code: [Select]
int R, G, B;

void ColorToRGB(int c) {
  B = c % 32;
  c -= B;
  B = B * 8;
  G = c % 2048;
  c -= G;
  G = G / 8;
  R = c / 256;
}

void GetPixel(int x, int y) {
  DynamicSprite*d =  DynamicSprite.CreateFromScreenShot();
  DrawingSurface*ds = d.GetDrawingSurface();
  ColorToRGB(ds.GetPixel(x, y));
  ds.Release();
  d.Delete();
}

EDIT: added tidying up
« Last Edit: 14 Jul 2010, 00:39 by Khris »

Chrille

  • Posts: 726
    • Chrille worked on a game that was nominated for an AGS Award!
      Chrille worked on a game that won an AGS Award!
Re: Retrieving RGB values
« Reply #5 on: 13 Jul 2010, 20:09 »
That's perfect, Khris. Saves me using a module too. I'll try that right away.

I actually tried searching first, Dualnames. Problem was I didn't think of searching for RGB. When searching for RGB just now, among the results I was surprised and happy to find a thread on my crummy old game Pleurghburg (mispelled pleurgburg, how rude!).

Thanks again!
GASPOP software
http://www.gaspop.com

Dualnames

  • AGS Baker
  • Posts: 7,166
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
Re: Retrieving RGB values
« Reply #6 on: 13 Jul 2010, 22:36 »
I'm not teaching you, that'd be blasphemy.  :D

I'm just pointing out my coolness in front of you. So enjoy my coolness factor.
No more military army stuff. I'm alive and back.