1- #include " lsb.h"
1+ #include " lsb.h"
22
33LSB::LSB ()
44{
@@ -15,30 +15,41 @@ void LSB::LoadImg(const QString & path)
1515 img.load (path);
1616 width = img.width ();
1717 height = img.height ();
18- max = (width * height * 3 - 12 ) / 8 ;
18+ max = (width * height * 3 - 12 ) / 4 ;
1919}
2020
2121void LSB::WriteImg (const QString & path)
2222{
2323 img.save (path);
2424}
2525
26- void LSB::CoverPixel ()
26+ void LSB::CoverPixel (int TYPE )
2727{
2828 int len = coded.length ();
2929 int index = 0 ;
30+ int red, green, blue, alpha;
31+ QRgb pixelValue, newPixelValue;
32+ QVector <QString> list;
33+ QString value;
3034 for (int i=0 ;i<width;i++) {
3135 for (int j=0 ;j<height;j++) {
32- QRgb pixelValue = img.pixel (i, j);
33- int red = qRed (pixelValue);
34- int green = qGreen (pixelValue);
35- int blue = qBlue (pixelValue);
36- QVector <QString> list;
36+ if (index <= len)
37+ {
38+ pixelValue = img.pixel (i, j);
39+ red = qRed (pixelValue);
40+ green = qGreen (pixelValue);
41+ blue = qBlue (pixelValue);
42+ if (TYPE == PNG)
43+ {
44+ alpha = qAlpha (pixelValue);
45+ }
46+ list.clear ();
47+ list.shrink_to_fit ();
3748 list.append (QString::number (red, 2 ));
3849 list.append (QString::number (green, 2 ));
3950 list.append (QString::number (blue, 2 ));
4051 for (int t=0 ;t<3 ;t++) {
41- QString value = list[t];
52+ value = list[t];
4253 if (index >= len)
4354 {
4455 value[value.length ()-1 ] = ' 0' ;
@@ -52,8 +63,14 @@ void LSB::CoverPixel()
5263 red = list[0 ].toInt (&n, 2 );
5364 green = list[1 ].toInt (&n, 2 );
5465 blue = list[2 ].toInt (&n, 2 );
55- QRgb newPixelValue = qRgb (red, green, blue);
66+ if (TYPE == PNG)
67+ {
68+ newPixelValue = qRgba (red, green, blue, alpha);
69+ } else {
70+ newPixelValue = qRgb (red, green, blue);
71+ }
5672 img.setPixel (i, j, newPixelValue);
73+ }
5774 }
5875 }
5976}
@@ -63,20 +80,23 @@ QString LSB::SplitPixel()
6380 QString head = " " ;
6481 int len = 0 ;
6582 bool flag = false ;
66- QString decoded = " " ;
83+ QString decoded = " " , value;
84+ QRgb pixelValue;
6785 int index = 0 ;
86+ QVector <QString> list;
6887 for (int i=0 ;i<width;i++) {
6988 for (int j=0 ;j<height;j++) {
70- QRgb pixelValue = img.pixel (i, j);
89+ pixelValue = img.pixel (i, j);
7190 int red = qRed (pixelValue);
7291 int green = qGreen (pixelValue);
7392 int blue = qBlue (pixelValue);
74- QVector <QString> list;
93+ list.clear ();
94+ list.shrink_to_fit ();
7595 list.append (QString::number (red, 2 ));
7696 list.append (QString::number (green, 2 ));
7797 list.append (QString::number (blue, 2 ));
7898 for (int t=0 ;t<3 ;t++) {
79- QString value = list[t];
99+ value = list[t];
80100 if (index < 12 )
81101 {
82102 head += value[value.length () - 1 ];
@@ -100,6 +120,7 @@ QString LSB::SplitPixel()
100120 return " " ;
101121}
102122
123+
103124void LSB::SetText (const QString & string)
104125{
105126 raw = string;
0 commit comments