javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/graphics/qt/imagedataimpl.cpp
equal
deleted
inserted
replaced
63 } |
63 } |
64 |
64 |
65 void ImageDataWrapperImpl::setData(Image* aSrc) |
65 void ImageDataWrapperImpl::setData(Image* aSrc) |
66 { |
66 { |
67 GFX_LOG_FUNC_CALL(); |
67 GFX_LOG_FUNC_CALL(); |
68 QImage image = aSrc->getPixmap()->toImage(); |
68 const QImage image = aSrc->toConstImage(); |
69 fillData(&image, aSrc->getAlpha(), aSrc->hasMask()); |
69 fillData(&image, aSrc->getAlpha(), aSrc->hasMask()); |
70 } |
70 } |
71 |
71 |
72 void ImageDataWrapperImpl::setData(ImageDataWrapper::TDataType aType, |
72 void ImageDataWrapperImpl::setData(ImageDataWrapper::TDataType aType, |
73 const QByteArray& aData) |
73 const QByteArray& aData) |
115 |
115 |
116 int bpp = mDepth / 8; |
116 int bpp = mDepth / 8; |
117 const uchar* data = aImage->scanLine(0); |
117 const uchar* data = aImage->scanLine(0); |
118 |
118 |
119 char* pixelData = mPixelData.data(); |
119 char* pixelData = mPixelData.data(); |
|
120 uchar* alphaData = 0; |
|
121 if (mDepth == 32 && !aMask && mAlpha == -1) |
|
122 { |
|
123 mAlphaData.fill(0xFF, aImage->width() * aImage->height()); |
|
124 alphaData = (uchar*) mAlphaData.data(); |
|
125 } |
120 |
126 |
121 int pixel = 0; |
127 int pixel = 0; |
|
128 int alpha = 0; |
|
129 bool alphaInUse = false; |
122 |
130 |
123 // Create |
131 // Create |
124 for (int i = 0; i < size; i += bpp) |
132 for (int i = 0, j = 0; i < size; i += bpp, j++) |
125 { |
133 { |
126 switch (mDepth) |
134 switch (mDepth) |
127 { |
135 { |
128 case 32: |
136 case 32: |
129 pixel = (data[i] & 0xFF) << 24 | (data[i+1] & 0xFF) << 16 | (data[i+2] & 0xFF) << 8 | (data[i+3] & 0xFF); |
137 alpha = data[i+3] & 0xFF; |
|
138 pixel = (data[i] & 0xFF) << 24 | (data[i+1] & 0xFF) << 16 | (data[i+2] & 0xFF) << 8 | alpha; |
|
139 if (!aMask && mAlpha == -1 && alpha != 0xFF) |
|
140 { |
|
141 *(uchar*)(alphaData + j) = alpha; |
|
142 if (!alphaInUse) |
|
143 { |
|
144 alphaInUse = true; |
|
145 } |
|
146 } |
130 *(int*)(pixelData + i) = pixel; |
147 *(int*)(pixelData + i) = pixel; |
131 break; |
148 break; |
132 case 24: |
149 case 24: |
133 pixel = (data[i] & 0xFF) << 16 | (data[i+1] & 0xFF) << 8 | (data[i+2] & 0xFF); |
150 pixel = (data[i] & 0xFF) << 16 | (data[i+1] & 0xFF) << 8 | (data[i+2] & 0xFF); |
134 *(int*)(pixelData + i) = pixel; |
151 *(int*)(pixelData + i) = pixel; |
141 *(pixelData + i) = (data[i] & 0xFF); |
158 *(pixelData + i) = (data[i] & 0xFF); |
142 break; |
159 break; |
143 default: |
160 default: |
144 throw GfxException(EGfxErrorIllegalArgument, "Unsupported bit depth"); |
161 throw GfxException(EGfxErrorIllegalArgument, "Unsupported bit depth"); |
145 } |
162 } |
|
163 } |
|
164 |
|
165 // According to eSWT's API, an alpha data should be present |
|
166 // only when there are actual semi or fully transparent pixels. |
|
167 if (!alphaInUse) |
|
168 { |
|
169 mAlphaData.clear(); |
146 } |
170 } |
147 |
171 |
148 if (aMask) |
172 if (aMask) |
149 { |
173 { |
150 // Mask data is 1 bit/pixel |
174 // Mask data is 1 bit/pixel |
162 } |
186 } |
163 else if (mAlpha != -1) |
187 else if (mAlpha != -1) |
164 { |
188 { |
165 mAlphaData.fill(mAlpha, aImage->width()*aImage->height()); |
189 mAlphaData.fill(mAlpha, aImage->width()*aImage->height()); |
166 } |
190 } |
167 else if (aImage->hasAlphaChannel()) |
|
168 { |
|
169 |
|
170 QImage alphaImage = aImage->alphaChannel(); |
|
171 const int w = alphaImage.width(); |
|
172 for(int j= 0; j < alphaImage.height(); j++) |
|
173 { |
|
174 for(int i = 0; i < w; i++) |
|
175 { |
|
176 mAlphaData[j * w + i] = alphaImage.pixel(i, j) & 0xFF; |
|
177 } |
|
178 } |
|
179 } |
|
180 |
191 |
181 // Create palette |
192 // Create palette |
182 if (aImage->numColors() > 0) |
193 if (aImage->numColors() > 0) |
183 { |
194 { |
184 // If image has color table set, create indexed palette |
195 // If image has color table set, create indexed palette |