[Kde-bindings] KDE/kdebindings/ruby/qtruby

Davor Ocelic docelic at spinlocksolutions.com
Fri Dec 12 14:32:19 UTC 2008


On Wed, Dec 10, 2008 at 12:46:23PM +0000, Richard Dale wrote:
> SVN commit 895236 by rdale:
> 
> 	* Special case the Qt::Image.bits() method. Use the const variant so that
> 	  Qt doesn't make a deep copy. Is that what Davor Ocelic and David Palacio
> 	  would like it to do?

Hello,

The change to bits() is useful in itself, but what I meant was something
a bit different.

We create a QImage using data stored in a narray.

- When uchar* function is preferred over const uchar*, it is possible to
change the narray data both using array[]= and through image.setPixel().

- But when const uchar* is preferred (like it is now in svn), Qt makes a copy
of the data before setPixel and the association between array and image
is lost.

Here's an example that works if uchar* is preferred and Narray is
patched to support function that exports raw data as string:


require 'Qt4'
require 'narray'
size= 100

a= NArray.int size, size

# buffer() exports narray's data as str
i= Qt::Image.new a.buffer, size, size, Qt::Image::Format_ARGB32

# then you can manipulate Image data through NArray:
a[]=-55
i.pixel 0,0 #-> 4294967241
[-55].pack('l').unpack('L') #-> [4294967241]

# and also through QImage, IF uchar* Qt::Image constructor is preferred
# over const uchar*:
i.setPixel 0,0, 90
a[0,0]  #-> 90


The simple patch that prefers uchar* over const uchar* is 
as follows:


--- ./ruby/qtruby/src/lib/Qt/qtruby4.rb 2008-12-12 15:18:58.000000000 +0100
+++ ./ruby/qtruby/src/lib/Qt/qtruby4.rb,p       2008-12-12 15:18:38.000000000 +0100
@@ -2447,9 +2447,9 @@
                                if typename =~ /^(const )?((QChar)[*&]?)$/
                                        return 3
                                elsif typename =~ /^(?:u?char\*)$/
-                                       return 1
-                               elsif typename =~ /^(?:const u?char\*)$/
                                        return 2
+                               elsif typename =~ /^(?:const u?char\*)$/
+                                       return 1
                                elsif typename =~ /^(?:(?:const )?(QString)[*&]?)$/
                                        return 4
                                end



Rgds,
-doc




More information about the Kde-bindings mailing list