Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Releases Libraries [Library] PAWN Colour Manipulation

 
  • 0 Vote(s) - 0 Average
Library PAWN Colour Manipulation
kristo
Offline

Burgershot Member
Posts: 47
Threads: 10
Joined: Feb 2019
Reputation: 7
Location: Estonia
#1
2019-04-16, 12:09 PM (This post was last modified: 2019-04-17, 12:48 PM by kristo.)
PAWN Colour Manipulation

[Image: sampctl-pawn--colour--manipulation-2f2f2...-the-badge]

This library provides a number of easy-to-use colour manipulation functions for PAWN.

Installation

Simply install to your project:

Code:
sampctl package install kristoisberg/pawn-colour-manipulation

Include in your code and begin using the library:

PHP Code:
#include <colour-manipulation> 

Testing

To test, simply run the package:

Code:
sampctl package run

There is also a separate test script (samp-grayscale-bitmap) that unfortunately doesn’t work yet due to a bug in samp-bitmapper.

Functions

PHP Code:
GetColourComponents(colour, &Float:r, &Float:g, &Float:b, &Float:a = 1.0, ColourMode:mode = COLOUR_MODE_RGBA) 

Extracts the RGB(A) components from a colour code.

PHP Code:
Float:GetColourComponent(colour, ColourComponent:component, ColourMode:mode = COLOUR_MODE_RGBA) 

Extracts an individual colour component from a colour code and returns it.

PHP Code:
SetColourComponent(colour, ColourComponent:component, Float:value, ColourMode:mode = COLOUR_MODE_RGBA) 

Modifies an individual component of an existing colour and returns the new colour.

PHP Code:
GetColourCode(Float:r, Float:g, Float:b, Float:a = 1.0, ColourMode:mode = COLOUR_MODE_RGBA) 

Creates a colour code from RGB(A) components.

PHP Code:
ConvertColour(colour, ColourMode:from, ColourMode:to, Float:alpha = 1.0) 

Converts a colour from one colour mode to another. Alpha should be specified when converting from RGB, otherwise 0xFF (fully non-transparent) is used.

PHP Code:
InterpolateColours(colour1, colour2, Float:amount, ColourMode:mode = COLOUR_MODE_RGBA) 

Interpolates two colours. amount must be in the range 0.0 - 1.0. The larger amount is, the closer the returned colour is to colour2.

PHP Code:
Float:GetColourBrightness(colour, ColourMode:mode = COLOUR_MODE_RGBA) 

Returns the brightness of a colour.

PHP Code:
DarkenColour(colour, Float:amount, ColourMode:mode = COLOUR_MODE_RGBA) 

Darkens a colour by interpolating it with the black colour.

PHP Code:
LightenColour(colour, Float:amount, ColourMode:mode = COLOUR_MODE_RGBA) 

Lightens a colour by interpolating it with the white colour.

PHP Code:
GrayscaleColour(colour, ColourMode:mode = COLOUR_MODE_RGBA) 

Returns the grayscale equivalent of a colour.

PHP Code:
Float:GetColourComponentFractValue(value) 

Converts a binary colour component value to a fractional value.

PHP Code:
GetColourComponentBinaryValue(Float:value) 

Converts a fractional colour component value to a binary value.

PHP Code:
Float:AddColourComponentGammaCor(Float:value) 

Adds sRGB gamma correction to a colour component.

PHP Code:
Float:RemoveColourComponentGammaCor(Float:value) 

Removes the sRGB gamma correction from a colour component.

Definitions

Colour modes

COLOUR_MODE_RGBA - The most common colour format in SA-MP: used by SendClientMessage, textdraws, etc.

COLOUR_MODE_ARGB- Colour format used by SetObjectMaterial, SetObjectMaterialText and SetPlayerAttachedObject.

COLOUR_MODE_RGB - Colour format used by embedded colours, probably the most common colour format outside of SA-MP, most notably in webpages.

Colour components

COLOUR_COMPONENT_R - Red

COLOUR_COMPONENT_G - Green

COLOUR_COMPONENT_B - Blue

COLOUR_COMPONENT_A - Alpha

Notes

Both British and American spellings (color/colour, gray/grey) are supported for everything noted above.
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#2
2019-04-20, 11:16 AM
Do you remember the link to the original article on the improved interpolation algorithm?
kristo
Offline

Burgershot Member
Posts: 47
Threads: 10
Joined: Feb 2019
Reputation: 7
Location: Estonia
#3
2019-04-20, 02:46 PM (This post was last modified: 2019-04-20, 02:59 PM by kristo.)
(2019-04-20, 11:16 AM)Y_Less Wrote: Do you remember the link to the original article on the improved interpolation algorithm?

I presume you mean this one?
http://entropymine.com/imageworsener/srgbformula/

Also, if anyone's interested, here are the other resources I used for reference when creating this library:
http://blog.johnnovak.net/2016/09/21/wha...out-gamma/
https://stackoverflow.com/questions/5962...0#13558570

And the person who wrote the first article has a few more interesting ones here:
http://entropymine.com/imageworsener/
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#4
2019-04-20, 11:04 PM
Actually I meant this one:

http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

But you linked it anyway, so thanks.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode