In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.
Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.
Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.
rgb to/from hsl
rgb to/from hsl
Hi,
Is there any sample to convert from rgb to hsl format and vice-versa?
tks,
Is there any sample to convert from rgb to hsl format and vice-versa?
tks,
rgb to/from hsl
I found the formula to convert from hsl to rgb, so...
function hsl2Rgb(H, S, L)
LOCAL C, X, m, v
H := H/240 * 360
S := S/240
L := L/240
C := (1 - Abs(2 * L - 1)) * S
X := C * (1 - Abs((H / 60) % 2 - 1))
m := L - C/2
IF H < 60 ; v := {C, X, 0}
ELSEIF H < 120 ; v := {X, C, 0}
ELSEIF H < 180 ; v := {0, C, X}
ELSEIF H < 240 ; v := {0, X, C}
ELSEIF H < 300 ; v := {X, 0, C}
ELSEIF H < 360 ; v := {C, 0, X}
endiF
AEval(v, { |q, p| v[p] := round((v[p] + m) * 255, 0) })
RETURN v[1] + 256 * v[2] + 256 * 256 * v[3]
function hsl2Rgb(H, S, L)
LOCAL C, X, m, v
H := H/240 * 360
S := S/240
L := L/240
C := (1 - Abs(2 * L - 1)) * S
X := C * (1 - Abs((H / 60) % 2 - 1))
m := L - C/2
IF H < 60 ; v := {C, X, 0}
ELSEIF H < 120 ; v := {X, C, 0}
ELSEIF H < 180 ; v := {0, C, X}
ELSEIF H < 240 ; v := {0, X, C}
ELSEIF H < 300 ; v := {X, 0, C}
ELSEIF H < 360 ; v := {C, 0, X}
endiF
AEval(v, { |q, p| v[p] := round((v[p] + m) * 255, 0) })
RETURN v[1] + 256 * v[2] + 256 * 256 * v[3]
rgb to/from hsl
Roberto, bom dia.
Apenas por curiosidade, qual é a finalidade desta conversão?
Abraços.
Mário Angelini
Apenas por curiosidade, qual é a finalidade desta conversão?
Abraços.
Mário Angelini
rgb to/from hsl
Olá, Mario.
Eu utilizo varias janelas e preciso fazer um contraste entre elas de modo que a aplicacao nao fique poluida visualmente. Entao, a primeira janela eu uso uma cor e, se preciso abrir uma segunda sobre esta, eu utilizo um cor para o fundo semelhante a primeira, so que com uma luminosidade maior ou menor. Como as cores sao definidas dinamicamente (para evitar repeticao) entao eu preciso de um funcao que faça isso. í‰ exatamento o efeito dos parametros H, L e S das cores do windows (veja a propriedade nClrPane e pressione F2). Tambem utilizo para dar aquele efeito de "acender" ou "apagar" a luz de um controle.
Eu utilizo varias janelas e preciso fazer um contraste entre elas de modo que a aplicacao nao fique poluida visualmente. Entao, a primeira janela eu uso uma cor e, se preciso abrir uma segunda sobre esta, eu utilizo um cor para o fundo semelhante a primeira, so que com uma luminosidade maior ou menor. Como as cores sao definidas dinamicamente (para evitar repeticao) entao eu preciso de um funcao que faça isso. í‰ exatamento o efeito dos parametros H, L e S das cores do windows (veja a propriedade nClrPane e pressione F2). Tambem utilizo para dar aquele efeito de "acender" ou "apagar" a luz de um controle.
-
- Mensajes: 291
- Registrado: Jue Ene 31, 2013 1:10 pm
rgb to/from hsl
Roberto,
el API de Windows tiene funciones para hacerlo.
Añade un módulo en C a tu proyecto (menú Archivo->Nuevo->C) e incluye este
código:
#include <shlwapi.h>
HB_FUNC( RGBTOHLS ) // RGBTOHLS( nColor ) --> { nHue, nLuminance, nSaturation }
{
WORD wHue = 0;
WORD wLuminance = 0;
WORD wSaturation = 0;
ColorRGBToHLS( (COLORREF) hb_parnl( 1 ), &wHue, &wLuminance,
&wSaturation );
hb_reta( 3 );
hb_storvnl( wHue, -1, 1 );
hb_storvnl( wLuminance, -1, 1 );
hb_storvnl( wSaturation, -1, 1 );
}
HB_FUNC( HLSTORGB ) // HLSTORGB( nHue, nLuminance, nSaturation ) --> nColor
{
hb_retnl( ColorHLSToRGB( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}
Si estás usando Borland tendrás que añadir shwlapi.lib al proyecto y si
compilas con MinGW tendrás que añadir libshwlapi.a
Saludos,
José Lalín
el API de Windows tiene funciones para hacerlo.
Añade un módulo en C a tu proyecto (menú Archivo->Nuevo->C) e incluye este
código:
#include <shlwapi.h>
HB_FUNC( RGBTOHLS ) // RGBTOHLS( nColor ) --> { nHue, nLuminance, nSaturation }
{
WORD wHue = 0;
WORD wLuminance = 0;
WORD wSaturation = 0;
ColorRGBToHLS( (COLORREF) hb_parnl( 1 ), &wHue, &wLuminance,
&wSaturation );
hb_reta( 3 );
hb_storvnl( wHue, -1, 1 );
hb_storvnl( wLuminance, -1, 1 );
hb_storvnl( wSaturation, -1, 1 );
}
HB_FUNC( HLSTORGB ) // HLSTORGB( nHue, nLuminance, nSaturation ) --> nColor
{
hb_retnl( ColorHLSToRGB( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}
Si estás usando Borland tendrás que añadir shwlapi.lib al proyecto y si
compilas con MinGW tendrás que añadir libshwlapi.a
Saludos,
José Lalín
rgb to/from hsl
tanks.
could you give me an working sample?
could you give me an working sample?
-
- Mensajes: 291
- Registrado: Jue Ene 31, 2013 1:10 pm
rgb to/from hsl
Roberto,
the source is autodocumented:
RGBTOHLS( nColor ) --> { nHue, nLuminance, nSaturation }
HLSTORGB( nHue, nLuminance, nSaturation ) --> nColor
Regards,
José Lalín
the source is autodocumented:
RGBTOHLS( nColor ) --> { nHue, nLuminance, nSaturation }
HLSTORGB( nHue, nLuminance, nSaturation ) --> nColor
Regards,
José Lalín
rgb to/from hsl
José,
Thanks for your answer. I know how to use the functions, the problem is when I try to compile the program.
I added the lib shwlapi.lib as you told me and the file HLS.c below:
/*
* Project: SI
* File: HLS.c
* Description:
* Author:
* Date: 07-01-2013
*/
#include <shlwapi.h>
HB_FUNC( RGBTOHLS ) // RGBTOHLS( nColor ) --> { nHue, nLuminance, nSaturation }
{
WORD wHue = 0;
WORD wLuminance = 0;
WORD wSaturation = 0;
ColorRGBToHLS( (COLORREF) hb_parnl( 1 ), &wHue, &wLuminance, &wSaturation );
hb_reta( 3 );
hb_storvnl( wHue, -1, 1 );
hb_storvnl( wLuminance, -1, 1 );
hb_storvnl( wSaturation, -1, 1 );
}
HB_FUNC( HLSTORGB ) // HLSTORGB( nHue, nLuminance, nSaturation ) --> nColor
{
hb_retnl( ColorHLSToRGB( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}
but I am receiving the following error:
Compiling: HLS.c...
Warning W8065 HLS.c 18: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 20: Call to function 'hb_reta' with no prototype in function HB_FUNC
Warning W8065 HLS.c 21: Call to function 'hb_storvnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 22: Call to function 'hb_storvnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 23: Call to function 'hb_storvnl' with no prototype in function HB_FUNC
Warning W8070 HLS.c 24: Function should return a value in function HB_FUNC
Warning W8057 HLS.c 24: Parameter 'RGBTOHLS' is never used in function HB_FUNC
Error E2238 HLS.c 28: Multiple declaration for 'HB_FUNC'
Error E2344 HLS.c 12: Earlier declaration of 'HB_FUNC'
Warning W8065 HLS.c 29: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 29: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 29: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 29: Call to function 'hb_retnl' with no prototype in function HB_FUNC
Warning W8070 HLS.c 30: Function should return a value in function HB_FUNC
Warning W8057 HLS.c 30: Parameter 'HLSTORGB' is never used in function HB_FUNC
1 Files, 13 Warnings, 2 Errors
Compile time: 0.26s Link time: 0s Total time: 0.34s
What am I doing wrong?
TIA
Thanks for your answer. I know how to use the functions, the problem is when I try to compile the program.
I added the lib shwlapi.lib as you told me and the file HLS.c below:
/*
* Project: SI
* File: HLS.c
* Description:
* Author:
* Date: 07-01-2013
*/
#include <shlwapi.h>
HB_FUNC( RGBTOHLS ) // RGBTOHLS( nColor ) --> { nHue, nLuminance, nSaturation }
{
WORD wHue = 0;
WORD wLuminance = 0;
WORD wSaturation = 0;
ColorRGBToHLS( (COLORREF) hb_parnl( 1 ), &wHue, &wLuminance, &wSaturation );
hb_reta( 3 );
hb_storvnl( wHue, -1, 1 );
hb_storvnl( wLuminance, -1, 1 );
hb_storvnl( wSaturation, -1, 1 );
}
HB_FUNC( HLSTORGB ) // HLSTORGB( nHue, nLuminance, nSaturation ) --> nColor
{
hb_retnl( ColorHLSToRGB( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );
}
but I am receiving the following error:
Compiling: HLS.c...
Warning W8065 HLS.c 18: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 20: Call to function 'hb_reta' with no prototype in function HB_FUNC
Warning W8065 HLS.c 21: Call to function 'hb_storvnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 22: Call to function 'hb_storvnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 23: Call to function 'hb_storvnl' with no prototype in function HB_FUNC
Warning W8070 HLS.c 24: Function should return a value in function HB_FUNC
Warning W8057 HLS.c 24: Parameter 'RGBTOHLS' is never used in function HB_FUNC
Error E2238 HLS.c 28: Multiple declaration for 'HB_FUNC'
Error E2344 HLS.c 12: Earlier declaration of 'HB_FUNC'
Warning W8065 HLS.c 29: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 29: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 29: Call to function 'hb_parnl' with no prototype in function HB_FUNC
Warning W8065 HLS.c 29: Call to function 'hb_retnl' with no prototype in function HB_FUNC
Warning W8070 HLS.c 30: Function should return a value in function HB_FUNC
Warning W8057 HLS.c 30: Parameter 'HLSTORGB' is never used in function HB_FUNC
1 Files, 13 Warnings, 2 Errors
Compile time: 0.26s Link time: 0s Total time: 0.34s
What am I doing wrong?
TIA
-
- Mensajes: 291
- Registrado: Jue Ene 31, 2013 1:10 pm
rgb to/from hsl
Roberto,
> What am I doing wrong?
#include <windows.h>
#include <shlwapi.h>
#include <xailer.h>
Regards,
José Lalín
> What am I doing wrong?
#include <windows.h>
#include <shlwapi.h>
#include <xailer.h>
Regards,
José Lalín
rgb to/from hsl
thanks, again.
right now I am getting this:
Compiling: HLS.c...
Warning W8065 HLS.c 22: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 23: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 24: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Linking: SI.exe...
Error: Unresolved external '_hb_storvnl' referenced from C:DEVSIOBJHLS.DBJ
1 Files, 3 Warnings, 1 Errors
Compile time: 0.20s Link time: 0.62s Total time: 1.04s
sorry to boring you,
TIA
right now I am getting this:
Compiling: HLS.c...
Warning W8065 HLS.c 22: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 23: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 24: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Linking: SI.exe...
Error: Unresolved external '_hb_storvnl' referenced from C:DEVSIOBJHLS.DBJ
1 Files, 3 Warnings, 1 Errors
Compile time: 0.20s Link time: 0.62s Total time: 1.04s
sorry to boring you,
TIA
rgb to/from hsl
thanks, again.
I am still doing something wrong.
Compiling: HLS.c...
Warning W8065 HLS.c 22: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 23: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 24: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Linking: SI.exe...
Error: Unresolved external '_hb_storvnl' referenced from C:DEVSIOBJHLS.DBJ
1 Files, 3 Warnings, 1 Errors
Compile time: 0.20s Link time: 0.62s Total time: 1.04s
I am still doing something wrong.
Compiling: HLS.c...
Warning W8065 HLS.c 22: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 23: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Warning W8065 HLS.c 24: Call to function 'hb_storvnl' with no prototype in function HB_FUN_RGBTOHLS
Linking: SI.exe...
Error: Unresolved external '_hb_storvnl' referenced from C:DEVSIOBJHLS.DBJ
1 Files, 3 Warnings, 1 Errors
Compile time: 0.20s Link time: 0.62s Total time: 1.04s
-
- Mensajes: 291
- Registrado: Jue Ene 31, 2013 1:10 pm
rgb to/from hsl
Roberto,
hb_storvnl is a Harbour function. If you want to use xHarbour change it to
hb_stornl.
Regards,
José Lalín
hb_storvnl is a Harbour function. If you want to use xHarbour change it to
hb_stornl.
Regards,
José Lalín