-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransimagergb.cpp
More file actions
114 lines (95 loc) · 2.92 KB
/
transimagergb.cpp
File metadata and controls
114 lines (95 loc) · 2.92 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "transimagergb.h"
#include <QImageReader>
#include <QImageWriter>
#include <QImage>
#include <QColor>
#include <QMatrix>
#include <QDebug>
using namespace TransImageRGB;
bool TransImageRGB::transImage(std::string target, std::string path, int width, int height,int rotate)
{
QImageReader ir(target.data());
auto oriImg = ir.read();
QImage srcImage;
QImage saveImage(width, height, QImage::Format_RGB32);
qDebug() << "trans start";
if(rotate){
QPoint center = oriImg.rect().center();
QMatrix matrix;
matrix.translate(center.x(), center.y());
matrix.rotate(rotate);
srcImage = oriImg.transformed(matrix);
}else{
srcImage = oriImg;
}
for(int y = 0; y < srcImage.height(); y++){
int x = 0;
for(int i = 0; i < srcImage.width();i+=3){
int transRed = 0;
int transGreen = 0;
int transBlue = 0;
for(int j = 0; j < 3; j++){
if(i + j > srcImage.width()){
break;
}
auto col = srcImage.pixelColor(i + j,y);
int total = col.red();
if(j == 0){
transRed = total;
}else if(j == 1){
transGreen = total;
}else{
transBlue = total;
}
}
saveImage.setPixel(x++,y,QColor(transRed,transGreen,transBlue).rgb());
}
}
QImageWriter iw(path.data());
iw.write(saveImage);
qDebug() << "trans finish";
return true;
}
std::optional<QImage> TransImageRGB::L10transImage(std::string target)
{
std::optional<QImage> img;
img.emplace(540, 2560, QImage::Format_RGB32);
QImageReader ir(target.data());
if(!ir.canRead()){
return img;
}
auto oriImg = ir.read();
if(oriImg.width() != 2560 || oriImg.height() != 1620){
return img;
}
auto imgE = img.value();
int sourceWidth = oriImg.width();
int sourceHeight = oriImg.height();
int targetWidth = 540;
// int targetheight = 2560;
for(int x = 0; x < sourceWidth; x++){
int y = 1;
for(int i = 0; i < sourceHeight;i+=3){
uint32_t transRed = 0;
uint32_t transGreen = 0;
uint32_t transBlue = 0;
for(int j = 0; j < 3; j++){
if(i + j > sourceWidth){
break;
}
auto col = oriImg.pixel(x,i + j);
uint32_t total = col & 0x000000ff;
if(j == 0){
transRed = total;
}else if(j == 1){
transGreen = total;
}else{
transBlue = total;
}
}
QRgb rgb = RGB_MASK & (transBlue << 16 | transGreen << 8 | transRed);
imgE.setPixel(targetWidth - y++,x, rgb);
}
}
return imgE;
}