-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagewrapper.cpp
65 lines (57 loc) · 1.59 KB
/
imagewrapper.cpp
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
#include "imagewrapper.h"
#include <QImage>
#include <QImageReader>
#include <QDebug>
#include "toolkit.h"
ImageWrapper::ImageWrapper(): Cache(), imageFrames(0), formatFlag(REGULAR_FLAG)
, header(NULL){
}
ImageWrapper::~ImageWrapper(){
}
void ImageWrapper::load(const QString& filePath, bool preReading){
if(filePath.isEmpty())
return;
attributes = QString::null;
formatFlag = REGULAR_FLAG;
QImageReader reader(imagePath);
reader.setDecideFormatFromContent(true);
imageFormat = reader.format();
imageFrames = reader.imageCount();
qDebug("format is %s, filename is %s", qPrintable(imageFormat),
qPrintable(ToolKit::fileName(filePath)));
if(formatFlag == REGULAR_FLAG){
if(imageFormat == "ico"){
reader.read(&image);
int maxIndex = 0;
int maxWidth = image.width();
for(int i=1; i < imageFrames; ++i){
if(!reader.jumpToNextImage())
break;
reader.read(&image);
if(maxWidth < image.width())
maxWidth = image.width();
maxIndex = i;
}
reader.jumpToImage(maxIndex);
}
}
if(!reader.read(&image)){
image = QImage();
}
if(image.isNull()){
imageFormat = "";
imageFrames = 0;
}
isReady = true;
}
QString ImageWrapper::attibute(){
return attributes;
}
QImage ImageWrapper::currentImage(){
return image;
}
void ImageWrapper::readHeader(const QString& filePath){
if(filePath.isEmpty())
return;
imagePath = filePath;
}