Revert Bytes changes, prevents ppremature GC on audio decoding
This commit is contained in:
@@ -155,12 +155,12 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_audio_load (value data) {
|
||||
value lime_audio_load (value data, value buffer) {
|
||||
|
||||
Resource resource;
|
||||
Bytes bytes;
|
||||
|
||||
AudioBuffer audioBuffer;
|
||||
AudioBuffer audioBuffer = AudioBuffer (buffer);
|
||||
|
||||
if (val_is_string (data)) {
|
||||
|
||||
@@ -216,9 +216,9 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_bytes_read_file (HxString path) {
|
||||
value lime_bytes_read_file (HxString path, value bytes) {
|
||||
|
||||
Bytes data;
|
||||
Bytes data (bytes);
|
||||
data.ReadFile (path.c_str ());
|
||||
return data.Value ();
|
||||
|
||||
@@ -276,11 +276,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_deflate_compress (value buffer) {
|
||||
value lime_deflate_compress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_ZLIB
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
Zlib::Compress (DEFLATE, &data, &result);
|
||||
|
||||
@@ -292,11 +292,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_deflate_decompress (value buffer) {
|
||||
value lime_deflate_decompress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_ZLIB
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
Zlib::Decompress (DEFLATE, &data, &result);
|
||||
|
||||
@@ -666,11 +666,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_gzip_compress (value buffer) {
|
||||
value lime_gzip_compress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_ZLIB
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
Zlib::Compress (GZIP, &data, &result);
|
||||
|
||||
@@ -682,11 +682,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_gzip_decompress (value buffer) {
|
||||
value lime_gzip_decompress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_ZLIB
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
Zlib::Decompress (GZIP, &data, &result);
|
||||
|
||||
@@ -707,10 +707,10 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_image_encode (value buffer, int type, int quality) {
|
||||
value lime_image_encode (value buffer, int type, int quality, value bytes) {
|
||||
|
||||
ImageBuffer imageBuffer = ImageBuffer (buffer);
|
||||
Bytes data;
|
||||
Bytes data = Bytes (bytes);
|
||||
|
||||
switch (type) {
|
||||
|
||||
@@ -745,12 +745,12 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_image_load (value data) {
|
||||
value lime_image_load (value data, value buffer) {
|
||||
|
||||
Resource resource;
|
||||
Bytes bytes;
|
||||
|
||||
ImageBuffer imageBuffer;
|
||||
ImageBuffer imageBuffer = ImageBuffer (buffer);
|
||||
|
||||
if (val_is_string (data)) {
|
||||
|
||||
@@ -989,9 +989,9 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_jpeg_decode_bytes (value data, bool decodeData) {
|
||||
value lime_jpeg_decode_bytes (value data, bool decodeData, value buffer) {
|
||||
|
||||
ImageBuffer imageBuffer;
|
||||
ImageBuffer imageBuffer (buffer);
|
||||
|
||||
Bytes bytes (data);
|
||||
Resource resource = Resource (&bytes);
|
||||
@@ -1009,9 +1009,9 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_jpeg_decode_file (HxString path, bool decodeData) {
|
||||
value lime_jpeg_decode_file (HxString path, bool decodeData, value buffer) {
|
||||
|
||||
ImageBuffer imageBuffer;
|
||||
ImageBuffer imageBuffer (buffer);
|
||||
Resource resource = Resource (path.c_str ());
|
||||
|
||||
#ifdef LIME_JPEG
|
||||
@@ -1054,11 +1054,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_lzma_compress (value buffer) {
|
||||
value lime_lzma_compress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_LZMA
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
LZMA::Compress (&data, &result);
|
||||
|
||||
@@ -1070,11 +1070,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_lzma_decompress (value buffer) {
|
||||
value lime_lzma_decompress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_LZMA
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
LZMA::Decompress (&data, &result);
|
||||
|
||||
@@ -1146,9 +1146,9 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_png_decode_bytes (value data, bool decodeData) {
|
||||
value lime_png_decode_bytes (value data, bool decodeData, value buffer) {
|
||||
|
||||
ImageBuffer imageBuffer;
|
||||
ImageBuffer imageBuffer (buffer);
|
||||
Bytes bytes (data);
|
||||
Resource resource = Resource (&bytes);
|
||||
|
||||
@@ -1165,9 +1165,9 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_png_decode_file (HxString path, bool decodeData) {
|
||||
value lime_png_decode_file (HxString path, bool decodeData, value buffer) {
|
||||
|
||||
ImageBuffer imageBuffer;
|
||||
ImageBuffer imageBuffer (buffer);
|
||||
Resource resource = Resource (path.c_str ());
|
||||
|
||||
#ifdef LIME_PNG
|
||||
@@ -1245,10 +1245,10 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_renderer_read_pixels (value renderer, value rect) {
|
||||
value lime_renderer_read_pixels (value renderer, value rect, value imageBuffer) {
|
||||
|
||||
Renderer* targetRenderer = (Renderer*)val_data (renderer);
|
||||
ImageBuffer buffer;
|
||||
ImageBuffer buffer (imageBuffer);
|
||||
|
||||
if (!val_is_null (rect)) {
|
||||
|
||||
@@ -1627,11 +1627,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_zlib_compress (value buffer) {
|
||||
value lime_zlib_compress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_ZLIB
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
Zlib::Compress (ZLIB, &data, &result);
|
||||
|
||||
@@ -1643,11 +1643,11 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_zlib_decompress (value buffer) {
|
||||
value lime_zlib_decompress (value buffer, value bytes) {
|
||||
|
||||
#ifdef LIME_ZLIB
|
||||
Bytes data (buffer);
|
||||
Bytes result;
|
||||
Bytes result (bytes);
|
||||
|
||||
Zlib::Decompress (ZLIB, &data, &result);
|
||||
|
||||
@@ -1666,16 +1666,16 @@ namespace lime {
|
||||
DEFINE_PRIME1 (lime_application_quit);
|
||||
DEFINE_PRIME2v (lime_application_set_frame_rate);
|
||||
DEFINE_PRIME1 (lime_application_update);
|
||||
DEFINE_PRIME1 (lime_audio_load);
|
||||
DEFINE_PRIME2 (lime_audio_load);
|
||||
DEFINE_PRIME2 (lime_bytes_from_data_pointer);
|
||||
DEFINE_PRIME1 (lime_bytes_get_data_pointer);
|
||||
DEFINE_PRIME1 (lime_bytes_read_file);
|
||||
DEFINE_PRIME2 (lime_bytes_read_file);
|
||||
DEFINE_PRIME1 (lime_cffi_get_native_pointer);
|
||||
DEFINE_PRIME1 (lime_cffi_set_finalizer);
|
||||
DEFINE_PRIME0 (lime_clipboard_get_text);
|
||||
DEFINE_PRIME1v (lime_clipboard_set_text);
|
||||
DEFINE_PRIME1 (lime_deflate_compress);
|
||||
DEFINE_PRIME1 (lime_deflate_decompress);
|
||||
DEFINE_PRIME2 (lime_deflate_compress);
|
||||
DEFINE_PRIME2 (lime_deflate_decompress);
|
||||
DEFINE_PRIME2v (lime_drop_event_manager_register);
|
||||
DEFINE_PRIME2 (lime_file_dialog_open_directory);
|
||||
DEFINE_PRIME2 (lime_file_dialog_open_file);
|
||||
@@ -1701,8 +1701,8 @@ namespace lime {
|
||||
DEFINE_PRIME2v (lime_gamepad_event_manager_register);
|
||||
DEFINE_PRIME1 (lime_gamepad_get_device_guid);
|
||||
DEFINE_PRIME1 (lime_gamepad_get_device_name);
|
||||
DEFINE_PRIME1 (lime_gzip_compress);
|
||||
DEFINE_PRIME1 (lime_gzip_decompress);
|
||||
DEFINE_PRIME2 (lime_gzip_compress);
|
||||
DEFINE_PRIME2 (lime_gzip_decompress);
|
||||
DEFINE_PRIME2v (lime_haptic_vibrate);
|
||||
DEFINE_PRIME3v (lime_image_data_util_color_transform);
|
||||
DEFINE_PRIME6v (lime_image_data_util_copy_channel);
|
||||
@@ -1717,8 +1717,8 @@ namespace lime {
|
||||
DEFINE_PRIME4v (lime_image_data_util_set_pixels);
|
||||
DEFINE_PRIME12 (lime_image_data_util_threshold);
|
||||
DEFINE_PRIME1v (lime_image_data_util_unmultiply_alpha);
|
||||
DEFINE_PRIME3 (lime_image_encode);
|
||||
DEFINE_PRIME1 (lime_image_load);
|
||||
DEFINE_PRIME4 (lime_image_encode);
|
||||
DEFINE_PRIME2 (lime_image_load);
|
||||
DEFINE_PRIME0 (lime_jni_getenv);
|
||||
DEFINE_PRIME2v (lime_joystick_event_manager_register);
|
||||
DEFINE_PRIME1 (lime_joystick_get_device_guid);
|
||||
@@ -1727,12 +1727,12 @@ namespace lime {
|
||||
DEFINE_PRIME1 (lime_joystick_get_num_buttons);
|
||||
DEFINE_PRIME1 (lime_joystick_get_num_hats);
|
||||
DEFINE_PRIME1 (lime_joystick_get_num_trackballs);
|
||||
DEFINE_PRIME2 (lime_jpeg_decode_bytes);
|
||||
DEFINE_PRIME2 (lime_jpeg_decode_file);
|
||||
DEFINE_PRIME3 (lime_jpeg_decode_bytes);
|
||||
DEFINE_PRIME3 (lime_jpeg_decode_file);
|
||||
DEFINE_PRIME2v (lime_key_event_manager_register);
|
||||
DEFINE_PRIME0 (lime_locale_get_system_locale);
|
||||
DEFINE_PRIME1 (lime_lzma_compress);
|
||||
DEFINE_PRIME1 (lime_lzma_decompress);
|
||||
DEFINE_PRIME2 (lime_lzma_compress);
|
||||
DEFINE_PRIME2 (lime_lzma_decompress);
|
||||
DEFINE_PRIME2v (lime_mouse_event_manager_register);
|
||||
DEFINE_PRIME0v (lime_mouse_hide);
|
||||
DEFINE_PRIME1v (lime_mouse_set_cursor);
|
||||
@@ -1740,8 +1740,8 @@ namespace lime {
|
||||
DEFINE_PRIME0v (lime_mouse_show);
|
||||
DEFINE_PRIME3v (lime_mouse_warp);
|
||||
DEFINE_PRIME1v (lime_neko_execute);
|
||||
DEFINE_PRIME2 (lime_png_decode_bytes);
|
||||
DEFINE_PRIME2 (lime_png_decode_file);
|
||||
DEFINE_PRIME3 (lime_png_decode_bytes);
|
||||
DEFINE_PRIME3 (lime_png_decode_file);
|
||||
DEFINE_PRIME1 (lime_renderer_create);
|
||||
DEFINE_PRIME1v (lime_renderer_flip);
|
||||
DEFINE_PRIME1 (lime_renderer_get_context);
|
||||
@@ -1749,7 +1749,7 @@ namespace lime {
|
||||
DEFINE_PRIME1 (lime_renderer_get_type);
|
||||
DEFINE_PRIME1 (lime_renderer_lock);
|
||||
DEFINE_PRIME1v (lime_renderer_make_current);
|
||||
DEFINE_PRIME2 (lime_renderer_read_pixels);
|
||||
DEFINE_PRIME3 (lime_renderer_read_pixels);
|
||||
DEFINE_PRIME1v (lime_renderer_unlock);
|
||||
DEFINE_PRIME2v (lime_render_event_manager_register);
|
||||
DEFINE_PRIME2v (lime_sensor_event_manager_register);
|
||||
@@ -1790,8 +1790,8 @@ namespace lime {
|
||||
DEFINE_PRIME2 (lime_window_set_minimized);
|
||||
DEFINE_PRIME2 (lime_window_set_resizable);
|
||||
DEFINE_PRIME2 (lime_window_set_title);
|
||||
DEFINE_PRIME1 (lime_zlib_compress);
|
||||
DEFINE_PRIME1 (lime_zlib_decompress);
|
||||
DEFINE_PRIME2 (lime_zlib_compress);
|
||||
DEFINE_PRIME2 (lime_zlib_decompress);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace lime {
|
||||
|
||||
bitsPerSample = 0;
|
||||
channels = 0;
|
||||
data = new ArrayBufferView ();
|
||||
sampleRate = 0;
|
||||
mValue = 0;
|
||||
|
||||
@@ -37,14 +38,14 @@ namespace lime {
|
||||
|
||||
bitsPerSample = val_int (val_field (audioBuffer, id_bitsPerSample));
|
||||
channels = val_int (val_field (audioBuffer, id_channels));
|
||||
data.Set (val_field (audioBuffer, id_data));
|
||||
data = new ArrayBufferView (val_field (audioBuffer, id_data));
|
||||
sampleRate = val_int (val_field (audioBuffer, id_sampleRate));
|
||||
|
||||
} else {
|
||||
|
||||
bitsPerSample = 0;
|
||||
channels = 0;
|
||||
data.Clear ();
|
||||
data = new ArrayBufferView ();
|
||||
sampleRate = 0;
|
||||
|
||||
}
|
||||
@@ -56,6 +57,8 @@ namespace lime {
|
||||
|
||||
AudioBuffer::~AudioBuffer () {
|
||||
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +74,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
if (mValue == 0 || val_is_null (mValue)) {
|
||||
if (val_is_null (mValue)) {
|
||||
|
||||
mValue = alloc_empty_object ();
|
||||
|
||||
@@ -79,7 +82,7 @@ namespace lime {
|
||||
|
||||
alloc_field (mValue, id_bitsPerSample, alloc_int (bitsPerSample));
|
||||
alloc_field (mValue, id_channels, alloc_int (channels));
|
||||
alloc_field (mValue, id_data, data.Value ());
|
||||
alloc_field (mValue, id_data, data ? data->Value () : alloc_null ());
|
||||
alloc_field (mValue, id_sampleRate, alloc_int (sampleRate));
|
||||
return mValue;
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace lime {
|
||||
bool OGG::Decode (Resource *resource, AudioBuffer *audioBuffer) {
|
||||
|
||||
OggVorbis_File oggFile;
|
||||
Bytes data;
|
||||
Bytes *data = NULL;
|
||||
OAL_OggMemoryFile fakeFile;
|
||||
|
||||
if (resource->path) {
|
||||
@@ -132,15 +132,16 @@ namespace lime {
|
||||
} else {
|
||||
|
||||
lime::fclose (file);
|
||||
data.ReadFile (resource->path);
|
||||
data = new Bytes (resource->path);
|
||||
|
||||
fakeFile = OAL_OggMemoryFile ();
|
||||
fakeFile.data = data.Data ();
|
||||
fakeFile.size = data.Length ();
|
||||
fakeFile.data = data->Data ();
|
||||
fakeFile.size = data->Length ();
|
||||
fakeFile.pos = 0;
|
||||
|
||||
if (ov_open_callbacks (&fakeFile, &oggFile, NULL, 0, OAL_CALLBACKS_BUFFER) != 0) {
|
||||
|
||||
delete data;
|
||||
return false;
|
||||
|
||||
}
|
||||
@@ -181,6 +182,13 @@ namespace lime {
|
||||
|
||||
//LOG_SOUND("FAILED TO READ OGG SOUND INFO, IS THIS EVEN AN OGG FILE?\n");
|
||||
ov_clear (&oggFile);
|
||||
|
||||
if (data) {
|
||||
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
@@ -191,18 +199,18 @@ namespace lime {
|
||||
audioBuffer->bitsPerSample = 16;
|
||||
|
||||
int dataLength = ov_pcm_total (&oggFile, -1) * audioBuffer->channels * audioBuffer->bitsPerSample / 8;
|
||||
audioBuffer->data.Resize (dataLength);
|
||||
audioBuffer->data->Resize (dataLength);
|
||||
|
||||
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->Data () + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream);
|
||||
totalBytes += bytes;
|
||||
|
||||
}
|
||||
|
||||
if (dataLength != totalBytes) {
|
||||
|
||||
audioBuffer->data.Resize (totalBytes);
|
||||
audioBuffer->data->Resize (totalBytes);
|
||||
|
||||
}
|
||||
|
||||
@@ -210,6 +218,12 @@ namespace lime {
|
||||
|
||||
#undef BUFFER_READ_TYPE
|
||||
|
||||
if (data) {
|
||||
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@@ -125,9 +125,9 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
audioBuffer->data.Resize (wave_data.subChunkSize);
|
||||
audioBuffer->data->Resize (wave_data.subChunkSize);
|
||||
|
||||
if (!lime::fread (audioBuffer->data.Data (), 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);
|
||||
@@ -186,7 +186,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
audioBuffer->data.Resize (wave_data.subChunkSize);
|
||||
audioBuffer->data->Resize (wave_data.subChunkSize);
|
||||
|
||||
size_t size = wave_data.subChunkSize;
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
unsigned char* bytes = audioBuffer->data.Data ();
|
||||
unsigned char* bytes = audioBuffer->data->Data ();
|
||||
memcpy (bytes, base, size);
|
||||
|
||||
}
|
||||
|
||||
@@ -219,9 +219,9 @@ 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->Data (), buffer->Stride ());
|
||||
|
||||
for (unsigned char *it=buffer->data.Data () + 3; it < (buffer->data.Data () + buffer->data.Length ()); it += 4) {
|
||||
for (unsigned char *it=buffer->data->Data () + 3; it < (buffer->data->Data () + buffer->data->Length ()); it += 4) {
|
||||
|
||||
*it = 0xff;
|
||||
|
||||
|
||||
@@ -321,7 +321,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->Data (), imageBuffer->width, imageBuffer->height, imageBuffer->bitsPerPixel, imageBuffer->Stride (), 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
|
||||
if (surface) {
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace lime {
|
||||
|
||||
width = val_int (val_field (image, id_width));
|
||||
height = val_int (val_field (image, id_height));
|
||||
buffer.Set (val_field (image, id_buffer));
|
||||
buffer = new ImageBuffer (val_field (image, id_buffer));
|
||||
offsetX = val_int (val_field (image, id_offsetX));
|
||||
offsetY = val_int (val_field (image, id_offsetY));
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace lime {
|
||||
|
||||
Image::~Image () {
|
||||
|
||||
delete buffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,51 +30,6 @@ namespace lime {
|
||||
|
||||
ImageBuffer::ImageBuffer (value imageBuffer) {
|
||||
|
||||
Set (imageBuffer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ImageBuffer::~ImageBuffer () {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Blit (const unsigned char *data, int x, int y, int width, int height) {
|
||||
|
||||
if (x < 0 || x + width > this->width || y < 0 || y + height > this->height) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int stride = Stride ();
|
||||
unsigned char *bytes = this->data.buffer.Data ();
|
||||
|
||||
for (int i = 0; i < height; i++) {
|
||||
|
||||
memcpy (&bytes[(i + y) * this->width + x], &data[i * width], stride);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Resize (int width, int height, int bitsPerPixel) {
|
||||
|
||||
this->bitsPerPixel = bitsPerPixel;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
int stride = Stride ();
|
||||
|
||||
this->data.Resize (height * stride);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Set (value imageBuffer) {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_bitsPerPixel = val_id ("bitsPerPixel");
|
||||
@@ -96,7 +51,7 @@ namespace lime {
|
||||
format = (PixelFormat)val_int (val_field (imageBuffer, id_format));
|
||||
transparent = val_bool (val_field (imageBuffer, id_transparent));
|
||||
premultiplied = val_bool (val_field (imageBuffer, id_premultiplied));
|
||||
data.Set (val_field (imageBuffer, id_data));
|
||||
data = new ArrayBufferView (val_field (imageBuffer, id_data));
|
||||
|
||||
} else {
|
||||
|
||||
@@ -104,6 +59,7 @@ namespace lime {
|
||||
height = 0;
|
||||
bitsPerPixel = 32;
|
||||
format = RGBA32;
|
||||
data = 0;
|
||||
premultiplied = false;
|
||||
transparent = false;
|
||||
|
||||
@@ -114,6 +70,54 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
ImageBuffer::~ImageBuffer () {
|
||||
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Blit (const unsigned char *data, int x, int y, int width, int height) {
|
||||
|
||||
if (x < 0 || x + width > this->width || y < 0 || y + height > this->height) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int stride = Stride ();
|
||||
unsigned char *bytes = this->data->buffer->Data ();
|
||||
|
||||
for (int i = 0; i < height; i++) {
|
||||
|
||||
memcpy (&bytes[(i + y) * this->width + x], &data[i * width], stride);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Resize (int width, int height, int bitsPerPixel) {
|
||||
|
||||
this->bitsPerPixel = bitsPerPixel;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
int stride = Stride ();
|
||||
|
||||
if (!this->data) {
|
||||
|
||||
this->data = new ArrayBufferView (height * stride);
|
||||
|
||||
} else {
|
||||
|
||||
this->data->Resize (height * stride);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int ImageBuffer::Stride () {
|
||||
|
||||
return width * (((bitsPerPixel + 3) & ~0x3) >> 3);
|
||||
@@ -136,7 +140,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
if (mValue == 0 || val_is_null (mValue)) {
|
||||
if (val_is_null (mValue)) {
|
||||
|
||||
mValue = alloc_empty_object ();
|
||||
|
||||
@@ -145,7 +149,7 @@ namespace lime {
|
||||
alloc_field (mValue, id_width, alloc_int (width));
|
||||
alloc_field (mValue, id_height, alloc_int (height));
|
||||
alloc_field (mValue, id_bitsPerPixel, alloc_int (bitsPerPixel));
|
||||
alloc_field (mValue, id_data, data.Value ());
|
||||
alloc_field (mValue, id_data, data ? data->Value () : alloc_null ());
|
||||
alloc_field (mValue, id_transparent, alloc_bool (transparent));
|
||||
alloc_field (mValue, id_format, alloc_int (format));
|
||||
alloc_field (mValue, id_premultiplied, alloc_bool (premultiplied));
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace lime {
|
||||
jpegError.base.output_message = OnOutput;
|
||||
|
||||
FILE_HANDLE *file = NULL;
|
||||
Bytes data;
|
||||
Bytes *data = NULL;
|
||||
MySrcManager *manager = NULL;
|
||||
|
||||
if (resource->path) {
|
||||
@@ -220,6 +220,12 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
if (data) {
|
||||
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
jpeg_destroy_decompress (&cinfo);
|
||||
return false;
|
||||
|
||||
@@ -235,8 +241,8 @@ namespace lime {
|
||||
|
||||
} else {
|
||||
|
||||
data.ReadFile (resource->path);
|
||||
manager = new MySrcManager (data.Data (), data.Length ());
|
||||
data = new Bytes (resource->path);
|
||||
manager = new MySrcManager (data->Data (), data->Length ());
|
||||
cinfo.src = &manager->pub;
|
||||
|
||||
}
|
||||
@@ -260,7 +266,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->Data ();
|
||||
unsigned char *scanline = new unsigned char [imageBuffer->width * components];
|
||||
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
@@ -309,6 +315,12 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
if (data) {
|
||||
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
jpeg_destroy_decompress (&cinfo);
|
||||
return decoded;
|
||||
|
||||
@@ -351,7 +363,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->Data();
|
||||
int stride = imageBuffer->Stride ();
|
||||
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace lime {
|
||||
int bit_depth, color_type, interlace_type;
|
||||
|
||||
FILE_HANDLE *file = NULL;
|
||||
Bytes data;
|
||||
Bytes *data = NULL;
|
||||
|
||||
if (resource->path) {
|
||||
|
||||
@@ -144,8 +144,8 @@ namespace lime {
|
||||
|
||||
} else {
|
||||
|
||||
data.ReadFile (resource->path);
|
||||
ReadBuffer buffer (data.Data (), data.Length ());
|
||||
data = new Bytes (resource->path);
|
||||
ReadBuffer buffer (data->Data (), data->Length ());
|
||||
png_set_read_fn (png_ptr, &buffer, user_read_data_fn);
|
||||
|
||||
}
|
||||
@@ -185,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->Data ();
|
||||
|
||||
int number_of_passes = png_set_interlace_handling (png_ptr);
|
||||
|
||||
@@ -212,6 +212,7 @@ namespace lime {
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL);
|
||||
|
||||
if (file) lime::fclose (file);
|
||||
if (data) delete data;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -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->Data();
|
||||
int stride = imageBuffer->Stride ();
|
||||
|
||||
{
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace lime {
|
||||
|
||||
void ImageDataUtil::ColorTransform (Image* image, Rectangle* rect, ColorMatrix* colorMatrix) {
|
||||
|
||||
PixelFormat format = image->buffer.format;
|
||||
bool premultiplied = image->buffer.premultiplied;
|
||||
uint8_t* data = (uint8_t*)image->buffer.data.Data ();
|
||||
PixelFormat format = image->buffer->format;
|
||||
bool premultiplied = image->buffer->premultiplied;
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
|
||||
ImageDataView dataView = ImageDataView (image, rect);
|
||||
|
||||
@@ -51,17 +51,17 @@ 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->Data ();
|
||||
uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
|
||||
|
||||
ImageDataView srcView = ImageDataView (sourceImage, sourceRect);
|
||||
Rectangle destRect = Rectangle (destPoint->x, destPoint->y, srcView.width, srcView.height);
|
||||
ImageDataView destView = ImageDataView (image, &destRect);
|
||||
|
||||
PixelFormat srcFormat = sourceImage->buffer.format;
|
||||
PixelFormat destFormat = image->buffer.format;
|
||||
bool srcPremultiplied = sourceImage->buffer.premultiplied;
|
||||
bool destPremultiplied = image->buffer.premultiplied;
|
||||
PixelFormat srcFormat = sourceImage->buffer->format;
|
||||
PixelFormat destFormat = image->buffer->format;
|
||||
bool srcPremultiplied = sourceImage->buffer->premultiplied;
|
||||
bool destPremultiplied = image->buffer->premultiplied;
|
||||
|
||||
int srcPosition, destPosition;
|
||||
RGBA srcPixel, destPixel;
|
||||
@@ -109,22 +109,22 @@ 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->Data ();
|
||||
uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
|
||||
|
||||
ImageDataView sourceView = ImageDataView (sourceImage, sourceRect);
|
||||
Rectangle destRect = Rectangle (destPoint->x, destPoint->y, sourceView.width, sourceView.height);
|
||||
ImageDataView destView = ImageDataView (image, &destRect);
|
||||
|
||||
PixelFormat sourceFormat = sourceImage->buffer.format;
|
||||
PixelFormat destFormat = image->buffer.format;
|
||||
bool sourcePremultiplied = sourceImage->buffer.premultiplied;
|
||||
bool destPremultiplied = image->buffer.premultiplied;
|
||||
PixelFormat sourceFormat = sourceImage->buffer->format;
|
||||
PixelFormat destFormat = image->buffer->format;
|
||||
bool sourcePremultiplied = sourceImage->buffer->premultiplied;
|
||||
bool destPremultiplied = image->buffer->premultiplied;
|
||||
|
||||
int sourcePosition, destPosition;
|
||||
RGBA sourcePixel;
|
||||
|
||||
if (!mergeAlpha || !sourceImage->buffer.transparent) {
|
||||
if (!mergeAlpha || !sourceImage->buffer->transparent) {
|
||||
|
||||
for (int y = 0; y < destView.height; y++) {
|
||||
|
||||
@@ -189,9 +189,9 @@ namespace lime {
|
||||
|
||||
} else {
|
||||
|
||||
uint8_t* alphaData = (uint8_t*)alphaImage->buffer.data.Data ();
|
||||
PixelFormat alphaFormat = alphaImage->buffer.format;
|
||||
bool alphaPremultiplied = alphaImage->buffer.premultiplied;
|
||||
uint8_t* alphaData = (uint8_t*)alphaImage->buffer->data->Data ();
|
||||
PixelFormat alphaFormat = alphaImage->buffer->format;
|
||||
bool alphaPremultiplied = alphaImage->buffer->premultiplied;
|
||||
|
||||
Rectangle alphaRect = Rectangle (alphaPoint->x, alphaPoint->y, destView.width, destView.height);
|
||||
ImageDataView alphaView = ImageDataView (alphaImage, &alphaRect);
|
||||
@@ -246,9 +246,9 @@ namespace lime {
|
||||
|
||||
void ImageDataUtil::FillRect (Image* image, Rectangle* rect, int32_t color) {
|
||||
|
||||
uint8_t* data = (uint8_t*)image->buffer.data.Data ();
|
||||
PixelFormat format = image->buffer.format;
|
||||
bool premultiplied = image->buffer.premultiplied;
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
PixelFormat format = image->buffer->format;
|
||||
bool premultiplied = image->buffer->premultiplied;
|
||||
|
||||
ImageDataView dataView = ImageDataView (image, rect);
|
||||
int row;
|
||||
@@ -273,18 +273,18 @@ namespace lime {
|
||||
|
||||
void ImageDataUtil::FloodFill (Image* image, int x, int y, int32_t color) {
|
||||
|
||||
uint8_t* data = (uint8_t*)image->buffer.data.Data ();
|
||||
PixelFormat format = image->buffer.format;
|
||||
bool premultiplied = image->buffer.premultiplied;
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
PixelFormat format = image->buffer->format;
|
||||
bool premultiplied = image->buffer->premultiplied;
|
||||
|
||||
RGBA fillColor (color);
|
||||
|
||||
if (premultiplied) fillColor.MultiplyAlpha ();
|
||||
|
||||
RGBA hitColor;
|
||||
hitColor.ReadUInt8 (data, ((y + image->offsetY) * (image->buffer.width * 4)) + ((x + image->offsetX) * 4), format, premultiplied);
|
||||
hitColor.ReadUInt8 (data, ((y + image->offsetY) * (image->buffer->width * 4)) + ((x + image->offsetX) * 4), format, premultiplied);
|
||||
|
||||
if (!image->buffer.transparent) {
|
||||
if (!image->buffer->transparent) {
|
||||
|
||||
fillColor.a = 0xFF;
|
||||
hitColor.a = 0xFF;
|
||||
@@ -348,11 +348,11 @@ namespace lime {
|
||||
int length = int (rect->width * rect->height);
|
||||
pixels->Resize (length * 4);
|
||||
|
||||
uint8_t* data = (uint8_t*)image->buffer.data.Data ();
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
uint8_t* destData = (uint8_t*)pixels->Data ();
|
||||
|
||||
PixelFormat sourceFormat = image->buffer.format;
|
||||
bool premultiplied = image->buffer.premultiplied;
|
||||
PixelFormat sourceFormat = image->buffer->format;
|
||||
bool premultiplied = image->buffer->premultiplied;
|
||||
|
||||
ImageDataView dataView = ImageDataView (image, rect);
|
||||
int position, destPosition = 0;
|
||||
@@ -383,12 +383,12 @@ 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 ();
|
||||
PixelFormat sourceFormat = sourceImage->buffer.format;
|
||||
PixelFormat destFormat = image->buffer.format;
|
||||
bool sourcePremultiplied = sourceImage->buffer.premultiplied;
|
||||
bool destPremultiplied = image->buffer.premultiplied;
|
||||
uint8_t* sourceData = (uint8_t*)sourceImage->buffer->data->Data ();
|
||||
uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
|
||||
PixelFormat sourceFormat = sourceImage->buffer->format;
|
||||
PixelFormat destFormat = image->buffer->format;
|
||||
bool sourcePremultiplied = sourceImage->buffer->premultiplied;
|
||||
bool destPremultiplied = image->buffer->premultiplied;
|
||||
|
||||
int sourcePosition, destPosition;
|
||||
RGBA sourcePixel, destPixel;
|
||||
@@ -422,9 +422,9 @@ 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);
|
||||
PixelFormat format = image->buffer->format;
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
int length = int (image->buffer->data->Length () / 4);
|
||||
RGBA pixel;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
@@ -442,8 +442,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->Data ();
|
||||
uint8_t* newData = (uint8_t*)buffer->data->Data ();
|
||||
|
||||
int sourceIndex, sourceIndexX, sourceIndexY, sourceIndexXY, index;
|
||||
int sourceX, sourceY;
|
||||
@@ -497,11 +497,11 @@ namespace lime {
|
||||
void ImageDataUtil::SetFormat (Image* image, PixelFormat format) {
|
||||
|
||||
int index, a16;
|
||||
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;
|
||||
|
||||
switch (image->buffer.format) {
|
||||
switch (image->buffer->format) {
|
||||
|
||||
case RGBA32:
|
||||
|
||||
@@ -557,7 +557,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
unsigned char* data = image->buffer.data.Data ();
|
||||
unsigned char* data = image->buffer->data->Data ();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
@@ -580,9 +580,9 @@ namespace lime {
|
||||
|
||||
void ImageDataUtil::SetPixels (Image* image, Rectangle* rect, Bytes* bytes, PixelFormat format) {
|
||||
|
||||
uint8_t* data = (uint8_t*)image->buffer.data.Data ();
|
||||
PixelFormat sourceFormat = image->buffer.format;
|
||||
bool premultiplied = image->buffer.premultiplied;
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
PixelFormat sourceFormat = image->buffer->format;
|
||||
bool premultiplied = image->buffer->premultiplied;
|
||||
ImageDataView dataView = ImageDataView (image, rect);
|
||||
int row;
|
||||
RGBA pixel;
|
||||
@@ -590,7 +590,7 @@ namespace lime {
|
||||
uint8_t* byteArray = (uint8_t*)bytes->Data ();
|
||||
int srcPosition = 0;
|
||||
|
||||
bool transparent = image->buffer.transparent;
|
||||
bool transparent = image->buffer->transparent;
|
||||
|
||||
for (int y = 0; y < dataView.height; y++) {
|
||||
|
||||
@@ -672,17 +672,17 @@ 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->Data ();
|
||||
uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
|
||||
|
||||
ImageDataView srcView = ImageDataView (sourceImage, sourceRect);
|
||||
Rectangle destRect = Rectangle (destPoint->x, destPoint->y, srcView.width, srcView.height);
|
||||
ImageDataView destView = ImageDataView (image, &destRect);
|
||||
|
||||
PixelFormat srcFormat = sourceImage->buffer.format;
|
||||
PixelFormat destFormat = image->buffer.format;
|
||||
bool srcPremultiplied = sourceImage->buffer.premultiplied;
|
||||
bool destPremultiplied = image->buffer.premultiplied;
|
||||
PixelFormat srcFormat = sourceImage->buffer->format;
|
||||
PixelFormat destFormat = image->buffer->format;
|
||||
bool srcPremultiplied = sourceImage->buffer->premultiplied;
|
||||
bool destPremultiplied = image->buffer->premultiplied;
|
||||
|
||||
int srcPosition, destPosition, value;
|
||||
RGBA srcPixel, destPixel;
|
||||
@@ -738,9 +738,9 @@ 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);
|
||||
PixelFormat format = image->buffer->format;
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Data ();
|
||||
int length = int (image->buffer->data->Length () / 4);
|
||||
RGBA pixel;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
@@ -765,7 +765,7 @@ namespace lime {
|
||||
if (rect->height < 0) rect->height = 0;
|
||||
this->rect = rect;
|
||||
|
||||
stride = image->buffer.Stride ();
|
||||
stride = image->buffer->Stride ();
|
||||
|
||||
x = ceil (this->rect->x);
|
||||
y = ceil (this->rect->y);
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace lime {
|
||||
|
||||
ArrayBufferView::ArrayBufferView () {
|
||||
|
||||
buffer = new Bytes ();
|
||||
byteLength = 0;
|
||||
length = 0;
|
||||
mValue = 0;
|
||||
@@ -21,7 +22,7 @@ namespace lime {
|
||||
|
||||
ArrayBufferView::ArrayBufferView (int size) {
|
||||
|
||||
buffer.Resize (size);
|
||||
buffer = new Bytes (size);
|
||||
byteLength = size;
|
||||
length = size;
|
||||
mValue = 0;
|
||||
@@ -31,58 +32,6 @@ namespace lime {
|
||||
|
||||
ArrayBufferView::ArrayBufferView (value arrayBufferView) {
|
||||
|
||||
Set (arrayBufferView);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ArrayBufferView::~ArrayBufferView () {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ArrayBufferView::Clear () {
|
||||
|
||||
buffer.Clear ();
|
||||
byteLength = 0;
|
||||
length = 0;
|
||||
mValue = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
byteLength = size;
|
||||
length = size;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ArrayBufferView::Set (value arrayBufferView) {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_buffer = val_id ("buffer");
|
||||
@@ -94,13 +43,13 @@ namespace lime {
|
||||
|
||||
if (!val_is_null (arrayBufferView)) {
|
||||
|
||||
buffer.Set (val_field (arrayBufferView, id_buffer));
|
||||
buffer = new Bytes (val_field (arrayBufferView, id_buffer));
|
||||
byteLength = val_int (val_field (arrayBufferView, id_byteLength));
|
||||
length = val_int (val_field (arrayBufferView, id_length));
|
||||
|
||||
} else {
|
||||
|
||||
buffer.Clear ();
|
||||
buffer = new Bytes ();
|
||||
byteLength = 0;
|
||||
length = 0;
|
||||
|
||||
@@ -111,10 +60,56 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
ArrayBufferView::~ArrayBufferView () {
|
||||
|
||||
delete buffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
byteLength = size;
|
||||
length = size;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ArrayBufferView::Set (value bytes) {
|
||||
|
||||
buffer->Set (bytes);
|
||||
byteLength = buffer->Length ();
|
||||
length = byteLength;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ArrayBufferView::Set (const QuickVec<unsigned char> data) {
|
||||
|
||||
buffer.Set (data);
|
||||
byteLength = buffer.Length ();
|
||||
buffer->Set (data);
|
||||
byteLength = buffer->Length ();
|
||||
length = byteLength;
|
||||
|
||||
}
|
||||
@@ -131,13 +126,13 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
if (mValue == 0 || val_is_null (mValue)) {
|
||||
if (val_is_null (mValue)) {
|
||||
|
||||
mValue = alloc_empty_object ();
|
||||
|
||||
}
|
||||
|
||||
alloc_field (mValue, id_buffer, buffer.Value ());
|
||||
alloc_field (mValue, id_buffer, buffer ? buffer->Value () : alloc_null ());
|
||||
alloc_field (mValue, id_byteLength, alloc_int (byteLength));
|
||||
alloc_field (mValue, id_length, alloc_int (length));
|
||||
return mValue;
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace lime {
|
||||
|
||||
_data = 0;
|
||||
_length = 0;
|
||||
_root = 0;
|
||||
_value = 0;
|
||||
|
||||
}
|
||||
@@ -50,6 +51,7 @@ namespace lime {
|
||||
|
||||
_data = 0;
|
||||
_length = 0;
|
||||
_root = 0;
|
||||
_value = 0;
|
||||
|
||||
Resize (size);
|
||||
@@ -63,6 +65,7 @@ namespace lime {
|
||||
|
||||
_data = 0;
|
||||
_length = 0;
|
||||
_root = 0;
|
||||
_value = 0;
|
||||
|
||||
Set (bytes);
|
||||
@@ -76,6 +79,7 @@ namespace lime {
|
||||
|
||||
_data = 0;
|
||||
_length = 0;
|
||||
_root = 0;
|
||||
_value = 0;
|
||||
|
||||
ReadFile (path);
|
||||
@@ -89,6 +93,7 @@ namespace lime {
|
||||
|
||||
_data = 0;
|
||||
_length = 0;
|
||||
_root = 0;
|
||||
_value = 0;
|
||||
|
||||
Set (data);
|
||||
@@ -98,14 +103,11 @@ namespace lime {
|
||||
|
||||
Bytes::~Bytes () {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Bytes::Clear () {
|
||||
|
||||
_data = 0;
|
||||
_length = 0;
|
||||
_value = 0;
|
||||
if (_root) {
|
||||
|
||||
delete _root;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -164,6 +166,7 @@ namespace lime {
|
||||
if (!_value) {
|
||||
|
||||
_value = alloc_empty_object ();
|
||||
_root = new AutoGCRoot (_value);
|
||||
|
||||
}
|
||||
|
||||
@@ -222,9 +225,28 @@ namespace lime {
|
||||
_data = 0;
|
||||
_value = 0;
|
||||
|
||||
if (_root) {
|
||||
|
||||
delete _root;
|
||||
|
||||
}
|
||||
|
||||
_root = 0;
|
||||
|
||||
} else {
|
||||
|
||||
_value = bytes;
|
||||
|
||||
if (!_root) {
|
||||
|
||||
_root = new AutoGCRoot (_value);
|
||||
|
||||
} else {
|
||||
|
||||
_root->set (_value);
|
||||
|
||||
}
|
||||
|
||||
_length = val_int (val_field (bytes, id_length));
|
||||
|
||||
if (_length > 0) {
|
||||
@@ -266,6 +288,14 @@ namespace lime {
|
||||
_data = 0;
|
||||
_length = 0;
|
||||
|
||||
if (_root) {
|
||||
|
||||
delete _root;
|
||||
|
||||
}
|
||||
|
||||
_root = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user