@@ -277,24 +277,27 @@ void Graphics::drawPixel(int posX, int posY) {
277277}
278278
279279void Graphics::drawRGB (const MAPoint2d *dstPoint, const void *src,
280- const MARect *srcRect, int opacity, int bytesPerLine ) {
280+ const MARect *srcRect, int opacity, int stride ) {
281281 uint8_t *image = (uint8_t *)src;
282- size_t scale = 1 ;
283- int w = bytesPerLine;
284282 float op = opacity / 100 .0f ;
283+ int top = srcRect->top ;
284+ int left = srcRect->left ;
285+ int width = srcRect->width ;
286+ int height = srcRect->height ;
285287
286- for (int y = srcRect-> top ; y < srcRect-> height ; y += scale ) {
288+ for (int y = 0 ; y < height; y += 1 ) {
287289 int dY = dstPoint->y + y;
288290 if (dY >= _drawTarget->y () &&
289291 dY < _drawTarget->h ()) {
292+ int imgPos = (left + ((y + top) * stride)) * 4 ;
290293 pixel_t *line = _drawTarget->getLine (dY);
291- for (int x = srcRect-> left ; x < srcRect-> width ; x += scale ) {
294+ for (int x = 0 ; x < width; x += 1 ) {
292295 int dX = dstPoint->x + x;
293296 if (dX >= _drawTarget->x () &&
294297 dX < _drawTarget->w ()) {
295298 // get RGBA components
296299 uint8_t a, r, g, b;
297- GET_IMAGE_ARGB (image, (y * w * 4 ) + ( x * 4 ) , a, r, g, b);
300+ GET_IMAGE_ARGB (image, imgPos + x * 4 , a, r, g, b);
298301 uint8_t dR, dG, dB;
299302 GET_RGB (line[dX], dR, dG, dB);
300303 if (opacity > 0 && opacity < 100 && a > 64 ) {
@@ -364,8 +367,7 @@ void Graphics::drawText(int left, int top, const char *str, int len) {
364367 }
365368}
366369
367- void Graphics::getImageData (Canvas *canvas, uint8_t *image,
368- const MARect *srcRect, int bytesPerLine) {
370+ void Graphics::getImageData (Canvas *canvas, uint8_t *image, const MARect *srcRect, int stride) {
369371 size_t scale = 1 ;
370372 int x_end = srcRect->left + srcRect->width ;
371373 int y_end = srcRect->top + srcRect->height ;
@@ -375,7 +377,7 @@ void Graphics::getImageData(Canvas *canvas, uint8_t *image,
375377 for (int dy = 0 , y = srcRect->top ; y < y_end; y += scale, dy++) {
376378 if (y >= canvas->y () && y < canvas->h ()) {
377379 pixel_t *line = canvas->getLine (y);
378- int yoffs = (dy * bytesPerLine );
380+ int yoffs = (dy * stride );
379381 for (int dx = 0 , x = srcRect->left ; x < x_end; x += scale, dx++) {
380382 if (x >= canvas->x () && x < canvas->w ()) {
381383 uint8_t r, g, b;
@@ -635,8 +637,8 @@ void maDrawText(int left, int top, const char *str, int length) {
635637}
636638
637639void maDrawRGB (const MAPoint2d *dstPoint, const void *src,
638- const MARect *srcRect, int opacity, int bytesPerLine ) {
639- graphics->drawRGB (dstPoint, src, srcRect, opacity, bytesPerLine );
640+ const MARect *srcRect, int opacity, int stride ) {
641+ graphics->drawRGB (dstPoint, src, srcRect, opacity, stride );
640642}
641643
642644MAExtent maGetTextSize (const char *str) {
@@ -681,12 +683,12 @@ void maDestroyPlaceholder(MAHandle maHandle) {
681683}
682684
683685void maGetImageData (MAHandle maHandle, void *dst,
684- const MARect *srcRect, int bytesPerLine ) {
686+ const MARect *srcRect, int stride ) {
685687 Canvas *holder = (Canvas *)maHandle;
686688 if (srcRect->width == 1 && srcRect->height == 1 ) {
687689 *((int *)dst) = graphics->getPixel (holder, srcRect->left , srcRect->top );
688690 } else {
689- graphics->getImageData (holder, (uint8_t *)dst, srcRect, bytesPerLine );
691+ graphics->getImageData (holder, (uint8_t *)dst, srcRect, stride );
690692 }
691693}
692694
0 commit comments