1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include <QtGui>
#include <limits>
struct FxdHeader
{
qint32 FileMagic; // 4 bytes that identiy the file format
qint32 NbColumns; // number of columns in the image
qint32 NbRows; // number of rows in the image
qint32 NbFrames; // number of frames in the image
qint32 PixelType; // type of the pixel in the file (one of the IMG_STORAGE_* constant)
qint32 QuantLevels; // number of quantization levels
float MaxSignalLevel; // maximum value in the image
float MinSignalLevel; // minimum value in the image
qint32 CommentLength; // length of the comment len
char Reserved[92]; // reserved data to make the header size to 128 bytes
} ;
const unsigned int fxHeaderSize = 128;
#include "main.moc"
int main(int argc, char **argv) {
QApplication app(argc, argv);
QFile fin("C:/Documents and Settings/VY/Bureau/Image_float/Image_float.fxd");
fin.open(QIODevice::ReadOnly);
FxdHeader fxd;
QDataStream in(&fin);//Lecture des donnees contenues dans le fichier.
in.setByteOrder(QDataStream::LittleEndian) ;
//lecture de l'entête
in >> fxd.FileMagic
>> fxd.NbColumns
>> fxd.NbRows
>> fxd.NbFrames
>> fxd.PixelType
>> fxd.QuantLevels
>> fxd.MaxSignalLevel
>> fxd.MinSignalLevel
>> fxd.CommentLength;
//position debut d'image
fin.seek(fxHeaderSize + fxd.CommentLength) ;
//lecture de l'image dans un buffer temporaire
//recherche du min max
unsigned int bufferSize = fxd.NbColumns * fxd.NbRows;
float min = std::numeric_limits<float>::max();;
float max = - std::numeric_limits<float>::max();
std::vector<float> imageBuffer(bufferSize);
for ( int i = 0; i < bufferSize; ++i)
{
float f;
in >> f;
if (f >max) max = f;
if (f <min) min = f;
imageBuffer[i] =f;
}
//convertion vers une QImage
QImage img(fxd.NbColumns , fxd.NbRows,QImage::Format_RGB32);
for (int y = 0; y < fxd.NbRows; y++)
for (int x = 0; x < fxd.NbColumns; x++)
{
//simple règle de trois
unsigned char pixel = 255
*
(imageBuffer[y*fxd.NbColumns + x] - min)
/
(max - min);
img.setPixel(x , y , qRgb( pixel , pixel, pixel ));
}
//affiche de l'image
QScrollArea w;
{
QLabel *label = new QLabel(&w);
label->setPixmap(QPixmap::fromImage(img).scaled(800,600,Qt::KeepAspectRatio));
w.setWidget(label);
}
w.show();
return app.exec();
} |