Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::image Namespace Reference

Classes

class  NinePatch
 Represents a nine-patch image as described in the Android SDK reference. More...
 

Typedefs

typedef base::ReferentPtr
< NinePatch >::Type 
NinePatchPtr
 Convenience typedef. More...
 

Enumerations

enum  ExternalImageFormat { kPng }
 External image formats supported by ConvertToExternalImageData(). More...
 

Functions

const ImagePtr ION_API ConvertImage (const ImagePtr &image, Image::Format target_format, bool is_wipeable, const base::AllocatorPtr &allocator, const base::AllocatorPtr &temporary_allocator)
 Public functions. More...
 
const ImagePtr ION_API ConvertFromExternalImageData (const void *data, size_t data_size, bool flip_vertically, bool is_wipeable, const base::AllocatorPtr &allocator)
 Converts external image data to an ImagePtr with data in canonical format. More...
 
bool ION_API IsIonRawImageFormat (const void *data, size_t data_size)
 Returns true if "Ion raw" format header is detected in data. More...
 
const std::vector< uint8 > ION_API ConvertToExternalImageData (const ImagePtr &image, ExternalImageFormat external_format, bool flip_vertically)
 
const ImagePtr ION_API DownsampleImage2x (const ImagePtr &image, bool is_wipeable, const base::AllocatorPtr &allocator)
 
const gfx::ImagePtr ResizeImage (const gfx::ImagePtr &image, uint32 out_width, uint32 out_height, bool is_wipeable, const base::AllocatorPtr &allocator)
 Returns a copy of image scaled to the specified dimensions. More...
 
ION_API void FlipImage (const gfx::ImagePtr &image)
 Flips an image vertically in place. More...
 
ION_API void FlipImageHorizontally (const gfx::ImagePtr &image)
 Flips an image horizontally in place. More...
 
ION_API void StraightAlphaFromPremultipliedAlpha (const gfx::ImagePtr &image)
 Converts a "pre-multiplied alpha" RGBA image into a "straight alpha" RGBA image. More...
 
ION_API const gfx::ImagePtr ConvertImage (const gfx::ImagePtr &image, gfx::Image::Format target_format, bool is_wipeable, const base::AllocatorPtr &allocator, const base::AllocatorPtr &temporary_allocator)
 Converts an existing Image to the given target format and returns the resulting Image. More...
 
ION_API const std::vector< uint8 > ConvertToExternalImageData (const gfx::ImagePtr &image, ExternalImageFormat external_format, bool flip_vertically)
 Converts an existing Image to data in external_format, returning a vector. More...
 
ION_API const gfx::ImagePtr DownsampleImage2x (const gfx::ImagePtr &image, bool is_wipeable, const base::AllocatorPtr &allocator)
 Returns an image half the width and height of image. More...
 
const gfx::ImagePtr RenderTextureImage (const gfx::TexturePtr &texture, uint32 width, uint32 height, const gfx::RendererPtr &renderer, const base::AllocatorPtr &allocator)
 Public functions. More...
 
const gfx::ImagePtr RenderCubeMapTextureFaceImage (const gfx::CubeMapTexturePtr &cubemap, gfx::CubeMapTexture::CubeFace face, uint32 width, uint32 height, const gfx::RendererPtr &renderer, const base::AllocatorPtr &allocator)
 This is similar to RenderTextureImage(), but instead operates on one face of a CubeMapTexture. More...
 

Typedef Documentation

Convenience typedef.

Definition at line 109 of file ninepatch.h.

Enumeration Type Documentation

External image formats supported by ConvertToExternalImageData().

Enumerator
kPng 

Definition at line 40 of file conversionutils.h.

Function Documentation

ION_API const gfx::ImagePtr ion::image::ConvertFromExternalImageData ( const void *  data,
size_t  data_size,
bool  flip_vertically,
bool  is_wipeable,
const base::AllocatorPtr &  allocator 
)

Converts external image data to an ImagePtr with data in canonical format.

data_size is the number of bytes in data. Input format is inferred from data.

Supported formats: JPEG, PNG, TGA, BMP, PSD, GIF, HDR, PIC and "ION raw" format (see below for specs of this "ION raw" format). This method attempts to interpret data as the above formats, one after another in the abov order until success, otherwise returns a NULL ImagePtr (i.e. when all supported formats fail for any reasons).

If flip_vertically is true, the resulting image is inverted in the Y dimension. The is_wipeable flag is passed to the DataContainer for the Image. allocator is used for the resulting image; if it is NULL, the default allocator is used.

"ION raw" image format specs:

  • byte #0: 1-byte const 0x89 (non-ASCII)
  • bytes #1-3: three 1-byte consts 0x52 0x41 0x57 (ASCII "RAW")
  • bytes #4-5: 2-byte const 0x0001 or 0x0100 (Endianness indicator)
  • bytes #6-7: 2-byte unsigned integer as format indicator
  • bytes #8-11: unsigned 4-byte integer for width (in pixels)
  • bytes #12-15: unsigned 4-byte integer for height (in pixels)
  • bytes #16-onwards: image data payload.

Endianness of "ION raw" format:

  • Applicable to format indicator, width, height and every pixel value
  • Big/Little Endian if bytes #6-7 are 0x0001/0x0100 respectively.

Formats supported in "ION raw":

  • Image::kRgba8888. Format indicator (bytes #4-5): 0 Payload structure (in Android at least, where it's called ARGB_8888): low-addr [R7...R0][G7...G0][B7...B0][A7...A0] high-addr (Little Endian) low-addr [A7...A0][B7...B0][G7...G0][R7...R0] high-addr (Big Endian)
  • Image::kRgb565. Format indicator (bytes #4-5): 1 Payload structure (in Android at least, where it's called RGB_565): low-addr [G2...G0B4...B0][R4...R0G5...G3] high-addr (Little Endian) low-addr [R4...R0G5...G3][G2...G0B4...B0] high-addr (Big Endian)
  • Image::kRgba4444. Format indicator (bytes #4-5): 2 Payload structure (in Android at least, where it's called ARGB_4444): low-addr [B3...B0A3...A0][R3...R0G3...G0] high-addr (Little Endian) low-addr [R3...R0G3...G0][B3...B0A3...A0] high-addr (Big Endian)
  • Image::kAlpha. Format indicator (bytes #4-5): 3 Payload structure (in Android at least, where it's called ALPHA_8): low-addr [A7...A0] high-addr (Little/Big Endian)

Definition at line 935 of file conversionutils.cc.

References ion::base::AllocationManager::GetNonNullAllocator().

ION_API const gfx::ImagePtr ion::image::ConvertImage ( const gfx::ImagePtr &  image,
gfx::Image::Format  target_format,
bool  is_wipeable,
const base::AllocatorPtr &  allocator,
const base::AllocatorPtr &  temporary_allocator 
)

Converts an existing Image to the given target format and returns the resulting Image.

It returns a NULL pointer if the conversion is not possible for any reason.

Currently-supported conversions: kDxt1 <-> kRgb888 kDxt5 <-> kRgba8888 kEtc1 <-> kRgb888 kPvrtc1Rgba2 <- kRgba8888 (i.e. only one conversion direction available). kR8 <- kRgba888 kR8 <- kRgb888 kR8 <- kDxt1 kR8 <- kDxt5 kR8 <- kEtc1

Note also that kPvrtc1Rgba2 only supports power-of-two-sized square textures at least 8x8 pixels in size.

The conversions to kR8 extract the red channel from an Rgb(a) image. These images can be used as luminance textures and use 1/4 the GPU memory of an uncompressed monochrome Rgb image.

Conversion between 3-component and 4-component formats is not yet supported. The is_wipeable flag is passed to the DataContainer for the new Image. allocator is used for the resulting image; if it is NULL, the default allocator is used. temporary_allocator is used for internal allocations that will be discarded.

const ImagePtr ION_API ion::image::ConvertImage ( const ImagePtr &  image,
Image::Format  target_format,
bool  is_wipeable,
const base::AllocatorPtr &  allocator,
const base::AllocatorPtr &  temporary_allocator 
)

Public functions.

Definition at line 905 of file conversionutils.cc.

References ion::base::AllocationManager::GetNonNullAllocator(), and image.

ION_API const std::vector<uint8> ion::image::ConvertToExternalImageData ( const gfx::ImagePtr &  image,
ExternalImageFormat  external_format,
bool  flip_vertically 
)

Converts an existing Image to data in external_format, returning a vector.

If flip_vertically is true, the resulting image is inverted in the Y dimension. The vector will be empty if the conversion is not possible for any reason. Note that converting to JPEG is not currently supported.

const std::vector<uint8> ION_API ion::image::ConvertToExternalImageData ( const ImagePtr &  image,
ExternalImageFormat  external_format,
bool  flip_vertically 
)

Definition at line 958 of file conversionutils.cc.

ION_API const gfx::ImagePtr ion::image::DownsampleImage2x ( const gfx::ImagePtr &  image,
bool  is_wipeable,
const base::AllocatorPtr &  allocator 
)

Returns an image half the width and height of image.

Currently only kDxt1, kDxt5, kEtc1, and 8-bit-per-channel images are supported; other input formats will return a NULL pointer. The is_wipeable flag is passed to the DataContainer for the new Image. allocator is used for allocating the resulting image, unless it is NULL, then the default C++ allocator will be used.

const ImagePtr ION_API ion::image::DownsampleImage2x ( const ImagePtr &  image,
bool  is_wipeable,
const base::AllocatorPtr &  allocator 
)

Definition at line 967 of file conversionutils.cc.

References LOG, and ion::port::WARNING.

ION_API void ion::image::FlipImage ( const gfx::ImagePtr &  image)

Flips an image vertically in place.

Doesn't work with compressed image formats (logs a warning).

Definition at line 1021 of file conversionutils.cc.

References DLOG, and ion::port::WARNING.

ION_API void ion::image::FlipImageHorizontally ( const gfx::ImagePtr &  image)

Flips an image horizontally in place.

Doesn't work with compressed image formats (logs a warning).

Definition at line 1054 of file conversionutils.cc.

References DLOG, ion::port::WARNING, and width.

ION_API bool ion::image::IsIonRawImageFormat ( const void *  data,
size_t  data_size 
)

Returns true if "Ion raw" format header is detected in data.

Definition at line 949 of file conversionutils.cc.

ION_API const gfx::ImagePtr ion::image::RenderCubeMapTextureFaceImage ( const gfx::CubeMapTexturePtr &  cubemap,
gfx::CubeMapTexture::CubeFace  face,
uint32  width,
uint32  height,
const gfx::RendererPtr &  renderer,
const base::AllocatorPtr &  allocator 
)

This is similar to RenderTextureImage(), but instead operates on one face of a CubeMapTexture.

Definition at line 267 of file renderutils.cc.

ION_API const gfx::ImagePtr ion::image::RenderTextureImage ( const gfx::TexturePtr &  texture,
uint32  width,
uint32  height,
const gfx::RendererPtr &  renderer,
const base::AllocatorPtr &  allocator 
)

Public functions.

Creates and returns an Image representing a Texture.

This uses the Renderer to render the Texture into a new Image that is created using allocator. The new Image will have dimensions width x height, which do not have to be the same as the dimensions of the texture. The Renderer must be the same one that was used previously to render a shape using the Texture.

Definition at line 258 of file renderutils.cc.

References ion::gfx::CubeMapTexture::kNegativeX.

const gfx::ImagePtr ion::image::ResizeImage ( const gfx::ImagePtr &  image,
uint32  out_width,
uint32  out_height,
bool  is_wipeable,
const base::AllocatorPtr &  allocator 
)

Returns a copy of image scaled to the specified dimensions.

Currently only 8-bit-per-channel formats work; other input formats will return a NULL pointer. The is_wipeable flag is passed to the DataContainer for the new Image. allocator is used for allocating the resulting image, unless it is NULL, then the default C++ allocator will be used.

Definition at line 993 of file conversionutils.cc.

References LOG, and ion::port::WARNING.

ION_API void ion::image::StraightAlphaFromPremultipliedAlpha ( const gfx::ImagePtr &  image)

Converts a "pre-multiplied alpha" RGBA image into a "straight alpha" RGBA image.

RGB values are divided by alpha (except when alpha = 0).

Definition at line 1082 of file conversionutils.cc.

References DLOG, ion::gfx::Image::kRgba8888, and ion::port::WARNING.