コード例 #1
0
ファイル: OpenALBindings.cpp プロジェクト: Leander1P/lime
	void lime_al_buffer_data (int buffer, int format, value data, int size, int freq) {
		
		Bytes bytes;
		bytes.Set (data);
		alBufferData (buffer, format, bytes.Data (), size, freq);
		
	}
コード例 #2
0
ファイル: ExternalInterface.cpp プロジェクト: Rezmason/lime
	value lime_bytes_from_data_pointer (double data, int length) {
		
		intptr_t ptr = (intptr_t)data;
		Bytes bytes = Bytes (length);
		
		if (ptr) {
			
			memcpy (bytes.Data (), (const void*)ptr, length);
			
		}
		
		return bytes.Value ();
		
	}
コード例 #3
0
ファイル: ExternalInterface.cpp プロジェクト: jarnik/lime
	value lime_bytes_from_data_pointer (value data, value length) {
		
		int size = val_int (length);
		intptr_t ptr = (intptr_t)val_float (data);
		Bytes bytes = Bytes (size);
		
		if (ptr) {
			
			memcpy (bytes.Data (), (const void*)ptr, size);
			
		}
		
		return bytes.Value ();
		
	}
コード例 #4
0
ファイル: CairoBindings.cpp プロジェクト: vroad/lime
	value lime_cairo_image_surface_create_for_data (value inData, int format, int width, int height, int stride) {
		
		Bytes *data = new Bytes (inData);
		cairo_surface_t *surface = cairo_image_surface_create_for_data (data->Data (), (cairo_format_t)format, width, height, stride);
		
		if (!surface) {
			
			delete data;
			return alloc_null ();
			
		}
		
		data->Pin ();
		cairo_surface_set_user_data (surface, &userData, data, gc_bytes);
		
		return CFFIPointer (surface, gc_cairo_surface);
		
	}
コード例 #5
0
ファイル: ExternalInterface.cpp プロジェクト: jarnik/lime
	value lime_bytes_get_data_pointer (value bytes) {
		
		Bytes data = Bytes (bytes);
		return alloc_float ((intptr_t)data.Data ());
		
	}
コード例 #6
0
ファイル: OGG.cpp プロジェクト: Gemioli/lime
	bool OGG::Decode (Resource *resource, AudioBuffer *audioBuffer) {
		
		OggVorbis_File oggFile;
		Bytes *data = NULL;
		OAL_OggMemoryFile fakeFile;
		
		if (resource->path) {
			
			FILE_HANDLE *file = lime::fopen (resource->path, "rb");
			
			if (!file) {
				
				return false;
				
			}
			
			if (file->isFile ()) {
				
				if (ov_open (file->getFile (), &oggFile, NULL, file->getLength ()) != 0) {
					
					lime::fclose (file);
					return false;
					
				}
				
			} else {
				
				lime::fclose (file);
				data = new Bytes (resource->path);
				
				fakeFile = OAL_OggMemoryFile ();
				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;
					
				}
				
			}
			
		} else {
			
			fakeFile = OAL_OggMemoryFile ();
			fakeFile.data = resource->data->Data ();
			fakeFile.size = resource->data->Length ();
			fakeFile.pos = 0;
			
			if (ov_open_callbacks (&fakeFile, &oggFile, NULL, 0, OAL_CALLBACKS_BUFFER) != 0) {
				
				return false;
				
			}
			
		}
		
		// 0 for Little-Endian, 1 for Big-Endian
		#ifdef HXCPP_BIG_ENDIAN
		#define BUFFER_READ_TYPE 1
		#else
		#define BUFFER_READ_TYPE 0
		#endif
		
		int bitStream;
		long bytes = 1;
		int totalBytes = 0;
		
		#define BUFFER_SIZE 4096
		
		vorbis_info *pInfo = ov_info (&oggFile, -1);
		
		if (pInfo == NULL) {
			
			//LOG_SOUND("FAILED TO READ OGG SOUND INFO, IS THIS EVEN AN OGG FILE?\n");
			ov_clear (&oggFile);
			
			if (data) {
				
				delete data;
				
			}
			
			return false;
			
		}
		
		audioBuffer->channels = pInfo->channels;
		audioBuffer->sampleRate = pInfo->rate;
		
		audioBuffer->bitsPerSample = 16;
		
		int dataLength = ov_pcm_total (&oggFile, -1) * audioBuffer->channels * audioBuffer->bitsPerSample / 8;
		audioBuffer->data->Resize (dataLength);
		
		while (bytes > 0) {
			
			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);
			
		}
		
		ov_clear (&oggFile);
		
		#undef BUFFER_READ_TYPE
		
		if (data) {
			
			delete data;
			
		}
		
		return true;
		
	}
コード例 #7
0
ファイル: JPEG.cpp プロジェクト: pshtif/lime
	bool JPEG::Decode (Resource *resource, ImageBuffer* imageBuffer, bool decodeData) {
		
		struct jpeg_decompress_struct cinfo;
		
		//struct jpeg_error_mgr jerr;
		//cinfo.err = jpeg_std_error (&jerr);
		
		struct ErrorData jpegError;
		cinfo.err = jpeg_std_error (&jpegError.base);
		jpegError.base.error_exit = OnError;
		jpegError.base.output_message = OnOutput;
		
		FILE_HANDLE *file = NULL;
		
		if (resource->path) {
			
			file = lime::fopen (resource->path, "rb");
			
			if (!file) {
				
				return false;
				
			}
			
		}
		
		if (setjmp (jpegError.on_error)) {
			
			if (file) {
				
				lime::fclose (file);
				
			}
			
			jpeg_destroy_decompress (&cinfo);
			return false;
			
		}
		
		jpeg_create_decompress (&cinfo);
		
		if (file) {
			
			if (file->isFile ()) {
				
				jpeg_stdio_src (&cinfo, file->getFile ());
				
			} else {
				
				Bytes data = Bytes (resource->path);
				MySrcManager manager (data.Data (), data.Length ());
				cinfo.src = &manager.pub;
				
			}
			
		} else {
			
			MySrcManager manager (resource->data->Data (), resource->data->Length ());
			cinfo.src = &manager.pub;
			
		}
		
		bool decoded = false;
		
		if (jpeg_read_header (&cinfo, TRUE) == JPEG_HEADER_OK) {
			
			cinfo.out_color_space = JCS_RGB;
			
			if (decodeData) {
				
				jpeg_start_decompress (&cinfo);
				int components = cinfo.output_components;
				imageBuffer->Resize (cinfo.output_width, cinfo.output_height, 32);
				
				unsigned char *bytes = imageBuffer->data->Data ();
				unsigned char *scanline = new unsigned char [imageBuffer->width * imageBuffer->height * components];
				
				while (cinfo.output_scanline < cinfo.output_height) {
					
					jpeg_read_scanlines (&cinfo, &scanline, 1);
					
					// convert 24-bit scanline to 32-bit
					const unsigned char *line = scanline;
					const unsigned char *const end = line + imageBuffer->width * components;
					
					while (line != end) {
						
						*bytes++ = *line++;
						*bytes++ = *line++;
						*bytes++ = *line++;
						*bytes++ = 0xFF;
						
					}
					
				}
				
				delete[] scanline;
				
				jpeg_finish_decompress (&cinfo);
				
			} else {
				
				imageBuffer->width = cinfo.image_width;
				imageBuffer->height = cinfo.image_height;
				
			}
			
			decoded = true;
			
		}
		
		if (file) {
			
			lime::fclose (file);
			
		}
		
		jpeg_destroy_decompress (&cinfo);
		return decoded;
		
	}
コード例 #8
0
ファイル: ExternalInterface.cpp プロジェクト: Rezmason/lime
	double lime_bytes_get_data_pointer (value bytes) {
		
		Bytes data = Bytes (bytes);
		return (intptr_t)data.Data ();
		
	}