[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Pixel Manipulation Very Slow?
From:       zhangmdev () gmail ! com
Date:       2010-08-24 19:26:01
Message-ID: 001636417a574897ff048e96bcca () google ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Also there is some experiment about how to get image data from PyQt to  
C/C++ via SIP. Must let the method receive void*

void Word::addColor(void *d)
{
unsigned char* bits = (unsigned char *)d;

for(int j=0; j< _img_h; j++) {
for(int i=0; i< _img_w; i++) {

_color[(j*_img_w+i)*4] = *bits/255.f;//Blue
bits++;
_color[(j*_img_w+i)*4+1] = *bits/255.f;//Green
bits++;
_color[(j*_img_w+i)*4+2] = *bits/255.f;//Red
bits++;
_color[(j*_img_w+i)*4+3] = *bits/255.f;//Alpha
bits++;

}
}
}

I convert the unsigned char array into a float array. In python

self.a.addColor(image.bits());

Seems it is working.

zhang

On Aug 25, 2010 2:06am, zhangmdev@gmail.com wrote:
> Hi,

> I tried SIP to do the pixel manipulation in C/C++. Word is the class I  
> adopted from SIP hello world example. Must have a method return void*

> void *Word::display()
> {
> for(int j=0; j for(int i=0; i _data[(j*w+i)*4] = 127;//Blue
> _data[(j*w+i)*4+1] = 127;//Green
> _data[(j*w+i)*4+2] = 255*_red;//Red
> _data[(j*w+i)*4+3] = 0;//Alpha

> }
> }
> return _data;
> }

> actually it returns char* _data, the pixels. I found the order of color  
> is a bit interesting, first the Blue, second is Green, third is Red, then  
> Alpha. The pointer will be sip.voidptr In python, I think.

> image = QImage(self.a.display() , w, h, QtGui.QImage.Format_RGB32)
> painter.drawImage(0, 0, image)

> Now the speed is quite interactive.

> zhang

[Attachment #5 (text/html)]

Also there is some experiment about how to get image data from PyQt to C/C++ via SIP. \
Must let the method receive void*<br /><br />void Word::addColor(void *d)<br />{<br \
/>	unsigned char* bits = (unsigned char *)d;<br /><br />	for(int j=0; j&lt; _img_h; \
j++) {<br />		for(int i=0; i&lt; _img_w; i++) {<br />			<br \
/>			_color[(j*_img_w+i)*4] = *bits/255.f;//Blue<br />			bits++;<br \
/>			_color[(j*_img_w+i)*4+1] = *bits/255.f;//Green<br />			bits++;<br \
/>			_color[(j*_img_w+i)*4+2] = *bits/255.f;//Red<br />			bits++;<br \
/>			_color[(j*_img_w+i)*4+3] = *bits/255.f;//Alpha<br />			bits++;<br />			<br \
/>		}<br />	}<br />}<br /><br />I convert the unsigned char array into a float array. \
In python<br /><br />self.a.addColor(image.bits());<br /><br />Seems it is \
working.<br /><br />zhang <br /><br />On Aug 25, 2010 2:06am, zhangmdev@gmail.com \
wrote:<br />&gt; Hi,<br />&gt; <br />&gt; I tried SIP to do the pixel manipulation in \
C/C++. Word is the class I adopted from SIP hello world example. Must have a method \
return void*<br />&gt; <br />&gt; void *Word::display()<br />&gt; {<br />&gt; \
for(int j=0; j 		for(int i=0; i 			_data[(j*w+i)*4] = 127;//Blue<br />&gt; \
_data[(j*w+i)*4+1] = 127;//Green<br />&gt; 			_data[(j*w+i)*4+2] = 255*_red;//Red<br \
/>&gt; 			_data[(j*w+i)*4+3] = 0;//Alpha<br />&gt; 			<br />&gt; 		}<br />&gt; 	}<br \
/>&gt; 	return _data;<br />&gt; }<br />&gt; <br />&gt; actually it returns char* \
_data, the pixels. I found the order of color is a bit interesting, first the Blue, \
second is Green, third is Red, then Alpha. The pointer will be sip.voidptr In python, \
I think.<br />&gt; <br />&gt; image = QImage(self.a.display() , w, h, \
QtGui.QImage.Format_RGB32)<br />&gt; painter.drawImage(0, 0, image)<br />&gt; <br \
/>&gt; Now the speed is quite interactive. <br />&gt; <br />&gt; zhang



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic