- if (alpha == 0)
- *data = 0;
- else
- *data = ( alpha/255 << 24
- | (p.Red() * alpha/255) << 16
- | (p.Green() * alpha/255) << 8
- | (p.Blue() * alpha/255) );
- ++data;
- ++p;
- }
- p = rowStart;
- p.OffsetY(pixData, 1);
- }
- }
- else // no alpha
- {
- surface = gs_cairo->cairo_image_surface_create_for_data(
- buffer, CAIRO_FORMAT_RGB24, bw, bh, bw*4);
- wxNativePixelData pixData(bmpSource, wxPoint(0,0), wxSize(bw, bh));
- wxCHECK_RET( pixData, wxT("Failed to gain raw access to bitmap data."));
-
- wxNativePixelData::Iterator p(pixData);
- int y, x;
- for (y=0; y<bh; y++)
- {
- wxNativePixelData::Iterator rowStart = p;
- for (x=0; x<bw; x++)
- {
- // Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with
- // the upper 8 bits unused. Red, Green, and Blue are stored in
- // the remaining 24 bits in that order. The 32-bit quantities
- // are stored native-endian.
- *data = ( p.Red() << 16 | p.Green() << 8 | p.Blue() );
- ++data;
- ++p;
- }
- p = rowStart;
- p.OffsetY(pixData, 1);
- }
- }
-
-
- gs_cairo->cairo_save(m_cairo);
- // In case we're scaling the image by using a width and height different
- // than the bitmap's size create a pattern transformation on the surface and
- // draw the transformed pattern.
- cairo_pattern_t* pattern = gs_cairo->cairo_pattern_create_for_surface(surface);
-
- // Prepare to draw the image.
- gs_cairo->cairo_translate(m_cairo, x, y);
- gs_cairo->cairo_set_source(m_cairo, pattern);
- // Use the original size here since the context is scaled already.
- gs_cairo->cairo_rectangle(m_cairo, 0, 0, bw, bh);
- // Fill the rectangle using the pattern.
- gs_cairo->cairo_fill(m_cairo);
-
- // Clean up.
- gs_cairo->cairo_pattern_destroy(pattern);
- gs_cairo->cairo_surface_destroy(surface);
- delete [] buffer;
-
- CalcBoundingBox(0,0);
- CalcBoundingBox(bw,bh);