[Fxruby-commits] CVS: FXRuby/swig-interfaces FXMemoryBuffer.i,NONE,1.1.2.1 FXImage.i,1.15.2.1,1.15.2
Status: Inactive
Brought to you by:
lyle
From: Lyle J. <ly...@us...> - 2002-05-08 16:45:12
|
Update of /cvsroot/fxruby/FXRuby/swig-interfaces In directory usw-pr-cvs1:/tmp/cvs-serv5170/swig-interfaces Modified Files: Tag: release10 FXImage.i Added Files: Tag: release10 FXMemoryBuffer.i Log Message: Modified the interface to FXImage#data so that it returns an FXMemoryBuffer instance instead of a string (See SF Bug #550996). The primary difference is that FXMemoryBuffer wraps the actual data pointer stored by the FXImage instead of making a copy; this way you should be able to modify the buffer and re-render the image as you can in C++. --- NEW FILE: FXMemoryBuffer.i --- /*********************************************************************** * FXRuby -- the Ruby language bindings for the FOX GUI toolkit. * Copyright (c) 2001 by J. Lyle Johnson. All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For further information please contact the author by e-mail * at "ly...@us...". ***********************************************************************/ /*********************************************************************** * $Id: FXMemoryBuffer.i,v 1.1.2.1 2002/05/08 16:45:09 lyle Exp $ ***********************************************************************/ class FXMemoryBuffer { public: // Create an memory buffer object FXMemoryBuffer(FXuchar *data,FXuint size); // Returns a pointer to the data FXuchar* getData() const; // Returns the size (in bytes) FXuint getSize() const; %extend { // Indexed access FXuchar __getitem__(FXuint i) const { return self->getData()[i]; } void __setitem__(FXuint i,FXuchar value){ self->getData()[i] = value; } // Convert it to a Ruby string VALUE to_s() const { if(self->getSize()>0){ const char *str=const_cast<const char*>(reinterpret_cast<char*>(self->getData())); long len=static_cast<long>(self->getSize()); return rb_str_new(str,len); } else{ return rb_str_new2(""); } } } // Destructor ~FXMemoryBuffer(); }; Index: FXImage.i =================================================================== RCS file: /cvsroot/fxruby/FXRuby/swig-interfaces/FXImage.i,v retrieving revision 1.15.2.1 retrieving revision 1.15.2.2 diff -C2 -d -r1.15.2.1 -r1.15.2.2 *** FXImage.i 6 May 2002 19:16:29 -0000 1.15.2.1 --- FXImage.i 8 May 2002 16:45:09 -0000 1.15.2.2 *************** *** 74,89 **** /// To get to the pixel data %extend { ! VALUE getData() const { ! FXuchar* data=self->getData(); ! if(data){ ! FXuint options=self->getOptions(); ! FXuint channels=3; ! if(options&IMAGE_ALPHA) channels=4; ! long len=3*channels*self->getWidth()*self->getHeight(); ! return rb_str_new((const char*)data,len); ! } ! else{ ! return Qnil; ! } } } --- 74,79 ---- /// To get to the pixel data %extend { ! FXMemoryBuffer *getData() const { ! return new FXMemoryBuffer(self->getData(),self->getChannels()*self->getWidth()*self->getHeight()); } } |