diff --git a/lime/audio/AudioBuffer.hx b/lime/audio/AudioBuffer.hx index b6af8f56d..8946a6cdc 100644 --- a/lime/audio/AudioBuffer.hx +++ b/lime/audio/AudioBuffer.hx @@ -1,6 +1,7 @@ package lime.audio; +import haxe.io.Bytes; import lime.audio.openal.AL; import lime.system.System; import lime.utils.ByteArray; @@ -56,7 +57,13 @@ class AudioBuffer { var audioBuffer = new AudioBuffer (); audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.channels = data.channels; - audioBuffer.data = data.data; + #if neko + var bytes = @:privateAccess (new Bytes (data.data.length, data.data.b)); + #else + var bytes = Bytes.ofString (data.data.b); + @:privateAccess (bytes).length = data.data.length; + #end + audioBuffer.data = ByteArray.fromBytes (bytes); audioBuffer.sampleRate = data.sampleRate; return audioBuffer; @@ -80,7 +87,13 @@ class AudioBuffer { var audioBuffer = new AudioBuffer (); audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.channels = data.channels; - audioBuffer.data = data.data; + #if neko + var bytes = @:privateAccess (new Bytes (data.data.length, data.data.b)); + #else + var bytes = Bytes.ofString (data.data.b); + @:privateAccess (bytes).length = data.data.length; + #end + audioBuffer.data = ByteArray.fromBytes (bytes); audioBuffer.sampleRate = data.sampleRate; return audioBuffer; diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index c94dfc445..ffbe2b641 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -3,6 +3,7 @@ package lime.graphics; import haxe.crypto.BaseCode; import haxe.io.Bytes; +import haxe.io.BytesData; import haxe.io.BytesInput; import haxe.io.BytesOutput; import lime.app.Application; @@ -14,6 +15,7 @@ import lime.graphics.utils.ImageDataUtil; import lime.math.ColorMatrix; import lime.math.Rectangle; import lime.math.Vector2; +import lime.utils.ArrayBuffer; import lime.utils.ByteArray; import lime.utils.UInt8Array; import lime.system.System; @@ -946,8 +948,13 @@ class Image { if (data != null) { - var byteArray:ByteArray = data.data; - __fromImageBuffer (new ImageBuffer (new UInt8Array (byteArray), data.width, data.height, data.bpp)); + #if neko + var bytes = @:privateAccess (new Bytes (data.data.length, data.data.b)); + #else + var bytes = Bytes.ofString (data.data.b); + @:privateAccess (bytes).length = data.data.length; + #end + __fromImageBuffer (new ImageBuffer (new UInt8Array (bytes), data.width, data.height, data.bitsPerPixel)); if (onload != null) { @@ -1011,14 +1018,18 @@ class Image { if (#if (sys && (!disable_cffi || !format) && !java) true #else false #end && !System.disableCFFI) { var data = lime_image_load (path); + if (data != null) { - var ba:ByteArray = cast(data.data, ByteArray); - #if nodejs - var u8a = ba.byteView; + + #if neko + var bytes = @:privateAccess (new Bytes (data.data.length, data.data.b)); #else - var u8a = new UInt8Array(ba); + var bytes = Bytes.ofString (data.data.b); + @:privateAccess (bytes).length = data.data.length; #end - buffer = new ImageBuffer (u8a, data.width, data.height, data.bpp); + var u8a = new UInt8Array (bytes); + buffer = new ImageBuffer (u8a, data.width, data.height, data.bitsPerPixel); + } } @@ -1035,7 +1046,7 @@ class Image { var data = Tools.extract32 (png); var header = Tools.getHeader (png); - var data = new UInt8Array (ByteArray.fromBytes (Bytes.ofData (data.getData ()))); + var data = new UInt8Array (Bytes.ofData (data.getData ())); var length = header.width * header.height; var b, g, r, a; diff --git a/lime/graphics/ImageBuffer.hx b/lime/graphics/ImageBuffer.hx index 36d276146..4b975ecef 100644 --- a/lime/graphics/ImageBuffer.hx +++ b/lime/graphics/ImageBuffer.hx @@ -103,8 +103,7 @@ class ImageBuffer { var bytes = Bytes.alloc (data.byteLength); bytes.blit (0, buffer.data.buffer, 0, data.byteLength); - var byteArray = ByteArray.fromBytes (bytes); - buffer.data = new UInt8Array (byteArray); + buffer.data = new UInt8Array (bytes); } #end diff --git a/lime/graphics/cairo/CairoSurface.hx b/lime/graphics/cairo/CairoSurface.hx index d81a75c7e..725ef20d1 100644 --- a/lime/graphics/cairo/CairoSurface.hx +++ b/lime/graphics/cairo/CairoSurface.hx @@ -58,11 +58,7 @@ abstract CairoSurface(Dynamic) { public static function fromImage (image:Image):CairoSurface { #if lime_cairo - #if nodejs - return createForData (lime_buffer_get_native_pointer (#if nodejs image.data #else image.data.buffer #end), CairoFormat.ARGB32, image.width, image.height, image.buffer.stride); - #else - return createForData (ByteArray.fromBytes (image.data.buffer).__getNativePointer (), CairoFormat.ARGB32, image.width, image.height, image.buffer.stride); - #end + return createForData (lime_bytes_get_data_pointer (#if nodejs image.data #else image.data.buffer #end), CairoFormat.ARGB32, image.width, image.height, image.buffer.stride); #else return null; #end @@ -107,13 +103,13 @@ abstract CairoSurface(Dynamic) { #if lime_cairo + private static var lime_bytes_get_data_pointer = System.load ("lime", "lime_bytes_get_data_pointer", 1); private static var lime_cairo_image_surface_create = System.load ("lime", "lime_cairo_image_surface_create", 3); private static var lime_cairo_image_surface_create_for_data = System.load ("lime", "lime_cairo_image_surface_create_for_data", 5); private static var lime_cairo_image_surface_get_height = System.load ("lime", "lime_cairo_image_surface_get_height", 1); private static var lime_cairo_image_surface_get_width = System.load ("lime", "lime_cairo_image_surface_get_width", 1); private static var lime_cairo_surface_destroy = System.load ("lime", "lime_cairo_surface_destroy", 1); private static var lime_cairo_surface_flush = System.load ("lime", "lime_cairo_surface_flush", 1); - private static var lime_buffer_get_native_pointer = System.load ("lime", "lime_buffer_get_native_pointer", 1); #end diff --git a/lime/graphics/opengl/GL.hx b/lime/graphics/opengl/GL.hx index 26272a125..5ee1bf702 100644 --- a/lime/graphics/opengl/GL.hx +++ b/lime/graphics/opengl/GL.hx @@ -544,11 +544,11 @@ class GL { #if (js && html5 && !display) context.bufferData (target, data, usage); #elseif ((cpp || neko) && lime_opengl) - lime_gl_buffer_data (target, ByteArray.fromBytes (data.buffer), data.byteOffset, data.byteLength, usage); + lime_gl_buffer_data (target, data.buffer, data.byteOffset, data.byteLength, usage); #elseif (nodejs && lime_opengl) lime_gl_buffer_data (target, data, data.byteOffset, data.byteLength, usage); #elseif java - //GL15.glBufferData (target, ByteArray.fromBytes (data.buffer), data.byteOffset, data.byteLength, usage); + //GL15.glBufferData (target, data.buffer, data.byteOffset, data.byteLength, usage); #end } @@ -559,11 +559,11 @@ class GL { #if (js && html5 && !display) context.bufferSubData (target, offset, data); #elseif ((cpp || neko) && lime_opengl) - lime_gl_buffer_sub_data (target, offset, ByteArray.fromBytes (data.buffer), data.byteOffset, data.byteLength); + lime_gl_buffer_sub_data (target, offset, data.buffer, data.byteOffset, data.byteLength); #elseif (nodejs && lime_opengl) lime_gl_buffer_sub_data (target, offset, data, data.byteOffset, data.byteLength); #elseif java - //GL15.glBufferSubData (target, offset, ByteArray.fromBytes (data.buffer), data.byteOffset, data.byteLength); + //GL15.glBufferSubData (target, offset, data.buffer, data.byteOffset, data.byteLength); #end } @@ -667,11 +667,11 @@ class GL { #if (js && html5 && !display) context.compressedTexImage2D (target, level, internalformat, width, height, border, data); #elseif ((cpp || neko) && lime_opengl) - lime_gl_compressed_tex_image_2d (target, level, internalformat, width, height, border, data == null ? null : ByteArray.fromBytes (data.buffer), data == null ? null : data.byteOffset); + lime_gl_compressed_tex_image_2d (target, level, internalformat, width, height, border, data == null ? null : data.buffer, data == null ? null : data.byteOffset); #elseif (nodejs && lime_opengl) lime_gl_compressed_tex_image_2d (target, level, internalformat, width, height, border, data == null ? null : data , data == null ? null : data.byteOffset); #elseif java - //GL13.glCompressedTexImage2D (target, level, internalformat, width, height, border, data == null ? null : ByteArray.fromBytes (data.buffer), data == null ? null : data.byteOffset); + //GL13.glCompressedTexImage2D (target, level, internalformat, width, height, border, data == null ? null : data.buffer, data == null ? null : data.byteOffset); #end } @@ -682,11 +682,11 @@ class GL { #if (js && html5 && !display) context.compressedTexSubImage2D (target, level, xoffset, yoffset, width, height, format, data); #elseif ((cpp || neko) && lime_opengl) - lime_gl_compressed_tex_sub_image_2d (target, level, xoffset, yoffset, width, height, format, data == null ? null : ByteArray.fromBytes (data.buffer), data == null ? null : data.byteOffset); + lime_gl_compressed_tex_sub_image_2d (target, level, xoffset, yoffset, width, height, format, data == null ? null : data.buffer, data == null ? null : data.byteOffset); #elseif (nodejs && lime_opengl) lime_gl_compressed_tex_sub_image_2d (target, level, xoffset, yoffset, width, height, format, data == null ? null : data, data == null ? null : data.byteOffset); #elseif java - //GL13.glCompressedTexSubImage2D (target, level, xoffset, yoffset, width, height, format, data == null ? null : ByteArray.fromBytes (data.buffer), data == null ? null : data.byteOffset); + //GL13.glCompressedTexSubImage2D (target, level, xoffset, yoffset, width, height, format, data == null ? null : data.buffer, data == null ? null : data.byteOffset); #end } @@ -1649,7 +1649,7 @@ class GL { #if (js && html5 && !display) context.readPixels (x, y, width, height, format, type, pixels); #elseif ((cpp || neko) && lime_opengl) - lime_gl_read_pixels (x, y, width, height, format, type, pixels == null ? null : ByteArray.fromBytes (pixels.buffer), pixels == null ? null : pixels.byteOffset); + lime_gl_read_pixels (x, y, width, height, format, type, pixels == null ? null : pixels.buffer, pixels == null ? null : pixels.byteOffset); #elseif (nodejs && lime_opengl) lime_gl_read_pixels (x, y, width, height, format, type, pixels == null ? null : pixels, pixels == null ? null : pixels.byteOffset); #end @@ -1772,7 +1772,7 @@ class GL { #if (js && html5 && !display) context.texImage2D (target, level, internalformat, width, height, border, format, type, pixels); #elseif ((cpp || neko) && lime_opengl) - lime_gl_tex_image_2d (target, level, internalformat, width, height, border, format, type, pixels == null ? null : ByteArray.fromBytes (pixels.buffer), pixels == null ? null : pixels.byteOffset); + lime_gl_tex_image_2d (target, level, internalformat, width, height, border, format, type, pixels == null ? null : pixels.buffer, pixels == null ? null : pixels.byteOffset); #elseif (nodejs && lime_opengl) lime_gl_tex_image_2d (target, level, internalformat, width, height, border, format, type, pixels == null ? null : pixels, pixels == null ? null : pixels.byteOffset); #end @@ -1807,7 +1807,7 @@ class GL { #if (js && html5 && !display) context.texSubImage2D (target, level, xoffset, yoffset, width, height, format, type, pixels); #elseif ((cpp || neko) && lime_opengl) - lime_gl_tex_sub_image_2d (target, level, xoffset, yoffset, width, height, format, type, pixels == null ? null : ByteArray.fromBytes (pixels.buffer), pixels == null ? null : pixels.byteOffset); + lime_gl_tex_sub_image_2d (target, level, xoffset, yoffset, width, height, format, type, pixels == null ? null : pixels.buffer, pixels == null ? null : pixels.byteOffset); #elseif (nodejs && lime_opengl) lime_gl_tex_sub_image_2d (target, level, xoffset, yoffset, width, height, format, type, pixels == null ? null : pixels, pixels == null ? null : pixels.byteOffset); #end @@ -1831,7 +1831,7 @@ class GL { #if (js && html5 && !display) context.uniform1fv (location, x); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform1fv (location, ByteArray.fromBytes (x.buffer)); + lime_gl_uniform1fv (location, x.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform1fv (location, x); #end @@ -1855,7 +1855,7 @@ class GL { #if (js && html5 && !display) context.uniform1iv (location, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform1iv (location, ByteArray.fromBytes (v.buffer)); + lime_gl_uniform1iv (location, v.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform1iv (location, v); #end @@ -1879,7 +1879,7 @@ class GL { #if (js && html5 && !display) context.uniform2fv (location, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform2fv (location, ByteArray.fromBytes (v.buffer)); + lime_gl_uniform2fv (location, v.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform2fv (location, v); #end @@ -1903,7 +1903,7 @@ class GL { #if (js && html5 && !display) context.uniform2iv (location, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform2iv (location, ByteArray.fromBytes (v.buffer)); + lime_gl_uniform2iv (location, v.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform2iv (location, v); #end @@ -1927,7 +1927,7 @@ class GL { #if (js && html5 && !display) context.uniform3fv (location, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform3fv (location, ByteArray.fromBytes (v.buffer)); + lime_gl_uniform3fv (location, v.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform3fv (location, v); #end @@ -1951,7 +1951,7 @@ class GL { #if (js && html5 && !display) context.uniform3iv (location, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform3iv (location, ByteArray.fromBytes (v.buffer)); + lime_gl_uniform3iv (location, v.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform3iv (location, v); #end @@ -1975,7 +1975,7 @@ class GL { #if (js && html5 && !display) context.uniform4fv (location, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform4fv (location, ByteArray.fromBytes (v.buffer)); + lime_gl_uniform4fv (location, v.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform4fv (location, v); #end @@ -1999,7 +1999,7 @@ class GL { #if (js && html5 && !display) context.uniform4iv (location, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform4iv (location, ByteArray.fromBytes (v.buffer)); + lime_gl_uniform4iv (location, v.buffer); #elseif (nodejs && lime_opengl) lime_gl_uniform4iv (location, v); #end @@ -2012,7 +2012,7 @@ class GL { #if (js && html5 && !display) context.uniformMatrix2fv (location, transpose, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform_matrix (location, transpose, ByteArray.fromBytes (v.buffer), 2); + lime_gl_uniform_matrix (location, transpose, v.buffer, 2); #elseif (nodejs && lime_opengl) lime_gl_uniform_matrix (location, transpose, v, 2); #end @@ -2025,7 +2025,7 @@ class GL { #if (js && html5 && !display) context.uniformMatrix3fv (location, transpose, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform_matrix (location, transpose, ByteArray.fromBytes (v.buffer), 3); + lime_gl_uniform_matrix (location, transpose, v.buffer, 3); #elseif (nodejs && lime_opengl) lime_gl_uniform_matrix (location, transpose, v, 3); #end @@ -2038,7 +2038,7 @@ class GL { #if (js && html5 && !display) context.uniformMatrix4fv (location, transpose, v); #elseif ((cpp || neko) && lime_opengl) - lime_gl_uniform_matrix (location, transpose, ByteArray.fromBytes (v.buffer), 4); + lime_gl_uniform_matrix (location, transpose, v.buffer, 4); #elseif (nodejs && lime_opengl) lime_gl_uniform_matrix (location, transpose, v, 4); #end @@ -2091,7 +2091,7 @@ class GL { #if (js && html5 && !display) context.vertexAttrib1fv (indx, values); #elseif ((cpp || neko) && lime_opengl) - lime_gl_vertex_attrib1fv (indx, ByteArray.fromBytes (values.buffer)); + lime_gl_vertex_attrib1fv (indx, values.buffer); #elseif (nodejs && lime_opengl) lime_gl_vertex_attrib1fv (indx, values); #end @@ -2115,7 +2115,7 @@ class GL { #if (js && html5 && !display) context.vertexAttrib2fv (indx, values); #elseif ((cpp || neko) && lime_opengl) - lime_gl_vertex_attrib2fv (indx, ByteArray.fromBytes (values.buffer)); + lime_gl_vertex_attrib2fv (indx, values.buffer); #elseif (nodejs && lime_opengl) lime_gl_vertex_attrib2fv (indx, values); #end @@ -2139,7 +2139,7 @@ class GL { #if (js && html5 && !display) context.vertexAttrib3fv (indx, values); #elseif ((cpp || neko) && lime_opengl) - lime_gl_vertex_attrib3fv (indx, ByteArray.fromBytes (values.buffer)); + lime_gl_vertex_attrib3fv (indx, values.buffer); #elseif (nodejs && lime_opengl) lime_gl_vertex_attrib3fv (indx, values); #end @@ -2163,7 +2163,7 @@ class GL { #if (js && html5 && !display) context.vertexAttrib4fv (indx, values); #elseif ((cpp || neko) && lime_opengl) - lime_gl_vertex_attrib4fv (indx, ByteArray.fromBytes (values.buffer)); + lime_gl_vertex_attrib4fv (indx, values.buffer); #elseif (nodejs && lime_opengl) lime_gl_vertex_attrib4fv (indx, values); #end diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 90ac83de9..6413ebd06 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -2,6 +2,7 @@ package lime.graphics.utils; import haxe.ds.Vector; +import haxe.io.Bytes; import lime.graphics.Image; import lime.graphics.ImageBuffer; import lime.graphics.PixelFormat; @@ -676,7 +677,7 @@ class ImageDataUtil { #end #if ((cpp || neko) && !disable_cffi) - if (!System.disableCFFI) byteArray = lime_image_data_util_get_pixels (image, rect, format); else + if (!System.disableCFFI) lime_image_data_util_get_pixels (image, rect, format, byteArray); else #end { @@ -1213,7 +1214,7 @@ class ImageDataUtil { private static var lime_image_data_util_copy_pixels = System.load ("lime", "lime_image_data_util_copy_pixels", 5); private static var lime_image_data_util_fill_rect = System.load ("lime", "lime_image_data_util_fill_rect", 3); private static var lime_image_data_util_flood_fill = System.load ("lime", "lime_image_data_util_flood_fill", 4); - private static var lime_image_data_util_get_pixels = System.load ("lime", "lime_image_data_util_get_pixels", 3); + private static var lime_image_data_util_get_pixels = System.load ("lime", "lime_image_data_util_get_pixels", 4); private static var lime_image_data_util_merge = System.load ("lime", "lime_image_data_util_merge", -1); private static var lime_image_data_util_multiply_alpha = System.load ("lime", "lime_image_data_util_multiply_alpha", 1); private static var lime_image_data_util_resize = System.load ("lime", "lime_image_data_util_resize", 4); diff --git a/lime/text/TextLayout.hx b/lime/text/TextLayout.hx index 572d9c674..44ebbb55f 100644 --- a/lime/text/TextLayout.hx +++ b/lime/text/TextLayout.hx @@ -62,7 +62,7 @@ class TextLayout { } - lime_text_layout_position (__handle, font.src, size, text, __buffer); + var data = lime_text_layout_position (__handle, font.src, size, text, __buffer); if (__buffer.length > 4) { @@ -83,7 +83,7 @@ class TextLayout { } - } + } } #end diff --git a/project/Build.xml b/project/Build.xml index 7f7e95501..9ea73b2a7 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -199,6 +199,7 @@ + diff --git a/project/include/audio/AudioBuffer.h b/project/include/audio/AudioBuffer.h index f4b276769..5287716fa 100644 --- a/project/include/audio/AudioBuffer.h +++ b/project/include/audio/AudioBuffer.h @@ -3,7 +3,7 @@ #include -#include +#include #ifdef ANDROID #include @@ -42,7 +42,7 @@ namespace lime { int bitsPerSample; int channels; int sampleRate; - ByteArray *data; + Bytes *data; private: diff --git a/project/include/graphics/ImageBuffer.h b/project/include/graphics/ImageBuffer.h index d092f9964..96219c7c0 100644 --- a/project/include/graphics/ImageBuffer.h +++ b/project/include/graphics/ImageBuffer.h @@ -4,7 +4,7 @@ #include #include -#include +#include namespace lime { @@ -24,7 +24,7 @@ namespace lime { value Value (); int bpp; - ByteArray *data; + Bytes *data; PixelFormat format; int height; int width; diff --git a/project/include/graphics/format/JPEG.h b/project/include/graphics/format/JPEG.h index a3499d498..d5dc1eea0 100644 --- a/project/include/graphics/format/JPEG.h +++ b/project/include/graphics/format/JPEG.h @@ -3,7 +3,7 @@ #include -#include +#include #include @@ -16,7 +16,7 @@ namespace lime { public: static bool Decode (Resource *resource, ImageBuffer *imageBuffer, bool decodeData = true); - static bool Encode (ImageBuffer *imageBuffer, ByteArray *bytes, int quality); + static bool Encode (ImageBuffer *imageBuffer, Bytes *bytes, int quality); }; diff --git a/project/include/graphics/format/PNG.h b/project/include/graphics/format/PNG.h index c536a59a8..de8c540bd 100644 --- a/project/include/graphics/format/PNG.h +++ b/project/include/graphics/format/PNG.h @@ -3,7 +3,7 @@ #include -#include +#include #include @@ -16,7 +16,7 @@ namespace lime { public: static bool Decode (Resource *resource, ImageBuffer *imageBuffer, bool decodeData = true); - static bool Encode (ImageBuffer *imageBuffer, ByteArray *bytes); + static bool Encode (ImageBuffer *imageBuffer, Bytes *bytes); }; diff --git a/project/include/graphics/utils/ImageDataUtil.h b/project/include/graphics/utils/ImageDataUtil.h index 1b06ef15b..02e1e86fc 100644 --- a/project/include/graphics/utils/ImageDataUtil.h +++ b/project/include/graphics/utils/ImageDataUtil.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace lime { @@ -25,12 +25,12 @@ namespace lime { static void CopyPixels (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, bool mergeAlpha); static void FillRect (Image* image, Rectangle* rect, int color); static void FloodFill (Image* image, int x, int y, int color); - static void GetPixels (Image* image, Rectangle* rect, PixelFormat format, ByteArray* pixels); + static void GetPixels (Image* image, Rectangle* rect, PixelFormat format, Bytes* pixels); static void Merge (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, int redMultiplier, int greenMultiplier, int blueMultiplier, int alphaMultiplier); static void MultiplyAlpha (Image* image); static void Resize (Image* image, ImageBuffer* buffer, int width, int height); static void SetFormat (Image* image, PixelFormat format); - static void SetPixels (Image* image, Rectangle* rect, ByteArray* bytes, PixelFormat format); + static void SetPixels (Image* image, Rectangle* rect, Bytes* bytes, PixelFormat format); static void UnmultiplyAlpha (Image* image); diff --git a/project/include/text/Font.h b/project/include/text/Font.h index 16b1c0990..e5ce323c2 100644 --- a/project/include/text/Font.h +++ b/project/include/text/Font.h @@ -58,8 +58,8 @@ namespace lime { int GetUnderlinePosition (); int GetUnderlineThickness (); int GetUnitsPerEM (); - int RenderGlyph (int index, ByteArray *bytes, int offset = 0); - int RenderGlyphs (value indices, ByteArray *bytes); + int RenderGlyph (int index, Bytes *bytes, int offset = 0); + int RenderGlyphs (value indices, Bytes *bytes); void SetSize (size_t size); void* face; diff --git a/project/include/text/TextLayout.h b/project/include/text/TextLayout.h index 8e8f309af..c5b4b88f4 100644 --- a/project/include/text/TextLayout.h +++ b/project/include/text/TextLayout.h @@ -3,7 +3,7 @@ #include -#include +#include namespace lime { @@ -27,7 +27,7 @@ namespace lime { TextLayout (int direction, const char *script, const char *language); ~TextLayout (); - void Position (Font *font, size_t size, const char *text, ByteArray *bytes); + void Position (Font *font, size_t size, const char *text, Bytes *bytes); void SetDirection (int direction); void SetLanguage (const char* language); void SetScript (const char* script); diff --git a/project/include/utils/Bytes.h b/project/include/utils/Bytes.h new file mode 100644 index 000000000..71e15b31a --- /dev/null +++ b/project/include/utils/Bytes.h @@ -0,0 +1,39 @@ +#ifndef LIME_UTILS_BYTES_H +#define LIME_UTILS_BYTES_H + + +#include +#include + + +namespace lime { + + + struct Bytes { + + + Bytes (); + Bytes (int size); + Bytes (value bytes); + Bytes (const char* path); + Bytes (const QuickVec data); + ~Bytes (); + + unsigned char *Data (); + const unsigned char *Data () const; + int Length () const; + void Resize (int size); + value Value (); + + unsigned char *_data; + int _length; + value _value; + + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/include/utils/Resource.h b/project/include/utils/Resource.h index 36dcd0dd1..f2b47c211 100644 --- a/project/include/utils/Resource.h +++ b/project/include/utils/Resource.h @@ -2,7 +2,7 @@ #define LIME_UTILS_RESOURCE_H -#include +#include namespace lime { @@ -13,9 +13,9 @@ namespace lime { Resource () : data (NULL), path (NULL) {} Resource (const char* path) : data (NULL), path (path) {} - Resource (ByteArray *data) : data (data), path (NULL) {} + Resource (Bytes *data) : data (data), path (NULL) {} - ByteArray *data; + Bytes *data; const char* path; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 64b0f5dc6..66da8ab33 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -102,7 +102,7 @@ namespace lime { } else { - ByteArray bytes (data); + Bytes bytes (data); resource = Resource (&bytes); } @@ -126,6 +126,14 @@ namespace lime { } + value lime_bytes_get_data_pointer (value bytes) { + + Bytes data = Bytes (bytes); + return alloc_float ((intptr_t)data.Data ()); + + } + + void lime_font_destroy (value handle) { Font *font = (Font*)(intptr_t)val_float (handle); @@ -278,7 +286,7 @@ namespace lime { } else { - ByteArray bytes (data); + Bytes bytes (data); resource = Resource (&bytes); } @@ -323,7 +331,7 @@ namespace lime { #ifdef LIME_FREETYPE Font *font = (Font*)(intptr_t)val_float (fontHandle); - ByteArray bytes = ByteArray (data); + Bytes bytes = Bytes (data); return alloc_bool (font->RenderGlyph (val_int (index), &bytes)); #else return alloc_bool (false); @@ -336,7 +344,7 @@ namespace lime { #ifdef LIME_FREETYPE Font *font = (Font*)(intptr_t)val_float (fontHandle); - ByteArray bytes = ByteArray (data); + Bytes bytes = Bytes (data); return alloc_bool (font->RenderGlyphs (indices, &bytes)); #else return alloc_bool (false); @@ -398,7 +406,7 @@ namespace lime { value lime_image_encode (value buffer, value type, value quality) { ImageBuffer imageBuffer = ImageBuffer (buffer); - ByteArray data; + Bytes data; switch (val_int (type)) { @@ -408,7 +416,7 @@ namespace lime { if (PNG::Encode (&imageBuffer, &data)) { //delete imageBuffer.data; - return data.mValue; + return data.Value (); } #endif @@ -420,7 +428,7 @@ namespace lime { if (JPEG::Encode (&imageBuffer, &data, val_int (quality))) { //delete imageBuffer.data; - return data.mValue; + return data.Value (); } #endif @@ -438,7 +446,7 @@ namespace lime { value lime_image_load (value data) { - ImageBuffer imageBuffer; + ImageBuffer buffer; Resource resource; if (val_is_string (data)) { @@ -447,23 +455,23 @@ namespace lime { } else { - ByteArray bytes (data); + Bytes bytes (data); resource = Resource (&bytes); } #ifdef LIME_PNG - if (PNG::Decode (&resource, &imageBuffer)) { + if (PNG::Decode (&resource, &buffer)) { - return imageBuffer.Value (); + return buffer.Value (); } #endif #ifdef LIME_JPEG - if (JPEG::Decode (&resource, &imageBuffer)) { + if (JPEG::Decode (&resource, &buffer)) { - return imageBuffer.Value (); + return buffer.Value (); } #endif @@ -529,14 +537,14 @@ namespace lime { } - value lime_image_data_util_get_pixels (value image, value rect, value format) { + value lime_image_data_util_get_pixels (value image, value rect, value format, value bytes) { Image _image = Image (image); Rectangle _rect = Rectangle (rect); PixelFormat _format = (PixelFormat)val_int (format); - ByteArray pixels = ByteArray (); + Bytes pixels = Bytes (bytes); ImageDataUtil::GetPixels (&_image, &_rect, _format, &pixels); - return pixels.mValue; + return alloc_null (); } @@ -588,7 +596,7 @@ namespace lime { Image _image = Image (image); Rectangle _rect = Rectangle (rect); - ByteArray _bytes = ByteArray (bytes); + Bytes _bytes = Bytes (bytes); PixelFormat _format = (PixelFormat)val_int (format); ImageDataUtil::SetPixels (&_image, &_rect, &_bytes, _format); return alloc_null (); @@ -620,7 +628,7 @@ namespace lime { ImageBuffer imageBuffer; - ByteArray bytes (data); + Bytes bytes (data); Resource resource = Resource (&bytes); #ifdef LIME_JPEG @@ -760,7 +768,7 @@ namespace lime { ImageBuffer imageBuffer; - ByteArray bytes (data); + Bytes bytes (data); Resource resource = Resource (&bytes); #ifdef LIME_PNG @@ -908,8 +916,9 @@ namespace lime { TextLayout *text = (TextLayout*)(intptr_t)val_float (textHandle); Font *font = (Font*)(intptr_t)val_float (fontHandle); - ByteArray bytes = ByteArray (data); + Bytes bytes = Bytes (data); text->Position (font, val_int (size), val_string (textString), &bytes); + return bytes.Value (); #endif @@ -1095,6 +1104,7 @@ namespace lime { DEFINE_PRIM (lime_application_set_frame_rate, 2); DEFINE_PRIM (lime_application_update, 1); DEFINE_PRIM (lime_audio_load, 1); + DEFINE_PRIM (lime_bytes_get_data_pointer, 1); DEFINE_PRIM (lime_font_get_ascender, 1); DEFINE_PRIM (lime_font_get_descender, 1); DEFINE_PRIM (lime_font_get_family_name, 1); @@ -1120,7 +1130,7 @@ namespace lime { DEFINE_PRIM (lime_image_data_util_copy_pixels, 5); DEFINE_PRIM (lime_image_data_util_fill_rect, 3); DEFINE_PRIM (lime_image_data_util_flood_fill, 4); - DEFINE_PRIM (lime_image_data_util_get_pixels, 3); + DEFINE_PRIM (lime_image_data_util_get_pixels, 4); DEFINE_PRIM_MULT (lime_image_data_util_merge); DEFINE_PRIM (lime_image_data_util_multiply_alpha, 1); DEFINE_PRIM (lime_image_data_util_resize, 4); diff --git a/project/src/audio/AudioBuffer.cpp b/project/src/audio/AudioBuffer.cpp index 29bb83377..4f7100355 100644 --- a/project/src/audio/AudioBuffer.cpp +++ b/project/src/audio/AudioBuffer.cpp @@ -15,7 +15,7 @@ namespace lime { bitsPerSample = 0; channels = 0; - data = new ByteArray (); + data = new Bytes (); sampleRate = 0; } @@ -43,7 +43,7 @@ namespace lime { mValue = alloc_empty_object (); alloc_field (mValue, id_bitsPerSample, alloc_int (bitsPerSample)); alloc_field (mValue, id_channels, alloc_int (channels)); - alloc_field (mValue, id_data, data->mValue); + alloc_field (mValue, id_data, data ? data->Value () : alloc_null ()); alloc_field (mValue, id_sampleRate, alloc_int (sampleRate)); return mValue; diff --git a/project/src/audio/format/OGG.cpp b/project/src/audio/format/OGG.cpp index 61c863775..98931240c 100644 --- a/project/src/audio/format/OGG.cpp +++ b/project/src/audio/format/OGG.cpp @@ -130,9 +130,9 @@ namespace lime { } else { lime::fclose (file); - ByteArray data = ByteArray (resource->path); + Bytes data = Bytes (resource->path); - OAL_OggMemoryFile fakeFile = { data.Bytes (), data.Size (), 0 }; + OAL_OggMemoryFile fakeFile = { data.Data (), data.Length (), 0 }; if (ov_open_callbacks (&fakeFile, &oggFile, NULL, 0, OAL_CALLBACKS_BUFFER) != 0) { @@ -144,7 +144,7 @@ namespace lime { } else { - OAL_OggMemoryFile fakeFile = { resource->data->Bytes (), resource->data->Size (), 0 }; + OAL_OggMemoryFile fakeFile = { resource->data->Data (), resource->data->Length (), 0 }; if (ov_open_callbacks (&fakeFile, &oggFile, NULL, 0, OAL_CALLBACKS_BUFFER) != 0) { @@ -187,7 +187,7 @@ namespace lime { while (bytes > 0) { - bytes = ov_read (&oggFile, (char *)audioBuffer->data->Bytes () + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream); + bytes = ov_read (&oggFile, (char *)audioBuffer->data->Data () + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream); totalBytes += bytes; } @@ -197,8 +197,9 @@ namespace lime { audioBuffer->data->Resize (totalBytes); } + ov_clear (&oggFile); - + #undef BUFFER_READ_TYPE return true; diff --git a/project/src/audio/format/WAV.cpp b/project/src/audio/format/WAV.cpp index 2afe61877..a78576d08 100644 --- a/project/src/audio/format/WAV.cpp +++ b/project/src/audio/format/WAV.cpp @@ -141,7 +141,7 @@ namespace lime { audioBuffer->data->Resize (wave_data.subChunkSize); - if (!lime::fread (audioBuffer->data->Bytes (), wave_data.subChunkSize, 1, file)) { + if (!lime::fread (audioBuffer->data->Data (), wave_data.subChunkSize, 1, file)) { LOG_SOUND ("error loading WAVE data into struct!\n"); lime::fclose (file); @@ -153,8 +153,8 @@ namespace lime { } else { - const char* start = (const char*)resource->data->Bytes (); - const char* end = start + resource->data->Size (); + const char* start = (const char*)resource->data->Data (); + const char* end = start + resource->data->Length (); const char* ptr = start; memcpy (&riff_header, ptr, sizeof (RIFF_Header)); @@ -211,7 +211,7 @@ namespace lime { } - unsigned char* bytes = audioBuffer->data->Bytes (); + unsigned char* bytes = audioBuffer->data->Data (); memcpy (bytes, base, size); } diff --git a/project/src/audio/openal/OpenALBindings.cpp b/project/src/audio/openal/OpenALBindings.cpp index 0a1efc851..09e66b627 100644 --- a/project/src/audio/openal/OpenALBindings.cpp +++ b/project/src/audio/openal/OpenALBindings.cpp @@ -7,7 +7,7 @@ #endif #include -#include +#include namespace lime { @@ -15,13 +15,13 @@ namespace lime { value lime_al_buffer_data (value buffer, value format, value data, value size, value freq) { - ByteArray byteArray (data); + Bytes bytes (data); //int arraySize = byteArray.Size (); - const float *bytes = (float *)byteArray.Bytes (); + const float *b = (float *)bytes.Data (); //int elements = arraySize / sizeof (float); int count = val_int (size); - alBufferData (val_int (buffer), val_int (format), bytes, count, val_int (freq)); + alBufferData (val_int (buffer), val_int (format), b, count, val_int (freq)); return alloc_null (); } diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index eebbe27c0..4e93fd515 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -219,7 +219,7 @@ namespace lime { void SDLWindow::SetIcon (ImageBuffer *imageBuffer) { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Bytes (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp * 8, imageBuffer->width * imageBuffer->bpp, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Data (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp * 8, imageBuffer->width * imageBuffer->bpp, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); if (surface) { diff --git a/project/src/graphics/ImageBuffer.cpp b/project/src/graphics/ImageBuffer.cpp index 2073e6ff9..d82e178cb 100644 --- a/project/src/graphics/ImageBuffer.cpp +++ b/project/src/graphics/ImageBuffer.cpp @@ -5,7 +5,6 @@ namespace lime { static int id_bitsPerPixel; - static int id_bpp; static int id_buffer; static int id_data; static int id_format; @@ -31,7 +30,6 @@ namespace lime { if (!init) { - id_bpp = val_id ("bpp"); id_bitsPerPixel = val_id ("bitsPerPixel"); id_transparent = val_id ("transparent"); id_buffer = val_id ("buffer"); @@ -50,11 +48,7 @@ namespace lime { transparent = val_bool (val_field (imageBuffer, id_transparent)); value data_value = val_field (imageBuffer, id_data); value buffer_value = val_field (data_value, id_buffer); - - //if (val_is_buffer (buffer_value)) - data = new ByteArray (buffer_value); - //else - //data = new ByteArray (data_value); + data = new Bytes (buffer_value); } @@ -74,7 +68,7 @@ namespace lime { } - unsigned char *bytes = this->data->Bytes (); + unsigned char *bytes = this->data->Data (); for (int i = 0; i < height; i++) { @@ -90,8 +84,16 @@ namespace lime { this->bpp = bpp; this->width = width; this->height = height; - if (this->data) delete this->data; - this->data = new ByteArray (width * height * bpp); + + if (!this->data) { + + this->data = new Bytes (width * height * bpp); + + } else { + + this->data->Resize (width * height * bpp); + + } } @@ -100,7 +102,6 @@ namespace lime { if (!init) { - id_bpp = val_id ("bpp"); id_bitsPerPixel = val_id ("bitsPerPixel"); id_transparent = val_id ("transparent"); id_buffer = val_id ("buffer"); @@ -115,9 +116,9 @@ namespace lime { mValue = alloc_empty_object (); alloc_field (mValue, id_width, alloc_int (width)); alloc_field (mValue, id_height, alloc_int (height)); - alloc_field (mValue, id_bpp, alloc_int (bpp)); + alloc_field (mValue, id_bitsPerPixel, alloc_int (bpp)); + alloc_field (mValue, id_data, data ? data->Value () : alloc_null ()); alloc_field (mValue, id_transparent, alloc_bool (transparent)); - alloc_field (mValue, id_data, data ? data->mValue : alloc_null ()); alloc_field (mValue, id_format, alloc_int (format)); return mValue; diff --git a/project/src/graphics/format/JPEG.cpp b/project/src/graphics/format/JPEG.cpp index 732ad39f7..7e4dd2f26 100644 --- a/project/src/graphics/format/JPEG.cpp +++ b/project/src/graphics/format/JPEG.cpp @@ -124,8 +124,8 @@ namespace lime { enum { BUF_SIZE = 4096 }; struct jpeg_destination_mgr pub; /* public fields */ - QuickVec mOutput; - uint8 mTmpBuf[BUF_SIZE]; + QuickVec mOutput; + unsigned char mTmpBuf[BUF_SIZE]; MyDestManager () { @@ -227,15 +227,15 @@ namespace lime { } else { - ByteArray data = ByteArray (resource->path); - MySrcManager manager (data.Bytes (), data.Size ()); + Bytes data = Bytes (resource->path); + MySrcManager manager (data.Data (), data.Length ()); cinfo.src = &manager.pub; } } else { - MySrcManager manager (resource->data->Bytes (), resource->data->Size ()); + MySrcManager manager (resource->data->Data (), resource->data->Length ()); cinfo.src = &manager.pub; } @@ -252,7 +252,7 @@ namespace lime { int components = cinfo.num_components; imageBuffer->Resize (cinfo.output_width, cinfo.output_height); - unsigned char *bytes = imageBuffer->data->Bytes (); + unsigned char *bytes = imageBuffer->data->Data (); unsigned char *scanline = new unsigned char [imageBuffer->width * imageBuffer->height * components]; while (cinfo.output_scanline < cinfo.output_height) { @@ -301,7 +301,7 @@ namespace lime { } - bool JPEG::Encode (ImageBuffer *imageBuffer, ByteArray *bytes, int quality) { + bool JPEG::Encode (ImageBuffer *imageBuffer, Bytes *bytes, int quality) { struct jpeg_compress_struct cinfo; @@ -314,7 +314,7 @@ namespace lime { int w = imageBuffer->width; int h = imageBuffer->height; - QuickVec row_buf (w * 3); + QuickVec row_buf (w * 3); jpeg_create_compress (&cinfo); @@ -337,13 +337,13 @@ namespace lime { jpeg_start_compress (&cinfo, true); JSAMPROW row_pointer = &row_buf[0]; - unsigned char* imageData = imageBuffer->data->Bytes(); + unsigned char* imageData = imageBuffer->data->Data(); int stride = w * imageBuffer->bpp; while (cinfo.next_scanline < cinfo.image_height) { - const uint8 *src = (const uint8 *)(imageData + (stride * cinfo.next_scanline)); - uint8 *dest = &row_buf[0]; + const unsigned char *src = (const unsigned char *)(imageData + (stride * cinfo.next_scanline)); + unsigned char *dest = &row_buf[0]; for(int x = 0; x < w; x++) { @@ -361,7 +361,7 @@ namespace lime { jpeg_finish_compress (&cinfo); - *bytes = ByteArray (dest.mOutput); + *bytes = Bytes (dest.mOutput); return true; diff --git a/project/src/graphics/format/PNG.cpp b/project/src/graphics/format/PNG.cpp index cb652a484..72e039a9d 100644 --- a/project/src/graphics/format/PNG.cpp +++ b/project/src/graphics/format/PNG.cpp @@ -10,7 +10,7 @@ extern "C" { #include #include #include -#include +#include #include @@ -100,7 +100,7 @@ namespace lime { } else { - memcpy (png_sig, resource->data->Bytes (), PNG_SIG_SIZE); + memcpy (png_sig, resource->data->Data (), PNG_SIG_SIZE); if (png_sig_cmp (png_sig, 0, PNG_SIG_SIZE)) { @@ -143,15 +143,15 @@ namespace lime { } else { - ByteArray data = ByteArray (resource->path); - ReadBuffer buffer (data.Bytes (), data.Size ()); + Bytes data = Bytes (resource->path); + ReadBuffer buffer (data.Data (), data.Length ()); png_set_read_fn (png_ptr, &buffer, user_read_data_fn); } } else { - ReadBuffer buffer (resource->data->Bytes (), resource->data->Size ()); + ReadBuffer buffer (resource->data->Data (), resource->data->Length ()); png_set_read_fn (png_ptr, &buffer, user_read_data_fn); } @@ -185,7 +185,7 @@ namespace lime { int bpp = 4; const unsigned int stride = width * bpp; imageBuffer->Resize (width, height, bpp); - unsigned char *bytes = imageBuffer->data->Bytes (); + unsigned char *bytes = imageBuffer->data->Data (); int number_of_passes = png_set_interlace_handling (png_ptr); @@ -218,7 +218,7 @@ namespace lime { } - bool PNG::Encode (ImageBuffer *imageBuffer, ByteArray *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); @@ -243,7 +243,7 @@ namespace lime { } - QuickVec out_buffer; + QuickVec out_buffer; png_set_write_fn (png_ptr, &out_buffer, user_write_data, user_flush_data); @@ -258,17 +258,17 @@ namespace lime { png_write_info (png_ptr, info_ptr); bool do_alpha = (color_type == PNG_COLOR_TYPE_RGBA); - unsigned char* imageData = imageBuffer->data->Bytes(); + unsigned char* imageData = imageBuffer->data->Data(); int stride = w * imageBuffer->bpp; { - QuickVec row_data (w * 4); + QuickVec row_data (w * 4); png_bytep row = &row_data[0]; for (int y = 0; y < h; y++) { - uint8 *buf = &row_data[0]; - const uint8 *src = (const uint8 *)(imageData + (stride * y)); + unsigned char *buf = &row_data[0]; + const unsigned char *src = (const unsigned char *)(imageData + (stride * y)); for (int x = 0; x < w; x++) { @@ -296,7 +296,7 @@ namespace lime { png_write_end (png_ptr, NULL); - *bytes = ByteArray (out_buffer); + *bytes = Bytes (out_buffer); return true; diff --git a/project/src/graphics/opengl/OpenGLBindings.cpp b/project/src/graphics/opengl/OpenGLBindings.cpp index 87c8e4439..f64967aea 100644 --- a/project/src/graphics/opengl/OpenGLBindings.cpp +++ b/project/src/graphics/opengl/OpenGLBindings.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "OpenGL.h" #include "OpenGLBindings.h" #include @@ -126,9 +126,9 @@ namespace lime { if (len == 0) return alloc_null (); - ByteArray bytes (inByteBuffer); - const unsigned char *data = bytes.Bytes (); - int size = bytes.Size (); + Bytes bytes (inByteBuffer); + const unsigned char *data = bytes.Data (); + int size = bytes.Length (); if (len + start > size) { @@ -149,10 +149,10 @@ namespace lime { if (len == 0) return alloc_null (); - ByteArray bytes (inByteBuffer); + Bytes bytes (inByteBuffer); - const unsigned char *data = bytes.Bytes (); - int size = bytes.Size (); + const unsigned char *data = bytes.Data (); + int size = bytes.Length (); if (len + start > size) { @@ -233,12 +233,12 @@ namespace lime { unsigned char *data = 0; int size = 0; - ByteArray bytes (arg[aBuffer]); + Bytes bytes (arg[aBuffer]); - if (!val_is_null (bytes.mValue)) { + if (bytes.Length ()) { - data = bytes.Bytes () + val_int (arg[aOffset]); - size = bytes.Size () - val_int (arg[aOffset]); + data = bytes.Data () + val_int (arg[aOffset]); + size = bytes.Length () - val_int (arg[aOffset]); } @@ -255,12 +255,12 @@ namespace lime { unsigned char *data = 0; int size = 0; - ByteArray bytes (arg[aBuffer]); + Bytes bytes (arg[aBuffer]); - if (!val_is_null (bytes.mValue)) { + if (bytes.Length ()) { - data = bytes.Bytes() + val_int (arg[aOffset]); - size = bytes.Size() - val_int (arg[aOffset]); + data = bytes.Data () + val_int (arg[aOffset]); + size = bytes.Length () - val_int (arg[aOffset]); } @@ -1178,11 +1178,11 @@ namespace lime { enum { aX, aY, aWidth, aHeight, aFormat, aType, aBuffer, aOffset }; unsigned char *data = 0; - ByteArray bytes (arg[aBuffer]); + Bytes bytes (arg[aBuffer]); - if (bytes.mValue) { + if (bytes.Length ()) { - data = bytes.Bytes () + val_int (arg[aOffset]); + data = bytes.Data () + val_int (arg[aOffset]); } @@ -1282,11 +1282,11 @@ namespace lime { unsigned char *data = 0; - ByteArray bytes (arg[aBuffer]); + Bytes bytes (arg[aBuffer]); - if (!val_is_null (bytes.mValue)) { + if (bytes.Length ()) { - data = bytes.Bytes () + val_int (arg[aOffset]); + data = bytes.Data () + val_int (arg[aOffset]); } @@ -1317,11 +1317,11 @@ namespace lime { enum { aTarget, aLevel, aXOffset, aYOffset, aWidth, aHeight, aFormat, aType, aBuffer, aOffset }; unsigned char *data = 0; - ByteArray bytes (arg[aBuffer]); + Bytes bytes (arg[aBuffer]); - if (!val_is_null (bytes.mValue)) { + if (bytes.Length ()) { - data = bytes.Bytes () + val_int (arg[aOffset]); + data = bytes.Data () + val_int (arg[aOffset]); } @@ -1337,9 +1337,9 @@ namespace lime { int count = val_int (inCount); bool trans = val_bool (inTranspose); - ByteArray bytes (inBytes); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inBytes); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); int nbElems = size / sizeof (float); switch (count) { @@ -1367,9 +1367,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); int nbElems = size / sizeof (float); glUniform1fv (loc, nbElems, data); @@ -1391,9 +1391,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const int *data = (int *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const int *data = (int *)bytes.Data (); int nbElems = size / sizeof (int); glUniform1iv (loc, nbElems, data); @@ -1415,9 +1415,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); int nbElems = size / sizeof (float); glUniform2fv (loc, nbElems >> 1, data); @@ -1439,9 +1439,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const int *data = (int *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const int *data = (int *)bytes.Data (); int nbElems = size / sizeof (int); glUniform2iv (loc, nbElems >> 1, data); @@ -1463,9 +1463,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); int nbElems = size / sizeof (float); glUniform3fv (loc, nbElems / 3, data); @@ -1487,9 +1487,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const int *data = (int *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const int *data = (int *)bytes.Data (); int nbElems = size / sizeof (int); glUniform3iv (loc, nbElems / 3, data); @@ -1511,9 +1511,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); int nbElems = size / sizeof (float); glUniform4fv (loc, nbElems >> 2, data); @@ -1535,9 +1535,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const int *data = (int *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const int *data = (int *)bytes.Data (); int nbElems = size / sizeof (int); glUniform4iv (loc, nbElems >> 2, data); @@ -1614,9 +1614,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); glVertexAttrib1fv (loc, data); @@ -1637,9 +1637,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); glVertexAttrib2fv (loc, data); @@ -1660,9 +1660,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); glVertexAttrib3fv (loc, data); @@ -1683,9 +1683,9 @@ namespace lime { int loc = val_int (inLocation); - ByteArray bytes (inByteBuffer); - int size = bytes.Size (); - const float *data = (float *)bytes.Bytes (); + Bytes bytes (inByteBuffer); + int size = bytes.Length (); + const float *data = (float *)bytes.Data (); glVertexAttrib4fv (loc, data); diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index 73b5e5622..21c0539c6 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -47,7 +47,7 @@ namespace lime { int columnStart = int (rect->x + image->offsetX); int columnEnd = int (rect->x + rect->width + image->offsetX); - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); + uint8_t* data = (uint8_t*)image->buffer->data->Data (); int r, g, b, a, ex = 0; float alphaMultiplier = colorMatrix->GetAlphaMultiplier (); @@ -91,13 +91,13 @@ namespace lime { int srcPosition = ((sourceRect->x + sourceImage->offsetX) * 4) + (srcStride * (sourceRect->y + sourceImage->offsetY)) + srcChannel; int srcRowOffset = srcStride - int (4 * (sourceRect->width + sourceImage->offsetX)); int srcRowEnd = 4 * (sourceRect->x + sourceImage->offsetX + sourceRect->width); - uint8_t* srcData = (uint8_t*)sourceImage->buffer->data->Bytes (); + uint8_t* srcData = (uint8_t*)sourceImage->buffer->data->Data (); int destStride = image->buffer->width * 4; int destPosition = ((destPoint->x + image->offsetX) * 4) + (destStride * (destPoint->y + image->offsetY)) + destChannel; int destRowOffset = destStride - int (4 * (sourceRect->width + image->offsetX)); int destRowEnd = 4 * (destPoint->x + image->offsetX + sourceRect->width); - uint8_t* destData = (uint8_t*)image->buffer->data->Bytes (); + uint8_t* destData = (uint8_t*)image->buffer->data->Data (); int length = sourceRect->width * sourceRect->height; @@ -130,11 +130,11 @@ namespace lime { int rowOffset = int (destPoint->y + image->offsetY - sourceRect->y - sourceImage->offsetY); int columnOffset = int (destPoint->x + image->offsetX - sourceRect->x - sourceImage->offsetY); - uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Bytes (); + uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Data (); int sourceStride = sourceImage->buffer->width * 4; int sourceOffset = 0; - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); + uint8_t* data = (uint8_t*)image->buffer->data->Data (); int stride = image->buffer->width * 4; int offset = 0; @@ -194,7 +194,7 @@ namespace lime { void ImageDataUtil::FillRect (Image* image, Rectangle* rect, int color) { - int* data = (int*)image->buffer->data->Bytes (); + int* data = (int*)image->buffer->data->Data (); if (rect->width == image->buffer->width && rect->height == image->buffer->height && rect->x == 0 && rect->y == 0 && image->offsetX == 0 && image->offsetY == 0) { @@ -242,7 +242,7 @@ namespace lime { void ImageDataUtil::FloodFill (Image* image, int x, int y, int color) { - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); + uint8_t* data = (uint8_t*)image->buffer->data->Data (); int offset = (((y + image->offsetY) * (image->buffer->width * 4)) + ((x + image->offsetX) * 4)); uint8_t hitColorR = data[offset + 0]; @@ -308,20 +308,20 @@ namespace lime { } - void ImageDataUtil::GetPixels (Image* image, Rectangle* rect, PixelFormat format, ByteArray* pixels) { + void ImageDataUtil::GetPixels (Image* image, Rectangle* rect, PixelFormat format, Bytes* pixels) { int length = int (rect->width * rect->height); pixels->Resize (length * 4); if (format == RGBA && rect->width == image->buffer->width && rect->height == image->buffer->height && rect->x == 0 && rect->y == 0) { - memcpy (pixels->Bytes (), image->buffer->data->Bytes (), image->buffer->data->Size ()); + memcpy (pixels->Data (), image->buffer->data->Data (), image->buffer->data->Length ()); return; } - uint8_t* data = (uint8_t*)pixels->Bytes (); - uint8_t* srcData = (uint8_t*)image->buffer->data->Bytes (); + uint8_t* data = (uint8_t*)pixels->Data (); + uint8_t* srcData = (uint8_t*)image->buffer->data->Data (); int srcStride = int (image->buffer->width * 4); int srcPosition = int ((rect->x * 4) + (srcStride * rect->y)); @@ -372,11 +372,11 @@ namespace lime { int rowOffset = int (destPoint->y + image->offsetY - sourceRect->y - sourceImage->offsetY); int columnOffset = int (destPoint->x + image->offsetX - sourceRect->x - sourceImage->offsetY); - uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Bytes (); + uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Data (); int sourceStride = sourceImage->buffer->width * 4; int sourceOffset = 0; - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); + uint8_t* data = (uint8_t*)image->buffer->data->Data (); int stride = image->buffer->width * 4; int offset = 0; @@ -405,8 +405,8 @@ namespace lime { void ImageDataUtil::MultiplyAlpha (Image* image) { int a16 = 0; - int length = image->buffer->data->Size () / 4; - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); + int length = image->buffer->data->Length () / 4; + uint8_t* data = (uint8_t*)image->buffer->data->Data (); for (int i = 0; i < length; i++) { @@ -426,8 +426,8 @@ namespace lime { int imageWidth = image->width; int imageHeight = image->height; - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); - uint8_t* newData = (uint8_t*)buffer->data->Bytes (); + uint8_t* data = (uint8_t*)image->buffer->data->Data (); + uint8_t* newData = (uint8_t*)buffer->data->Data (); int sourceIndex, sourceIndexX, sourceIndexY, sourceIndexXY, index; int sourceX, sourceY; @@ -481,7 +481,7 @@ namespace lime { void ImageDataUtil::SetFormat (Image* image, PixelFormat format) { int index, a16; - int length = image->buffer->data->Size () / 4; + int length = image->buffer->data->Length () / 4; int r1, g1, b1, a1, r2, g2, b2, a2; int r, g, b, a; @@ -541,7 +541,7 @@ namespace lime { } - unsigned char* data = image->buffer->data->Bytes (); + unsigned char* data = image->buffer->data->Data (); for (int i = 0; i < length; i++) { @@ -562,11 +562,11 @@ namespace lime { } - void ImageDataUtil::SetPixels (Image* image, Rectangle* rect, ByteArray* bytes, PixelFormat format) { + void ImageDataUtil::SetPixels (Image* image, Rectangle* rect, Bytes* bytes, PixelFormat format) { if (format == RGBA && rect->width == image->buffer->width && rect->height == image->buffer->height && rect->x == 0 && rect->y == 0) { - memcpy (image->buffer->data->Bytes (), bytes->Bytes (), bytes->Size ()); + memcpy (image->buffer->data->Data (), bytes->Data (), bytes->Length ()); return; } @@ -580,8 +580,8 @@ namespace lime { int pos = offset * 4; int len = int (rect->width * rect->height * 4); - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); - uint8_t* byteArray = (uint8_t*)bytes->Bytes (); + uint8_t* data = (uint8_t*)image->buffer->data->Data (); + uint8_t* byteArray = (uint8_t*)bytes->Data (); for (int i = 0; i < len; i += 4) { @@ -604,8 +604,8 @@ namespace lime { int pos = offset; int len = int (rect->width * rect->height); - int* data = (int*)image->buffer->data->Bytes (); - int* byteArray = (int*)bytes->Bytes (); + int* data = (int*)image->buffer->data->Data (); + int* byteArray = (int*)bytes->Data (); // TODO: memcpy rows at once @@ -629,8 +629,8 @@ namespace lime { void ImageDataUtil::UnmultiplyAlpha (Image* image) { - int length = image->buffer->data->Size () / 4; - uint8_t* data = (uint8_t*)image->buffer->data->Bytes (); + int length = image->buffer->data->Length () / 4; + uint8_t* data = (uint8_t*)image->buffer->data->Data (); int unmultiply; uint8_t a; diff --git a/project/src/math/ColorMatrix.cpp b/project/src/math/ColorMatrix.cpp index 9ae84251a..34263b3ae 100644 --- a/project/src/math/ColorMatrix.cpp +++ b/project/src/math/ColorMatrix.cpp @@ -1,5 +1,5 @@ #include -#include +#include namespace lime { @@ -38,8 +38,8 @@ namespace lime { } value buffer_value = val_field (colorMatrix, id_buffer); - ByteArray bytes = ByteArray (buffer_value); - float* src = (float*)bytes.Bytes (); + Bytes bytes = Bytes (buffer_value); + float* src = (float*)bytes.Data (); for (int i = 0; i < 20; i++) { diff --git a/project/src/text/Font.cpp b/project/src/text/Font.cpp index f0a53b835..02320cd57 100644 --- a/project/src/text/Font.cpp +++ b/project/src/text/Font.cpp @@ -389,20 +389,20 @@ namespace lime { } else { - ByteArray data = ByteArray (resource->path); - unsigned char *buffer = (unsigned char*)malloc (data.Size ()); - memcpy (buffer, data.Bytes (), data.Size ()); + Bytes data = Bytes (resource->path); + unsigned char *buffer = (unsigned char*)malloc (data.Length ()); + memcpy (buffer, data.Data (), data.Length ()); lime::fclose (file); file = 0; - error = FT_New_Memory_Face (library, buffer, data.Size (), faceIndex, &face); + error = FT_New_Memory_Face (library, buffer, data.Length (), faceIndex, &face); } } else { - unsigned char *buffer = (unsigned char*)malloc (resource->data->Size ()); - memcpy (buffer, resource->data->Bytes (), resource->data->Size ()); - error = FT_New_Memory_Face (library, buffer, resource->data->Size (), faceIndex, &face); + unsigned char *buffer = (unsigned char*)malloc (resource->data->Length ()); + memcpy (buffer, resource->data->Data (), resource->data->Length ()); + error = FT_New_Memory_Face (library, buffer, resource->data->Length (), faceIndex, &face); } @@ -781,7 +781,7 @@ namespace lime { } - int Font::RenderGlyph (int index, ByteArray *bytes, int offset) { + int Font::RenderGlyph (int index, Bytes *bytes, int offset) { if (FT_Load_Glyph ((FT_Face)face, index, FT_LOAD_FORCE_AUTOHINT | FT_LOAD_DEFAULT) == 0) { @@ -797,13 +797,13 @@ namespace lime { uint32_t size = (4 * 5) + (width * height); - if (bytes->Size() < size + offset) { + if (bytes->Length () < size + offset) { bytes->Resize (size + offset); } - GlyphImage *data = (GlyphImage*)(bytes->Bytes () + offset); + GlyphImage *data = (GlyphImage*)(bytes->Data () + offset); data->index = index; data->width = width; @@ -830,7 +830,7 @@ namespace lime { } - int Font::RenderGlyphs (value indices, ByteArray *bytes) { + int Font::RenderGlyphs (value indices, Bytes *bytes) { int offset = 0; int totalOffset = 4; @@ -853,7 +853,7 @@ namespace lime { if (count > 0) { - *(bytes->Bytes ()) = count; + *(bytes->Data ()) = count; } diff --git a/project/src/text/TextLayout.cpp b/project/src/text/TextLayout.cpp index 9edbb739f..a5d69ec72 100644 --- a/project/src/text/TextLayout.cpp +++ b/project/src/text/TextLayout.cpp @@ -36,7 +36,7 @@ namespace lime { } - void TextLayout::Position (Font *font, size_t size, const char *text, ByteArray *bytes) { + void TextLayout::Position (Font *font, size_t size, const char *text, Bytes *bytes) { if (mFont != font) { @@ -64,16 +64,16 @@ namespace lime { //float hres = 100; int posIndex = 0; - int glyphSize = sizeof(GlyphPosition); + int glyphSize = sizeof (GlyphPosition); uint32_t dataSize = 4 + (glyph_count * glyphSize); - if (bytes->Size() < dataSize) { + if (bytes->Length () < dataSize) { bytes->Resize (dataSize); } - unsigned char* bytesPosition = bytes->Bytes (); + unsigned char* bytesPosition = bytes->Data (); *(bytesPosition) = glyph_count; bytesPosition += 4; diff --git a/project/src/utils/ByteArray.cpp b/project/src/utils/ByteArray.cpp index 6ddc54f39..b83efd63d 100644 --- a/project/src/utils/ByteArray.cpp +++ b/project/src/utils/ByteArray.cpp @@ -145,12 +145,6 @@ namespace lime { return alloc_null (); } - - value lime_buffer_get_native_pointer (buffer inBuffer) { - - return alloc_float ((intptr_t)buffer_data (inBuffer)); - - } value lime_byte_array_init (value inFactory, value inLen, value inResize, value inBytes) { @@ -203,12 +197,12 @@ namespace lime { } + + DEFINE_PRIM (lime_byte_array_get_native_pointer, 1); DEFINE_PRIM (lime_byte_array_init, 4); DEFINE_PRIM (lime_byte_array_overwrite_file, 2); DEFINE_PRIM (lime_byte_array_read_file, 1); - - DEFINE_PRIM (lime_buffer_get_native_pointer, 1); } \ No newline at end of file diff --git a/project/src/utils/Bytes.cpp b/project/src/utils/Bytes.cpp new file mode 100644 index 000000000..4f126b797 --- /dev/null +++ b/project/src/utils/Bytes.cpp @@ -0,0 +1,239 @@ +#include +#include + + +namespace lime { + + + static int id_b; + static int id_length; + static bool init = false; + + + Bytes::Bytes () { + + _data = 0; + _length = 0; + _value = 0; + + } + + + Bytes::Bytes (int size) { + + _data = (unsigned char*)malloc (size); + _length = size; + _value = 0; + + } + + + Bytes::Bytes (value bytes) { + + if (!init) { + + id_b = val_id ("b"); + id_length = val_id ("length"); + init = true; + + } + + if (val_is_null (bytes)) { + + _length = 0; + _data = 0; + _value = 0; + + } else { + + _value = bytes; + _length = val_int (val_field (bytes, id_length)); + + if (_length > 0) { + + value b = val_field (bytes, id_b); + + if (val_is_string (b)) { + + _data = (unsigned char*)val_string (b); + + } else { + + _data = (unsigned char*)buffer_data (val_to_buffer (b)); + + } + + } else { + + _data = 0; + + } + + } + + } + + + Bytes::Bytes (const char* path) { + + FILE_HANDLE *file = lime::fopen (path, "rb"); + + if (!file) { + + return; + + } + + lime::fseek (file, 0, SEEK_END); + _length = lime::ftell (file); + lime::fseek (file, 0, SEEK_SET); + + _data = (unsigned char*)malloc (_length); + + int status = lime::fread (_data, _length, 1, file); + lime::fclose (file); + delete file; + + _value = 0; + + } + + + Bytes::Bytes (const QuickVec data) { + + _length = data.size (); + + if (_length > 0) { + + _data = (unsigned char*)malloc (_length); + memcpy (_data, &data[0], _length); + + } else { + + _data = 0; + + } + + _value = 0; + + } + + + Bytes::~Bytes () { + + if (!_value && _data) { + + free (_data); + + } + + } + + + 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::Resize (int size) { + + if (_value) { + + if (size > _length) { + + if (val_is_null (val_field (_value, id_b))) { + + buffer buf = alloc_buffer_len (size); + _data = (unsigned char*)buffer_data (buf); + + if (_data) { + + alloc_field (_value, id_b, buffer_val (buf)); + + } else { + + value newString = alloc_raw_string (size); + alloc_field (_value, id_b, newString); + _data = (unsigned char*)val_string (val_field (_value, id_b)); + memset (_data, 0, size); + + } + + } else { + + resizeByteData (_value, size); + + } + + } + + alloc_field (_value, id_length, alloc_int (size)); + + } else { + + if (size > _length) { + + if (_data) { + + realloc (_data, size); + + } else { + + _data = (unsigned char*)malloc (size); + + } + + } + + } + + _length = size; + + } + + + value Bytes::Value () { + + if (_value) { + + return _value; + + } else { + + if (!init) { + + id_b = val_id ("b"); + id_length = val_id ("length"); + init = true; + + } + + value object = alloc_empty_object (); + value newString = alloc_raw_string (_length); + memcpy ((char*)val_string (newString), _data, _length); + alloc_field (object, id_b, newString); + alloc_field (object, id_length, alloc_int (_length)); + return object; + + } + + } + + +} \ No newline at end of file