예제 #1
0
IoObject *IoTokyoCabinetPrefixCursor_key(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor key
	Returns current cursor key or nil.
	*/
	
	int size;
	char *ks;
	
	IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix"));
	IOASSERT(ISSEQ(prefix), "prefix must be a sequence");
	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	ks = tcbdbcurkey(TokyoCabinetPrefixCursor(self), &size);

	if (ks)
	{
		UArray *k = UArray_newWithData_type_size_copy_(ks, CTYPE_uint8_t, size, 1);
	
		if (UArray_beginsWith_(k, IoSeq_rawUArray(prefix)))
		{
			//printf("prefix '%s'\n", UArray_bytes(IoSeq_rawUArray(prefix)));
			//printf("before clip '%s'\n", UArray_bytes(k));
			UArray_clipBeforeEndOf_(k, IoSeq_rawUArray(prefix));
			UArray_removeFirst(k); // remove separator
			//printf("after clip  '%s'\n", UArray_bytes(k));
			return IoSeq_newWithUArray_copy_(IOSTATE, k, 0);
		}

		UArray_free(k);
	}

	return IONIL(self);
}
예제 #2
0
파일: IoBox.c 프로젝트: ADTSH/io
IoObject *IoBox_containsPoint(IoBox *self, IoObject *locals, IoMessage *m)
{
	/*doc Box containsPoint(aPoint)
	Returns true if aPoint is within the receiver's bounds, false otherwise.
	*/

	int result;

	IoVector *otherPoint = IoMessage_locals_pointArgAt_(m, locals, 0);

	UArray *bo = IoSeq_rawUArray(IoBox_rawOrigin(self));
	UArray *bs = IoSeq_rawUArray(IoBox_rawSize(self));
	UArray *p  = IoSeq_rawUArray(otherPoint);

	// do a malloc since the vectors might be large

	UArray *b1 = UArray_clone(bo);
	UArray *b2 = UArray_clone(bs);

	// make bo2 the box endpoint

	UArray_add_(b2, b1);

	// ensure bo1 is on the left bottom and bo2 is on the top right

	UArray_Min(b1, b2);
	UArray_Max(b2, bo);

	result = UArray_greaterThanOrEqualTo_(p, b1) && UArray_greaterThanOrEqualTo_(b2, p);

	UArray_free(b1);
	UArray_free(b2);

	return IOBOOL(self, result);
}
예제 #3
0
파일: IoSocket.c 프로젝트: BMeph/io
IoObject *IoSocket_asyncStreamRead(IoSocket *self, IoObject *locals, IoMessage *m)
{
	/*doc Socket asyncStreamRead(aSeq, readSize) 
	Reads up to readSize number of bytes into aSeq if data is available. 
	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
	*/
	
	IoSeq *bufferSeq = IoMessage_locals_mutableSeqArgAt_(m, locals, 0);
	UArray *buffer = IoSeq_rawUArray(bufferSeq);
	size_t readSize = IoMessage_locals_intArgAt_(m, locals, 1);

	if (Socket_streamRead(SOCKET(self), buffer, readSize))
	{
		return self;
	}

	if (Socket_asyncFailed())
	{
		IoSocket_close(self, locals, m);
		return SOCKETERROR("Socket stream read failed");
	}

	//if (readSize == 0) //SocketErrorStatus() == 0)
	if (SocketErrorStatus() == 0)
	{
		// 0 bytes means the other end disconnected
		//printf("SocketErrorStatus() == 0, closing\n");
		IoSocket_close(self, locals, m);
	}
	
	return IONIL(self);
}
예제 #4
0
파일: IoFile.c 프로젝트: achoy/io
IO_METHOD(IoFile, contents)
{
	/*doc File contents
	Returns contents of the file as a mutable Sequence of bytes.
	*/

	UArray *ba = UArray_new();
	long result = -1;

	if (DATA(self)->stream == stdin)
	{
		result = UArray_readFromCStream_(ba, DATA(self)->stream);
	}
	else
	{
		result = UArray_readFromFilePath_(ba, IoSeq_rawUArray(DATA(self)->path));
	}

	if (result != -1)
	{
		return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
	}
	else
	{
		UArray_free(ba);
		IoState_error_(IOSTATE, m, "unable to read file '%s'", UTF8CSTRING(DATA(self)->path));
	}

	return IONIL(self);
}
예제 #5
0
파일: IoMP3Decoder.c 프로젝트: Akiyah/io
static enum mad_flow IoMP3Decoder_inputCallback(void *data, struct mad_stream *stream)
{
	IoMP3Decoder *self = data;
	struct mad_decoder *decoder = &(DATA(self)->decoder);
	
	IoMessage_locals_performOn_(DATA(self)->willProcessMessage, self, self);

	if (DATA(self)->isRunning)
	{
		UArray *ba = IoSeq_rawUArray(DATA(self)->inputBuffer);
		
		UArray_removeRange(ba, 0, DATA(self)->lastInputPos);
		
		{
			size_t size = UArray_size(ba);
			UArray_setSize_(ba, size + MAD_BUFFER_GUARD);
			memset(UArray_bytes(ba) + size, 0x0, MAD_BUFFER_GUARD);
			UArray_setSize_(ba, size);
		}
		
		if (UArray_size(ba) == 0) 
		{
			return MAD_FLOW_CONTINUE;
		}
		
		DATA(self)->lastInputPos = UArray_size(ba);
		
		mad_stream_buffer(stream, UArray_bytes(ba), UArray_size(ba));
	}
	
	return DATA(self)->isRunning ? MAD_FLOW_CONTINUE : MAD_FLOW_STOP;
}
예제 #6
0
파일: IoAudioMixer.c 프로젝트: ADTSH/io
IoAudioMixer *IoAudioMixer_rawClone(IoAudioMixer *proto) 
{ 
	IoObject *self = IoObject_rawClonePrimitive(proto);
	self->data = cpalloc(proto->data, sizeof(IoAudioMixerData));
	
	DATA(self)->ioBuffer = IoSeq_new(IOSTATE);
	DATA(self)->buffer = IoSeq_rawUArray(DATA(self)->ioBuffer);
	DATA(proto)->mixBuffer = UArray_new();
	DATA(self)->writeMessage = 
		IoMessage_newWithName_label_(IOSTATE, 
							    IOSYMBOL("write"), 
							    IOSYMBOL("AudioMixer"));
	IoMessage_setCachedArg_to_(DATA(self)->writeMessage, 0, DATA(self)->ioBuffer);
	
	DATA(self)->nonBlockingWriteMessage = 
		IoMessage_newWithName_label_(IOSTATE, 
							    IOSYMBOL("nonBlockingWrite"), 
							    IOSYMBOL("AudioMixer"));
	IoMessage_setCachedArg_to_(DATA(self)->nonBlockingWriteMessage, 0, DATA(self)->ioBuffer);
	
	DATA(self)->sounds = List_new();
	DATA(self)->soundsToRemove = List_new();
	DATA(self)->events = List_new();
	DATA(self)->activeEvents = List_new();
	DATA(self)->volume = DATA(self)->volume;
	
	DATA(self)->soundTouch = SoundTouch_init();
	SoundTouch_setSampleRate(DATA(self)->soundTouch, 44100);
	SoundTouch_setChannels(DATA(self)->soundTouch, 2);
	DATA(self)->tempo = 1.0;
	IoState_addValue_(IOSTATE, self);
	return self; 
}
예제 #7
0
파일: IoAsyncRequest.c 프로젝트: Akiyah/io
IoObject *IoAsyncRequest_write(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest write(fileOffset, aSeq, bufferOffset, numberOfBytesToWrite)
	Submits an async write request. Returns nil on error, self otherwise. 
	*/
	
	int r;
	IoSeq *data;
	UArray *ba;
	int bufferOffset;
	int bytesToWrite;

	IOCB(self)->aio_offset = (size_t)CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0));

	data = IoMessage_locals_seqArgAt_(m, locals, 1);
	ba = IoSeq_rawUArray(data);

	bufferOffset = IoMessage_locals_intArgAt_(m, locals, 2);
	bytesToWrite = IoMessage_locals_intArgAt_(m, locals, 3);

	if (bytesToWrite > UArray_size(ba) - bufferOffset)
	{
		bytesToWrite = UArray_size(ba) - bufferOffset;
	}

	IOCB(self)->aio_nbytes = bytesToWrite;
	IOCB(self)->aio_buf = realloc(IOCB_BUFFER(self), bytesToWrite);
	memcpy(IOCB_BUFFER(self), UArray_bytes(ba), bytesToWrite);

	r = aio_write(IOCB(self));

	return r == 0 ? self : IONIL(self);
}
예제 #8
0
IoObject *IoDirectory_itemForDirent_(IoDirectory *self, struct dirent *dp)
{
    IoSymbol *pathString;
    int isDir;
    UArray *path = IoSeq_rawUArray(DATA(self)->path);
    UArray *ba = UArray_clone(path);

    /*
    printf("IoDirectory_itemForDirent_ path = \"%s\" %i\n", p, path->itemSize);
    printf("IoDirectory_itemForDirent_ ba = \"%s\" %i\n", UArray_asCString(ba), ba->itemSize);
    */
    if (UArray_size(ba) && !IS_PATH_SEPERATOR(UArray_longAt_(ba, UArray_size(ba) - 1)))
    {
        UArray_appendCString_(ba, IO_PATH_SEPARATOR);
    }

    UArray_appendCString_(ba, dp->d_name);
    pathString = IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);

    isDir = isDirectory(dp, CSTRING(pathString));

    if (isDir)
    {
        return IoDirectory_newWithPath_(IOSTATE, pathString);
    }

    return IoFile_newWithPath_(IOSTATE, pathString);
}
예제 #9
0
파일: IoFile.c 프로젝트: achoy/io
IO_METHOD(IoFile, write)
{
	/*doc File write(aSequence1, aSequence2, ...)
	Writes the arguments to the receiver file. Returns self.
	*/

	int i;

	IoFile_assertOpen(self, locals, m);
	IoFile_assertWrite(self, locals, m);

	for (i = 0; i < IoMessage_argCount(m); i ++)
	{
		IoSymbol *string = IoMessage_locals_seqArgAt_(m, locals, i);
		UArray_writeToCStream_(IoSeq_rawUArray(string), DATA(self)->stream);

		if (ferror(DATA(self)->stream) != 0)
		{
			IoState_error_(IOSTATE, m, "error writing to file '%s'",
							UTF8CSTRING(DATA(self)->path));
		}
	}

	return self;
}
예제 #10
0
파일: IoSocket.c 프로젝트: BMeph/io
IoObject *IoSocket_asyncUdpRead(IoSocket *self, IoObject *locals, IoMessage *m)
{
	/*doc Socket asyncUdpRead(ipAddress, aSeq, readSize) 
	Reads up to readSize number of bytes from ipAddress into aSeq if data is available. 
	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
	*/
	
	IoObject *address = IoMessage_locals_addressArgAt_(m, locals, 0);
	UArray *buffer = IoSeq_rawUArray(IoMessage_locals_mutableSeqArgAt_(m, locals, 1));
	size_t readSize = IoMessage_locals_sizetArgAt_(m, locals, 2);
	
	if (Socket_udpRead(SOCKET(self), IoSocket_rawAddressFrom_(address), buffer, readSize))
	{
		return self;
	}
	else
	{
		if (Socket_asyncFailed())
		{
			return SOCKETERROR("Socket udp read failed");
		}
		else
		{
			return IONIL(self);
		}
	}
}
예제 #11
0
파일: IoImage.c 프로젝트: Alessandroo/io
IOIMAGE_API IoImage *IoImage_newWithImage_(void *state, Image* image)
{
	IoImage* self = IoImage_new(state);
	DATA(self)->image = image;
	DATA(self)->buffer = IoSeq_newWithData_length_(state, Image_data(image), Image_sizeInBytes(image));
	Image_setExternalUArray_(image, IoSeq_rawUArray(DATA(self)->buffer));
	return self;
}
예제 #12
0
IoSymbol *IoState_addSymbol_(IoState *self, IoSymbol *s)
{
	CHash_at_put_(self->symbols, IoSeq_rawUArray(s), s);
	IoObject_isSymbol_(s, 1);
	s->hash1 = RandomGen_randomInt(self->randomGen) | 0x1;
	s->hash2 = RandomGen_randomInt(self->randomGen) << 1;
	return s;
}
예제 #13
0
파일: IoImage.c 프로젝트: Alessandroo/io
IoImage *IoImage_rawClone(IoImage *proto)
{
	IoObject *self = IoObject_rawClonePrimitive(proto);
	IoObject_setDataPointer_(self, cpalloc(IoObject_dataPointer(proto), sizeof(IoImageData)));
	DATA(self)->buffer = IOCLONE(DATA(proto)->buffer);
	DATA(self)->image = Image_copyWithUArray_(DATA(proto)->image, IoSeq_rawUArray(DATA(self)->buffer));
	return self;
}
예제 #14
0
파일: IoMP3Decoder.c 프로젝트: Akiyah/io
static enum mad_flow IoMP3Decoder_outputCallback(void *data,
									    struct mad_header const *header,
									    struct mad_pcm *pcm)
{
	IoMP3Decoder *self = data;
	UArray *ba = IoSeq_rawUArray(DATA(self)->outputBuffer);
	unsigned int oldSize = UArray_size(ba);
	unsigned int newSize = oldSize + (pcm->length * 2 * sizeof(float));

	UArray_setSize_(ba, newSize);

	if (!DATA(self)->isRunning) 
	{
		return MAD_FLOW_STOP;
	}
	
	// MAD data is in 4 byte signed ints 
	// and on separated (not interleaved channels) 
	// so we interleave them here 
	
	{
		float *out = (float *)(UArray_bytes(ba) + oldSize);
		unsigned int nsamples  = pcm->length;
		
		mad_fixed_t const *left  = pcm->samples[0];
		mad_fixed_t const *right = pcm->samples[1];
		
		if (pcm->channels == 2)
		{
			// this would be much faster as a vector op
			while (nsamples --) 
			{
				*out = ((float)(*left)) / INT_MAX; 
				out ++; 
				*out = ((float)(*right)) / INT_MAX;
				out ++; 
				left ++;
				right ++;      
			}
		}
		else
		{
			while (nsamples --) 
			{
				float f = ((float)(*left)) / INT_MAX; 
				*out = f; 
				out ++; 
				*out = f;
				out ++; 
				left ++;
			}
		}		
	}
	
	IoMessage_locals_performOn_(DATA(self)->didProcessMessage, self, self);
	
	return DATA(self)->isRunning ? MAD_FLOW_CONTINUE : MAD_FLOW_STOP;
}
예제 #15
0
파일: IoLinker.c 프로젝트: ADTSH/io
IoObject *IoLinker_hexSeqToBytes(IoLinker *self, IoObject *locals, IoMessage *m)
{
/*doc Linker hexSeqToBytes(aSeq)
Returns a Sequence containing a binary representation of the hex data in aSeq. 
*/
	IoSeq *buffer = IoMessage_locals_seqArgAt_(m, locals, 0);
	UArray *ba = IoSeq_rawUArray(buffer);
	return IoSeq_newWithUArray_copy_(IOSTATE, UArray_fromHexStringUArray(ba), 0);
}
예제 #16
0
파일: IoNumber.c 프로젝트: Akiyah/io
IO_METHOD(IoNumber, asCharacter)
{
	/*doc Number asCharacter
	Returns a String containing a single character whose
	value is the value of the first byte of the receiver.
	Returns nil if the number has no valid UCS mapping.
	*/
	
	double d =DATA(self);
	long ld = d;
	
	if (d < 0 || d != ld)
	{
		return IONIL(self);
	}
	else
	{	
		uint32_t i = io_uint32InBigEndian((uint32_t)d);
		int bytes = countBytes(ld);
		IoSeq *s;
		
		if (bytes == 0) 
		{ 
			bytes = 1;
		}
		
		if (bytes == 3) 
		{ 
			bytes = 4;
		}
		
		if (bytes > 4) 
		{
			// no valid UCS encoding for this value
			return IONIL(self);
		}
		
		s = IoSeq_newWithData_length_(IOSTATE, (unsigned char *)&i, bytes);
		
		{
			UArray *u = IoSeq_rawUArray(s);
			int e = CENCODING_ASCII;
			
			switch (bytes)
			{
				case 1: e = CENCODING_ASCII; break;
				case 2: e = CENCODING_UCS2; break;
				case 4: e = CENCODING_UCS4; break;
			}
			
			UArray_setEncoding_(u, e);
		}
		
		return s;
	}
}
예제 #17
0
파일: IoLinker.c 프로젝트: ADTSH/io
IoObject *IoLinker_bytesToHexSeq(IoLinker *self, IoObject *locals, IoMessage *m)
{
/*doc Linker bytesToHexSeq(aSeq)
Returns a Sequence containing a hex representation of aSeq. 
*/
	
	IoSeq *buffer = IoMessage_locals_seqArgAt_(m, locals, 0);
	UArray *ba = IoSeq_rawUArray(buffer);
	return IoSeq_newWithUArray_copy_(IOSTATE, UArray_asNewHexStringUArray(ba), 0);
}
예제 #18
0
파일: IoBox.c 프로젝트: ADTSH/io
IoObject *IoBox_resizeBy(IoBox *self, IoObject *locals, IoMessage *m)
{
	IoSeq *d         = IoMessage_locals_pointArgAt_(m, locals, 0);
	int resizeWidth  = IoMessage_locals_intArgAt_(m, locals, 1);
	int resizeHeight = IoMessage_locals_intArgAt_(m, locals, 2);
	IoSeq *minSize   = IoMessage_locals_valueArgAt_(m, locals, 3);
	IoSeq *maxSize   = IoMessage_locals_valueArgAt_(m, locals, 4);

	UArray *mins = ISNIL(minSize) ? 0x0 : IoSeq_rawUArray(minSize);
	UArray *maxs = ISNIL(maxSize) ? 0x0 : IoSeq_rawUArray(maxSize);

	UArray *outd = IoBox_rawResizeBy(self,
	IoSeq_rawUArray(d),
	resizeWidth, resizeHeight,
	mins, maxs);

	IoSeq *out = IoSeq_newWithUArray_copy_(IOSTATE, outd, 0);

	return out;
}
예제 #19
0
파일: IoBox.c 프로젝트: ADTSH/io
UArray *IoBox_rawResizeBy(IoBox *self,
	UArray *d,
	int resizeWidth, int resizeHeight,
	UArray *minSize, UArray *maxSize)
{
	double x, w, y, h;
	UArray *position = IoSeq_rawUArray(IoBox_rawOrigin(self));
	UArray *size     = IoSeq_rawUArray(IoBox_rawSize(self));
	UArray *outd     = UArray_new();

	UArray_setItemType_(outd, CTYPE_float32_t);
	UArray_setSize_(outd, 2);

	x = resizeXFunc(resizeWidth, UArray_x(d), UArray_x(position));
	w = resizeWFunc(resizeWidth, UArray_x(d), UArray_x(size));

	y = resizeXFunc(resizeHeight, UArray_y(d), UArray_y(position));
	h = resizeWFunc(resizeHeight, UArray_y(d), UArray_y(size));

	if (minSize)
	{
		w = max(w, UArray_x(minSize));
		h = max(h, UArray_y(minSize));
	}

	if (maxSize)
	{
		w = min(w, UArray_x(maxSize));
		h = min(h, UArray_y(maxSize));
	}

	UArray_setXY(outd, w - UArray_x(size), h - UArray_y(size));
	UArray_setXY(position, x, y);
	UArray_setXY(size, w, h);

	UArray_round(position);
	UArray_round(size);

	return outd;
}
예제 #20
0
파일: IoFile.c 프로젝트: achoy/io
IO_METHOD(IoFile, readToBufferLength)
{
	/*doc File readToBufferLength(aBuffer, aNumber)
	Reads at most aNumber number of items and appends them to aBuffer.
	Returns number of items read.
	*/

	IoSeq *buffer = IoMessage_locals_mutableSeqArgAt_(m, locals, 0);
	size_t length = IoMessage_locals_longArgAt_(m, locals, 1);
	UArray *ba = IoSeq_rawUArray(buffer);
	size_t itemsRead = UArray_readNumberOfItems_fromCStream_(ba, length, DATA(self)->stream);
	return IONUMBER(itemsRead);
}
예제 #21
0
파일: IoODEBody.c 프로젝트: cdcarter/io
IoObject *IoODEBody_quaternion(IoODEBody *self, IoObject *locals, IoMessage *m)
{
	IoODEBody_assertValidBody(self, locals, m);
	{
		const dReal *q = dBodyGetQuaternion(BODYID);
		IoSeq *v = IoSeq_makeFloatArrayOfSize_(IOSTATE, 4);
		UArray *u = IoSeq_rawUArray(v);
		UArray_at_put_(u, 0, q[0]);
		UArray_at_put_(u, 1, q[1]);
		UArray_at_put_(u, 2, q[2]);
		UArray_at_put_(u, 3, q[3]);
		return v;
	}
}
예제 #22
0
IoObject *IoTokyoCabinetPrefixCursor_jump(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor jump(key)
	Move cursor to record before key. Returns self
	*/
	
	IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0);
	int result;
	UArray *p;
	
	IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix"));
	IOASSERT(ISSEQ(prefix), "prefix must be a sequence");

	p = UArray_clone(IoSeq_rawUArray(prefix));
	UArray_appendPath_(p, IoSeq_rawUArray(key));
	
	result = tcbdbcurjump(TokyoCabinetPrefixCursor(self), 
						  (const void *)UArray_bytes(p), 
						  (int)UArray_sizeInBytes(p));
	UArray_free(p);
	
	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	return IOBOOL(self, result);
}
예제 #23
0
int IoTokyoCabinetPrefixCursor_keyBeginsWithPrefix_(IoObject *self, IoSeq *prefix)
{	
	int size;
	char *value = tcbdbcurkey(TokyoCabinetPrefixCursor(self), &size);
	
	if(value)
	{
		UArray o = UArray_stackAllocedWithData_type_size_(value, CTYPE_uint8_t, size);
		UArray *p = IoSeq_rawUArray(prefix);
		
		return UArray_beginsWith_(&o, p);
	}
	
	return 0;
}
예제 #24
0
파일: IoFile.c 프로젝트: achoy/io
IoObject *IoFile_rawAsString(IoFile *self)
{
	UArray *ba = UArray_new();

	if (UArray_readFromFilePath_(ba, IoSeq_rawUArray(DATA(self)->path)) == 1)
	{
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}
	else
	{
		UArray_free(ba);
		IoState_error_(IOSTATE, NULL, "unable to read file '%s'", UTF8CSTRING(DATA(self)->path));
	}

	return IONIL(self);
}
예제 #25
0
파일: IoAsyncRequest.c 프로젝트: Akiyah/io
IoObject *IoAsyncRequest_copyBufferTo(IoAsyncRequest *self, IoObject *locals, IoMessage *m)
{
	/*doc AsyncRequest copyBufferto(aSeq)
	Copies the request buffer's data to aSeq.
	Returns nil on error or self otherwise.
	*/
	if (IOCB_BUFFER(self))
	{
		IoSeq *data = IoMessage_locals_mutableSeqArgAt_(m, locals, 0);
		UArray *ba = IoSeq_rawUArray(data);
		UArray_setData_type_size_copy_(ba, IOCB_BUFFER(self), CTYPE_uint8_t, IOCB(self)->aio_nbytes, 1);
		return self;
	}

	return IONIL(self);
}
예제 #26
0
파일: IoImage.c 프로젝트: Alessandroo/io
IOIMAGE_API IoObject *IoImage_filterWeightedMedian(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image filterWeightedMedian(filterSizeX, filterSizeY, filter)
	Returns new image as a result of applying filter.
	*/
	int filterSizeX = IoMessage_locals_intArgAt_(m, locals, 0);
	int filterSizeY = IoMessage_locals_intArgAt_(m, locals, 1);
	IoObject *ioFilter = IoMessage_locals_seqArgAt_(m, locals, 2);
	if(IoSeq_rawSize(ioFilter) < filterSizeX * filterSizeY)
	{
		IoState_error_(IOSTATE, m, "filter should be a Sequence with size >= filterSizeX * filterSizeY");
		return self;
	}
	UArray* filter = IoSeq_rawUArray(ioFilter);
	return IoImage_newWithImage_(IOSTATE, Image_applyWeightedMedianFilter(DATA(self)->image, filterSizeX, filterSizeY, filter));
}
예제 #27
0
파일: IoImage.c 프로젝트: Alessandroo/io
IoObject *IoImage_setDataWidthHeightComponentCount(IoImage *self, IoObject *locals, IoMessage *m)
{
	/*doc Image setDataWidthHeightComponentCount(aSequence, width, height, componentCount)
	Sets the image data and its parameters. Returns self.
	*/

	IoSeq *data = IoMessage_locals_seqArgAt_(m, locals, 0);
	int w = IoMessage_locals_intArgAt_(m, locals, 1);
	int h = IoMessage_locals_intArgAt_(m, locals, 2);
	int c = IoMessage_locals_intArgAt_(m, locals, 3);

	//printf("Image Image_setData_width_height_componentCount_\n");
	Image_setData_width_height_componentCount_(DATA(self)->image, IoSeq_rawUArray(data), w, h, c);
	//printf("Image returning self\n");
	return self;
}
예제 #28
0
파일: IoAudioDevice.c 프로젝트: Akiyah/io
IoObject *IoAudioDevice_asyncWrite(IoAudioDevice *self, IoObject *locals, IoMessage *m)
{
	/*doc AudioDevice asyncWrite(aBuffer)
	Writes aBuffer to the audio output buffer and returns immediately.
	*/

	IoSeq *buf = IoMessage_locals_seqArgAt_(m, locals, 0);

	if (IoSeq_rawSize(buf) == 0)
	{
		return self;
	}

	AudioDevice_checkForError(DATA(self)->audioDevice);
	AudioDevice_write_(DATA(self)->audioDevice, IoSeq_rawUArray(buf));
	return self;
}
예제 #29
0
파일: IoAudioDevice.c 프로젝트: Akiyah/io
IoObject *IoAudioDevice_read(IoAudioDevice *self, IoObject *locals, IoMessage *m)
{
	/*doc AudioDevice asyncRead
	Returns the audio read buffer.
	*/

	AudioDevice *device = DATA(self)->audioDevice;
	UArray *rba = IoSeq_rawUArray(DATA(self)->readBuffer);
	UArray *ba;

	while (device->locked)
	{
		AudioDevice_nanoSleep(device);
	}

	ba = AudioDevice_read(device);
	UArray_copy_(rba, ba);

	return DATA(self)->readBuffer;
}
예제 #30
0
파일: IoDate.c 프로젝트: bomma/io
IoDate *IoDate_fromSerialization(IoDate *self, IoObject *locals, IoMessage *m)
{
	/*doc Date fromSerialization
	Sets the date based on the serialization sequence.  Return self.
	*/
	
	IoSeq *serializationSeq = IoMessage_locals_seqArgAt_(m, locals, 0);
	UArray *serialization = UArray_clone(IoSeq_rawUArray(serializationSeq));
	
	UArray_setItemType_(serialization, CTYPE_int32_t);
	if(UArray_size(serialization) != 4)
	{
		IoState_error_(IOSTATE, self, "Expected a serialization sequence comprising 4 int32 items.");
	}
	
	Date_fromSerialization(DATA(self), serialization);
	
	UArray_free(serialization);
	
	return self;
}