diff --git a/project/include/graphics/Image.h b/project/include/graphics/Image.h index 9da284dd9..cab2a53d6 100644 --- a/project/include/graphics/Image.h +++ b/project/include/graphics/Image.h @@ -10,10 +10,10 @@ namespace lime { - struct HL_Image { + struct Image { hl_type* t; - HL_ImageBuffer* buffer; + ImageBuffer* buffer; bool dirty; int height; int offsetX; @@ -25,29 +25,8 @@ namespace lime { double x; double y; - }; - - - class Image { - - - public: - - Image (); - Image (value image); - Image (HL_Image* image); - ~Image (); - - ImageBuffer *buffer; - int height; - int offsetX; - int offsetY; - int width; - - private: - - value mValue; - + Image (value image); + ~Image (); }; diff --git a/project/include/graphics/ImageBuffer.h b/project/include/graphics/ImageBuffer.h index 108ee9245..233877660 100644 --- a/project/include/graphics/ImageBuffer.h +++ b/project/include/graphics/ImageBuffer.h @@ -10,11 +10,11 @@ namespace lime { - struct HL_ImageBuffer { + struct ImageBuffer { hl_type* t; int bitsPerPixel; - HL_ArrayBufferView* data; + ArrayBufferView* data; PixelFormat format; int height; bool premultiplied; @@ -28,37 +28,14 @@ namespace lime { vdynamic* __srcImage; vdynamic* __srcImageData; - }; - - - class ImageBuffer { - - - public: - - ImageBuffer (); - ImageBuffer (value imageBuffer); - ImageBuffer (HL_ImageBuffer* imageBuffer); - ~ImageBuffer (); - - void Blit (const unsigned char* data, int x, int y, int width, int height); - void Resize (int width, int height, int bitsPerPixel = 32); - int Stride (); - void* Value (); - - int bitsPerPixel; - ArrayBufferView* data; - PixelFormat format; - int height; - bool premultiplied; - bool transparent; - int width; - - private: - - HL_ImageBuffer* _buffer; - value _value; + ImageBuffer (value imageBuffer); + ~ImageBuffer (); + void Blit (const unsigned char* data, int x, int y, int width, int height); + void Resize (int width, int height, int bitsPerPixel = 32); + int Stride (); + value Value (); + value Value (value imageBuffer); }; diff --git a/project/include/math/ColorMatrix.h b/project/include/math/ColorMatrix.h index cf9fc4f9b..844cac6c0 100644 --- a/project/include/math/ColorMatrix.h +++ b/project/include/math/ColorMatrix.h @@ -18,7 +18,7 @@ namespace lime { ColorMatrix (); ColorMatrix (value colorMatrix); - ColorMatrix (HL_ArrayBufferView* colorMatrix); + ColorMatrix (ArrayBufferView* colorMatrix); ~ColorMatrix (); float GetAlphaMultiplier (); diff --git a/project/include/media/AudioBuffer.h b/project/include/media/AudioBuffer.h index 0c564620a..b176cffc0 100644 --- a/project/include/media/AudioBuffer.h +++ b/project/include/media/AudioBuffer.h @@ -29,12 +29,12 @@ namespace lime { - struct HL_AudioBuffer { + struct AudioBuffer { hl_type* t; int bitsPerSample; int channels; - HL_ArrayBufferView* data; + ArrayBufferView* data; int sampleRate; vdynamic* __srcAudio; @@ -45,31 +45,10 @@ namespace lime { vdynamic* __srcSound; vdynamic* __srcVorbisFile; - }; - - - class AudioBuffer { - - - public: - - AudioBuffer (); - AudioBuffer (value audioBuffer); - AudioBuffer (HL_AudioBuffer* audioBuffer); - ~AudioBuffer (); - - void* Value (); - - int bitsPerSample; - int channels; - int sampleRate; - ArrayBufferView *data; - - private: - - HL_AudioBuffer* _buffer; - value _value; - + AudioBuffer (value audioBuffer); + ~AudioBuffer (); + value Value (value audioBuffer); + value Value (); }; diff --git a/project/include/utils/ArrayBufferView.h b/project/include/utils/ArrayBufferView.h index 900ad86b0..92ead661d 100644 --- a/project/include/utils/ArrayBufferView.h +++ b/project/include/utils/ArrayBufferView.h @@ -9,47 +9,24 @@ namespace lime { - struct HL_ArrayBufferView { + struct ArrayBufferView { hl_type* t; /*TypedArrayType*/ int type; - HL_Bytes* buffer; + Bytes* buffer; int byteOffset; int byteLength; int length; int bytesPerElement; - }; - - - class ArrayBufferView { - - - public: - - ArrayBufferView (); - ArrayBufferView (int size); - ArrayBufferView (value arrayBufferView); - ArrayBufferView (HL_ArrayBufferView* arrayBufferView); - ~ArrayBufferView (); - - unsigned char* Data (); - const unsigned char* Data () const; - int Length () const; - void Resize (int size); - void Set (value bytes); - void Set (const QuickVec data); - value Value (); - - Bytes* buffer; - int byteLength; - int length; - - private: - - HL_ArrayBufferView* _bufferView; - value _value; + ArrayBufferView (value arrayBufferView); + ~ArrayBufferView (); + void Resize (int size); + void Set (value bytes); + void Set (const QuickVec data); + value Value (); + value Value (value arrayBufferView); }; diff --git a/project/include/utils/Bytes.h b/project/include/utils/Bytes.h index b3d63fe4d..ac1c87b4a 100644 --- a/project/include/utils/Bytes.h +++ b/project/include/utils/Bytes.h @@ -9,41 +9,22 @@ namespace lime { - struct HL_Bytes { + struct Bytes { hl_type* t; int length; unsigned char* b; - }; - - - struct Bytes { - - Bytes (); - Bytes (int size); Bytes (value bytes); - Bytes (HL_Bytes* bytes); - Bytes (const char* path); - Bytes (const QuickVec data); ~Bytes (); - unsigned char* Data (); - const unsigned char* Data () const; - int Length () const; void ReadFile (const char* path); void Resize (int size); void Set (value bytes); - void Set (HL_Bytes* bytes); void Set (const QuickVec data); - void* Value (); - - HL_Bytes* _bytes; - unsigned char* _data; - int _length; - value _value; - + value Value (value bytes); + value Value (); }; diff --git a/project/include/utils/Resource.h b/project/include/utils/Resource.h index 8dbdd6c1d..21b5d58be 100644 --- a/project/include/utils/Resource.h +++ b/project/include/utils/Resource.h @@ -18,7 +18,7 @@ namespace lime { Resource (HL_String* path) : data (NULL), path (path ? hl_to_utf8 ((const uchar*)path->bytes) : NULL) {} Resource (Bytes* data) : data (data), path (NULL) {} - Bytes *data; + Bytes* data; const char* path; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index c39a3e962..39e6f64bf 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -306,14 +306,14 @@ namespace lime { if (WAV::Decode (&resource, &audioBuffer)) { - return (value)audioBuffer.Value (); + return audioBuffer.Value (buffer); } #ifdef LIME_OGG if (OGG::Decode (&resource, &audioBuffer)) { - return (value)audioBuffer.Value (); + return audioBuffer.Value (buffer); } #endif @@ -323,26 +323,20 @@ namespace lime { } - HL_PRIM HL_AudioBuffer* hl_lime_audio_load_bytes (HL_Bytes* data, HL_AudioBuffer* buffer) { + HL_PRIM AudioBuffer* hl_lime_audio_load_bytes (Bytes* data, AudioBuffer* buffer) { - Resource resource; - Bytes bytes; + Resource resource = Resource (data); - AudioBuffer audioBuffer = AudioBuffer (buffer); - - bytes.Set (data); - resource = Resource (&bytes); - - if (WAV::Decode (&resource, &audioBuffer)) { + if (WAV::Decode (&resource, buffer)) { - return (HL_AudioBuffer*)audioBuffer.Value (); + return buffer; } #ifdef LIME_OGG - if (OGG::Decode (&resource, &audioBuffer)) { + if (OGG::Decode (&resource, buffer)) { - return (HL_AudioBuffer*)audioBuffer.Value (); + return buffer; } #endif @@ -355,7 +349,6 @@ namespace lime { value lime_audio_load_file (value data, value buffer) { Resource resource; - Bytes bytes; AudioBuffer audioBuffer = AudioBuffer (buffer); @@ -363,14 +356,14 @@ namespace lime { if (WAV::Decode (&resource, &audioBuffer)) { - return (value)audioBuffer.Value (); + return audioBuffer.Value (buffer); } #ifdef LIME_OGG if (OGG::Decode (&resource, &audioBuffer)) { - return (value)audioBuffer.Value (); + return audioBuffer.Value (buffer); } #endif @@ -380,25 +373,20 @@ namespace lime { } - HL_PRIM HL_AudioBuffer* hl_lime_audio_load_file (HL_String* data, HL_AudioBuffer* buffer) { + HL_PRIM AudioBuffer* hl_lime_audio_load_file (HL_String* data, AudioBuffer* buffer) { - Resource resource; - Bytes bytes; + Resource resource = Resource (data ? hl_to_utf8 ((const uchar*)data->bytes) : NULL); - AudioBuffer audioBuffer = AudioBuffer (buffer); - - resource = Resource (data ? hl_to_utf8 ((const uchar*)data->bytes) : NULL); - - if (WAV::Decode (&resource, &audioBuffer)) { + if (WAV::Decode (&resource, buffer)) { - return (HL_AudioBuffer*)audioBuffer.Value (); + return buffer; } #ifdef LIME_OGG - if (OGG::Decode (&resource, &audioBuffer)) { + if (OGG::Decode (&resource, buffer)) { - return (HL_AudioBuffer*)audioBuffer.Value (); + return buffer; } #endif @@ -425,16 +413,17 @@ namespace lime { value lime_bytes_from_data_pointer (double data, int length) { - uintptr_t ptr = (uintptr_t)data; - Bytes bytes (length); + // uintptr_t ptr = (uintptr_t)data; + // Bytes bytes (length); - if (ptr) { + // if (ptr) { - memcpy (bytes.Data (), (const void*)ptr, length); + // memcpy (bytes.b, (const void*)ptr, length); - } + // } - return (value)bytes.Value (); + // return bytes.Value (); + return alloc_null (); } @@ -442,12 +431,12 @@ namespace lime { double lime_bytes_get_data_pointer (value bytes) { Bytes data = Bytes (bytes); - return (uintptr_t)data.Data (); + return (uintptr_t)data.b; } - HL_PRIM double hl_lime_bytes_get_data_pointer (HL_Bytes* bytes) { + HL_PRIM double hl_lime_bytes_get_data_pointer (Bytes* bytes) { return bytes ? (uintptr_t)bytes->b : 0; @@ -457,12 +446,12 @@ namespace lime { double lime_bytes_get_data_pointer_offset (value bytes, int offset) { Bytes data = Bytes (bytes); - return (uintptr_t)data.Data () + offset; + return (uintptr_t)data.b + offset; } - HL_PRIM double hl_lime_bytes_get_data_pointer_offset (HL_Bytes* bytes, int offset) { + HL_PRIM double hl_lime_bytes_get_data_pointer_offset (Bytes* bytes, int offset) { return (uintptr_t)bytes->b + offset; @@ -473,18 +462,16 @@ namespace lime { Bytes data (bytes); data.ReadFile (path.c_str ()); - return (value)data.Value (); + return data.Value (bytes); } - HL_PRIM HL_Bytes* hl_lime_bytes_read_file (HL_String* path, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_bytes_read_file (HL_String* path, Bytes* bytes) { if (!path) return 0; - Bytes data (bytes); - data.ReadFile (hl_to_utf8 ((const uchar*)path->bytes)); - HL_Bytes* ret = (HL_Bytes*)data.Value (); - return ret; + bytes->ReadFile (hl_to_utf8 ((const uchar*)path->bytes)); + return bytes; } @@ -614,7 +601,7 @@ namespace lime { Zlib::Compress (DEFLATE, &data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null(); #endif @@ -622,15 +609,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_deflate_compress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_deflate_compress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_ZLIB - Bytes data (buffer); - Bytes result (bytes); - - Zlib::Compress (DEFLATE, &data, &result); - - return (HL_Bytes*)result.Value (); + Zlib::Compress (DEFLATE, buffer, bytes); + return bytes; #else return 0; #endif @@ -646,7 +629,7 @@ namespace lime { Zlib::Decompress (DEFLATE, &data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null (); #endif @@ -654,15 +637,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_deflate_decompress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_deflate_decompress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_ZLIB - Bytes data (buffer); - Bytes result (bytes); - - Zlib::Decompress (DEFLATE, &data, &result); - - return (HL_Bytes*)result.Value (); + Zlib::Decompress (DEFLATE, buffer, bytes); + return bytes; #else return 0; #endif @@ -1343,14 +1322,10 @@ namespace lime { } - HL_PRIM HL_CFFIPointer* hl_lime_font_load_bytes (HL_Bytes* data) { + HL_PRIM HL_CFFIPointer* hl_lime_font_load_bytes (Bytes* data) { #ifdef LIME_FREETYPE - Resource resource; - Bytes bytes; - - bytes.Set (data); - resource = Resource (&bytes); + Resource resource = Resource (data); Font *font = new Font (&resource, 0); @@ -1377,10 +1352,7 @@ namespace lime { value lime_font_load_file (value data) { #ifdef LIME_FREETYPE - Resource resource; - Bytes bytes; - - resource = Resource (val_string (data)); + Resource resource = Resource (val_string (data)); Font *font = new Font (&resource, 0); @@ -1407,10 +1379,7 @@ namespace lime { HL_PRIM HL_CFFIPointer* hl_lime_font_load_file (HL_String* data) { #ifdef LIME_FREETYPE - Resource resource; - Bytes bytes; - - resource = Resource (data ? hl_to_utf8 ((const uchar*)data->bytes) : NULL); + Resource resource = Resource (data ? hl_to_utf8 ((const uchar*)data->bytes) : NULL); Font *font = new Font (&resource, 0); @@ -1486,12 +1455,11 @@ namespace lime { } - HL_PRIM bool hl_lime_font_render_glyph (HL_CFFIPointer* fontHandle, int index, HL_Bytes* data) { + HL_PRIM bool hl_lime_font_render_glyph (HL_CFFIPointer* fontHandle, int index, Bytes* data) { #ifdef LIME_FREETYPE Font *font = (Font*)fontHandle->ptr; - Bytes bytes (data); - return font->RenderGlyph (index, &bytes); + return font->RenderGlyph (index, data); #else return false; #endif @@ -1512,11 +1480,10 @@ namespace lime { } - HL_PRIM bool hl_lime_font_render_glyphs (HL_CFFIPointer* fontHandle, hl_varray* indices, HL_Bytes* data) { + HL_PRIM bool hl_lime_font_render_glyphs (HL_CFFIPointer* fontHandle, hl_varray* indices, Bytes* data) { // #ifdef LIME_FREETYPE // Font *font = (Font*)fontHandle->ptr; - // Bytes bytes (data); // return font->RenderGlyphs (indices, &bytes); // #else return false; @@ -1650,7 +1617,7 @@ namespace lime { Zlib::Compress (GZIP, &data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null (); #endif @@ -1658,15 +1625,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_gzip_compress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_gzip_compress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_ZLIB - Bytes data (buffer); - Bytes result (bytes); - - Zlib::Compress (GZIP, &data, &result); - - return (HL_Bytes*)result.Value (); + Zlib::Compress (GZIP, buffer, bytes); + return bytes; #else return 0; #endif @@ -1682,7 +1645,7 @@ namespace lime { Zlib::Decompress (GZIP, &data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null (); #endif @@ -1690,15 +1653,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_gzip_decompress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_gzip_decompress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_ZLIB - Bytes data (buffer); - Bytes result (bytes); - - Zlib::Decompress (GZIP, &data, &result); - - return (HL_Bytes*)result.Value (); + Zlib::Decompress (GZIP, buffer, bytes); + return bytes; #else return 0; #endif @@ -1736,7 +1695,7 @@ namespace lime { #ifdef LIME_PNG if (PNG::Encode (&imageBuffer, &data)) { - return (value)data.Value (); + return data.Value (bytes); } #endif @@ -1747,7 +1706,7 @@ namespace lime { #ifdef LIME_JPEG if (JPEG::Encode (&imageBuffer, &data, quality)) { - return (value)data.Value (); + return data.Value (bytes); } #endif @@ -1762,19 +1721,16 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_image_encode (HL_ImageBuffer* buffer, int type, int quality, HL_Bytes* bytes) { - - ImageBuffer imageBuffer = ImageBuffer (buffer); - Bytes data = Bytes (bytes); + HL_PRIM Bytes* hl_lime_image_encode (ImageBuffer* buffer, int type, int quality, Bytes* bytes) { switch (type) { case 0: #ifdef LIME_PNG - if (PNG::Encode (&imageBuffer, &data)) { + if (PNG::Encode (buffer, bytes)) { - return (HL_Bytes*)data.Value (); + return bytes; } #endif @@ -1783,9 +1739,9 @@ namespace lime { case 1: #ifdef LIME_JPEG - if (JPEG::Encode (&imageBuffer, &data, quality)) { + if (JPEG::Encode (buffer, bytes, quality)) { - return (HL_Bytes*)data.Value (); + return bytes; } #endif @@ -1813,7 +1769,7 @@ namespace lime { #ifdef LIME_PNG if (PNG::Decode (&resource, &imageBuffer)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -1821,7 +1777,7 @@ namespace lime { #ifdef LIME_JPEG if (JPEG::Decode (&resource, &imageBuffer)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -1831,28 +1787,22 @@ namespace lime { } - HL_PRIM HL_ImageBuffer* hl_lime_image_load_bytes (HL_Bytes* data, HL_ImageBuffer* buffer) { + HL_PRIM ImageBuffer* hl_lime_image_load_bytes (Bytes* data, ImageBuffer* buffer) { - Resource resource; - Bytes bytes; - - ImageBuffer imageBuffer = ImageBuffer (buffer); - - bytes.Set (data); - resource = Resource (&bytes); + Resource resource = Resource (data); #ifdef LIME_PNG - if (PNG::Decode (&resource, &imageBuffer)) { + if (PNG::Decode (&resource, buffer)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif #ifdef LIME_JPEG - if (JPEG::Decode (&resource, &imageBuffer)) { + if (JPEG::Decode (&resource, buffer)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif @@ -1864,17 +1814,13 @@ namespace lime { value lime_image_load_file (value data, value buffer) { - Resource resource; - Bytes bytes; - + Resource resource = Resource (val_string (data)); ImageBuffer imageBuffer = ImageBuffer (buffer); - resource = Resource (val_string (data)); - #ifdef LIME_PNG if (PNG::Decode (&resource, &imageBuffer)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -1882,7 +1828,7 @@ namespace lime { #ifdef LIME_JPEG if (JPEG::Decode (&resource, &imageBuffer)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -1892,27 +1838,22 @@ namespace lime { } - HL_PRIM HL_ImageBuffer* hl_lime_image_load_file (HL_String* data, HL_ImageBuffer* buffer) { + HL_PRIM ImageBuffer* hl_lime_image_load_file (HL_String* data, ImageBuffer* buffer) { - Resource resource; - Bytes bytes; - - ImageBuffer imageBuffer = ImageBuffer (buffer); - - resource = Resource (data); + Resource resource = Resource (data); #ifdef LIME_PNG - if (PNG::Decode (&resource, &imageBuffer)) { + if (PNG::Decode (&resource, buffer)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif #ifdef LIME_JPEG - if (JPEG::Decode (&resource, &imageBuffer)) { + if (JPEG::Decode (&resource, buffer)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif @@ -1947,12 +1888,11 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_color_transform (HL_Image* image, HL_Rectangle* rect, HL_ArrayBufferView* colorMatrix) { + HL_PRIM void hl_lime_image_data_util_color_transform (Image* image, HL_Rectangle* rect, ArrayBufferView* colorMatrix) { - Image _image = Image (image); Rectangle _rect = Rectangle (rect); ColorMatrix _colorMatrix = ColorMatrix (colorMatrix); - ImageDataUtil::ColorTransform (&_image, &_rect, &_colorMatrix); + ImageDataUtil::ColorTransform (image, &_rect, &_colorMatrix); } @@ -1968,13 +1908,11 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_copy_channel (HL_Image* image, HL_Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, int srcChannel, int destChannel) { + HL_PRIM void hl_lime_image_data_util_copy_channel (Image* image, Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, int srcChannel, int destChannel) { - Image _image = Image (image); - Image _sourceImage = Image (sourceImage); Rectangle _sourceRect = Rectangle (sourceRect); Vector2 _destPoint = Vector2 (destPoint); - ImageDataUtil::CopyChannel (&_image, &_sourceImage, &_sourceRect, &_destPoint, srcChannel, destChannel); + ImageDataUtil::CopyChannel (image, sourceImage, &_sourceRect, &_destPoint, srcChannel, destChannel); } @@ -2002,23 +1940,20 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_copy_pixels (HL_Image* image, HL_Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, HL_Image* alphaImage, HL_Vector2* alphaPoint, bool mergeAlpha) { + HL_PRIM void hl_lime_image_data_util_copy_pixels (Image* image, Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, Image* alphaImage, HL_Vector2* alphaPoint, bool mergeAlpha) { - Image _image = Image (image); - Image _sourceImage = Image (sourceImage); Rectangle _sourceRect = Rectangle (sourceRect); Vector2 _destPoint = Vector2 (destPoint); if (!alphaImage) { - ImageDataUtil::CopyPixels (&_image, &_sourceImage, &_sourceRect, &_destPoint, 0, 0, mergeAlpha); + ImageDataUtil::CopyPixels (image, sourceImage, &_sourceRect, &_destPoint, NULL, NULL, mergeAlpha); } else { - Image _alphaImage = Image (alphaImage); Vector2 _alphaPoint = Vector2 (alphaPoint); - ImageDataUtil::CopyPixels (&_image, &_sourceImage, &_sourceRect, &_destPoint, &_alphaImage, &_alphaPoint, mergeAlpha); + ImageDataUtil::CopyPixels (image, sourceImage, &_sourceRect, &_destPoint, alphaImage, &_alphaPoint, mergeAlpha); } @@ -2035,12 +1970,11 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_fill_rect (HL_Image* image, HL_Rectangle* rect, int rg, int ba) { + HL_PRIM void hl_lime_image_data_util_fill_rect (Image* image, HL_Rectangle* rect, int rg, int ba) { - Image _image = Image (image); Rectangle _rect = Rectangle (rect); int32_t color = (rg << 16) | ba; - ImageDataUtil::FillRect (&_image, &_rect, color); + ImageDataUtil::FillRect (image, &_rect, color); } @@ -2054,11 +1988,10 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_flood_fill (HL_Image* image, int x, int y, int rg, int ba) { + HL_PRIM void hl_lime_image_data_util_flood_fill (Image* image, int x, int y, int rg, int ba) { - Image _image = Image (image); int32_t color = (rg << 16) | ba; - ImageDataUtil::FloodFill (&_image, x, y, color); + ImageDataUtil::FloodFill (image, x, y, color); } @@ -2074,13 +2007,11 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_get_pixels (HL_Image* image, HL_Rectangle* rect, int format, HL_Bytes* bytes) { + HL_PRIM void hl_lime_image_data_util_get_pixels (Image* image, HL_Rectangle* rect, int format, Bytes* bytes) { - Image _image = Image (image); Rectangle _rect = Rectangle (rect); PixelFormat _format = (PixelFormat)format; - Bytes pixels = Bytes (bytes); - ImageDataUtil::GetPixels (&_image, &_rect, _format, &pixels); + ImageDataUtil::GetPixels (image, &_rect, _format, bytes); } @@ -2096,13 +2027,11 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_merge (HL_Image* image, HL_Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, int redMultiplier, int greenMultiplier, int blueMultiplier, int alphaMultiplier) { + HL_PRIM void hl_lime_image_data_util_merge (Image* image, Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, int redMultiplier, int greenMultiplier, int blueMultiplier, int alphaMultiplier) { - Image _image = Image (image); - Image _sourceImage = Image (sourceImage); Rectangle _sourceRect = Rectangle (sourceRect); Vector2 _destPoint = Vector2 (destPoint); - ImageDataUtil::Merge (&_image, &_sourceImage, &_sourceRect, &_destPoint, redMultiplier, greenMultiplier, blueMultiplier, alphaMultiplier); + ImageDataUtil::Merge (image, sourceImage, &_sourceRect, &_destPoint, redMultiplier, greenMultiplier, blueMultiplier, alphaMultiplier); } @@ -2115,10 +2044,9 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_multiply_alpha (HL_Image* image) { + HL_PRIM void hl_lime_image_data_util_multiply_alpha (Image* image) { - Image _image = Image (image); - ImageDataUtil::MultiplyAlpha (&_image); + ImageDataUtil::MultiplyAlpha (image); } @@ -2132,11 +2060,9 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_resize (HL_Image* image, HL_ImageBuffer* buffer, int width, int height) { + HL_PRIM void hl_lime_image_data_util_resize (Image* image, ImageBuffer* buffer, int width, int height) { - Image _image = Image (image); - ImageBuffer _buffer = ImageBuffer (buffer); - ImageDataUtil::Resize (&_image, &_buffer, width, height); + ImageDataUtil::Resize (image, buffer, width, height); } @@ -2150,11 +2076,9 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_set_format (HL_Image* image, int format) { + HL_PRIM void hl_lime_image_data_util_set_format (Image* image, PixelFormat format) { - Image _image = Image (image); - PixelFormat _format = (PixelFormat)format; - ImageDataUtil::SetFormat (&_image, _format); + ImageDataUtil::SetFormat (image, format); } @@ -2171,14 +2095,10 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_set_pixels (HL_Image* image, HL_Rectangle* rect, HL_Bytes* bytes, int offset, int format, int endian) { + HL_PRIM void hl_lime_image_data_util_set_pixels (Image* image, HL_Rectangle* rect, Bytes* bytes, int offset, PixelFormat format, Endian endian) { - Image _image = Image (image); Rectangle _rect = Rectangle (rect); - Bytes _bytes (bytes); - PixelFormat _format = (PixelFormat)format; - Endian _endian = (Endian)endian; - ImageDataUtil::SetPixels (&_image, &_rect, &_bytes, offset, _format, _endian); + ImageDataUtil::SetPixels (image, &_rect, bytes, offset, format, endian); } @@ -2197,16 +2117,14 @@ namespace lime { } - HL_PRIM int hl_lime_image_data_util_threshold (HL_Image* image, HL_Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, int operation, int thresholdRG, int thresholdBA, int colorRG, int colorBA, int maskRG, int maskBA, bool copySource) { + HL_PRIM int hl_lime_image_data_util_threshold (Image* image, Image* sourceImage, HL_Rectangle* sourceRect, HL_Vector2* destPoint, int operation, int thresholdRG, int thresholdBA, int colorRG, int colorBA, int maskRG, int maskBA, bool copySource) { - Image _image = Image (image); - Image _sourceImage = Image (sourceImage); Rectangle _sourceRect = Rectangle (sourceRect); Vector2 _destPoint = Vector2 (destPoint); int32_t threshold = (thresholdRG << 16) | thresholdBA; int32_t color = (colorRG << 16) | colorBA; int32_t mask = (maskRG << 16) | maskBA; - return ImageDataUtil::Threshold (&_image, &_sourceImage, &_sourceRect, &_destPoint, operation, threshold, color, mask, copySource); + return ImageDataUtil::Threshold (image, sourceImage, &_sourceRect, &_destPoint, operation, threshold, color, mask, copySource); } @@ -2219,10 +2137,9 @@ namespace lime { } - HL_PRIM void hl_lime_image_data_util_unmultiply_alpha (HL_Image* image) { + HL_PRIM void hl_lime_image_data_util_unmultiply_alpha (Image* image) { - Image _image = Image (image); - ImageDataUtil::UnmultiplyAlpha (&_image); + ImageDataUtil::UnmultiplyAlpha (image); } @@ -2361,7 +2278,7 @@ namespace lime { #ifdef LIME_JPEG if (JPEG::Decode (&resource, &imageBuffer, decodeData)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -2371,17 +2288,14 @@ namespace lime { } - HL_PRIM HL_ImageBuffer* hl_lime_jpeg_decode_bytes (HL_Bytes* data, bool decodeData, HL_ImageBuffer* buffer) { + HL_PRIM ImageBuffer* hl_lime_jpeg_decode_bytes (Bytes* data, bool decodeData, ImageBuffer* buffer) { - ImageBuffer imageBuffer (buffer); - - Bytes bytes (data); - Resource resource = Resource (&bytes); + Resource resource = Resource (data); #ifdef LIME_JPEG - if (JPEG::Decode (&resource, &imageBuffer, decodeData)) { + if (JPEG::Decode (&resource, buffer, decodeData)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif @@ -2399,7 +2313,7 @@ namespace lime { #ifdef LIME_JPEG if (JPEG::Decode (&resource, &imageBuffer, decodeData)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -2409,15 +2323,14 @@ namespace lime { } - HL_PRIM HL_ImageBuffer* hl_lime_jpeg_decode_file (HL_String* path, bool decodeData, HL_ImageBuffer* buffer) { + HL_PRIM ImageBuffer* hl_lime_jpeg_decode_file (HL_String* path, bool decodeData, ImageBuffer* buffer) { - ImageBuffer imageBuffer (buffer); Resource resource = Resource (path); #ifdef LIME_JPEG - if (JPEG::Decode (&resource, &imageBuffer, decodeData)) { + if (JPEG::Decode (&resource, buffer, decodeData)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif @@ -2520,7 +2433,7 @@ namespace lime { LZMA::Compress (&data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null (); #endif @@ -2528,15 +2441,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_lzma_compress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_lzma_compress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_LZMA - Bytes data (buffer); - Bytes result (bytes); - - LZMA::Compress (&data, &result); - - return (HL_Bytes*)result.Value (); + LZMA::Compress (buffer, bytes); + return bytes; #else return 0; #endif @@ -2552,7 +2461,7 @@ namespace lime { LZMA::Decompress (&data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null (); #endif @@ -2560,15 +2469,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_lzma_decompress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_lzma_decompress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_LZMA - Bytes data (buffer); - Bytes result (bytes); - - LZMA::Decompress (&data, &result); - - return (HL_Bytes*)result.Value (); + LZMA::Decompress (buffer, bytes); + return bytes; #else return 0; #endif @@ -2696,7 +2601,7 @@ namespace lime { #ifdef LIME_PNG if (PNG::Decode (&resource, &imageBuffer, decodeData)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -2706,16 +2611,14 @@ namespace lime { } - HL_PRIM HL_ImageBuffer* hl_lime_png_decode_bytes (HL_Bytes* data, bool decodeData, HL_ImageBuffer* buffer) { + HL_PRIM ImageBuffer* hl_lime_png_decode_bytes (Bytes* data, bool decodeData, ImageBuffer* buffer) { - ImageBuffer imageBuffer (buffer); - Bytes bytes (data); - Resource resource = Resource (&bytes); + Resource resource = Resource (data); #ifdef LIME_PNG - if (PNG::Decode (&resource, &imageBuffer, decodeData)) { + if (PNG::Decode (&resource, buffer, decodeData)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif @@ -2733,7 +2636,7 @@ namespace lime { #ifdef LIME_PNG if (PNG::Decode (&resource, &imageBuffer, decodeData)) { - return (value)imageBuffer.Value (); + return imageBuffer.Value (buffer); } #endif @@ -2743,15 +2646,14 @@ namespace lime { } - HL_PRIM HL_ImageBuffer* hl_lime_png_decode_file (HL_String* path, bool decodeData, HL_ImageBuffer* buffer) { + HL_PRIM ImageBuffer* hl_lime_png_decode_file (HL_String* path, bool decodeData, ImageBuffer* buffer) { - ImageBuffer imageBuffer (buffer); Resource resource = Resource (path); #ifdef LIME_PNG - if (PNG::Decode (&resource, &imageBuffer, decodeData)) { + if (PNG::Decode (&resource, buffer, decodeData)) { - return (HL_ImageBuffer*)imageBuffer.Value (); + return buffer; } #endif @@ -2900,28 +2802,27 @@ namespace lime { } - return (value)buffer.Value (); + return buffer.Value (imageBuffer); } - HL_PRIM HL_ImageBuffer* hl_lime_renderer_read_pixels (HL_CFFIPointer* renderer, HL_Rectangle* rect, HL_ImageBuffer* imageBuffer) { + HL_PRIM ImageBuffer* hl_lime_renderer_read_pixels (HL_CFFIPointer* renderer, HL_Rectangle* rect, ImageBuffer* imageBuffer) { Renderer* targetRenderer = (Renderer*)renderer->ptr; - ImageBuffer buffer (imageBuffer); if (rect) { Rectangle _rect = Rectangle (rect); - targetRenderer->ReadPixels (&buffer, &_rect); + targetRenderer->ReadPixels (imageBuffer, &_rect); } else { - targetRenderer->ReadPixels (&buffer, NULL); + targetRenderer->ReadPixels (imageBuffer, NULL); } - return (HL_ImageBuffer*)buffer.Value (); + return imageBuffer; } @@ -3431,7 +3332,7 @@ namespace lime { Font *font = (Font*)val_data (fontHandle); Bytes bytes (data); text->Position (font, size, textString.c_str (), &bytes); - return (value)bytes.Value (); + return bytes.Value (data); #endif @@ -3440,15 +3341,14 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_text_layout_position (HL_CFFIPointer* textHandle, HL_CFFIPointer* fontHandle, int size, HL_String* textString, HL_Bytes* data) { + HL_PRIM Bytes* hl_lime_text_layout_position (HL_CFFIPointer* textHandle, HL_CFFIPointer* fontHandle, int size, HL_String* textString, Bytes* data) { #if defined(LIME_FREETYPE) && defined(LIME_HARFBUZZ) - TextLayout *text = (TextLayout*)textHandle->ptr; - Font *font = (Font*)fontHandle->ptr; - Bytes bytes (data); - text->Position (font, size, textString ? hl_to_utf8 ((const uchar*)textString->bytes) : NULL, &bytes); - return (HL_Bytes*)bytes.Value (); + TextLayout* text = (TextLayout*)textHandle->ptr; + Font* font = (Font*)fontHandle->ptr; + text->Position (font, size, textString ? hl_to_utf8 ((const uchar*)textString->bytes) : NULL, data); + return data; #endif @@ -3856,11 +3756,10 @@ namespace lime { } - HL_PRIM void hl_lime_window_set_icon (HL_CFFIPointer* window, HL_ImageBuffer* buffer) { + HL_PRIM void hl_lime_window_set_icon (HL_CFFIPointer* window, ImageBuffer* buffer) { Window* targetWindow = (Window*)window->ptr; - ImageBuffer imageBuffer = ImageBuffer (buffer); - targetWindow->SetIcon (&imageBuffer); + targetWindow->SetIcon (buffer); } @@ -3975,7 +3874,7 @@ namespace lime { Zlib::Compress (ZLIB, &data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null (); #endif @@ -3983,15 +3882,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_zlib_compress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_zlib_compress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_ZLIB - Bytes data (buffer); - Bytes result (bytes); - - Zlib::Compress (ZLIB, &data, &result); - - return (HL_Bytes*)result.Value (); + Zlib::Compress (ZLIB, buffer, bytes); + return bytes; #else return 0; #endif @@ -4007,7 +3902,7 @@ namespace lime { Zlib::Decompress (ZLIB, &data, &result); - return (value)result.Value (); + return result.Value (bytes); #else return alloc_null (); #endif @@ -4015,15 +3910,11 @@ namespace lime { } - HL_PRIM HL_Bytes* hl_lime_zlib_decompress (HL_Bytes* buffer, HL_Bytes* bytes) { + HL_PRIM Bytes* hl_lime_zlib_decompress (Bytes* buffer, Bytes* bytes) { #ifdef LIME_ZLIB - Bytes data (buffer); - Bytes result (bytes); - - Zlib::Decompress (ZLIB, &data, &result); - - return (HL_Bytes*)result.Value (); + Zlib::Decompress (ZLIB, buffer, bytes); + return bytes; #else return 0; #endif diff --git a/project/src/backend/sdl/SDLRenderer.cpp b/project/src/backend/sdl/SDLRenderer.cpp index 1be9db218..8e7018180 100644 --- a/project/src/backend/sdl/SDLRenderer.cpp +++ b/project/src/backend/sdl/SDLRenderer.cpp @@ -302,7 +302,7 @@ namespace lime { buffer->Resize (bounds.w, bounds.h, 32); - SDL_RenderReadPixels (sdlRenderer, &bounds, SDL_PIXELFORMAT_ABGR8888, buffer->data->Data (), buffer->Stride ()); + SDL_RenderReadPixels (sdlRenderer, &bounds, SDL_PIXELFORMAT_ABGR8888, buffer->data->buffer->b, buffer->Stride ()); } else if (context) { diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index da7037f73..04b3febde 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -446,7 +446,7 @@ namespace lime { void SDLWindow::SetIcon (ImageBuffer *imageBuffer) { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Data (), imageBuffer->width, imageBuffer->height, imageBuffer->bitsPerPixel, imageBuffer->Stride (), 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->buffer->b, imageBuffer->width, imageBuffer->height, imageBuffer->bitsPerPixel, imageBuffer->Stride (), 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); if (surface) { diff --git a/project/src/graphics/Image.cpp b/project/src/graphics/Image.cpp index 15beb3f45..c4fc901de 100644 --- a/project/src/graphics/Image.cpp +++ b/project/src/graphics/Image.cpp @@ -12,17 +12,6 @@ namespace lime { static bool init = false; - Image::Image () { - - buffer = 0; - height = 0; - offsetX = 0; - offsetY = 0; - width = 0; - - } - - Image::Image (value image) { if (!init) { @@ -45,20 +34,13 @@ namespace lime { } - Image::Image (HL_Image* image) { - - width = image->width; - height = image->height; - buffer = new ImageBuffer (image->buffer); - offsetX = image->offsetX; - offsetY = image->offsetY; - - } - - Image::~Image () { - delete buffer; + if (buffer) { + + delete buffer; + + } } diff --git a/project/src/graphics/ImageBuffer.cpp b/project/src/graphics/ImageBuffer.cpp index bb7962332..6a835d0b9 100644 --- a/project/src/graphics/ImageBuffer.cpp +++ b/project/src/graphics/ImageBuffer.cpp @@ -14,21 +14,6 @@ namespace lime { static bool init = false; - ImageBuffer::ImageBuffer () { - - width = 0; - height = 0; - bitsPerPixel = 32; - format = RGBA32; - data = 0; - premultiplied = false; - transparent = false; - _buffer = 0; - _value = 0; - - } - - ImageBuffer::ImageBuffer (value imageBuffer) { if (!init) { @@ -66,40 +51,6 @@ namespace lime { } - _buffer = 0; - _value = imageBuffer; - - } - - - ImageBuffer::ImageBuffer (HL_ImageBuffer* imageBuffer) { - - if (imageBuffer) { - - width = imageBuffer->width; - height = imageBuffer->height; - bitsPerPixel = imageBuffer->bitsPerPixel; - format = imageBuffer->format; - transparent = imageBuffer->transparent; - premultiplied = imageBuffer->premultiplied; - data = new ArrayBufferView (imageBuffer->data); - _buffer = imageBuffer; - - } else { - - width = 0; - height = 0; - bitsPerPixel = 32; - format = RGBA32; - data = 0; - premultiplied = false; - transparent = false; - _buffer = 0; - - } - - _value = 0; - } @@ -123,7 +74,7 @@ namespace lime { } int stride = Stride (); - unsigned char *bytes = this->data->buffer->Data (); + unsigned char *bytes = this->data->buffer->b; for (int i = 0; i < height; i++) { @@ -144,7 +95,7 @@ namespace lime { if (!this->data) { - this->data = new ArrayBufferView (height * stride); + //this->data = new ArrayBufferView (height * stride); } else { @@ -162,51 +113,37 @@ namespace lime { } - void* ImageBuffer::Value () { + value ImageBuffer::Value () { - if (_buffer) { + return Value (alloc_empty_object ()); + + } + + + value ImageBuffer::Value (value imageBuffer) { + + if (!init) { - _buffer->width = width; - _buffer->height = height; - _buffer->bitsPerPixel = bitsPerPixel; - _buffer->format = format; - _buffer->transparent = transparent; - _buffer->premultiplied = premultiplied; - //_buffer->data - return _buffer; - - } else { - - if (!init) { - - id_bitsPerPixel = val_id ("bitsPerPixel"); - id_transparent = val_id ("transparent"); - id_data = val_id ("data"); - id_width = val_id ("width"); - id_height = val_id ("height"); - id_format = val_id ("format"); - id_premultiplied = val_id ("premultiplied"); - init = true; - - } - - if (val_is_null (_value)) { - - _value = alloc_empty_object (); - - } - - alloc_field (_value, id_width, alloc_int (width)); - alloc_field (_value, id_height, alloc_int (height)); - alloc_field (_value, id_bitsPerPixel, alloc_int (bitsPerPixel)); - alloc_field (_value, id_data, data ? data->Value () : alloc_null ()); - alloc_field (_value, id_transparent, alloc_bool (transparent)); - alloc_field (_value, id_format, alloc_int (format)); - alloc_field (_value, id_premultiplied, alloc_bool (premultiplied)); - return _value; + id_bitsPerPixel = val_id ("bitsPerPixel"); + id_transparent = val_id ("transparent"); + id_data = val_id ("data"); + id_width = val_id ("width"); + id_height = val_id ("height"); + id_format = val_id ("format"); + id_premultiplied = val_id ("premultiplied"); + init = true; } + alloc_field (imageBuffer, id_width, alloc_int (width)); + alloc_field (imageBuffer, id_height, alloc_int (height)); + alloc_field (imageBuffer, id_bitsPerPixel, alloc_int (bitsPerPixel)); + alloc_field (imageBuffer, id_data, data ? data->Value (val_field (imageBuffer, id_data)) : alloc_null ()); + alloc_field (imageBuffer, id_transparent, alloc_bool (transparent)); + alloc_field (imageBuffer, id_format, alloc_int (format)); + alloc_field (imageBuffer, id_premultiplied, alloc_bool (premultiplied)); + return imageBuffer; + } diff --git a/project/src/graphics/format/JPEG.cpp b/project/src/graphics/format/JPEG.cpp index d807e6ff5..9cd3b40da 100644 --- a/project/src/graphics/format/JPEG.cpp +++ b/project/src/graphics/format/JPEG.cpp @@ -241,15 +241,16 @@ namespace lime { } else { - data = new Bytes (resource->path); - manager = new MySrcManager (data->Data (), data->Length ()); + data = (Bytes*)malloc (sizeof (Bytes)); + data->ReadFile (resource->path); + manager = new MySrcManager (data->b, data->length); cinfo.src = &manager->pub; } } else { - manager = new MySrcManager (resource->data->Data (), resource->data->Length ()); + manager = new MySrcManager (resource->data->b, resource->data->length); cinfo.src = &manager->pub; } @@ -266,7 +267,7 @@ namespace lime { int components = cinfo.output_components; imageBuffer->Resize (cinfo.output_width, cinfo.output_height, 32); - unsigned char *bytes = imageBuffer->data->Data (); + unsigned char *bytes = imageBuffer->data->buffer->b; unsigned char *scanline = new unsigned char [imageBuffer->width * components]; while (cinfo.output_scanline < cinfo.output_height) { @@ -363,7 +364,7 @@ namespace lime { jpeg_start_compress (&cinfo, TRUE); JSAMPROW row_pointer = &row_buf[0]; - unsigned char* imageData = imageBuffer->data->Data(); + unsigned char* imageData = imageBuffer->data->buffer->b; int stride = imageBuffer->Stride (); while (cinfo.next_scanline < cinfo.image_height) { @@ -387,7 +388,14 @@ namespace lime { jpeg_finish_compress (&cinfo); - bytes->Set (dest.mOutput); + int size = dest.mOutput.size (); + + if (size > 0) { + + bytes->Resize (size); + memcpy (bytes->b, &dest.mOutput[0], size); + + } return true; diff --git a/project/src/graphics/format/PNG.cpp b/project/src/graphics/format/PNG.cpp index 8260a1e78..5c12f2c85 100644 --- a/project/src/graphics/format/PNG.cpp +++ b/project/src/graphics/format/PNG.cpp @@ -82,8 +82,8 @@ namespace lime { png_uint_32 width, height; int bit_depth, color_type, interlace_type; - FILE_HANDLE *file = NULL; - Bytes *data = NULL; + FILE_HANDLE* file = NULL; + Bytes* data = NULL; if (resource->path) { @@ -101,7 +101,7 @@ namespace lime { } else { - if (png_sig_cmp (resource->data->Data (), 0, PNG_SIG_SIZE)) { + if (png_sig_cmp (resource->data->b, 0, PNG_SIG_SIZE)) { return false; @@ -142,15 +142,16 @@ namespace lime { } else { - data = new Bytes (resource->path); - ReadBuffer buffer (data->Data (), data->Length ()); + data = (Bytes*)malloc (sizeof (Bytes)); + data->ReadFile (resource->path); + ReadBuffer buffer (data->b, data->length); png_set_read_fn (png_ptr, &buffer, user_read_data_fn); } } else { - ReadBuffer buffer (resource->data->Data (), resource->data->Length ()); + ReadBuffer buffer (resource->data->b, resource->data->length); png_set_read_fn (png_ptr, &buffer, user_read_data_fn); } @@ -184,7 +185,7 @@ namespace lime { imageBuffer->Resize (width, height, 32); const unsigned int stride = imageBuffer->Stride (); - unsigned char *bytes = imageBuffer->data->Data (); + unsigned char *bytes = imageBuffer->data->buffer->b; int number_of_passes = png_set_interlace_handling (png_ptr); @@ -218,7 +219,7 @@ namespace lime { } - bool PNG::Encode (ImageBuffer *imageBuffer, Bytes *bytes) { + bool PNG::Encode (ImageBuffer *imageBuffer, Bytes* bytes) { png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, user_error_fn, user_warning_fn); @@ -258,7 +259,7 @@ namespace lime { png_write_info (png_ptr, info_ptr); bool do_alpha = (color_type == PNG_COLOR_TYPE_RGBA); - unsigned char* imageData = imageBuffer->data->Data(); + unsigned char* imageData = imageBuffer->data->buffer->b; int stride = imageBuffer->Stride (); { @@ -296,7 +297,14 @@ namespace lime { png_write_end (png_ptr, NULL); - bytes->Set (out_buffer); + int size = out_buffer.size (); + + if (size > 0) { + + bytes->Resize (size); + memcpy (bytes->b, &out_buffer[0], size); + + } return true; diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index b8d96bedd..ffa762395 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -17,7 +17,7 @@ namespace lime { PixelFormat format = image->buffer->format; bool premultiplied = image->buffer->premultiplied; - uint8_t* data = (uint8_t*)image->buffer->data->Data (); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; ImageDataView dataView = ImageDataView (image, rect); @@ -50,8 +50,8 @@ namespace lime { void ImageDataUtil::CopyChannel (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, int srcChannel, int destChannel) { - uint8_t* srcData = (uint8_t*)sourceImage->buffer->data->Data (); - uint8_t* destData = (uint8_t*)image->buffer->data->Data (); + uint8_t* srcData = (uint8_t*)sourceImage->buffer->data->buffer->b; + uint8_t* destData = (uint8_t*)image->buffer->data->buffer->b; ImageDataView srcView = ImageDataView (sourceImage, sourceRect); Rectangle destRect = Rectangle (destPoint->x, destPoint->y, srcView.width, srcView.height); @@ -108,8 +108,8 @@ namespace lime { void ImageDataUtil::CopyPixels (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, Image* alphaImage, Vector2* alphaPoint, bool mergeAlpha) { - uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Data (); - uint8_t* destData = (uint8_t*)image->buffer->data->Data (); + uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->buffer->b; + uint8_t* destData = (uint8_t*)image->buffer->data->buffer->b; if (!sourceData || !destData) return; @@ -207,7 +207,7 @@ namespace lime { } else { - uint8_t* alphaData = (uint8_t*)alphaImage->buffer->data->Data (); + uint8_t* alphaData = (uint8_t*)alphaImage->buffer->data->buffer->b; PixelFormat alphaFormat = alphaImage->buffer->format; bool alphaPremultiplied = alphaImage->buffer->premultiplied; int alphaPosition; @@ -291,10 +291,9 @@ namespace lime { void ImageDataUtil::FillRect (Image* image, Rectangle* rect, int32_t color) { - uint8_t* data = (uint8_t*)image->buffer->data->Data (); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; PixelFormat format = image->buffer->format; bool premultiplied = image->buffer->premultiplied; - RGBA fillColor (color); if (rect->x == 0 && rect->y == 0 && rect->width == image->width && rect->height == image->height) { @@ -330,7 +329,7 @@ namespace lime { void ImageDataUtil::FloodFill (Image* image, int x, int y, int32_t color) { - uint8_t* data = (uint8_t*)image->buffer->data->Data (); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; PixelFormat format = image->buffer->format; bool premultiplied = image->buffer->premultiplied; @@ -405,8 +404,8 @@ namespace lime { int length = int (rect->width * rect->height); pixels->Resize (length * 4); - uint8_t* data = (uint8_t*)image->buffer->data->Data (); - uint8_t* destData = (uint8_t*)pixels->Data (); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; + uint8_t* destData = (uint8_t*)pixels->b; PixelFormat sourceFormat = image->buffer->format; bool premultiplied = image->buffer->premultiplied; @@ -440,8 +439,8 @@ namespace lime { Rectangle destRect = Rectangle (destPoint->x, destPoint->y, sourceView.width, sourceView.height); ImageDataView destView = ImageDataView (image, &destRect); - uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Data (); - uint8_t* destData = (uint8_t*)image->buffer->data->Data (); + uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->buffer->b; + uint8_t* destData = (uint8_t*)image->buffer->data->buffer->b; PixelFormat sourceFormat = sourceImage->buffer->format; PixelFormat destFormat = image->buffer->format; bool sourcePremultiplied = sourceImage->buffer->premultiplied; @@ -480,8 +479,8 @@ namespace lime { void ImageDataUtil::MultiplyAlpha (Image* image) { PixelFormat format = image->buffer->format; - uint8_t* data = (uint8_t*)image->buffer->data->Data (); - int length = int (image->buffer->data->Length () / 4); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; + int length = int (image->buffer->data->length / 4); RGBA pixel; for (int i = 0; i < length; i++) { @@ -499,8 +498,8 @@ namespace lime { int imageWidth = image->width; int imageHeight = image->height; - uint8_t* data = (uint8_t*)image->buffer->data->Data (); - uint8_t* newData = (uint8_t*)buffer->data->Data (); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; + uint8_t* newData = (uint8_t*)buffer->data->buffer->b; int sourceIndex, sourceIndexX, sourceIndexY, sourceIndexXY, index; int sourceX, sourceY; @@ -554,7 +553,7 @@ namespace lime { void ImageDataUtil::SetFormat (Image* image, PixelFormat format) { int index; - int length = image->buffer->data->Length () / 4; + int length = image->buffer->data->length / 4; int r1, g1, b1, a1, r2, g2, b2, a2; int r, g, b, a; @@ -614,7 +613,7 @@ namespace lime { } - unsigned char* data = image->buffer->data->Data (); + unsigned char* data = image->buffer->data->buffer->b; for (int i = 0; i < length; i++) { @@ -637,14 +636,14 @@ namespace lime { void ImageDataUtil::SetPixels (Image* image, Rectangle* rect, Bytes* bytes, int offset, PixelFormat format, Endian endian) { - uint8_t* data = (uint8_t*)image->buffer->data->Data (); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; PixelFormat sourceFormat = image->buffer->format; bool premultiplied = image->buffer->premultiplied; ImageDataView dataView = ImageDataView (image, rect); int row; RGBA pixel; - uint8_t* byteArray = (uint8_t*)bytes->Data (); + uint8_t* byteArray = (uint8_t*)bytes->b; int srcPosition = offset; bool transparent = image->buffer->transparent; @@ -729,8 +728,8 @@ namespace lime { RGBA _color (color); int hits = 0; - uint8_t* srcData = (uint8_t*)sourceImage->buffer->data->Data (); - uint8_t* destData = (uint8_t*)image->buffer->data->Data (); + uint8_t* srcData = (uint8_t*)sourceImage->buffer->data->buffer->b; + uint8_t* destData = (uint8_t*)image->buffer->data->buffer->b; ImageDataView srcView = ImageDataView (sourceImage, sourceRect); Rectangle destRect = Rectangle (destPoint->x, destPoint->y, srcView.width, srcView.height); @@ -796,8 +795,8 @@ namespace lime { void ImageDataUtil::UnmultiplyAlpha (Image* image) { PixelFormat format = image->buffer->format; - uint8_t* data = (uint8_t*)image->buffer->data->Data (); - int length = int (image->buffer->data->Length () / 4); + uint8_t* data = (uint8_t*)image->buffer->data->buffer->b; + int length = int (image->buffer->data->length / 4); RGBA pixel; for (int i = 0; i < length; i++) { diff --git a/project/src/math/ColorMatrix.cpp b/project/src/math/ColorMatrix.cpp index e741c8b32..a96d4401f 100644 --- a/project/src/math/ColorMatrix.cpp +++ b/project/src/math/ColorMatrix.cpp @@ -40,7 +40,7 @@ namespace lime { value buffer_value = val_field (colorMatrix, id_buffer); Bytes bytes; bytes.Set (buffer_value); - float* src = (float*)bytes.Data (); + float* src = (float*)bytes.b; for (int i = 0; i < 20; i++) { @@ -51,11 +51,9 @@ namespace lime { } - ColorMatrix::ColorMatrix (HL_ArrayBufferView* colorMatrix) { + ColorMatrix::ColorMatrix (ArrayBufferView* colorMatrix) { - Bytes bytes; - bytes.Set (colorMatrix->buffer); - float* src = (float*)bytes.Data (); + float* src = (float*)colorMatrix->buffer->b; for (int i = 0; i < 20; i++) { diff --git a/project/src/media/AudioBuffer.cpp b/project/src/media/AudioBuffer.cpp index 1f4df3b19..6b8f66e9c 100644 --- a/project/src/media/AudioBuffer.cpp +++ b/project/src/media/AudioBuffer.cpp @@ -11,18 +11,6 @@ namespace lime { static bool init = false; - AudioBuffer::AudioBuffer () { - - bitsPerSample = 0; - channels = 0; - data = new ArrayBufferView (); - sampleRate = 0; - _buffer = 0; - _value = 0; - - } - - AudioBuffer::AudioBuffer (value audioBuffer) { if (!init) { @@ -46,73 +34,53 @@ namespace lime { bitsPerSample = 0; channels = 0; - data = new ArrayBufferView (); + // data = new ArrayBufferView (); sampleRate = 0; } - _buffer = 0; - _value = audioBuffer; - - } - - - AudioBuffer::AudioBuffer (HL_AudioBuffer* audioBuffer) { - - bitsPerSample = audioBuffer->bitsPerSample; - channels = audioBuffer->channels; - data = new ArrayBufferView (audioBuffer->data); - sampleRate = audioBuffer->sampleRate; - _buffer = audioBuffer; - _value = 0; + // _value = audioBuffer; } AudioBuffer::~AudioBuffer () { - delete data; - - } - - - void* AudioBuffer::Value () { - - if (_buffer) { + if (data) { - _buffer->bitsPerSample = bitsPerSample; - _buffer->channels = channels; - //data - _buffer->sampleRate = sampleRate; - return _buffer; - - } else { - - if (!init) { - - id_bitsPerSample = val_id ("bitsPerSample"); - id_channels = val_id ("channels"); - id_data = val_id ("data"); - id_sampleRate = val_id ("sampleRate"); - init = true; - - } - - if (val_is_null (_value)) { - - _value = alloc_empty_object (); - - } - - alloc_field (_value, id_bitsPerSample, alloc_int (bitsPerSample)); - alloc_field (_value, id_channels, alloc_int (channels)); - alloc_field (_value, id_data, data ? data->Value () : alloc_null ()); - alloc_field (_value, id_sampleRate, alloc_int (sampleRate)); - return _value; + delete data; } } + value AudioBuffer::Value () { + + return Value (alloc_empty_object ()); + + } + + + value AudioBuffer::Value (value audioBuffer) { + + if (!init) { + + id_bitsPerSample = val_id ("bitsPerSample"); + id_channels = val_id ("channels"); + id_data = val_id ("data"); + id_sampleRate = val_id ("sampleRate"); + init = true; + + } + + alloc_field (audioBuffer, id_bitsPerSample, alloc_int (bitsPerSample)); + alloc_field (audioBuffer, id_channels, alloc_int (channels)); + alloc_field (audioBuffer, id_data, data ? data->Value (val_field (audioBuffer, id_data)) : alloc_null ()); + alloc_field (audioBuffer, id_sampleRate, alloc_int (sampleRate)); + return audioBuffer; + + } + + } \ No newline at end of file diff --git a/project/src/media/codecs/vorbis/VorbisBindings.cpp b/project/src/media/codecs/vorbis/VorbisBindings.cpp index a808b83f3..b58ba1311 100644 --- a/project/src/media/codecs/vorbis/VorbisBindings.cpp +++ b/project/src/media/codecs/vorbis/VorbisBindings.cpp @@ -286,7 +286,7 @@ namespace lime { int bitstream; OggVorbis_File* file = (OggVorbis_File*)(uintptr_t)val_data (vorbisFile); - long result = ov_read (file, (char*)bytes.Data () + position, length, bigendianp, word, sgned, &bitstream); + long result = ov_read (file, (char*)bytes.b + position, length, bigendianp, word, sgned, &bitstream); _initializeVorbis (); diff --git a/project/src/media/codecs/vorbis/VorbisFile.cpp b/project/src/media/codecs/vorbis/VorbisFile.cpp index 1b68583c3..179581b82 100644 --- a/project/src/media/codecs/vorbis/VorbisFile.cpp +++ b/project/src/media/codecs/vorbis/VorbisFile.cpp @@ -148,8 +148,8 @@ namespace lime { memset (vorbisFile, 0, sizeof (OggVorbis_File)); VorbisFile_Buffer* buffer = new VorbisFile_Buffer (); - buffer->data = bytes->Data (); - buffer->size = bytes->Length (); + buffer->data = bytes->b; + buffer->size = bytes->length; buffer->pos = 0; if (ov_open_callbacks (buffer, vorbisFile, NULL, 0, VORBIS_FILE_BUFFER_CALLBACKS) != 0) { diff --git a/project/src/media/containers/OGG.cpp b/project/src/media/containers/OGG.cpp index 92e87bf25..1388614af 100644 --- a/project/src/media/containers/OGG.cpp +++ b/project/src/media/containers/OGG.cpp @@ -61,7 +61,7 @@ namespace lime { while (bytes > 0) { - bytes = ov_read (oggFile, (char *)audioBuffer->data->Data () + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream); + bytes = ov_read (oggFile, (char *)audioBuffer->data->buffer->b + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream); if (bytes > 0) { diff --git a/project/src/media/containers/WAV.cpp b/project/src/media/containers/WAV.cpp index 5eace7b75..54291a706 100644 --- a/project/src/media/containers/WAV.cpp +++ b/project/src/media/containers/WAV.cpp @@ -127,7 +127,7 @@ namespace lime { audioBuffer->data->Resize (wave_data.subChunkSize); - if (!lime::fread (audioBuffer->data->Data (), wave_data.subChunkSize, 1, file)) { + if (!lime::fread (audioBuffer->data->buffer->b, wave_data.subChunkSize, 1, file)) { LOG_SOUND ("error loading WAVE data into struct!\n"); lime::fclose (file); @@ -139,8 +139,8 @@ namespace lime { } else { - const char* start = (const char*)resource->data->Data (); - const char* end = start + resource->data->Length (); + const char* start = (const char*)resource->data->b; + const char* end = start + resource->data->length; const char* ptr = start; memcpy (&riff_header, ptr, sizeof (RIFF_Header)); @@ -196,7 +196,7 @@ namespace lime { } - unsigned char* bytes = audioBuffer->data->Data (); + unsigned char* bytes = audioBuffer->data->buffer->b; memcpy (bytes, base, size); } diff --git a/project/src/media/openal/OpenALBindings.cpp b/project/src/media/openal/OpenALBindings.cpp index 404a4f76c..1be2a2f52 100644 --- a/project/src/media/openal/OpenALBindings.cpp +++ b/project/src/media/openal/OpenALBindings.cpp @@ -327,16 +327,15 @@ namespace lime { ALuint id = (ALuint)(uintptr_t)val_data (buffer); ArrayBufferView bufferView (data); - alBufferData (id, format, bufferView.Data (), size, freq); + alBufferData (id, format, bufferView.buffer->b, size, freq); } - HL_PRIM void hl_lime_al_buffer_data (HL_CFFIPointer* buffer, int format, HL_ArrayBufferView* data, int size, int freq) { + HL_PRIM void hl_lime_al_buffer_data (HL_CFFIPointer* buffer, int format, ArrayBufferView* data, int size, int freq) { ALuint id = (ALuint)(uintptr_t)buffer->ptr; - ArrayBufferView bufferView (data); - alBufferData (id, format, bufferView.Data (), size, freq); + alBufferData (id, format, data->buffer->b, size, freq); } diff --git a/project/src/net/curl/CURLBindings.cpp b/project/src/net/curl/CURLBindings.cpp index 753c8942d..9c38ae7fe 100644 --- a/project/src/net/curl/CURLBindings.cpp +++ b/project/src/net/curl/CURLBindings.cpp @@ -194,7 +194,7 @@ namespace lime { if (headerCallbacks.find (handle) != headerCallbacks.end ()) { callback = headerCallbacks[handle]; - _writeBytes = new Bytes (1024); + // _writeBytes = new Bytes (1024); writeBytes[callback] = _writeBytes; writeBytesRoot[callback] = new AutoGCRoot ((value)_writeBytes->Value ()); headerCallbacks[duphandle] = new AutoGCRoot (headerCallbacks[handle]->get()); @@ -210,7 +210,7 @@ namespace lime { if (writeCallbacks.find (handle) != writeCallbacks.end ()) { callback = writeCallbacks[handle]; - _writeBytes = new Bytes (1024); + // _writeBytes = new Bytes (1024); writeBytes[callback] = _writeBytes; writeBytesRoot[callback] = new AutoGCRoot ((value)_writeBytes->Value ()); writeCallbacks[duphandle] = new AutoGCRoot (writeCallbacks[handle]->get()); @@ -440,7 +440,7 @@ namespace lime { Bytes* _writeBytes = writeBytes[callback]; if (!_writeBytes) return 0; _writeBytes->Resize (size * nmemb); - memcpy (_writeBytes->Data (), ptr, size * nmemb); + memcpy (_writeBytes->b, ptr, size * nmemb); return val_int (val_call3 (callback->get (), (value)_writeBytes->Value (), alloc_int (size), alloc_int (nmemb))); @@ -465,9 +465,9 @@ namespace lime { Bytes bytes; bytes.Set (val_call1 (callback->get (), alloc_int (length))); - if (bytes.Length () <= length) length = bytes.Length (); + if (bytes.length <= length) length = bytes.length; - memcpy (buffer, bytes.Data (), length); + memcpy (buffer, bytes.b, length); } diff --git a/project/src/text/Font.cpp b/project/src/text/Font.cpp index cfe0a5e68..57d6f2e75 100644 --- a/project/src/text/Font.cpp +++ b/project/src/text/Font.cpp @@ -360,22 +360,23 @@ namespace lime { } else { - Bytes data = Bytes (resource->path); - faceMemory = (unsigned char*)malloc (data.Length ()); - memcpy (faceMemory, data.Data (), data.Length ()); + Bytes data; + data.ReadFile (resource->path); + faceMemory = (unsigned char*)malloc (data.length); + memcpy (faceMemory, data.b, data.length); lime::fclose (file); file = 0; - error = FT_New_Memory_Face (library, faceMemory, data.Length (), faceIndex, &face); + error = FT_New_Memory_Face (library, faceMemory, data.length, faceIndex, &face); } } else { - faceMemory = (unsigned char*)malloc (resource->data->Length ()); - memcpy (faceMemory, resource->data->Data (), resource->data->Length ()); - error = FT_New_Memory_Face (library, faceMemory, resource->data->Length (), faceIndex, &face); + faceMemory = (unsigned char*)malloc (resource->data->length); + memcpy (faceMemory, resource->data->b, resource->data->length); + error = FT_New_Memory_Face (library, faceMemory, resource->data->length, faceIndex, &face); } @@ -786,13 +787,13 @@ namespace lime { uint32_t size = (4 * 5) + (width * height); - if (bytes->Length () < size + offset) { + if (bytes->length < size + offset) { bytes->Resize (size + offset); } - GlyphImage *data = (GlyphImage*)(bytes->Data () + offset); + GlyphImage *data = (GlyphImage*)(bytes->b + offset); data->index = index; data->width = width; @@ -842,7 +843,7 @@ namespace lime { if (count > 0) { - *(uint32_t*)(bytes->Data ()) = count; + *(uint32_t*)(bytes->b) = count; } diff --git a/project/src/text/TextLayout.cpp b/project/src/text/TextLayout.cpp index 786e714b9..088bc7fb0 100644 --- a/project/src/text/TextLayout.cpp +++ b/project/src/text/TextLayout.cpp @@ -82,13 +82,13 @@ namespace lime { int glyphSize = sizeof (GlyphPosition); uint32_t dataSize = 5 + (glyph_count * glyphSize); - if (bytes->Length () < dataSize) { + if (bytes->length < dataSize) { bytes->Resize (dataSize); } - unsigned char* bytesPosition = bytes->Data (); + unsigned char* bytesPosition = bytes->b; *(uint32_t *)(bytesPosition) = glyph_count; bytesPosition += 4; diff --git a/project/src/utils/ArrayBufferView.cpp b/project/src/utils/ArrayBufferView.cpp index 5da063578..287ad5d95 100644 --- a/project/src/utils/ArrayBufferView.cpp +++ b/project/src/utils/ArrayBufferView.cpp @@ -8,29 +8,6 @@ namespace lime { static int id_byteLength; static int id_length; static bool init = false; - static bool isHL = false; - - - ArrayBufferView::ArrayBufferView () { - - buffer = new Bytes (); - byteLength = 0; - length = 0; - _value = 0; - _bufferView = 0; - - } - - - ArrayBufferView::ArrayBufferView (int size) { - - buffer = new Bytes (size); - byteLength = size; - length = size; - _value = 0; - _bufferView = 0; - - } ArrayBufferView::ArrayBufferView (value arrayBufferView) { @@ -58,39 +35,6 @@ namespace lime { } - _value = arrayBufferView; - _bufferView = 0; - - } - - - ArrayBufferView::ArrayBufferView (HL_ArrayBufferView* arrayBufferView) { - - if (!init) { - - init = true; - isHL = true; - - } - - if (arrayBufferView) { - - buffer = new Bytes (arrayBufferView->buffer); - byteLength = arrayBufferView->byteLength; - length = arrayBufferView->length; - _bufferView = arrayBufferView; - - } else { - - buffer = 0; - byteLength = 0; - length = 0; - _bufferView = 0; - - } - - _value = 0; - } @@ -105,38 +49,10 @@ namespace lime { } - unsigned char* ArrayBufferView::Data () { - - return buffer->Data (); - - } - - - const unsigned char* ArrayBufferView::Data () const { - - return buffer->Data (); - - } - - - int ArrayBufferView::Length () const { - - return buffer->Length (); - - } - - void ArrayBufferView::Resize (int size) { buffer->Resize (size); - if (_bufferView) { - - _bufferView->byteLength = size; - _bufferView->length = size; // ? - - } - byteLength = size; length = size; @@ -146,7 +62,7 @@ namespace lime { void ArrayBufferView::Set (value bytes) { buffer->Set (bytes); - byteLength = buffer->Length (); + byteLength = buffer->length; length = byteLength; } @@ -155,7 +71,7 @@ namespace lime { void ArrayBufferView::Set (const QuickVec data) { buffer->Set (data); - byteLength = buffer->Length (); + byteLength = buffer->length; length = byteLength; } @@ -163,6 +79,13 @@ namespace lime { value ArrayBufferView::Value () { + return Value (alloc_empty_object ()); + + } + + + value ArrayBufferView::Value (value arrayBufferView) { + if (!init) { id_buffer = val_id ("buffer"); @@ -172,16 +95,10 @@ namespace lime { } - if (val_is_null (_value)) { - - _value = alloc_empty_object (); - - } - - alloc_field (_value, id_buffer, buffer ? (value)buffer->Value () : alloc_null ()); - alloc_field (_value, id_byteLength, alloc_int (byteLength)); - alloc_field (_value, id_length, alloc_int (length)); - return _value; + alloc_field (arrayBufferView, id_buffer, buffer ? buffer->Value (val_field (arrayBufferView, id_buffer)) : alloc_null ()); + alloc_field (arrayBufferView, id_byteLength, alloc_int (byteLength)); + alloc_field (arrayBufferView, id_length, alloc_int (length)); + return arrayBufferView; } diff --git a/project/src/utils/Bytes.cpp b/project/src/utils/Bytes.cpp index 7bff0bed2..8eb4ec848 100644 --- a/project/src/utils/Bytes.cpp +++ b/project/src/utils/Bytes.cpp @@ -8,7 +8,6 @@ namespace lime { static int id_b; static int id_length; static bool init = false; - static bool isHL = false; static bool useBuffer = false; @@ -19,9 +18,9 @@ namespace lime { id_b = val_id ("b"); id_length = val_id ("length"); - buffer b = alloc_buffer_len (1); + buffer _buffer = alloc_buffer_len (1); - if (buffer_data (b)) { + if (buffer_data (_buffer)) { useBuffer = true; @@ -38,24 +37,8 @@ namespace lime { _initializeBytes (); - _data = 0; - _length = 0; - _value = 0; - _bytes = 0; - - } - - - Bytes::Bytes (int size) { - - _initializeBytes (); - - _data = 0; - _length = 0; - _value = 0; - _bytes = 0; - - Resize (size); + b = 0; + length = 0; } @@ -64,65 +47,14 @@ namespace lime { _initializeBytes (); - _data = 0; - _length = 0; - _value = 0; - _bytes = 0; + b = 0; + length = 0; Set (bytes); } - Bytes::Bytes (HL_Bytes* bytes) { - - if (!init) { - - init = true; - isHL = true; - - } - - // _initializeBytes (); - - _data = 0; - _length = 0; - _value = 0; - _bytes = 0; - - Set (bytes); - - } - - - Bytes::Bytes (const char* path) { - - _initializeBytes (); - - _data = 0; - _length = 0; - _value = 0; - _bytes = 0; - - ReadFile (path); - - } - - - Bytes::Bytes (const QuickVec data) { - - _initializeBytes (); - - _data = 0; - _length = 0; - _value = 0; - _bytes = 0; - - Set (data); - - } - - Bytes::~Bytes () { @@ -130,27 +62,6 @@ namespace lime { } - unsigned char* Bytes::Data () { - - return (unsigned char*)_data; - - } - - - const unsigned char* Bytes::Data () const { - - return (const unsigned char*)_data; - - } - - - int Bytes::Length () const { - - return _length; - - } - - void Bytes::ReadFile (const char* path) { FILE_HANDLE *file = lime::fopen (path, "rb"); @@ -168,7 +79,7 @@ namespace lime { if (size > 0) { Resize (size); - int status = lime::fread (_data, 1, size, file); + int status = lime::fread (b, 1, size, file); } @@ -179,96 +90,40 @@ namespace lime { void Bytes::Resize (int size) { - if (size != _length) { + if (size != length) { - if (isHL) { + if (size <= 0) { - if (size <= 0) { + if (b) { - if (_bytes && _bytes->b) { - - free (_bytes->b); - _bytes->b = 0; - _bytes->length = 0; - _data = 0; - - } - - } else { - - unsigned char* data = (unsigned char*)malloc (sizeof (char) * size); - - if (_bytes->b && _bytes->length) { - - memcpy (data, _bytes->b, _bytes->length < size ? _bytes->length : size); - free (_bytes->b); - - } else if (_bytes->b) { - - free (_bytes->b); - - } - - _bytes->b = data; - _bytes->length = size; - _data = data; + free (b); + b = 0; + length = 0; } } else { - if (!_value) { + unsigned char* data = (unsigned char*)malloc (sizeof (char) * size); + + if (b && length) { - _value = alloc_empty_object (); + memcpy (data, b, length < size ? length : size); + free (b); + + } else if (b) { + + free (b); } - if (val_is_null (val_field (_value, id_b))) { - - value dataValue; - - if (useBuffer) { - - buffer b = alloc_buffer_len (size); - dataValue = buffer_val (b); - _data = (unsigned char*)buffer_data (b); - - } else { - - dataValue = alloc_raw_string (size); - _data = (unsigned char*)val_string (dataValue); - - } - - alloc_field (_value, id_b, dataValue); - - } else { - - if (useBuffer) { - - buffer b = val_to_buffer (val_field (_value, id_b)); - buffer_set_size (b, size); - _data = (unsigned char*)buffer_data (b); - - } else { - - value s = alloc_raw_string (size); - memcpy ((char *)val_string (s), val_string (val_field (_value, id_b)), _length); - alloc_field (_value, id_b, s); - _data = (unsigned char*)val_string (s); - - } - - } - - alloc_field (_value, id_length, alloc_int (size)); + b = data; + length = size; } } - _length = size; - } @@ -276,62 +131,30 @@ namespace lime { if (val_is_null (bytes)) { - _length = 0; - _data = 0; - _value = 0; + length = 0; + b = 0; } else { - _value = bytes; - _length = val_int (val_field (bytes, val_id ("length"))); + length = val_int (val_field (bytes, id_length)); - if (_length > 0) { + if (length > 0) { - value b = val_field (bytes, id_b); + value _b = val_field (bytes, id_b); - if (val_is_string (b)) { + if (val_is_string (_b)) { - _data = (unsigned char*)val_string (b); + b = (unsigned char*)val_string (_b); } else { - _data = (unsigned char*)buffer_data (val_to_buffer (b)); + b = (unsigned char*)buffer_data (val_to_buffer (_b)); } } else { - _data = 0; - - } - - } - - } - - - void Bytes::Set (HL_Bytes* bytes) { - - if (!bytes) { - - _bytes = 0; - _length = 0; - _data = 0; - _value = 0; - - } else { - - _bytes = bytes; - _value = 0; - _length = bytes->length; - - if (_length > 0) { - - _data = bytes->b; - - } else { - - _data = 0; + b = 0; } @@ -347,31 +170,60 @@ namespace lime { if (size > 0) { Resize (size); - memcpy (_data, &data[0], _length); + memcpy (b, &data[0], length); } else { - _data = 0; - _length = 0; + b = 0; + length = 0; } } - void* Bytes::Value () { + value Bytes::Value () { - if (isHL) { + return alloc_null (); + + } + + + value Bytes::Value (value bytes) { + + if (val_is_null (bytes)) { - return _bytes; - - } else if (_value) { - - return _value; + return alloc_null (); } else { - return alloc_null (); + alloc_field (bytes, id_length, alloc_int (length)); + + if (useBuffer) { + + value _buffer = val_field (bytes, id_b); + + if (val_is_null (_buffer) || (char*)b != buffer_data (val_to_buffer (_buffer))) { + + alloc_field (bytes, id_b, buffer_val (alloc_buffer ((const char*)b))); + + } + + } else { + + value _string = val_field (bytes, id_b); + + if (val_is_null (_string) || (const char*)b != val_string (_string)) { + + value data = alloc_raw_string (length); + memcpy ((void*)val_string (data), b, length); + alloc_field (bytes, id_b, data); + + } + + } + + return bytes; } diff --git a/project/src/utils/compress/LZMA.cpp b/project/src/utils/compress/LZMA.cpp index 661d56c05..d6e34c062 100644 --- a/project/src/utils/compress/LZMA.cpp +++ b/project/src/utils/compress/LZMA.cpp @@ -34,8 +34,8 @@ namespace lime { void LZMA::Compress (Bytes* data, Bytes* result) { - SizeT inputBufferSize = data->Length (); - Byte* inputBufferData = data->Data (); + SizeT inputBufferSize = data->length; + Byte* inputBufferData = data->b; SizeT outputBufferSize = inputBufferSize + inputBufferSize / 5 + (1 << 16); Byte* outputBufferData = (Byte *)malloc (outputBufferSize); @@ -56,7 +56,7 @@ namespace lime { LzmaEncode (outputBufferData, &outputBufferSize, inputBufferData, inputBufferSize, &props, propsData, &propsSize, props.writeEndMark, &progress, &allocSmall, &allocBig); result->Resize (outputBufferSize + propsSize + 8); - Byte* resultData = result->Data (); + Byte* resultData = result->b; memcpy (resultData, propsData, propsSize); WRITE_LE64 (resultData + propsSize, uncompressedLength); @@ -70,8 +70,8 @@ namespace lime { void LZMA::Decompress (Bytes* data, Bytes* result) { - SizeT inputBufferSize = data->Length (); - Byte* inputBufferData = data->Data (); + SizeT inputBufferSize = data->length; + Byte* inputBufferData = data->b; Int64 uncompressedLength = -1; ELzmaStatus status = LZMA_STATUS_NOT_SPECIFIED; @@ -83,8 +83,8 @@ namespace lime { result->Resize ((int)uncompressedLength); - SizeT outputBufferSize = result->Length (); - Byte* outputBufferData = result->Data (); + SizeT outputBufferSize = result->length; + Byte* outputBufferData = result->b; Byte* _inputBufferData = inputBufferData + LZMA_PROPS_SIZE + sizeof (uncompressedLength); SizeT _inputBufferSize = inputBufferSize - LZMA_PROPS_SIZE - sizeof (uncompressedLength); diff --git a/project/src/utils/compress/Zlib.cpp b/project/src/utils/compress/Zlib.cpp index f9c661de6..41c6d99b4 100644 --- a/project/src/utils/compress/Zlib.cpp +++ b/project/src/utils/compress/Zlib.cpp @@ -32,12 +32,12 @@ namespace lime { } - int bufferSize = deflateBound (stream, data->Length ()); + int bufferSize = deflateBound (stream, data->length); char* buffer = (char*)malloc (bufferSize); - stream->next_in = (Bytef*)data->Data (); + stream->next_in = (Bytef*)data->b; stream->next_out = (Bytef*)buffer; - stream->avail_in = data->Length (); + stream->avail_in = data->length; stream->avail_out = bufferSize; if ((ret = deflate (stream, Z_FINISH)) < 0) { @@ -53,7 +53,7 @@ namespace lime { int size = bufferSize - stream->avail_out; result->Resize (size); - memcpy (result->Data (), buffer, size); + memcpy (result->b, buffer, size); deflateEnd (stream); free (stream); free (buffer); @@ -93,14 +93,14 @@ namespace lime { int chunkSize = 1 << 16; int readSize = 0; - Bytef* sourcePosition = data->Data (); + Bytef* sourcePosition = data->b; int destSize = 0; int readTotal = 0; Bytef* buffer = (Bytef*)malloc (chunkSize); - stream->avail_in = data->Length (); - stream->next_in = data->Data (); + stream->avail_in = data->length; + stream->next_in = data->b; if (stream->avail_in > 0) { @@ -137,7 +137,7 @@ namespace lime { readTotal += readSize; result->Resize (readTotal); - memcpy (result->Data () + readTotal - readSize, buffer, readSize); + memcpy (result->b + readTotal - readSize, buffer, readSize); sourcePosition += readSize;