diff options
Diffstat (limited to 'o3d/core')
-rw-r--r-- | o3d/core/cross/bitmap.h | 2 | ||||
-rw-r--r-- | o3d/core/cross/bitmap_png.cc | 18 |
2 files changed, 20 insertions, 0 deletions
diff --git a/o3d/core/cross/bitmap.h b/o3d/core/cross/bitmap.h index 96e9b7b..8af80a5 100644 --- a/o3d/core/cross/bitmap.h +++ b/o3d/core/cross/bitmap.h @@ -239,6 +239,8 @@ class Bitmap : public ParamObject { // Generates Mips from the source_level for num_levels void GenerateMips(int source_level, int num_levels); + bool WriteToPNGStream(std::vector<uint8>* stream); + private: friend class IClassManager; static ObjectBase::Ref Create(ServiceLocator* service_locator); diff --git a/o3d/core/cross/bitmap_png.cc b/o3d/core/cross/bitmap_png.cc index 6b73b94..686e854 100644 --- a/o3d/core/cross/bitmap_png.cc +++ b/o3d/core/cross/bitmap_png.cc @@ -316,6 +316,24 @@ bool CreatePNGInUInt8Vector(const Bitmap& bitmap, std::vector<uint8>* buffer) { } // anonymous namespace +bool Bitmap::WriteToPNGStream(std::vector<uint8>* stream) { + if (format_ != Texture::ARGB8) { + O3D_ERROR(service_locator()) << "Can only write ARGB8 images to PNGs."; + return false; + } + if (num_mipmaps_ != 1) { + O3D_ERROR(service_locator()) << + "Can only write 2d images with no mips to PNGs."; + return false; + } + + if (!CreatePNGInUInt8Vector(*this, stream)) { + return false; + } + + return true; +} + String Bitmap::ToDataURL() { if (format_ != Texture::ARGB8) { O3D_ERROR(service_locator()) << "Can only get data URL from ARGB8 images."; |