39 unsigned char *src = srcImage->GetData();
41 c.Set(src[0], src[1], src[2]);
59 unsigned char *src = srcImage->GetData();
60 int width = srcImage->GetWidth();
61 int height = srcImage->GetHeight();
63 auto dstImage = std::make_unique<wxImage>(width, height);
64 unsigned char *dst = dstImage->GetData();
68 int srcVal[3], srcOpp[3];
69 srcVal[0] = srcColour.Red();
70 srcVal[1] = srcColour.Green();
71 srcVal[2] = srcColour.Blue();
73 int dstVal[3], dstOpp[3];
74 dstVal[0] = dstColour.Red();
75 dstVal[1] = dstColour.Green();
76 dstVal[2] = dstColour.Blue();
79 for (i = 0; i < 3; i++) {
80 srcOpp[i] = 256 - srcVal[i];
81 dstOpp[i] = 255 - dstVal[i];
85 for (i = 0; i < width * height * 3; i++) {
89 *dst++ = dstVal[c] + dstOpp[c] * (s - srcVal[c]) / srcOpp[c];
92 *dst++ = dstVal[c] * s / srcVal[c];
97 if (srcImage->HasAlpha()) {
99 dstImage->InitAlpha();
100 memcpy(dstImage->GetAlpha(), srcImage->GetAlpha(), width * height);
112 wxImage * mask,
int xoff,
int yoff)
114 unsigned char *bg = background->GetData();
115 unsigned char *fg = foreground->GetData();
116 unsigned char *mk = mask->GetData();
118 int bgWidth = background->GetWidth();
119 int bgHeight = background->GetHeight();
120 int fgWidth = foreground->GetWidth();
121 int fgHeight = foreground->GetHeight();
122 int mkWidth = mask->GetWidth();
123 int mkHeight = mask->GetHeight();
132 int wCutoff = (fgWidth < mkWidth) ? fgWidth : mkWidth;
133 int hCutoff = (fgHeight < mkHeight) ? fgHeight : mkHeight;
138 wCutoff = (bgWidth - xoff > wCutoff) ? wCutoff : bgWidth - xoff;
139 hCutoff = (bgHeight - yoff > hCutoff) ? hCutoff : bgHeight - yoff;
143 auto dstImage = std::make_unique<wxImage>(bgWidth, bgHeight);
144 unsigned char *dst = dstImage->GetData();
145 memcpy(dst, bg, bgWidth * bgHeight * 3);
153 for (y = 0; y < hCutoff; y++) {
155 unsigned char *bkp = bg + 3 * ((y + yoff) * bgWidth + xoff);
156 unsigned char *dstp = dst + 3 * ((y + yoff) * bgWidth + xoff);
158 for (x = 0; x < wCutoff; x++) {
160 int value = mk[3 * (y * mkWidth + x)];
161 int opp = 255 - value;
163 for (
int c = 0; c < 3; c++)
165 ((bkp[x * 3 + c] * opp) +
166 (fg[3 * (y * fgWidth + x) + c] * value)) / 255;
186 if (!imgFore.HasAlpha())
187 return std::make_unique<wxImage>(imgBack);
190 wxASSERT( imgFore.HasAlpha() );
192 unsigned char *bg = imgBack.GetData();
193 unsigned char *fg = imgFore.GetData();
194 unsigned char *mk = imgFore.GetAlpha();
196 int bgWidth = imgBack.GetWidth();
197 int bgHeight = imgBack.GetHeight();
198 int fgWidth = imgFore.GetWidth();
199 int fgHeight = imgFore.GetHeight();
208 int wCutoff = fgWidth;
209 int hCutoff = fgHeight;
214 wCutoff = (bgWidth - xoff > wCutoff) ? wCutoff : bgWidth - xoff;
215 hCutoff = (bgHeight - yoff > hCutoff) ? hCutoff : bgHeight - yoff;
218 auto dstImage = std::make_unique<wxImage>(bgWidth, bgHeight);
219 unsigned char *dst = dstImage->GetData();
220 memcpy(dst, bg, bgWidth * bgHeight * 3);
224 if( imgBack.HasAlpha() ){
225 unsigned char *pAlpha = imgBack.GetAlpha();
227 unsigned char onePixImage[3];
229 onePixImage[ 0 ] = c.Red();
230 onePixImage[ 1 ] = c.Green();
231 onePixImage[ 2 ] = c.Blue();
232 for(
int i=0;i< bgWidth*bgHeight;i++){
233 unsigned char * pPix = &dst[ 3*i];
234 float alpha = 1.0 - (pAlpha[i]/255.0);
235 pPix[0] = pPix[0] + alpha *( (int)onePixImage[0]-(
int)pPix[0]);
236 pPix[1] = pPix[1] + alpha *( (int)onePixImage[1]-(
int)pPix[1]);
237 pPix[2] = pPix[2] + alpha *( (int)onePixImage[2]-(
int)pPix[2]);
246 for (y = 0; y < hCutoff; y++) {
248 unsigned char *bkp = bg + 3 * ((y + yoff) * bgWidth + xoff);
249 unsigned char *dstp = dst + 3 * ((y + yoff) * bgWidth + xoff);
251 for (x = 0; x < wCutoff; x++) {
253 int value = mk[(y * fgWidth + x)];
254 int opp = 255 - value;
256 for (
int c = 0; c < 3; c++)
258 ((bkp[x * 3 + c] * opp) +
259 (fg[3 * (y * fgWidth + x) + c] * value)) / 255;
268 auto i = std::make_unique<wxImage>(width, height);
273 srcVal[0] = colour.Red();
274 srcVal[1] = colour.Green();
275 srcVal[2] = colour.Blue();
278 for(x=0; x<width*height; x++) {
288 (
int width,
int height,
int WXUNUSED(offset), wxColour colour)
300 unsigned char *bg = background->GetData();
301 unsigned char *fg = foreground->GetData();
302 unsigned char *bgAlpha = background->HasAlpha() ? background->GetAlpha() : NULL;
303 unsigned char *fgAlpha = foreground->HasAlpha() ? foreground->GetAlpha() : NULL;
307 int bgWidth = background->GetWidth();
308 int bgHeight = background->GetHeight();
309 int fgWidth = foreground->GetWidth();
310 int fgHeight = foreground->GetHeight();
312 int wCutoff = fgWidth;
313 int hCutoff = fgHeight;
317 wCutoff = (bgWidth - xoff > wCutoff) ? wCutoff : bgWidth - xoff;
318 hCutoff = (bgHeight - yoff > hCutoff) ? hCutoff : bgHeight - yoff;
327 unsigned char *bgAlphap;
328 unsigned char *fgAlphap;
329 for (y = 0; y < hCutoff; y++) {
331 bkp = bg + 3 * ((y + yoff) * bgWidth + xoff);
332 fgp = fg + 3 * ( y * fgWidth);
333 memcpy( bkp, fgp, 3 * wCutoff );
338 bgAlphap = bgAlpha + ((y+yoff) * bgWidth + xoff );
341 fgAlphap = fgAlpha + (y * fgWidth );
342 memcpy( bgAlphap, fgAlphap, wCutoff );
346 memset( bgAlphap, 255, wCutoff );
359 wxCHECK_MSG( Src.Ok(), image,
wxT(
"invalid image") );
361 wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (
362 rect.GetRight()<=Src.GetWidth()) && (rect.GetBottom()<=Src.GetHeight()),
363 image,
wxT(
"invalid subimage size") );
365 int subwidth=rect.GetWidth();
366 const int subheight=rect.GetHeight();
368 image.Create( subwidth, subheight,
false );
370 unsigned char *subdata = image.GetData(), *data=Src.GetData();
372 wxCHECK_MSG( subdata, image,
wxT(
"unable to create image") );
378 int subleft=3*rect.GetLeft();
379 int width=3*Src.GetWidth();
382 data+=rect.GetTop()*width+subleft;
384 for (
long j = 0; j < subheight; ++j)
386 memcpy( subdata, data, subwidth);
392 if( !Src.HasAlpha() )
402 data =Src.GetAlpha();
403 subdata =image.GetAlpha();
405 data+=rect.GetTop()*width+subleft;
407 for (
long j = 0; j < subheight; ++j)
409 memcpy( subdata, data, subwidth);
wxImage GetSubImageWithAlpha(const wxImage &Src, const wxRect &rect)
std::unique_ptr< wxImage > CreateSysBackground(int width, int height, int WXUNUSED(offset), wxColour colour)
std::unique_ptr< wxImage > OverlayImage(wxImage *background, wxImage *foreground, wxImage *mask, int xoff, int yoff)
void PasteSubImage(wxImage *background, wxImage *foreground, int xoff, int yoff)
std::unique_ptr< wxImage > CreateBackground(int width, int height, wxColour colour)
std::unique_ptr< wxImage > ChangeImageColour(wxImage *srcImage, wxColour &dstColour)
wxColour & Colour(int iIndex)
wxImage & Image(int iIndex)