Changeset 11469 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-01-16T22:10:58+01:00 (7 years ago)
Author:
bastiK
Message:

see #13124 - fix some Heat Map issues (patch by kidelo)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r11459 r11469  
    10091009        g.setStroke(new BasicStroke(outlineWidth));
    10101010
    1011         int lastPixelY = 0;
     1011        int lastPixelX = 0;
    10121012        int lastPixelColor = 0;
    10131013
    10141014        // resample gray scale image with line linear weight of next sample in line
    10151015        // process each line and draw pixels / rectangles with same color with one operations
    1016         for (int x = 0; x < maxPixelX; x += offX) {
    1017             for (int y = 0; y < maxPixelY; y += offY) {
    1018 
    1019                 int thePixelColor = 0;
     1016        for (int y = 0; y < maxPixelY; y += offY) {
     1017
     1018            // the lines offsets
     1019            final int lastLineOffset = maxPixelX * (y+0);
     1020            final int nextLineOffset = maxPixelX * (y+1);
     1021
     1022            for (int x = 0; x < maxPixelX; x += offX) {
     1023
     1024                int thePixelColor = 0; int thePixelCount = 0;
    10201025
    10211026                // sample the image (it is gray scale)
    1022                 int offset = (x * maxPixelX) + y;
     1027                int offset = lastLineOffset + x;
    10231028
    10241029                // merge next pixels of window of line
    1025                 for (int k = 0; k < offX && offset + k < imgPixels.length; k++) {
     1030                for (int k = 0; k < offX && (offset + k) < nextLineOffset; k++) {
    10261031                    thePixelColor += imgPixels[offset+k] & 0xFF;
     1032                    thePixelCount++;
    10271033                }
    10281034
    10291035                // mean value
    1030                 thePixelColor /= offX;
     1036                thePixelColor = thePixelCount > 0 ? (thePixelColor / thePixelCount) : 0;
    10311037
    10321038                // restart -> use initial sample
    1033                 if (0 == y) {
    1034                     lastPixelY = 0; lastPixelColor = thePixelColor - 1;
     1039                if (0 == x) {
     1040                    lastPixelX = 0; lastPixelColor = thePixelColor - 1;
    10351041                }
    10361042
     
    10561062                        // box from from last Y pixel to current pixel
    10571063                        if (drawOutlines) {
    1058                             g.drawRect(lastPixelY, x, offY + y - lastPixelY, offX);
     1064                            g.drawRect(lastPixelX, y, offX + x - lastPixelX, offY);
    10591065                        } else {
    1060                             g.fillRect(lastPixelY, x, offY + y - lastPixelY, offX);
     1066                            g.fillRect(lastPixelX, y, offX + x - lastPixelX, offY);
    10611067                        }
    10621068                    }
    10631069
    10641070                    // restart detection
    1065                     lastPixelY = y; lastPixelColor = thePixelColor;
     1071                    lastPixelX = x; lastPixelColor = thePixelColor;
    10661072                }
    10671073            }
     
    10811087
    10821088        // get bounds of screen image and projection, zoom and adjust input parameters
    1083         final Rectangle screenBounds = g.getDeviceConfiguration().getBounds();
     1089        final Rectangle screenBounds = new Rectangle(mv.getWidth(), mv.getHeight());
    10841090        final double zoomScale = mv.getScale();
    10851091
     
    10881094
    10891095        // 1st setup virtual paint area ----------------------------------------
    1090 
    1091         // HACK: sometime screen bounds does not return valid values when picture is shifted
    1092         // therefore we use a bigger area to avoid missing parts of image
    1093         screenBounds.width = screenBounds.width * 3 / 2;
    1094         screenBounds.height = screenBounds.height * 3 / 2;
    10951096
    10961097        // new image buffer needed
     
    11421143            heatMapCacheVisibleSegments = visibleSegments.size();
    11431144            heatMapCacheZoomScale = zoomScale;
    1144             heatMapCacheLineWith = lineWidth;
     1145            heatMapCacheLineWith = globalLineWidth;
    11451146        }
    11461147
    11471148        // 4th. Draw data on target layer, map data via color lookup table --------------
    1148         drawHeatMapGrayMap(g, heatMapImgGray,
    1149                 lineWidthB > 2 ? (lineWidthB / 2) : 1,
    1150                 lineWidth > 2 ? (lineWidth - 2) : 1);
     1149        drawHeatMapGrayMap(g, heatMapImgGray, lineWidthB > 2 ? (lineWidthB / 2) : 1, lineWidth > 2 ? (lineWidth - 2) : 1);
    11511150    }
    11521151
Note: See TracChangeset for help on using the changeset viewer.