summaryrefslogtreecommitdiff
path: root/core/image.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/image.h')
-rw-r--r--core/image.h200
1 files changed, 61 insertions, 139 deletions
diff --git a/core/image.h b/core/image.h
index d0f18841ad..2c585d74d9 100644
--- a/core/image.h
+++ b/core/image.h
@@ -55,35 +55,44 @@ public:
static SavePNGFunc save_png_func;
enum Format {
- FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255
- FORMAT_INTENSITY, ///< one byte per pixel, 0-255
- FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255
- FORMAT_RGB, ///< one byte R, one byte G, one byte B
- FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A
- FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette
- FORMAT_INDEXED_ALPHA, ///< index byte 0-256, and after image end, 256*4 bytes of palette (alpha)
- FORMAT_YUV_422,
- FORMAT_YUV_444,
- FORMAT_BC1, // DXT1
- FORMAT_BC2, // DXT3
- FORMAT_BC3, // DXT5
- FORMAT_BC4, // ATI1
- FORMAT_BC5, // ATI2
- FORMAT_PVRTC2,
- FORMAT_PVRTC2_ALPHA,
- FORMAT_PVRTC4,
- FORMAT_PVRTC4_ALPHA,
- FORMAT_ETC, // regular ETC, no transparency
- FORMAT_ATC,
- FORMAT_ATC_ALPHA_EXPLICIT,
- FORMAT_ATC_ALPHA_INTERPOLATED,
- /*FORMAT_ETC2_R, for the future..
- FORMAT_ETC2_RG,
- FORMAT_ETC2_RGB,
- FORMAT_ETC2_RGBA1,
- FORMAT_ETC2_RGBA,*/
- FORMAT_CUSTOM,
+ FORMAT_L8, //luminance
+ FORMAT_LA8, //luminance-alpha
+ FORMAT_R8,
+ FORMAT_RG8,
+ FORMAT_RGB8,
+ FORMAT_RGBA8,
+ FORMAT_RGB565, //16 bit
+ FORMAT_RGBA4444,
+ FORMAT_RGBA5551,
+ FORMAT_RF, //float
+ FORMAT_RGF,
+ FORMAT_RGBF,
+ FORMAT_RGBAF,
+ FORMAT_RH, //half float
+ FORMAT_RGH,
+ FORMAT_RGBH,
+ FORMAT_RGBAH,
+ FORMAT_DXT1, //s3tc bc1
+ FORMAT_DXT3, //bc2
+ FORMAT_DXT5, //bc3
+ FORMAT_ATI1, //bc4
+ FORMAT_ATI2, //bc5
+ FORMAT_BPTC_RGBA, //btpc bc6h
+ FORMAT_BPTC_RGBF, //float /
+ FORMAT_BPTC_RGBFU, //unsigned float
+ FORMAT_PVRTC2, //pvrtc
+ FORMAT_PVRTC2A,
+ FORMAT_PVRTC4,
+ FORMAT_PVRTC4A,
+ FORMAT_ETC, //etc1
+ FORMAT_ETC2_R11, //etc2
+ FORMAT_ETC2_R11S, //signed, NOT srgb.
+ FORMAT_ETC2_RG11,
+ FORMAT_ETC2_RG11S,
+ FORMAT_ETC2_RGB8,
+ FORMAT_ETC2_RGBA8,
+ FORMAT_ETC2_RGB8A1,
FORMAT_MAX
};
@@ -96,15 +105,21 @@ public:
/* INTERPOLATE GAUSS */
};
+ //some functions provided by something else
+
static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size);
static Image (*_jpg_mem_loader_func)(const uint8_t* p_png,int p_size);
+
static void (*_image_compress_bc_func)(Image *);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc_func)(Image *);
+ static void (*_image_compress_etc2_func)(Image *);
+
static void (*_image_decompress_pvrtc)(Image *);
static void (*_image_decompress_bc)(Image *);
static void (*_image_decompress_etc)(Image *);
+ static void (*_image_decompress_etc2)(Image *);
Error _decompress_bc();
@@ -114,92 +129,19 @@ public:
static Image (*lossless_unpacker)(const DVector<uint8_t>& p_buffer);
private:
- //internal byte based color
- struct BColor {
- union {
- uint8_t col[4];
- struct {
- uint8_t r,g,b,a;
- };
- };
-
- bool operator==(const BColor& p_color) const { for(int i=0;i<4;i++) {if (col[i]!=p_color.col[i]) return false; } return true; }
- _FORCE_INLINE_ uint8_t gray() const { return (uint16_t(col[0])+uint16_t(col[1])+uint16_t(col[2]))/3; }
- _FORCE_INLINE_ BColor() {}
- BColor(uint8_t p_r,uint8_t p_g,uint8_t p_b,uint8_t p_a=255) { col[0]=p_r; col[1]=p_g; col[2]=p_b; col[3]=p_a; }
- };
-
- //median cut classes
-
- struct BColorPos {
-
- uint32_t index;
- BColor color;
- struct SortR {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.r < cb.color.r; }
- };
-
- struct SortG {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.g < cb.color.g; }
- };
-
- struct SortB {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.b < cb.color.b; }
- };
-
- struct SortA {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.a < cb.color.a; }
- };
- };
-
- struct SPTree {
-
- bool leaf;
- uint8_t split_plane;
- uint8_t split_value;
- union {
- int left;
- int color;
- };
- int right;
- SPTree() { leaf=true; left=-1; right=-1;}
- };
-
- struct MCBlock {
-
- BColorPos min_color,max_color;
- BColorPos *colors;
- int sp_idx;
- int color_count;
- int get_longest_axis_index() const;
- int get_longest_axis_length() const;
- bool operator<(const MCBlock& p_block) const;
- void shrink();
- MCBlock();
- MCBlock(BColorPos *p_colors,int p_color_count);
- };
-
Format format;
DVector<uint8_t> data;
- int width,height,mipmaps;
-
-
+ int width,height;
+ bool mipmaps;
- _FORCE_INLINE_ BColor _get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const;
- _FORCE_INLINE_ BColor _get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const;
- _FORCE_INLINE_ void _put_pixelw(int p_x,int p_y, int p_width, const BColor& p_color, unsigned char *p_data);
- _FORCE_INLINE_ void _put_pixel(int p_x,int p_y, const BColor& p_color, unsigned char *p_data);
_FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
- _FORCE_INLINE_ static void _get_format_min_data_size(Format p_format,int &r_w, int &r_h);
static int _get_dst_image_size(int p_width, int p_height, Format p_format,int &r_mipmaps,int p_mipmaps=-1);
bool _can_modify(Format p_format) const;
+ _FORCE_INLINE_ void _put_pixelb(int p_x,int p_y, uint32_t p_pixelsize,uint8_t *p_dst,const uint8_t *p_src);
+ _FORCE_INLINE_ void _get_pixelb(int p_x,int p_y, uint32_t p_pixelsize,const uint8_t *p_src,uint8_t *p_dst);
public:
@@ -207,20 +149,11 @@ public:
int get_width() const; ///< Get image width
int get_height() const; ///< Get image height
- int get_mipmaps() const;
-
- /**
- * Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual
- * value.
- */
- Color get_pixel(int p_x,int p_y,int p_mipmap=0) const;
- /**
- * Set a pixel into the image. for grayscale or indexed formats, a suitable Color constructor.
- */
- void put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap=0); /* alpha and index are averaged */
+ bool has_mipmaps() const;
+ int get_mipmap_count() const;
/**
- * Convert the image to another format, as close as it can be done.
+ * Convert the image to another format, conversion only to raw byte format
*/
void convert( Format p_new_format );
@@ -259,25 +192,21 @@ public:
void flip_x();
void flip_y();
+
/**
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
*/
- Error generate_mipmaps(int p_amount=-1,bool p_keep_existing=false);
+ Error generate_mipmaps(bool p_keep_existing=false);
void clear_mipmaps();
- /**
- * Generate a normal map from a grayscale image
- */
-
- void make_normalmap(float p_height_scale=1.0);
/**
* Create a new image of a given size and format. Current image will be lost
*/
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
- void create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
+ void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
void create( const char ** p_xpm );
/**
@@ -301,7 +230,7 @@ public:
/**
* import an image of a specific size and format from a pointer
*/
- Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
+ Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
enum AlphaMode {
ALPHA_NONE,
@@ -312,32 +241,27 @@ public:
AlphaMode detect_alpha() const;
bool is_invisible() const;
- void put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap=0);
- uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const;
- void set_pallete(const DVector<uint8_t>& p_data);
-
static int get_format_pixel_size(Format p_format);
static int get_format_pixel_rshift(Format p_format);
- static int get_format_pallete_size(Format p_format);
+ static void get_format_min_pixel_size(Format p_format,int &r_w, int &r_h);
+
static int get_image_data_size(int p_width, int p_height, Format p_format,int p_mipmaps=0);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
-
-
bool operator==(const Image& p_image) const;
- void quantize();
-
enum CompressMode {
- COMPRESS_BC,
+ COMPRESS_16BIT,
+ COMPRESS_S3TC,
COMPRESS_PVRTC2,
COMPRESS_PVRTC4,
- COMPRESS_ETC
+ COMPRESS_ETC,
+ COMPRESS_ETC2
};
- Error compress(CompressMode p_mode=COMPRESS_BC);
+ Error compress(CompressMode p_mode=COMPRESS_S3TC);
Image compressed(int p_mode); /* from the Image::CompressMode enum */
Error decompress();
Image decompressed() const;
@@ -349,8 +273,6 @@ public:
void normalmap_to_xy();
void blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest);
- void brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest);
- Image brushed(const Image& p_src, const Image& p_brush, const Point2& p_dest) const;
Rect2 get_used_rect() const;
Image get_rect(const Rect2& p_area) const;