SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 03/10/2015, 06:56 PM   #1
AbyssMorgan
High-roller
 
AbyssMorgan's Avatar
 
Join Date: Apr 2015
Location: Poland
Posts: 1,211
Reputation: 351
Cool RGB RGBA ARGB Conversion

Include contain functions for color conversion

PHP Code:
/****************************************************************************************************
 *                                                                                                  *
 *                                   )(   R G B A Conversion   )(                                   *
 *                                                                                                  *
 * Copyright  2019 Abyss Morgan. All rights reserved.                                              *
 *                                                                                                  *
 * Website:  adm.ct8.pl                                                                             *
 * Download: adm.ct8.pl/r/download                                                                  *
 *                                                                                                  *
 * Plugins: None                                                                                    *
 * Modules: None                                                                                    *
 *                                                                                                  *
 * File Version: 2.5.0                                                                              *
 *                                                                                                  *
 * Functions:                                                                                       *
 * RGB::RGBAToHex(color,&red,&green,&blue,&alpha);                                                  *
 * RGB::RGBToHex(color,&red,&green,&blue);                                                          *
 * RGB::HexToRGBA(red,green,blue,alpha);                                                            *
 * RGB::HexToARGB(red,green,blue,alpha);                                                            *
 * RGB::HexToRGB(red,green,blue);                                                                   *
 * RGB::RGBAToRGB(color);                                                                           *
 * RGB::RGBToRGBA(color,alpha);                                                                     *
 * RGB::RGBToARGB(color,alpha);                                                                     *
 * RGB::ARGBToRGB(color);                                                                           *
 * RGB::RGBAToARGB(color);                                                                          *
 * RGB::ARGBToRGBA(color);                                                                          *
 * RGB::GetRFromRGBA(color);                       //RGBA:0xFAB0A0FF R:0xFA000000                   *
 * RGB::GetGFromRGBA(color);                       //RGBA:0xFAB0A0FF G:0x00B00000                   *
 * RGB::GetBFromRGBA(color);                       //RGBA:0xFAB0A0FF B:0x0000A000                   *
 * RGB::GetAFromRGBA(color);                       //RGBA:0xFAB0A0FF A:0x000000FF                   *
 * RGB::GetRHexFromRGBA(color);                    //RGBA:0xFAB0A0FF R:0xFA                         *
 * RGB::GetGHexFromRGBA(color);                    //RGBA:0xFAB0A0FF G:0xB0                         *
 * RGB::GetBHexFromRGBA(color);                    //RGBA:0xFAB0A0FF B:0xA0                         *
 * RGB::GetAHexFromRGBA(color);                    //RGBA:0xFAB0A0FF A:0xFF                         *
 * RGB::GetColorRGBA(color);                       //Return {RGB}                                   *
 * RGB::GetColorRGB(color);                        //Return {RGB}                                   *
 * RGB::GetColorARGB(color);                       //Return {RGB}                                   *
 * RGB::AdjustColorLuminance(color,Float:adjust);                                                   *
 *                                                                                                  *
 ****************************************************************************************************/ 
Download:
RGB.inc

Website:
Color Converter

Example 1:
PHP Code:
new col RGB::RGBAToARGB(0xFF6600FF); //return 0xFFFF6600; 
Example 2:
PHP Code:
new redgreenbluealpha;
RGB::RGBAToHex(0xFF6600AA,red,green,blue,alpha); //return red = 0xFF; green = 0x66; blue = 0x00; alpha = 0xAA; 
Example 3:
PHP Code:
new RGB::GetRHexFromRGBA(0xFF6600AA); //return 0xFF; 
Example 4:
PHP Code:
new RGB::GetRFromRGBA(0xFF6600AA); //return 0xFF000000; 

Last edited by AbyssMorgan; 26/09/2019 at 05:35 PM. Reason: Update 2.5.0
AbyssMorgan is offline   Reply With Quote
Old 03/02/2016, 04:27 PM   #2
AbyssMorgan
High-roller
 
AbyssMorgan's Avatar
 
Join Date: Apr 2015
Location: Poland
Posts: 1,211
Reputation: 351
Default Re: RGB RGBA ARGB Conversion

the new version is available, used macro definitions
AbyssMorgan is offline   Reply With Quote
Old 03/02/2016, 06:44 PM   #3
SecretBoss
Gangsta
 
SecretBoss's Avatar
 
Join Date: Dec 2014
Location: Greece
Posts: 808
Reputation: 103
Default Re: RGB RGBA ARGB Conversion

Very useful for converting the colors, +rep
__________________
SecretBoss is offline   Reply With Quote
Old 06/02/2016, 06:36 PM   #4
AbyssMorgan
High-roller
 
AbyssMorgan's Avatar
 
Join Date: Apr 2015
Location: Poland
Posts: 1,211
Reputation: 351
Default Re: RGB RGBA ARGB Conversion

updated ShiftRGBAToRGB, ShiftRGBToRGBA, ShiftRGBToARGB, ShiftRGBAToARGB, ShiftARGBToRGBA (less operations to perform)

added GetColor(color) improved version of YouServ

PHP Code:
//return {RGB}
stock GetColor(color){
    new 
string[10];
    
format(string,sizeof(string),"{%06x}",ShiftRGBAToRGB(color));
    return 
string;

AbyssMorgan is offline   Reply With Quote
Old 09/02/2016, 01:12 PM   #5
BlackBank
Gangsta
 
Join Date: Dec 2010
Location: The Netherlands
Posts: 525
Reputation: 437
Default Re: RGB RGBA ARGB Conversion

Since i'm already using RGBA to RGB(in my own way) in dialogs, i'm definitely gonna use this library to make it a lot easier, and the benefit of having more functions/macro's. Great work!
BlackBank is offline   Reply With Quote
Old 05/06/2016, 08:55 PM   #6
AbyssMorgan
High-roller
 
AbyssMorgan's Avatar
 
Join Date: Apr 2015
Location: Poland
Posts: 1,211
Reputation: 351
Default Re: RGB RGBA ARGB Conversion

Update RGB.inc to v2.3 now.

Added new macros and function:
PHP Code:
RGBToHex(color,&red,&green,&blue);
HexToRGB(&color,red,green,blue);

GetColor(color); //Return {RGB} 
The abbreviated names of macro (preserved old)
PHP Code:
RGBAToHex <-> ShiftRGBAToHex
HexToRGBA 
<-> ShiftHexToRGBA
RGBToHex 
<-> ShiftRGBToHex
HexToRGB 
<-> ShiftHexToRGB
RGBAToRGB 
<-> ShiftRGBAToRGB
RGBToRGBA 
<-> ShiftRGBToRGBA
RGBToARGB 
<-> ShiftRGBToARGB
ARGBToRGB 
<-> ShiftARGBToRGB
RGBAToARGB 
<-> ShiftRGBAToARGB
ARGBToRGBA 
<-> ShiftARGBToRGBA 
Optimized macro definition for all.
AbyssMorgan is offline   Reply With Quote
Old 24/07/2016, 05:20 PM   #7
gurmani11
Huge Clucker
 
gurmani11's Avatar
 
Join Date: Dec 2012
Location: Lucid Dreams
Posts: 355
Reputation: 18
Default Re: RGB RGBA ARGB Conversion

Damn Sophisticated macros. Much Helpful.
Thanks.
gurmani11 is offline   Reply With Quote
Old 23/08/2016, 09:47 AM   #8
AbyssMorgan
High-roller
 
AbyssMorgan's Avatar
 
Join Date: Apr 2015
Location: Poland
Posts: 1,211
Reputation: 351
Default Re: RGB RGBA ARGB Conversion

Update v2.4.0:

- Renamed function (preserved old):
PHP Code:
GetColor -> GetColorRGBA 
- Added functions:
PHP Code:
GetColorRGB(color);  //Return {RGB}
GetColorARGB(color); //Return {RGB}
AdjustColorLuminance(color,Float:adjust); 
AbyssMorgan is offline   Reply With Quote
Old 03/05/2017, 06:11 PM   #9
YouHack
Banned
 
Join Date: Jan 2017
Posts: 293
Reputation: 28
Default Re: RGB RGBA ARGB Conversion

All what i was looking for is :
Quote:
HexToRGBA(&color,red,green,blue,alpha); //ShiftHexToRGBA
Thanks man!
* Apologizes, but bumping this thread is better than bumping a "Help Me!" thread.
EDIT: Just noticed the web version, WTF... i have nothing to say
YouHack is offline   Reply With Quote
Old 04/03/2019, 07:16 AM   #10
Switel12
Banned
 
Join Date: Dec 2017
Location: Poland
Posts: 10
Reputation: 4
Default Re: RGB RGBA ARGB Conversion

Update v2.5.0:

- Added functions:
PHP Code:
RGB::HexToARGB(red,green,blue,alpha); 
- Updated functions:
PHP Code:
RGB::HexToRGBA(red,green,blue,alpha);
RGB::HexToARGB(red,green,blue,alpha); 
- Changed function names:
PHP Code:
RGBAToHex -> RGB::RGBAToHex
RGBToHex 
-> RGB::RGBToHex
HexToRGB 
-> RGB::HexToRGB
RGBAToRGB 
-> RGB::RGBAToRGB
RGBToRGBA 
-> RGB::RGBToRGBA
RGBToARGB 
-> RGB::RGBToARGB
ARGBToRGB 
-> RGB::ARGBToRGB
RGBAToARGB 
-> RGB::RGBAToARGB
ARGBToRGBA 
-> RGB::ARGBToRGBA
GetRFromRGBA 
-> RGB::GetRFromRGBA
GetGFromRGBA 
-> RGB::GetGFromRGBA
GetBFromRGBA 
-> RGB::GetBFromRGBA
GetAFromRGBA 
-> RGB::GetAFromRGBA
GetRHexFromRGBA 
-> RGB::GetRHexFromRGBA
GetGHexFromRGBA 
-> RGB::GetGHexFromRGBA
GetBHexFromRGBA 
-> RGB::GetBHexFromRGBA
GetAHexFromRGBA 
-> RGB::GetAHexFromRGBA
GetColorRGBA 
-> RGB::GetColorRGBA
GetColorRGB 
-> RGB::GetColorRGB
GetColorARGB 
-> RGB::GetColorARGB
AdjustColorLuminance 
-> RGB::AdjustColorLuminance 
Switel12 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[REP++] PROBLEM ! HEX TO ARGB buburuzu19 Scripting Help 17 13/08/2015 06:08 PM
RGBA to ARGB RedFusion Scripting Help 5 11/07/2014 10:04 PM
HEX/HTML > ARGB? BaubaS Scripting Help 2 06/07/2013 10:06 PM
ARGB Colors? Arnoo Scripting Help 3 16/02/2013 03:59 PM


All times are GMT. The time now is 08:43 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.