我看過qtopia 的displayer的程式…
發現它的程式想法大概如下:
1.先宣告一個QImage *currentframe;
2.再利用的 currentframe 格式來建立一個framebuffer來儲存要顯示的畫面
3.建立framebuffer的目的…是為了做YUV->RGB
4.最後以
p->drawImage(x,y,*currentFrame,framewidth,frameheight);來顯示
我寫了一個小程式…
功能:在視窗下顯示黑白相間的畫面
想法:
1.先宣告一個QImage *currentframe;
2.再利用的 currentframe 格式來建立一個
h=288 w=352*4的framebuffer來儲存畫面
3.再以自行寫入framebuffer
4.最後以
print->drawImage(x,y,*currentFrame,framewidth,frameheight);來顯示
但是有錯誤…高手們能否幫我看看…我的code技巧有很大的錯誤…能否指教…
/////////////////////////////////framebuffer////////////////////////////
#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H
typedef unsigned char uchar;
class FrameBuffer {
public:
FrameBuffer();
~FrameBuffer();
void create( uchar *bits, int lineStep, int x, int y, int w, int h );
uchar **jumpTable();
int width();
int height();
private:
uchar **jt;
int x, y, w, h;
uchar *bits;
int lineStep;
};
#endif // FRAMEBUFFER_H
#include <qpixmap.h>
#include "framebuffer.h"
FrameBuffer::FrameBuffer() :x(0), y(0), w(0), h(0), bits(0), lineStep(0)
{
jt = new uchar*[1];
}
FrameBuffer::~FrameBuffer()
{
delete []jt;
delete []write_reg;
delete []read_reg;
delete []bits;
}
void FrameBuffer::create( uchar *b, int ls, int x1, int y1, int width, int height )
{
if ( bits == b && ls == lineStep && x == x1 && y == y1 && w == width && h == height )
return;
delete []jt;
jt = new uchar*[height];
x = x1;
y = y1;
bits = b;
lineStep = ls;
w = width;
h = height;
uchar *fp = bits + lineStep * y + QPixmap::defaultDepth() * x / 8;
for ( int i = 0; i < h; i++,fp += lineStep )
{
jt[i] = fp;
}
}
uchar **FrameBuffer::jumpTable()
{
return jt;
}
int FrameBuffer::width()
{
return w;
}
int FrameBuffer::height()
{
return h;
}
template<class T>
static inline void rotateLoopTemplate(
uchar *src, int srcBytesPerLine, uchar *dst, int dstBytesPerLine,
int width, int height, bool rotateDirection )
{
int dstXAdd = 0;
int dstYAdd = 0;
int dstXOfs = 0;
int dstYOfs = 0;
int srcYAdd = srcBytesPerLine - width * sizeof(T);
if ( rotateDirection ) {
dstXOfs = 0;
dstYOfs = width - 1;
dstXAdd = -dstBytesPerLine;
dstYAdd = 1 * sizeof(T) + width * dstBytesPerLine;
} else {
dstXOfs = height - 1;
dstYOfs = 0;
dstXAdd = dstBytesPerLine;
dstYAdd = -1 * sizeof(T) - width * dstBytesPerLine;
}
T *dstPtr = (T *)(dst + dstYOfs * dstBytesPerLine) + dstXOfs;
T *srcPtr = (T *)src;
for ( int y = 0; y < height; y++ ) {
for ( int x = 0; x < width; x++ ) {
*dstPtr = *srcPtr++;
dstPtr = (T *)((uchar*)dstPtr + dstXAdd); // add dstXAdd number of bytes
}
srcPtr = (T *)((uchar*)srcPtr + srcYAdd); // add srcYAdd number of bytes
dstPtr = (T *)((uchar*)dstPtr + dstYAdd); // add dstYAdd number of bytes
}
}
/////////////////////////////point.cpp//////////////////////////////////
#define framewidth 352
#define frameheight 288
#include <qimage.h>
#include <qwidget.h>
#include <qpainter.h>
#include <qprinter.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qapplication.h>
#include <math.h>
#include <qpixmap.h>
#include <qrect.h>
#include <stdio.h>
#include "framebuffer.h"
typedef unsigned char uchar;
class DrawView : public QWidget
{
Q_OBJECT
public:
DrawView();
~DrawView();
void write_buffer(uchar **temp_data);
QColor *col;
protected:
void paintEvent(QPaintEvent*event);
private:
QPrinter *printer;
QPrinter p;
FrameBuffer imageFB;
FrameBuffer *framebuffer;
FrameBuffer *tempbuffer;
QImage *currentFrame;
uchar **temp_data;
};
DrawView::DrawView()
{
setCaption( "Qt Draw Demo Application" );
setBackgroundColor( white );
printer =new QPrinter;
currentFrame=new QImage(framewidth,frameheight,(QPixmap::defaultDepth()==16)?16:32);
imageFB.create( currentFrame->bits(),currentFrame->bytesPerLine(), 0, 0, framewidth,frameheight);
}
DrawView::~DrawView()
{
delete currentFrame;
}
void DrawView::paintEvent(QPaintEvent*event)
{
write_buffer(framebuffer->jumpTable());
printer->drawImage(0,0,*currentFrame,framewidth,frameheight);
char a[10];
scanf("%s",a);
}
void DrawView::write_buffer(uchar **temp_data)
{
for(int i=0;i<288;i++)
{
for(int j=0;j<1408;j++)
{
if(i%2)
temp_data[i][j]=255;
else
temp_data[i][j]=0;
}
}
}
//==================================================
#include "point.moc"
int main( int argc, char **argv )
{
QApplication app( argc, argv );
DrawView draw;
app.setMainWidget( &draw );
draw.setCaption("Drawdemo");
draw.show();
return app.exec();
}
/////////////////////////////make訊息///////////////////////////////
point.cpp: In member function `DrawView::DrawView()':
point.cpp:56: warning: unused variable `FrameBuffer*framebuffer'
point.cpp: In member function `virtual void
DrawView::paintEvent(QPaintEvent*)':
point.cpp:68: no matching function for call to `QPrinter::drawImage(int, int,
QImage&, int, int)'
point.cpp:66: warning: unused parameter `QPaintEvent*event'
make: *** [point.o] Error 1
[ 此贴被XChinux在2005-09-08 21:18重新编辑 ]