88
99#include " config.h"
1010#include < math.h>
11+ #include < stdint.h>
1112#include " ui/utils.h"
13+ #include " ui/rgb.h"
1214#include " platform/fltk/display.h"
1315
1416GraphicsWidget *graphics;
@@ -112,17 +114,44 @@ void Canvas::drawPixel(int posX, int posY) {
112114 fl_end_offscreen ();
113115}
114116
115- // x, y, w are position and width of scan line in image. copy w
116- // pixels from scanline y, starting at pixel x to this buffer.
117+ struct DrawData {
118+ uint8_t *_image;
119+ uint8_t *_screen;
120+ int _opacity;
121+ };
122+
123+ // x, y, w are position and width of scan line in image.
124+ // copy w pixels from scanline y, starting at pixel x to this buffer.
117125void drawImage (void *data, int x, int y, int w, uchar *out) {
118- uint8_t *image = (uint8_t *)data;
126+ DrawData *drawData = (DrawData *)data;
127+ uint8_t *image = drawData->_image ;
128+ uint8_t *screen = drawData->_screen ;
129+ int opacity = drawData->_opacity ;
119130 int scanLine = w * 3 ;
120131 int offs = y * w * 4 ;
132+ float op = opacity / 100 .0f ;
133+ fprintf (stderr, " op=%f\n " , op);
121134
122135 for (int sx = 0 ; sx < scanLine; sx += 3 , offs += 4 ) {
123- out[sx + 0 ] = image[offs + 0 ];
124- out[sx + 1 ] = image[offs + 1 ];
125- out[sx + 2 ] = image[offs + 2 ];
136+ uint8_t a = image[offs + 3 ];
137+ uint8_t r = image[offs + 2 ];
138+ uint8_t g = image[offs + 1 ];
139+ uint8_t b = image[offs + 0 ];
140+ uint8_t dR = screen[offs + 2 ];
141+ uint8_t dG = screen[offs + 1 ];
142+ uint8_t dB = screen[offs + 0 ];
143+ if (opacity > 0 && opacity < 100 && a > 64 ) {
144+ dR = (op * r) + ((1 - op) * dR);
145+ dG = (op * g) + ((1 - op) * dG);
146+ dB = (op * b) + ((1 - op) * dB);
147+ } else {
148+ dR = dR + ((r - dR) * a / 255 );
149+ dG = dG + ((g - dG) * a / 255 );
150+ dB = dB + ((b - dB) * a / 255 );
151+ }
152+ out[sx + 2 ] = dR;
153+ out[sx + 1 ] = dG;
154+ out[sx + 0 ] = dB;
126155 }
127156}
128157
@@ -131,9 +160,16 @@ void Canvas::drawRGB(const MAPoint2d *dstPoint, const void *src, const MARect *s
131160 int y = dstPoint->y ;
132161 int w = srcRect->width ;
133162 int h = srcRect->height ;
163+ DrawData data;
164+ data._image = (uint8_t *)src;
165+ data._opacity = opacity;
166+ data._screen = (uint8_t *)calloc (w * h * 4 , 1 );
167+
134168 fl_begin_offscreen (_offscreen);
135- fl_draw_image (drawImage, (void *)src, x, y, w, h);
169+ fl_read_image (data._screen , x, y, w, h, 1 );
170+ fl_draw_image (drawImage, (void *)&data, x, y, w, h, 3 );
136171 fl_end_offscreen ();
172+ free (data._screen );
137173}
138174
139175void Canvas::drawRegion (Canvas *src, const MARect *srcRect, int destX, int destY) {
0 commit comments