Merge tag '2.5.2'
Conflicts: lime/graphics/utils/ImageDataUtil.hx
This commit is contained in:
@@ -23,7 +23,6 @@ namespace lime {
|
||||
int height;
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
bool transparent;
|
||||
int width;
|
||||
|
||||
private:
|
||||
|
||||
@@ -28,8 +28,9 @@ namespace lime {
|
||||
Bytes *data;
|
||||
PixelFormat format;
|
||||
int height;
|
||||
int width;
|
||||
bool premultiplied;
|
||||
bool transparent;
|
||||
int width;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace lime {
|
||||
|
||||
enum PixelFormat {
|
||||
|
||||
RGBA,
|
||||
ARGB,
|
||||
BGRA
|
||||
RGBA32,
|
||||
ARGB32,
|
||||
BGRA32
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace lime {
|
||||
|
||||
virtual void Flip () = 0;
|
||||
virtual value Lock () = 0;
|
||||
virtual const char* Type () = 0;
|
||||
virtual void Unlock () = 0;
|
||||
|
||||
Window* currentWindow;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <math/Vector2.h>
|
||||
#include <system/System.h>
|
||||
#include <utils/Bytes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
@@ -22,9 +23,9 @@ namespace lime {
|
||||
|
||||
static void ColorTransform (Image* image, Rectangle* rect, ColorMatrix* ColorMatrix);
|
||||
static void CopyChannel (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, int srcChannel, int destChannel);
|
||||
static void CopyPixels (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, bool mergeAlpha);
|
||||
static void FillRect (Image* image, Rectangle* rect, int color);
|
||||
static void FloodFill (Image* image, int x, int y, int color);
|
||||
static void CopyPixels (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, Image* alphaImage, Vector2* alphaPoint, bool mergeAlpha);
|
||||
static void FillRect (Image* image, Rectangle* rect, int32_t color);
|
||||
static void FloodFill (Image* image, int x, int y, int32_t color);
|
||||
static void GetPixels (Image* image, Rectangle* rect, PixelFormat format, Bytes* pixels);
|
||||
static void Merge (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, int redMultiplier, int greenMultiplier, int blueMultiplier, int alphaMultiplier);
|
||||
static void MultiplyAlpha (Image* image);
|
||||
@@ -37,6 +38,32 @@ namespace lime {
|
||||
};
|
||||
|
||||
|
||||
class ImageDataView {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
ImageDataView (Image* image, Rectangle* rect);
|
||||
|
||||
void Clip (int x, int y, int width, int height);
|
||||
int Row (int y);
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
private:
|
||||
|
||||
Image* image;
|
||||
int offset;
|
||||
Rectangle* rect;
|
||||
int stride;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <hx/CFFI.h>
|
||||
#include <system/System.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
@@ -20,16 +21,24 @@ namespace lime {
|
||||
|
||||
float GetAlphaMultiplier ();
|
||||
float GetAlphaOffset ();
|
||||
void GetAlphaTable (unsigned char* table);
|
||||
float GetBlueMultiplier ();
|
||||
float GetBlueOffset ();
|
||||
int GetColor ();
|
||||
void GetBlueTable (unsigned char* table);
|
||||
int32_t GetColor ();
|
||||
float GetGreenMultiplier ();
|
||||
float GetGreenOffset ();
|
||||
void GetGreenTable (unsigned char* table);
|
||||
float GetRedMultiplier ();
|
||||
float GetRedOffset ();
|
||||
void GetRedTable (unsigned char* table);
|
||||
|
||||
float data[20];
|
||||
|
||||
private:
|
||||
|
||||
void GetDataTable (unsigned char* table, float multiplier, float offset);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace lime {
|
||||
Rectangle (double x, double y, double width, double height);
|
||||
Rectangle (value rect);
|
||||
|
||||
void Contract (double x, double y, double width, double height);
|
||||
|
||||
double height;
|
||||
double width;
|
||||
double x;
|
||||
|
||||
211
project/include/math/color/RGBA.h
Normal file
211
project/include/math/color/RGBA.h
Normal file
@@ -0,0 +1,211 @@
|
||||
#ifndef LIME_MATH_COLOR_RGBA_H
|
||||
#define LIME_MATH_COLOR_RGBA_H
|
||||
|
||||
|
||||
#include <graphics/PixelFormat.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
int __alpha16[0xFF + 1];
|
||||
int __clamp[0xFF + 0xFF + 1];
|
||||
static int a16;
|
||||
static double unmult;
|
||||
|
||||
int initValues () {
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
|
||||
__alpha16[i] = ceil ((float)(i + 1) * ((1 << 16) / 0xFF));
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < 0xFF; i++) {
|
||||
|
||||
__clamp[i] = i;
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0xFF; i < (0xFF + 0xFF + 1); i++) {
|
||||
|
||||
__clamp[i] = 0xFF;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int initValues_ = initValues ();
|
||||
|
||||
|
||||
struct RGBA {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
inline RGBA () {
|
||||
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
a = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline RGBA (int32_t rgba) {
|
||||
|
||||
r = (rgba >> 24) & 0xFF;
|
||||
g = (rgba >> 16) & 0xFF;
|
||||
b = (rgba >> 8) & 0xFF;
|
||||
a = rgba & 0xFF;
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline RGBA (unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
|
||||
|
||||
Set (r, g, b, a);
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline int32_t Get () {
|
||||
|
||||
int32_t value = ((r & 0xFF) << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF);
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void MultiplyAlpha () {
|
||||
|
||||
if (a == 0) {
|
||||
|
||||
Set (0, 0, 0, 0);
|
||||
|
||||
} else if (a != 0xFF) {
|
||||
|
||||
a16 = __alpha16[a];
|
||||
Set ((r * a16) >> 16, (g * a16) >> 16, (b * a16) >> 16, a);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void UnmultiplyAlpha () {
|
||||
|
||||
if (a != 0 && a != 0xFF) {
|
||||
|
||||
unmult = 255.0 / a;
|
||||
Set (__clamp[(int)(r * unmult)], __clamp[(int)(g * unmult)], __clamp[(int)(b * unmult)], a);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void ReadUInt8 (const unsigned char* data, int offset, PixelFormat format, bool premultiplied) {
|
||||
|
||||
switch (format) {
|
||||
|
||||
case BGRA32:
|
||||
|
||||
Set (data[offset + 2], data[offset + 1], data[offset], data[offset + 3]);
|
||||
break;
|
||||
|
||||
case RGBA32:
|
||||
|
||||
Set (data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
|
||||
break;
|
||||
|
||||
case ARGB32:
|
||||
|
||||
Set (data[offset + 1], data[offset + 2], data[offset + 3], data[offset]);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (premultiplied) {
|
||||
|
||||
UnmultiplyAlpha ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void Set (unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
|
||||
|
||||
this->r = r;
|
||||
this->g = g;
|
||||
this->b = b;
|
||||
this->a = a;
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void WriteUInt8 (unsigned char* data, int offset, PixelFormat format, bool premultiplied) {
|
||||
|
||||
if (premultiplied) {
|
||||
|
||||
MultiplyAlpha ();
|
||||
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
|
||||
case BGRA32:
|
||||
|
||||
data[offset] = b;
|
||||
data[offset + 1] = g;
|
||||
data[offset + 2] = r;
|
||||
data[offset + 3] = a;
|
||||
break;
|
||||
|
||||
case RGBA32:
|
||||
|
||||
data[offset] = r;
|
||||
data[offset + 1] = g;
|
||||
data[offset + 2] = b;
|
||||
data[offset + 3] = a;
|
||||
break;
|
||||
|
||||
case ARGB32:
|
||||
|
||||
data[offset] = a;
|
||||
data[offset + 1] = r;
|
||||
data[offset + 2] = g;
|
||||
data[offset + 3] = b;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline bool operator == (RGBA& rgba) {
|
||||
|
||||
return (a == rgba.a && r == rgba.r && g == rgba.g && b == rgba.b);
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user