INTEGER -> R, G, B Berechnung

Previous topic - Next topic

backslider

Haiho :)

Ich habe mir gerad ne Funktion geschrieben, mit welcher man den int-Wert von GetPixel() zu 3 RGB werten zurückrechnen kann.
Allerdings habe ich ein Problem damit, die Rückgabe in ein Array zu packen und bekomme einen Compilererror.
Vielleicht seht ihr ja "sofort" den Fehler =/ :)

Hier der Code:
Code (glbasic) Select
// --------------------------------- //
// Project: Test_GetPixel
// Start: Wednesday, June 23, 2010
// IDE Version: 8.002


SETCURRENTDIR("Media") // seperate media and binaries?

LOADSPRITE "sprite.png",0 //Load the Sprite you want

LOCAL color[] //Create a new array for pixelcolors
DIM color[64][64] //dim it to the size of your sprite

DRAWSPRITE 0,0,0 //Draw the sprite

FOR x=0 TO 63 //For each x and y pixel get the pixel color
FOR y=0 TO 63
color[x][y] = GETPIXEL(x,y) //<-
NEXT
NEXT

LOADSPRITE "",0//clear the sprite
BLACKSCREEN //Clear the screen before run the game



GLOBAL pixelcolor[] //in this array we put one rgb value
DIM pixelcolor[3] //R, G, B

pixelcolor = GetRgbFromInt(color[0][0]) //put the pixel 0,0 - color into the array as RGB


WHILE TRUE //main loop

PRINT "R:"+pixelcolor[0],0,0
PRINT "G:"+pixelcolor[1],0,10
PRINT "B:"+pixelcolor[2],0,20

DEBUG pixelcolor

SHOWSCREEN //Draw the screen
WEND //Back to topic :P



// ------------------------------------------------------------- //
// ---  GETRGBFROMINT  --- Returns RGB with 3 parameters (R, G, B)´in an array
// ------------------------------------------------------------- //
@FUNCTION GetRgbFromInt: value

LOCAL value, tmp
LOCAL color[]
DIM color[3]

color[2] = value / 65536//B
tmp = MOD(value, 65536)
color[1] = tmp / 256//G
color[0] = tmp - (color[1] * 256)//R

RETURN color
ENDFUNCTION // GETRGBFROMINT


Quotecompiling:
C:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\glbasic\gpc_temp0.cpp:201: error: no match for 'operator=' in '__GLBASIC__::pixelcolor = __GLBASIC__::GetRgbFromInt((&color)->__GLBASIC__::DGIntArray::operator()(0, 0))'
E:/Programme/GLBasic_Beta/Compiler/platform/Include/glb.h:342: note: candidates are: __GLBASIC__::DGIntArray& __GLBASIC__::DGIntArray::operator=(const __GLBASIC__::DGIntArray&)
*** FATAL ERROR - Bitte die Compiler-Ausgabe ins Forum kopieren

Kitty Hello

Code (glbasic) Select
DIM pixelcolor[3] //R, G, B

pixelcolor = GetRgbFromInt(color[0][0]) //put the pixel 0,0 - color into the array as RGB

Der Index links fehlt.

backslider

Hm funzt aber nicht so, wie ich mir das dachte...
Ich will ja ein array mit 3 Feldern zurückgeben und in pixelcolor reinpacken.
Sodass ich dann

pixelcolor[0] = R
pixelcolor[1] = G
pixelcolor[2] = B

aufrufen kann!?!

Kitty Hello

Übergib das Array als Parameter und schreib den Wert da rein.
Code (glbasic) Select

FUNCTION GetRGB%: rgb%[]
rgb[0] = ...
ENDFUNCTION

backslider

#4
Achja! Wieso kam ich da nicht drauf :)
Ich denke - glaub ich - zu sehr in OOP...

Naja, vielen Dank erstmal! ;)

Habs jetzt mal in Code-Schnipsel reingepostet:
http://www.glbasic.com/forum/index.php?topic=4646.0