Example usage for java.awt Rectangle getHeight

List of usage examples for java.awt Rectangle getHeight

Introduction

In this page you can find the example usage for java.awt Rectangle getHeight.

Prototype

public double getHeight() 

Source Link

Document

Returns the height of the bounding Rectangle in double precision.

Usage

From source file:org.netbeans.jbpmn.modeler.specification.bpmn.model.process.util.BPMNProcessUtil.java

public static void updateDiagramFlowElement(BPMNPlane plane, Widget widget) {
    //Diagram Model
    if (widget instanceof NodeWidget) { //reverse ref
        NodeWidget nodeWidget = (NodeWidget) widget;

        Rectangle rec = nodeWidget.getSceneViewBound();

        BPMNShape shape = new BPMNShape();
        shape.setBounds(new Bounds(rec));//(new Bounds(flowNodeWidget.getBounds()));
        shape.setBpmnElement(((BaseElementWidget) nodeWidget).getId());
        shape.setId(((BaseElementWidget) nodeWidget).getId() + "_gui");
        if (nodeWidget.getLabelManager() != null && nodeWidget.getLabelManager().isVisible()
                && nodeWidget.getLabelManager().getLabel() != null
                && !nodeWidget.getLabelManager().getLabel().trim().isEmpty()) {
            Rectangle bound = nodeWidget.getLabelManager().getLabelWidget().getParentWidget()
                    .getPreferredBounds();
            bound = nodeWidget.getLabelManager().getLabelWidget().getParentWidget().convertLocalToScene(bound);

            Rectangle rec_label = new Rectangle(bound.x, bound.y, (int) bound.getWidth(),
                    (int) bound.getHeight());

            BPMNLabel label = new BPMNLabel();
            label.setBounds(new Bounds(rec_label));
            shape.setBPMNLabel(label);/*from ww w.  j  a v a2s.  c  om*/
        }
        plane.addDiagramElement(shape);

        ShapeDesign shapeDesign = null;// BPMNShapeDesign XML Location Change Here
        if (nodeWidget instanceof FlowNodeWidget) {
            TFlowNode flowNode = (TFlowNode) ((FlowNodeWidget) nodeWidget).getBaseElementSpec();
            if (flowNode.getExtensionElements() == null) {
                flowNode.setExtensionElements(new TExtensionElements());
            }
            TExtensionElements extensionElements = flowNode.getExtensionElements();
            for (Object obj : extensionElements.getAny()) {
                if (obj instanceof Element) { //first time save
                    Element element = (Element) obj;
                    if ("ShapeDesign".equals(element.getNodeName())) {
                        shapeDesign = getBPMNShapeDesign(nodeWidget);
                        extensionElements.getAny().remove(obj);
                        extensionElements.getAny().add(shapeDesign);
                        break;
                    }
                } else if (obj instanceof ShapeDesign) {
                    shapeDesign = getBPMNShapeDesign(nodeWidget);
                    extensionElements.getAny().remove(obj);
                    extensionElements.getAny().add(shapeDesign);
                    break;
                }
            }
        }

        if (shapeDesign == null) {
            if (nodeWidget instanceof FlowNodeWidget) {
                TFlowNode flowNode = (TFlowNode) ((FlowNodeWidget) nodeWidget).getBaseElementSpec();
                TExtensionElements extensionElements = flowNode.getExtensionElements();
                shapeDesign = getBPMNShapeDesign(nodeWidget);
                extensionElements.getAny().add(shapeDesign);
            }
        }

        //            shape.setBpmnShapeDesign(getBPMNShapeDesign(nodeWidget));
        if (nodeWidget instanceof SubProcessWidget) {
            SubProcessWidget subProcessWidget = (SubProcessWidget) nodeWidget;
            for (FlowElementWidget flowElementChildrenWidget : subProcessWidget.getFlowElements()) {
                updateDiagramFlowElement(plane, (Widget) flowElementChildrenWidget);
            }
        }

    } else if (widget instanceof EdgeWidget) {
        EdgeWidget edgeWidget = (EdgeWidget) widget;
        BPMNEdge edge = new BPMNEdge();
        for (java.awt.Point point : edgeWidget.getControlPoints()) {
            edge.addWaypoint(point);
        }
        edge.setBpmnElement(((BaseElementWidget) edgeWidget).getId());
        edge.setId(((BaseElementWidget) edgeWidget).getId() + "_gui");

        if (widget instanceof SequenceFlowWidget) {
            if (edgeWidget.getLabelManager() != null && edgeWidget.getLabelManager().isVisible()
                    && edgeWidget.getLabelManager().getLabel() != null
                    && !edgeWidget.getLabelManager().getLabel().trim().isEmpty()) {
                Rectangle bound = edgeWidget.getLabelManager().getLabelWidget().getParentWidget()
                        .getPreferredBounds();
                bound = edgeWidget.getLabelManager().getLabelWidget().getParentWidget()
                        .convertLocalToScene(bound);

                Rectangle rec = new Rectangle(bound.x, bound.y, (int) bound.getWidth(),
                        (int) bound.getHeight());

                BPMNLabel label = new BPMNLabel();
                label.setBounds(new Bounds(rec));
                edge.setBPMNLabel(label);
            }
        }
        plane.addDiagramElement(edge);

    } else {
        throw new InvalidElmentException("Invalid BPMN Element");
    }

}

From source file:org.opencastproject.metadata.mpeg7.Mpeg7Test.java

/**
 * Tests the contents of the sample catalog mpeg7.xml.
 *///from   w  w  w  . j  a  va  2  s. c om
@SuppressWarnings("unchecked")
protected void testContent(Mpeg7Catalog mpeg7) {
    // Check presence of content
    assertTrue(mpeg7.hasAudioContent());
    assertTrue(mpeg7.hasVideoContent());
    assertFalse(mpeg7.hasAudioVisualContent());

    // Check content size
    assertTrue(mpeg7.getMultimediaContent(MultimediaContent.Type.AudioType).size() == 1);
    assertTrue(mpeg7.getMultimediaContent(MultimediaContent.Type.VideoType).size() == 2);

    // Check tracks
    assertNotNull(mpeg7.getAudioById("track-1"));
    assertNotNull(mpeg7.getVideoById("track-2"));
    assertNotNull(mpeg7.getVideoById("track-3"));

    //
    // Check audio track (track-1)
    //

    MultimediaContentType track1 = mpeg7.getAudioById("track-1");
    MediaTime audioMediaTime = track1.getMediaTime();

    // Media locator
    assertEquals(track1.getMediaLocator().getMediaURI(), URI.create("file:tracks/audio.pcm"));
    // Media time point
    assertEquals(0, audioMediaTime.getMediaTimePoint().getDay());
    assertEquals(0, audioMediaTime.getMediaTimePoint().getHour());
    assertEquals(0, audioMediaTime.getMediaTimePoint().getMinutes());
    assertEquals(0, audioMediaTime.getMediaTimePoint().getSeconds());
    assertEquals(25, audioMediaTime.getMediaTimePoint().getFractionsPerSecond());
    assertEquals(0, audioMediaTime.getMediaTimePoint().getNFractions());
    // Media duration
    assertEquals(0, audioMediaTime.getMediaDuration().getDays());
    assertEquals(1, audioMediaTime.getMediaDuration().getHours());
    assertEquals(30, audioMediaTime.getMediaDuration().getMinutes());
    assertEquals(0, audioMediaTime.getMediaDuration().getSeconds());
    // Segments
    assertFalse(track1.getTemporalDecomposition().segments().hasNext());

    //
    // Check video track (track-2)
    //

    MultimediaContentType track2 = mpeg7.getVideoById("track-2");
    MediaTime v1MediaTime = track2.getMediaTime();

    // Media locator
    assertEquals(track2.getMediaLocator().getMediaURI(), URI.create("file:tracks/presentation.mp4"));
    // Media time point
    assertEquals(0, v1MediaTime.getMediaTimePoint().getDay());
    assertEquals(0, v1MediaTime.getMediaTimePoint().getHour());
    assertEquals(0, v1MediaTime.getMediaTimePoint().getMinutes());
    assertEquals(0, v1MediaTime.getMediaTimePoint().getSeconds());
    assertEquals(25, v1MediaTime.getMediaTimePoint().getFractionsPerSecond());
    assertEquals(0, v1MediaTime.getMediaTimePoint().getNFractions());
    // Media duration
    assertEquals(0, v1MediaTime.getMediaDuration().getDays());
    assertEquals(1, v1MediaTime.getMediaDuration().getHours());
    assertEquals(30, v1MediaTime.getMediaDuration().getMinutes());
    assertEquals(0, v1MediaTime.getMediaDuration().getSeconds());
    // Segments
    TemporalDecomposition<VideoSegment> v1Decomposition = (TemporalDecomposition<VideoSegment>) track2
            .getTemporalDecomposition();
    assertFalse(v1Decomposition.hasGap());
    assertFalse(v1Decomposition.isOverlapping());
    assertEquals(v1Decomposition.getCriteria(), TemporalDecomposition.DecompositionCriteria.Temporal);
    assertTrue(v1Decomposition.segments().hasNext());
    // Segment track-2.segment-1
    VideoSegment v1Segment1 = v1Decomposition.getSegmentById("track-2.segment-1");
    assertNotNull(v1Segment1);
    MediaTime segment1MediaTime = v1Segment1.getMediaTime();
    // Media time point
    assertEquals(0, segment1MediaTime.getMediaTimePoint().getDay());
    assertEquals(0, segment1MediaTime.getMediaTimePoint().getHour());
    assertEquals(0, segment1MediaTime.getMediaTimePoint().getMinutes());
    assertEquals(0, segment1MediaTime.getMediaTimePoint().getSeconds());
    assertEquals(25, segment1MediaTime.getMediaTimePoint().getFractionsPerSecond());
    assertEquals(0, segment1MediaTime.getMediaTimePoint().getNFractions());
    // Media duration
    assertEquals(0, segment1MediaTime.getMediaDuration().getDays());
    assertEquals(1, segment1MediaTime.getMediaDuration().getHours());
    assertEquals(7, segment1MediaTime.getMediaDuration().getMinutes());
    assertEquals(35, segment1MediaTime.getMediaDuration().getSeconds());
    // Text annotations
    assertTrue(v1Segment1.hasTextAnnotations());
    assertTrue(v1Segment1.hasTextAnnotations(0.4f, 0.5f));
    assertFalse(v1Segment1.hasTextAnnotations(0.8f, 0.8f));
    assertTrue(v1Segment1.hasTextAnnotations("de"));
    assertFalse(v1Segment1.hasTextAnnotations("fr"));
    // Keywords
    TextAnnotation textAnnotation = v1Segment1.textAnnotations().next();
    assertEquals("Armin", textAnnotation.keywordAnnotations().next().getKeyword());
    assertEquals("Hint Armin", textAnnotation.freeTextAnnotations().next().getText());
    // Spaciotemporal decomposition
    SpatioTemporalDecomposition stdecomposition = v1Segment1.getSpatioTemporalDecomposition();
    assertNotNull(stdecomposition);
    assertTrue(stdecomposition.hasGap());
    assertFalse(stdecomposition.isOverlapping());
    // VideoText
    assertEquals(1, stdecomposition.getVideoText().length);
    VideoText videoText = stdecomposition.getVideoText("text1");
    assertNotNull(videoText);
    SpatioTemporalLocator locator = videoText.getSpatioTemporalLocator();
    assertNotNull(locator);
    MediaTime locatorMediaTime = locator.getMediaTime();
    assertNotNull(locatorMediaTime);
    assertEquals(MediaRelTimePointImpl.parseTimePoint("T00:00:00:0F25"), locatorMediaTime.getMediaTimePoint());
    assertEquals(MediaDurationImpl.parseDuration("PT01H07M35S"), locatorMediaTime.getMediaDuration());
    Textual textual = videoText.getText();
    assertNotNull(textual);
    assertEquals("Text", textual.getText());
    assertEquals("en", textual.getLanguage());
    Rectangle boundingBox = videoText.getBoundary();
    assertNotNull(boundingBox);
    assertEquals(10, (int) boundingBox.getX());
    assertEquals(150, (int) boundingBox.getWidth());
    assertEquals(20, (int) boundingBox.getY());
    assertEquals(15, (int) boundingBox.getHeight());

    //
    // Check video track (track-3)
    //

    MultimediaContentType track3 = mpeg7.getVideoById("track-3");
    MediaTime v2MediaTime = track3.getMediaTime();

    // Media locator
    assertEquals(track3.getMediaLocator().getMediaURI(), URI.create("file:tracks/presenter.mpg"));
    // Media time point
    assertEquals(0, v2MediaTime.getMediaTimePoint().getDay());
    assertEquals(0, v2MediaTime.getMediaTimePoint().getHour());
    assertEquals(0, v2MediaTime.getMediaTimePoint().getMinutes());
    assertEquals(0, v2MediaTime.getMediaTimePoint().getSeconds());
    assertEquals(25, v2MediaTime.getMediaTimePoint().getFractionsPerSecond());
    assertEquals(0, v2MediaTime.getMediaTimePoint().getNFractions());
    // Media duration
    assertEquals(0, v2MediaTime.getMediaDuration().getDays());
    assertEquals(1, v2MediaTime.getMediaDuration().getHours());
    assertEquals(30, v2MediaTime.getMediaDuration().getMinutes());
    assertEquals(0, v2MediaTime.getMediaDuration().getSeconds());
    // Segments
    TemporalDecomposition<VideoSegment> v2Decomposition = (TemporalDecomposition<VideoSegment>) track3
            .getTemporalDecomposition();
    assertFalse(v2Decomposition.segments().hasNext());

}

From source file:org.opencms.loader.CmsImageScaler.java

/**
 * Returns a scaled version of the given image byte content according this image scalers parameters.<p>
 *  /* w w w  . j  a  v a 2s.  c  o m*/
 * @param content the image byte content to scale
 * @param rootPath the root path of the image file in the VFS
 * 
 * @return a scaled version of the given image byte content according to the provided scaler parameters
 */
public byte[] scaleImage(byte[] content, String rootPath) {

    byte[] result = content;
    // flag for processed image
    boolean imageProcessed = false;
    // initialize image crop area
    initCropArea();

    RenderSettings renderSettings;
    if ((m_renderMode == 0) && (m_quality == 0)) {
        // use default render mode and quality
        renderSettings = new RenderSettings(Simapi.RENDER_QUALITY);
    } else {
        // use special render mode and/or quality
        renderSettings = new RenderSettings(m_renderMode);
        if (m_quality != 0) {
            renderSettings.setCompressionQuality(m_quality / 100f);
        }
    }
    // set max blur size
    renderSettings.setMaximumBlurSize(m_maxBlurSize);
    // new create the scaler
    Simapi scaler = new Simapi(renderSettings);
    // calculate a valid image type supported by the imaging library (e.g. "JPEG", "GIF")
    String imageType = Simapi.getImageType(rootPath);
    if (imageType == null) {
        // no type given, maybe the name got mixed up
        String mimeType = OpenCms.getResourceManager().getMimeType(rootPath, null, null);
        // check if this is another known MIME type, if so DONT use it (images should not be named *.pdf)
        if (mimeType == null) {
            // no MIME type found, use JPEG format to write images to the cache         
            imageType = Simapi.TYPE_JPEG;
        }
    }
    if (imageType == null) {
        // unknown type, unable to scale the image
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                    Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_SCALE_IMAGE_2, rootPath, toString()));
        }
        return result;
    }
    try {
        BufferedImage image = Simapi.read(content);

        if (isCropping()) {
            // check if the crop width / height are not larger then the source image
            if ((m_cropHeight > image.getHeight()) || (m_cropWidth > image.getWidth())) {
                // crop height / width is outside of image - return image unchanged
                return result;
            }
        }

        Color color = getColor();

        if (!m_filters.isEmpty()) {
            Iterator<String> i = m_filters.iterator();
            while (i.hasNext()) {
                String filter = i.next();
                if (FILTER_GRAYSCALE.equals(filter)) {
                    // add a gray scale filter
                    GrayscaleFilter grayscaleFilter = new GrayscaleFilter();
                    renderSettings.addImageFilter(grayscaleFilter);
                } else if (FILTER_SHADOW.equals(filter)) {
                    // add a drop shadow filter
                    ShadowFilter shadowFilter = new ShadowFilter();
                    shadowFilter.setXOffset(5);
                    shadowFilter.setYOffset(5);
                    shadowFilter.setOpacity(192);
                    shadowFilter.setBackgroundColor(color.getRGB());
                    color = Simapi.COLOR_TRANSPARENT;
                    renderSettings.setTransparentReplaceColor(Simapi.COLOR_TRANSPARENT);
                    renderSettings.addImageFilter(shadowFilter);
                }
            }
        }

        if (isCropping()) {
            // image crop operation
            image = scaler.cropToSize(image, m_cropX, m_cropY, m_cropWidth, m_cropHeight, getWidth(),
                    getHeight(), color);
            imageProcessed = true;
        } else {
            // only rescale the image, if the width and hight are different to the target size
            int imageWidth = image.getWidth();
            int imageHeight = image.getHeight();

            // image rescale operation
            switch (getType()) {
            // select the "right" method of scaling according to the "t" parameter
            case 1:
                // thumbnail generation mode (like 0 but no image enlargement)
                image = scaler.resize(image, getWidth(), getHeight(), color, getPosition(), false);
                imageProcessed = true;
                break;
            case 2:
                // scale to exact target size, crop what does not fit
                if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) {
                    image = scaler.resize(image, getWidth(), getHeight(), getPosition());
                    imageProcessed = true;
                }
                break;
            case 3:
                // scale and keep image proportions, target size variable
                if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) {
                    image = scaler.resize(image, getWidth(), getHeight(), true);
                    imageProcessed = true;
                }
                break;
            case 4:
                // don't keep image proportions, use exact target size
                if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) {
                    image = scaler.resize(image, getWidth(), getHeight(), false);
                    imageProcessed = true;
                }
                break;
            case 5:
                // scale and keep image proportions, target size variable, include maxWidth / maxHeight option
                // image proportions have already been calculated so should not be a problem, use 
                // 'false' to make sure image size exactly matches height and width attributes of generated tag
                if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) {
                    image = scaler.resize(image, getWidth(), getHeight(), false);
                    imageProcessed = true;
                }
                break;
            default:
                // scale to exact target size with background padding
                image = scaler.resize(image, getWidth(), getHeight(), color, getPosition(), true);
                imageProcessed = true;
            }

        }

        if (!m_filters.isEmpty()) {
            Rectangle targetSize = scaler.applyFilterDimensions(getWidth(), getHeight());
            image = scaler.resize(image, (int) targetSize.getWidth(), (int) targetSize.getHeight(),
                    Simapi.COLOR_TRANSPARENT, Simapi.POS_CENTER);
            image = scaler.applyFilters(image);
            imageProcessed = true;
        }

        // get the byte result for the scaled image if some changes have been made.
        // otherwiese use the original image
        if (imageProcessed) {
            result = scaler.getBytes(image, imageType);
        }
    } catch (Exception e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                    Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_SCALE_IMAGE_2, rootPath, toString()),
                    e);
        }
    }
    return result;
}

From source file:org.openstreetmap.josm.Main.java

static public void saveGuiGeometry() {
    // save the current window geometry
    String newGeometry = "";
    try {//from ww w  .  j a  va2  s.c  o m
        if (((JFrame) parent).getExtendedState() == JFrame.NORMAL) {
            Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
            Rectangle bounds = parent.getBounds();
            int width = (int) bounds.getWidth();
            int height = (int) bounds.getHeight();
            int x = (int) bounds.getX();
            int y = (int) bounds.getY();
            if (width > screenDimension.width)
                width = screenDimension.width;
            if (height > screenDimension.height)
                width = screenDimension.height;
            if (x < 0)
                x = 0;
            if (y < 0)
                y = 0;
            newGeometry = width + "x" + height + "+" + x + "+" + y;
        }
    } catch (Exception e) {
        System.out.println("Failed to save GUI geometry: " + e);
    }
    pref.put("gui.geometry", newGeometry);
}

From source file:org.pentaho.reporting.libraries.designtime.swing.LibSwingUtil.java

public static String rectangleToString(final Rectangle rectangle) {
    final StringBuilder buffer = new StringBuilder();
    buffer.append(rectangle.getX());//from   ww w . j a va2  s.c o  m
    buffer.append(",");
    buffer.append(rectangle.getY());
    buffer.append(",");
    buffer.append(rectangle.getWidth());
    buffer.append(",");
    buffer.append(rectangle.getHeight());
    return buffer.toString();
}

From source file:org.photovault.dcraw.AHDInterpolateOp.java

@Override
public Rectangle mapDestRect(Rectangle src, int srcIndex) {
    Rectangle ret = null;//from www.  j a va  2  s.  c om
    if (downSample == 1) {
        ret = new Rectangle((int) src.getMinX() - 3, (int) src.getMinY() - 3, (int) src.getWidth() + 6,
                (int) src.getHeight() + 6);
    } else {
        ret = new Rectangle((int) src.getMinX() * downSample, (int) src.getMinY() * downSample,
                (int) src.getWidth() * downSample, (int) src.getHeight() * downSample);
    }
    return ret;
}

From source file:org.photovault.dcraw.AHDInterpolateOp.java

@Override
public Rectangle mapSourceRect(Rectangle source, int srcIndex) {
    Rectangle ret = new Rectangle((int) source.getMinX() + 3, (int) source.getMinY() + 3,
            (int) source.getWidth() - 6, (int) source.getHeight() - 6);
    return ret;//ww  w  .j a  va  2s  .c  o  m
}

From source file:org.photovault.dcraw.AHDInterpolateOp.java

/**
 * Conpute a rectangle of destination image using AHD interpolation
 * @param img Array of soruce images (containing just one image in this case
 * @param dst Raster for the results//from ww  w  .jav a2 s  .c o m
 * @param area Area of dst that needs to be computed
 */
private void computeRectAHD(PlanarImage[] img, WritableRaster dst, Rectangle area) {
    log.debug("entry: computeAHD " + area);
    long entryTime = System.currentTimeMillis();

    // RandomIterFactory.create( img[0], area);
    int minx = Math.max((int) area.getMinX() - 3, 0);
    int miny = Math.max((int) area.getMinY() - 3, 0);
    int maxx = Math.min((int) area.getMaxX() + 3, getWidth() - 1);
    int maxy = Math.min((int) area.getMaxY() + 3, getHeight() - 1);
    Rectangle enlargedArea = new Rectangle(minx, miny, maxx - minx + 1, maxy - miny + 1);
    int[][][][] rgb = new int[2][(int) enlargedArea.getWidth()][(int) enlargedArea.getHeight()][3];
    int[][][][] lab = new int[2][(int) enlargedArea.getWidth()][(int) enlargedArea.getHeight()][3];
    byte[][][] homo = new byte[2][(int) enlargedArea.getWidth()][(int) enlargedArea.getHeight()];

    RandomIter riter = RandomIterFactory.create(img[0], enlargedArea);

    double xyz[] = new double[3];
    // Copy the data to temp array
    for (int y = 0; y < maxy - miny; y++) {
        for (int x = 0; x < maxx - minx; x++) {
            int color = fc(y + miny, x + minx);
            if (color == 3)
                color = 1;
            rgb[0][x][y][color] = rgb[1][x][y][color] = (int) (mult[color]
                    * riter.getSample(x + minx, y + miny, 0));

        }
    }

    // Interpolate green
    for (int y = 2; y < maxy - miny - 2; y++) {
        int firstColor = fc(y + miny, minx + 3);
        int startCol = minx + 3 - (firstColor % 2);
        for (int x = startCol - minx; x < maxx - minx - 2; x += 2) {
            int c = fc(y + miny, x + minx);
            if (c == 3) {
                c = 1;
            }
            int tc = rgb[0][x][y][c];
            int eg = rgb[0][x - 1][y][1];
            int wg = rgb[0][x + 1][y][1];
            int sg = rgb[0][x][y + 1][1];
            int ng = rgb[0][x][y - 1][1];
            int ec = rgb[0][x - 2][y][c];
            int wc = rgb[0][x + 2][y][c];
            int sc = rgb[0][x][y + 2][c];
            int nc = rgb[0][x][y - 2][c];

            // Horizonally
            int green = 2 * (wg + tc + eg) - (wc + ec);
            green >>= 2;
            if (green < 0)
                green = 0;
            rgb[0][x][y][1] = green;
            // Vertically
            green = 2 * (ng + tc + sg) - (nc + sc);
            green >>= 2;
            if (green < 0)
                green = 0;
            rgb[1][x][y][1] = green;
        }
    }
    // Interpolate R & B
    for (int dir = 0; dir < 2; dir++) {
        for (int y = 3; y < maxy - miny - 3; y++) {
            for (int x = 3; x < maxx - minx - 3; x++) {
                int color = fc(y + miny, x + minx);
                if (color == 1 || color == 3) {
                    // We need to interpolate both red and blue
                    int c = fc(y + 1 + miny, x + minx);
                    int tg = rgb[dir][x][y][1];
                    int ng = rgb[dir][x][y - 1][1];
                    int sg = rgb[dir][x][y + 1][1];
                    int eg = rgb[dir][x + 1][y][1];
                    int wg = rgb[dir][x - 1][y][1];
                    int nc = rgb[dir][x][y - 1][c];
                    int sc = rgb[dir][x][y + 1][c];
                    int wo = rgb[dir][x - 1][y][2 - c];
                    int eo = rgb[dir][x + 1][y][2 - c];
                    int val = tg + ((wo + eo - ng - sg) >> 1);
                    if (val < 0)
                        val = 0;
                    rgb[dir][x][y][2 - c] = val;
                    val = tg + ((nc + sc - ng - sg) >> 1);
                    if (val < 0)
                        val = 0;
                    rgb[dir][x][y][c] = val;
                } else {
                    /*
                    This pixel is either red or blue so only one of those needs
                    to be interpolated
                     */
                    int c = 2 - color;
                    int tg = rgb[dir][x][y][1];
                    int nwg = rgb[dir][x - 1][y - 1][1];
                    int seg = rgb[dir][x + 1][y + 1][1];
                    int swg = rgb[dir][x - 1][y + 1][1];
                    int neg = rgb[dir][x + 1][y - 1][1];
                    int nwc = rgb[dir][x - 1][y - 1][c];
                    int nec = rgb[dir][x + 1][y - 1][c];
                    int swc = rgb[dir][x - 1][y + 1][c];
                    int sec = rgb[dir][x + 1][y + 1][c];
                    int val = tg + ((nwc + nec + sec + swc - nwg - neg - swg - seg) >> 2);
                    if (val < 0)
                        val = 0;
                    rgb[dir][x][y][c] = val;
                }
                xyz[0] = xyz[1] = xyz[2] = 0.5;
                // Convert to cielab
                for (int i = 0; i < 3; i++) {
                    xyz[0] += xyz_cam[0][i] * rgb[dir][x][y][i];
                    xyz[1] += xyz_cam[1][i] * rgb[dir][x][y][i];
                    xyz[2] += xyz_cam[2][i] * rgb[dir][x][y][i];
                }
                xyz[0] = cbrt[Math.max(0, (int) Math.min(xyz[0], 65535.0))];
                xyz[1] = cbrt[Math.max(0, (int) Math.min(xyz[1], 65535.0))];
                xyz[2] = cbrt[Math.max(0, (int) Math.min(xyz[2], 65535.0))];
                lab[dir][x][y][0] = Math.max(0, (int) (64.0 * (116.0 * xyz[1] - 16.0)));
                lab[dir][x][y][1] = 0x8000 + 10 * (int) (64.0 * 500.0 * (xyz[0] - xyz[1]));
                lab[dir][x][y][2] = 0x8000 + 10 * (int) (64.0 * 200.0 * (xyz[1] - xyz[2]));
            }
        }
    }

    // Calculate the homogeneity maps
    int ldiff[][] = new int[2][4];
    int abdiff[][] = new int[2][4];
    int dx[] = { -1, 1, 0, 0 };
    int dy[] = { 0, 0, -1, 1 };
    for (int y = 2; y < maxy - miny - 2; y++) {
        for (int x = 2; x < maxx - minx - 2; x++) {
            for (int d = 0; d < 2; d++) {
                for (int i = 0; i < 4; i++) {
                    ldiff[d][i] = Math.abs(lab[d][x][y][0] - lab[d][x + dx[i]][y + dy[i]][0]);
                    int da = lab[d][x][y][1] - lab[d][x + dx[i]][y + dy[i]][1];
                    int db = lab[d][x][y][1] - lab[d][x + dx[i]][y + dy[i]][1];
                    abdiff[d][i] = da * da + db * db;
                }
            }
            int leps = Math.min(Math.max(ldiff[0][0], ldiff[0][1]), Math.max(ldiff[1][2], ldiff[1][3]));
            int abeps = Math.min(Math.max(abdiff[0][0], abdiff[0][1]), Math.max(abdiff[1][2], abdiff[1][3]));
            for (int d = 0; d < 2; d++) {
                for (int i = 0; i < 4; i++) {
                    if (ldiff[d][i] <= leps && abdiff[d][i] <= abeps) {
                        homo[d][x][y]++;
                    }
                }
            }
        }
    }

    int dstMinx = Math.max((int) area.getMinX(), 5);
    int dstMiny = Math.max((int) area.getMinY(), 5);
    int dstMaxy = Math.min((int) area.getMaxY(), getHeight() - 5);
    int dstMaxx = Math.min((int) area.getMaxX(), getWidth() - 5);
    for (int row = dstMiny; row < dstMaxy; row++) {
        for (int col = dstMinx; col < dstMaxx; col++) {
            int hm0 = 0, hm1 = 0;
            for (int i = row - miny - 1; i <= row - miny + 1; i++) {
                for (int j = col - minx - 1; j <= col - minx + 1; j++) {
                    hm0 += homo[0][j][i];
                    hm1 += homo[1][j][i];
                }
            }
            if (hm0 < hm1) {
                dst.setPixel(col, row, rgb[1][col - minx][row - miny]);
            } else if (hm0 > hm1) {
                dst.setPixel(col, row, rgb[0][col - minx][row - miny]);
            } else {
                for (int i = 0; i < 3; i++) {
                    rgb[0][col - minx][row - miny][i] += rgb[1][col - minx][row - miny][i];
                    rgb[0][col - minx][row - miny][i] /= 2;
                }
                dst.setPixel(col, row, rgb[0][col - minx][row - miny]);
            }
        }
    }
    long dur = System.currentTimeMillis() - entryTime;
    log.debug("exit: computeRectAHD in " + dur + "ms");
}

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

/**
 * //from  w w  w .java  2s  .c o m
 *
 * @param mouseEvent a <code>MouseEvent</code> value
 */
public void mouseReleased(MouseEvent mouseEvent) {
    firstMouseEvent = null;
    if (dragType == DRAG_TYPE_SELECT && photos != null) {

        // Find out thumbails inside the selection rectangle

        // First lets restrict search to those rows that intersect with selection
        int topRow = (int) dragSelectionRect.getMinY() / rowHeight;
        int bottomRow = ((int) dragSelectionRect.getMaxY() / rowHeight) + 1;
        int startPhoto = topRow * columnsToPaint;
        int endPhoto = bottomRow * columnsToPaint;
        if (endPhoto > photos.size()) {
            endPhoto = photos.size();
        }

        // Find out which photos are selected
        for (int n = startPhoto; n < endPhoto; n++) {
            /*
             Performance optimization: Since getPhotoBounds() needs access 
             to photo thumbnail which may not yet be loaded we will do first 
             a rough check of if the table cell is in the selection area.
             */
            Rectangle cellRect = getPhotoCellBounds(n);
            if (dragSelectionRect.intersects(cellRect)) {
                Rectangle photoRect = getPhotoBounds(n);
                if (dragSelectionRect.intersects(photoRect)) {
                    selection.add(photos.get(n));
                    repaintPhoto(photos.get(n));
                }
            }
        }
        fireSelectionChangeEvent();
        // Redrw the selection area so that the selection rectangle is not shown anymore
        Rectangle repaintRect = dragSelectionRect;
        if (lastDragSelectionRect != null) {
            repaintRect = dragSelectionRect.union(lastDragSelectionRect);
        }
        repaint((int) repaintRect.getX() - 1, (int) repaintRect.getY() - 1, (int) repaintRect.getWidth() + 2,
                (int) repaintRect.getHeight() + 2);

        dragSelectionRect = null;
        lastDragSelectionRect = null;
        // Notify the mouse click handler that it has to do nothing
        dragJustEnded = true;
    }
}

From source file:org.photovault.swingui.PhotoCollectionThumbView.java

protected void handleSelectionDragEvent(MouseEvent e) {
    dragSelectionRect = new Rectangle(firstMouseEvent.getX(), firstMouseEvent.getY(), 0, 0);
    dragSelectionRect.add(e.getX(), e.getY());

    // Determine which area needs to be redrawn. If there is a selection marker rectangle already drawn
    // the redraw are must be union of the previous and current areas (current area can be also smaller!
    Rectangle repaintRect = dragSelectionRect;
    if (lastDragSelectionRect != null) {
        repaintRect = dragSelectionRect.union(lastDragSelectionRect);
    }//w  ww.  j av  a  2s  .  co m
    repaint((int) repaintRect.getX() - 1, (int) repaintRect.getY() - 1, (int) repaintRect.getWidth() + 2,
            (int) repaintRect.getHeight() + 2);
}