Example usage for java.awt Image getWidth

List of usage examples for java.awt Image getWidth

Introduction

In this page you can find the example usage for java.awt Image getWidth.

Prototype

public abstract int getWidth(ImageObserver observer);

Source Link

Document

Determines the width of the image.

Usage

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

public boolean drawImage(Image arg0, int arg1, int arg2, ImageObserver arg3) {
    SVGImage image = (SVGImage) arg0;/*w w  w . jav a 2s .c o  m*/

    Element currentElement = createElement("image"); //$NON-NLS-1$
    currentElement.setAttribute("xlink:href", image.getUrl()); //$NON-NLS-1$
    currentElement.setAttribute("x", toString(arg1)); //$NON-NLS-1$
    currentElement.setAttribute("y", toString(arg2)); //$NON-NLS-1$
    currentElement.setAttribute("width", Integer.toString(arg0.getWidth(arg3))); //$NON-NLS-1$
    currentElement.setAttribute("height", Integer.toString(arg0.getHeight(arg3))); //$NON-NLS-1$
    if (clip != null)
        currentElement.setAttribute("clip-path", "url(#clip" + clip.hashCode() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    appendChild(currentElement);

    return true;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java

/**
 * @param content/*from  w  w  w .ja  va  2s .  c  o m*/
 * @param image
 */
protected boolean drawImage(final RenderableReplacedContentBox content, Image image) {
    final StyleSheet layoutContext = content.getStyleSheet();
    final boolean shouldScale = layoutContext.getBooleanStyleProperty(ElementStyleKeys.SCALE);

    final int x = (int) StrictGeomUtility.toExternalValue(content.getX());
    final int y = (int) StrictGeomUtility.toExternalValue(content.getY());
    final int width = (int) StrictGeomUtility.toExternalValue(content.getWidth());
    final int height = (int) StrictGeomUtility.toExternalValue(content.getHeight());

    if (width == 0 || height == 0) {
        LogicalPageDrawable.logger.debug("Error: Image area is empty: " + content);
        return false;
    }

    WaitingImageObserver obs = new WaitingImageObserver(image);
    obs.waitImageLoaded();
    final int imageWidth = image.getWidth(obs);
    final int imageHeight = image.getHeight(obs);
    if (imageWidth < 1 || imageHeight < 1) {
        return false;
    }

    final Rectangle2D.Double drawAreaBounds = new Rectangle2D.Double(x, y, width, height);
    final AffineTransform scaleTransform;

    final Graphics2D g2;
    if (shouldScale == false) {
        double deviceScaleFactor = 1;
        final double devResolution = metaData.getNumericFeatureValue(OutputProcessorFeature.DEVICE_RESOLUTION);
        if (metaData.isFeatureSupported(OutputProcessorFeature.IMAGE_RESOLUTION_MAPPING)) {
            if (devResolution != 72.0 && devResolution > 0) {
                // Need to scale the device to its native resolution before attempting to draw the image..
                deviceScaleFactor = (72.0 / devResolution);
            }
        }

        final int clipWidth = Math.min(width, (int) Math.ceil(deviceScaleFactor * imageWidth));
        final int clipHeight = Math.min(height, (int) Math.ceil(deviceScaleFactor * imageHeight));
        final ElementAlignment horizontalAlignment = (ElementAlignment) layoutContext
                .getStyleProperty(ElementStyleKeys.ALIGNMENT);
        final ElementAlignment verticalAlignment = (ElementAlignment) layoutContext
                .getStyleProperty(ElementStyleKeys.VALIGNMENT);
        final int alignmentX = (int) RenderUtility.computeHorizontalAlignment(horizontalAlignment, width,
                clipWidth);
        final int alignmentY = (int) RenderUtility.computeVerticalAlignment(verticalAlignment, height,
                clipHeight);

        g2 = (Graphics2D) getGraphics().create();
        g2.clip(drawAreaBounds);
        g2.translate(x, y);
        g2.translate(alignmentX, alignmentY);
        g2.clip(new Rectangle2D.Float(0, 0, clipWidth, clipHeight));
        g2.scale(deviceScaleFactor, deviceScaleFactor);

        scaleTransform = null;
    } else {
        g2 = (Graphics2D) getGraphics().create();
        g2.clip(drawAreaBounds);
        g2.translate(x, y);
        g2.clip(new Rectangle2D.Float(0, 0, width, height));

        final double scaleX;
        final double scaleY;

        final boolean keepAspectRatio = layoutContext
                .getBooleanStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO);
        if (keepAspectRatio) {
            final double scaleFactor = Math.min(width / (double) imageWidth, height / (double) imageHeight);
            scaleX = scaleFactor;
            scaleY = scaleFactor;
        } else {
            scaleX = width / (double) imageWidth;
            scaleY = height / (double) imageHeight;
        }

        final int clipWidth = (int) (scaleX * imageWidth);
        final int clipHeight = (int) (scaleY * imageHeight);

        final ElementAlignment horizontalAlignment = (ElementAlignment) layoutContext
                .getStyleProperty(ElementStyleKeys.ALIGNMENT);
        final ElementAlignment verticalAlignment = (ElementAlignment) layoutContext
                .getStyleProperty(ElementStyleKeys.VALIGNMENT);
        final int alignmentX = (int) RenderUtility.computeHorizontalAlignment(horizontalAlignment, width,
                clipWidth);
        final int alignmentY = (int) RenderUtility.computeVerticalAlignment(verticalAlignment, height,
                clipHeight);

        g2.translate(alignmentX, alignmentY);

        final Object contentCached = content.getContent().getContentCached();
        if (contentCached instanceof Image) {
            image = (Image) contentCached;
            scaleTransform = null;
        } else if (metaData.isFeatureSupported(OutputProcessorFeature.PREFER_NATIVE_SCALING) == false) {
            image = RenderUtility.scaleImage(image, clipWidth, clipHeight,
                    RenderingHints.VALUE_INTERPOLATION_BICUBIC, true);
            content.getContent().setContentCached(image);
            obs = new WaitingImageObserver(image);
            obs.waitImageLoaded();
            scaleTransform = null;
        } else {
            scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
        }
    }

    while (g2.drawImage(image, scaleTransform, obs) == false) {
        obs.waitImageLoaded();
        if (obs.isError()) {
            LogicalPageDrawable.logger.warn("Error while loading the image during the rendering.");
            break;
        }
    }

    g2.dispose();
    return true;
}

From source file:org.rdv.viz.image.ImageViz.java

/**
 * Print the displayed image. If no image is being displayed, this will method
 * will do nothing./*from  w w  w  . j av a2s .c o  m*/
 */
private void printImage() {
    // get the displayed image
    final Image displayedImage = getDisplayedImage();
    if (displayedImage == null) {
        return;
    }

    // setup a print job
    PrinterJob printJob = PrinterJob.getPrinterJob();

    // set the renderer for the image
    printJob.setPrintable(new Printable() {
        public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
            //we only have one page to print
            if (pageIndex != 0) {
                return Printable.NO_SUCH_PAGE;
            }

            Graphics2D g2d = (Graphics2D) g;

            // move to corner of imageable page
            g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

            // get page dimensions
            double pageWidth = pageFormat.getImageableWidth();
            double pageHeight = pageFormat.getImageableHeight();

            // get image dimensions
            int imageWidth = displayedImage.getWidth(null);
            int imageHeight = displayedImage.getHeight(null);

            // get scale factor for image
            double widthScale = pageWidth / imageWidth;
            double heightScale = pageHeight / imageHeight;
            double scale = Math.min(widthScale, heightScale);

            // draw image with width and height scaled to page
            int scaledWidth = (int) (scale * imageWidth);
            int scaledHeight = (int) (scale * imageHeight);
            g2d.drawImage(displayedImage, 0, 0, scaledWidth, scaledHeight, null);

            return Printable.PAGE_EXISTS;
        }

    });

    // set the job name to the channel name (plus jpg extension)
    // this is used as a hint for a file name when printing to file
    String channelName = (String) channels.iterator().next();
    String jobName = channelName.replace("/", " - ");
    if (!jobName.endsWith(".jpg")) {
        jobName += ".jpg";
    }
    printJob.setJobName(jobName);

    // show the print dialog and print if ok clicked
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (PrinterException pe) {
            JOptionPane.showMessageDialog(null, "Failed to print image.", "Print Image Error",
                    JOptionPane.ERROR_MESSAGE);
            pe.printStackTrace();
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * @see Graphics#drawImage(Image, int, int, int, int, int, int, int, int, Color, ImageObserver)
 *//*w w w. ja  va 2 s . c  o  m*/
@Override
public boolean drawImage(final Image img, final int dx1, final int dy1, final int dx2, final int dy2,
        final int sx1, final int sy1, final int sx2, final int sy2, final Color bgcolor,
        final ImageObserver observer) {
    waitForImage(img);
    final double dwidth = (double) dx2 - dx1;
    final double dheight = (double) dy2 - dy1;
    final double swidth = (double) sx2 - sx1;
    final double sheight = (double) sy2 - sy1;

    // if either width or height is 0, then there is nothing to draw
    if (dwidth == 0 || dheight == 0 || swidth == 0 || sheight == 0) {
        return true;
    }

    final double scalex = dwidth / swidth;
    final double scaley = dheight / sheight;

    final double transx = sx1 * scalex;
    final double transy = sy1 * scaley;
    final AffineTransform tx = AffineTransform.getTranslateInstance(dx1 - transx, dy1 - transy);
    tx.scale(scalex, scaley);

    final BufferedImage mask = new BufferedImage(img.getWidth(observer), img.getHeight(observer),
            BufferedImage.TYPE_BYTE_BINARY);
    final Graphics g = mask.getGraphics();
    g.fillRect(sx1, sy1, (int) swidth, (int) sheight);
    drawImage(img, mask, tx, null, observer);
    g.dispose();
    return true;
}

From source file:org.yccheok.jstock.gui.Utils.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }//from w w w  .  j  a  va  2  s.co m

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see e661 Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        // Determine the type of transparency of the new buffered image
        int transparency = Transparency.OPAQUE;
        if (hasAlpha) {
            transparency = Transparency.BITMASK;
        }

        // Create the buffered image
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }

    if (bimage == null) {
        // Create a buffered image using the default color model
        int type = BufferedImage.TYPE_INT_RGB;
        if (hasAlpha) {
            type = BufferedImage.TYPE_INT_ARGB;
        }
        bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawImage(ImageRenderEvent ire) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(ire);//from   w ww.  j a v  a 2  s.  c  om
    }
    if (ire.getImage() == null || ire.getLocation() == null) {
        return;
    }

    java.awt.Image img = null;

    if (ire.getImage() instanceof EmbeddedImage) {
        try {
            byte[] data = Base64.decodeBase64(((EmbeddedImage) ire.getImage()).getData().getBytes());

            img = createImage(data);
        } catch (Exception ilex) {
            throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, ilex);
        }
    } else if (ire.getImage().getSource() != ImageSourceType.FILE
            && ire.getImage().getSource() != ImageSourceType.REPORT) {
        try {
            final String sUrl = ire.getImage().getURL();
            img = (java.awt.Image) _ids.loadImage(SecurityUtil.newURL(sUrl));
        } catch (ChartException ilex) {
            // Ignore the invalid path, and log it only
            logger.log(new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, ilex));
        } catch (MalformedURLException muex) {
            throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, muex);
        }
    }

    if (img == null) {
        return;
    }

    Location loc = ire.getLocation();
    Position pos = ire.getPosition();
    if (pos == null) {
        pos = Position.INSIDE_LITERAL;
    }

    ImageObserver io = (ImageObserver) _ids.getObserver();

    final boolean bSizeSet = ire.getWidth() * ire.getHeight() > 0;
    int width = bSizeSet ? ire.getWidth() : img.getWidth(io);
    int height = bSizeSet ? ire.getHeight() : img.getHeight(io);
    int x = (int) loc.getX();
    int y = (int) loc.getY();

    switch (pos.getValue()) {
    case Position.INSIDE:
    case Position.OUTSIDE:
        x -= width / 2;
        y -= height / 2;
        break;
    case Position.LEFT:
        x -= width;
        y -= height / 2;
        break;
    case Position.RIGHT:
        y -= height / 2;
        break;
    case Position.ABOVE:
        x -= width / 2;
        y -= height;
        break;
    case Position.BELOW:
        x -= width / 2;
        break;
    }

    _g2d.drawImage(img, x, y, width, height, io);
}

From source file:tarea1.controlador.java

public void seleccionOpcion(int z) throws IOException, Exception {
    switch (z) {/* w  ww .j  a  v a  2  s.c  o  m*/
    case 1: {
        //ELEGIR UN ARCHIVO//
        //EN CASO DE QUERER CAMBIAR EL TIPO DE ARCHIVO.
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "bmp");
        JFileChooser abrir = new JFileChooser();
        abrir.setFileSelectionMode(JFileChooser.FILES_ONLY);
        abrir.setFileFilter(filter);
        abrir.setCurrentDirectory(new File(System.getProperty("user.home")));
        int result = abrir.showOpenDialog(inicio);
        if (result == JFileChooser.APPROVE_OPTION) {
            // se seleciona el archivo de imagen original
            File selectedFile = abrir.getSelectedFile();
            ruta = selectedFile.getAbsolutePath();
            System.out.println("El archivo es: " + ruta); //ruta
            img = ImageIO.read(new File(ruta)); //se lee el archivo
            rotate = false;
            zoomv = false;
            escalav = false;
            brillos = false;
            contrastes = false;
            undoDelete = false;
            undoIndex = 0;
            Change();
            inicio.setTitle("PDI: Tarea 3 -" + ruta);

        }
    }
        break;//end case 1

    case 2: //imagen en negativo
    {

        //se crea un buffer
        BufferedImage imagenNegativa = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);
        //se convierten los colores a negativo y se va guardando en el buffer
        for (int y = 0; y < alto; y++) {
            for (int x = 0; x < ancho; x++) {
                int p = img.getRGB(x, y);
                //obtenermos el valor r g b a de cada pixel
                // int a = (p>>24)&0xff;
                int r = (p >> 16) & 0xff;
                int g = (p >> 8) & 0xff;
                int b = p & 0xff;
                //se resta el rbg
                r = truncate(255 - r);
                g = truncate(255 - g);
                b = truncate(255 - b);
                //se guarda el rgb
                p = (r << 16) | (g << 8) | b;
                imagenNegativa.setRGB(x, y, p);
            }
        }
        //PARA LOS ROTACIONES
        img = imagenNegativa;

        ancho = img.getWidth();
        alto = img.getHeight();
        //se crea un buffer
        imagenNegativa = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);
        //se convierten los colores a negativo y se va guardando en el buffer
        for (int y = 0; y < alto; y++) {
            for (int x = 0; x < ancho; x++) {
                int p = original.getRGB(x, y);
                //obtenermos el valor r g b a de cada pixel
                int a = (p >> 24) & 0xff;
                int r = (p >> 16) & 0xff;
                int g = (p >> 8) & 0xff;
                int b = p & 0xff;
                //se resta el rbg
                r = 255 - r;
                g = 255 - g;
                b = 255 - b;
                //se guarda el rgb
                p = (a << 24) | (r << 16) | (g << 8) | b;
                imagenNegativa.setRGB(x, y, p);
            }
        }
        img = imagenNegativa;

        Change();
    }
        break;//end case 2

    case 3: //flip imagen vertical
    {

        //buffer para la imagen
        BufferedImage mirrorimgV = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);
        //recorremos pixel a pixel tooooooooooooodo el buffer
        for (int i = 0; i < alto; i++) {
            for (int izquierda = 0, derecha = ancho - 1; izquierda < alto; izquierda++, derecha--) {
                int p = img.getRGB(izquierda, i);
                mirrorimgV.setRGB(derecha, i, p);
            }
        }
        img = mirrorimgV;
        Change();

    }
        break;//end case 3

    case 4://flip imagen horizontal
    {

        BufferedImage mirrorimgH = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);

        for (int i = 0; i < ancho; i++) {
            for (int arriba = 0, abajo = alto - 1; arriba < alto; arriba++, abajo--) {
                int p = img.getRGB(i, arriba);
                mirrorimgH.setRGB(i, abajo, p);
            }
        }
        img = mirrorimgH;
        Change();

    }
        break;//end case 4

    case 5: { //boton de reset

        //RESET
        File f = null;
        //leer image
        try {
            f = new File(ruta);
            rotate = false;
            zoomv = false;
            escalav = false;
            brillos = false;
            contrastes = false;
            undoDelete = false;
            undoIndex = 0;
            img = ImageIO.read(f);
        } catch (IOException e) {
            System.out.println(e);
        }

        Change();

    }
        break; //end case 5

    case 6: { //leer en formato binario

        FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "bmp");
        JFileChooser abrir = new JFileChooser();
        abrir.setFileSelectionMode(JFileChooser.FILES_ONLY);
        abrir.setFileFilter(filter);
        //abrir.setCurrentDirectory(new File(System.getProperty("user.home")));
        abrir.setCurrentDirectory(new File(System.getProperty("user.dir")));
        int result = abrir.showOpenDialog(inicio);
        if (result == JFileChooser.APPROVE_OPTION) {

            try {
                File selectedFile = abrir.getSelectedFile();
                ruta = selectedFile.getAbsolutePath();

                FileInputStream is = null;

                is = new FileInputStream(ruta);
                bmp.read(is);
                System.out.println("aqui");
                MemoryImageSource mis = bmp.crearImageSource();
                System.out.println("hola");
                Image im = Toolkit.getDefaultToolkit().createImage(mis);
                //Para poder colorcarlo en el label
                //Image image = createImage(new MemoryImageSource(bmp.crearImageSource()));
                BufferedImage newImage = new BufferedImage(im.getWidth(null), im.getHeight(null),
                        BufferedImage.TYPE_INT_RGB);
                //obtenemos la imagen que si se puede desplgar
                Graphics2D g = newImage.createGraphics();
                g.drawImage(im, 0, 0, null);
                g.dispose();

                img = newImage;
                rotate = false;
                zoomv = false;
                escalav = false;
                brillos = false;
                contrastes = false;
                undoDelete = false;
                undoIndex = 0;
                Change();

                //add img info
                inicio.setTitle("PDI: Tarea 3 -" + ruta);
                //dimensiones, profundidad de bits, Mb ocupados
                content = ("Size: " + (bmp.tamArchivo) / 1000 + "kb\nDimension: " + bmp.ancho + " x " + bmp.alto
                        + "\nBpp: " + bmp.bitsPorPixel + "bits");
                ancho = bmp.ancho;
                alto = bmp.alto;

            } catch (Exception ex) {
                Logger.getLogger(controlador.class.getName()).log(Level.SEVERE, null, ex);
            }

        } //end approval if
    }
        break; //end case 6

    //girar CW
    case 7: {

        BufferedImage new_Image = new BufferedImage(alto, ancho, BufferedImage.TYPE_INT_RGB);
        for (int i = 0; i < ancho; i++) {
            for (int j = 0; j < alto; j++) {
                int p = img.getRGB(i, j);
                new_Image.setRGB(alto - j - 1, i, p);

            }
        }

        img = new_Image;
        Change();

    }
        break;//end case 7

    //girar CCW
    case 8: {

        BufferedImage new_Image = new BufferedImage(alto, ancho, BufferedImage.TYPE_INT_RGB);
        for (int i = 0; i < ancho; i++) {
            for (int j = 0; j < alto; j++) {
                int p = img.getRGB(i, j);
                new_Image.setRGB(j, ancho - i - 1, p);

            }
        }

        img = new_Image;
        Change();

    }
        break;//end case 8

    case 9: { //Guardar Imagen

        FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "bmp");
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileFilter(filter);
        fileChooser.setDialogTitle("Save");
        fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
        int userSelection = fileChooser.showSaveDialog(inicio);
        if (userSelection == JFileChooser.APPROVE_OPTION) {
            File fileToSave = fileChooser.getSelectedFile();
            System.out.println("Save as file: " + fileToSave.getAbsolutePath() + ".bmp");
            System.out.println("Save as: " + fileToSave.getName());
            bmp.saveMyLifeTonight(fileToSave, img);
        }
    }
        break;

    case 10: {
        //free rotation
        double anguloCartesiano = inicio.optionr;
        double aux;
        if (rotate == false) {
            original = img;
        }
        //para la ilusion de rotar sobre la "misma imagen"
        if (anguloCartesiano < 0) {

            aux = anguloCartesiano;
            anguloCartesiano = anguloCartesiano + angulo;
            angulo = anguloCartesiano;

        } else if (anguloCartesiano > 0) {

            aux = anguloCartesiano;
            anguloCartesiano = angulo + anguloCartesiano;
            angulo = anguloCartesiano;

        }

        anguloCartesiano = anguloCartesiano * Math.PI / 180;

        //CC coordinates
        int x, y;
        double distance, anguloPolar;
        int pisoX, techoX, pisoY, techoY;
        double rasterX, rasterY;
        // colores de los pixeles
        Color colorTL = null, colorTR, colorBL, colorBR = null;
        // interpolaciones
        double intX, intY;
        double rojoT, verdeT, azulT;
        double rojoB, verdeB, azulB;

        int centroX, centroY;

        centroX = original.getWidth() / 2;
        centroY = original.getHeight() / 2;

        BufferedImage imagenRotada = new BufferedImage(original.getWidth(), original.getHeight(),
                BufferedImage.TYPE_INT_ARGB);//fondo transparente

        for (int i = 0; i < original.getHeight(); ++i)
            for (int j = 0; j < original.getWidth(); ++j) {
                // convert raster to Cartesian
                x = j - centroX;
                y = centroY - i;

                // convert Cartesian to polar
                distance = Math.sqrt(x * x + y * y);
                anguloPolar = 0.0;
                if (x == 0) {
                    if (y == 0) {
                        // centre of image, no rotation needed
                        imagenRotada.setRGB(j, i, original.getRGB(j, i));

                        continue;
                    } else if (y < 0)
                        anguloPolar = 1.5 * Math.PI;
                    else
                        anguloPolar = 0.5 * Math.PI;
                } else
                    anguloPolar = Math.atan2((double) y, (double) x);

                // 
                anguloPolar -= anguloCartesiano;

                //polr a carte
                rasterX = distance * Math.cos(anguloPolar);
                rasterY = distance * Math.sin(anguloPolar);

                // cartesiano a raster
                rasterX = rasterX + (double) centroX;
                rasterY = (double) centroY - rasterY;

                pisoX = (int) (Math.floor(rasterX));
                pisoY = (int) (Math.floor(rasterY));
                techoX = (int) (Math.ceil(rasterX));
                techoY = (int) (Math.ceil(rasterY));

                // check bounds /// AQUIWWIUEI
                if (pisoX < 0 || techoX < 0 || pisoX >= original.getWidth() || techoX >= original.getWidth()
                        || pisoY < 0 || techoY < 0 || pisoY >= original.getHeight()
                        || techoY >= original.getHeight())
                    continue;

                intX = rasterX - (double) pisoX;
                intY = rasterY - (double) pisoY;

                colorTL = new Color(original.getRGB(pisoX, pisoY));
                colorTR = new Color(original.getRGB(techoX, pisoY));
                colorBL = new Color(original.getRGB(pisoX, techoY));
                colorBR = new Color(original.getRGB(techoX, techoY));

                // interpolacion horizontal top
                rojoT = (1 - intX) * colorTL.getRed() + intX * colorTR.getRed();
                verdeT = (1 - intX) * colorTL.getGreen() + intX * colorTR.getGreen();
                azulT = (1 - intX) * colorTL.getBlue() + intX * colorTR.getBlue();
                // interpolacion horizontal bot
                rojoB = (1 - intX) * colorBL.getRed() + intX * colorBR.getRed();
                verdeB = (1 - intX) * colorBL.getGreen() + intX * colorBR.getGreen();
                azulB = (1 - intX) * colorBL.getBlue() + intX * colorBR.getBlue();
                // interpolacion vertical
                int p = original.getRGB(j, i);
                int a = (p >> 24) & 0xff;
                int r = (p >> 16) & 0xff;
                int g = (p >> 8) & 0xff;
                int b = p & 0xff;
                r = truncate(Math.round((1 - intY) * rojoT + intY * rojoB));
                g = truncate(Math.round((1 - intY) * verdeT + intY * verdeB));
                b = truncate(Math.round((1 - intY) * azulT + intY * azulB));
                p = (a << 24) | (r << 16) | (g << 8) | b;
                imagenRotada.setRGB(j, i, p);

            }
        img = imagenRotada;
        rotate = true;
        inicio.jLabel3.setBounds(0, 0, ancho, alto);
        ImageIcon icon = new ImageIcon(img);
        inicio.jLabel3.setIcon(icon);

    }
        break; //case 10

    case 11: { //histogram

        //para recorrer todos los valores y obtener los samples
        /*
        for (y) {
            for (x) {
               pixel = raster.getDataElements(x, y, pixel);
            }
        }
                            */
        int BINS = 256;
        HistogramDataset dataset = new HistogramDataset();
        Raster raster = img.getRaster();

        double[] r = new double[ancho * alto];
        ChartPanel panelB = null;
        ChartPanel panelG = null;
        ChartPanel panelR = null;
        ChartPanel panel;

        if (bmp.bitsPorPixel == 1) {

            r = raster.getSamples(0, 0, ancho, alto, 0, r);
            ColorModel ColorM = img.getColorModel();

            dataset.addSeries("Grey", r, BINS);

            //de aqui para abajo es el plotting
            // chart all
            JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
                    PlotOrientation.VERTICAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
            renderer.setBarPainter(new StandardXYBarPainter());

            Paint[] paintArray = { new Color(0x80ff0000, true) };
            plot.setDrawingSupplier(
                    new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
            panel = new ChartPanel(chart);
            panel.setMouseWheelEnabled(true);

        } else {

            r = raster.getSamples(0, 0, ancho, alto, 0, r);
            dataset.addSeries("Red", r, BINS);
            r = raster.getSamples(0, 0, ancho, alto, 1, r);
            dataset.addSeries("Green", r, BINS);
            r = raster.getSamples(0, 0, ancho, alto, 2, r);
            dataset.addSeries("Blue", r, BINS);

            //de aqui para abajo es el plotting
            // chart all
            JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
                    PlotOrientation.VERTICAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
            renderer.setBarPainter(new StandardXYBarPainter());
            // translucent red, green & blue
            Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true),
                    new Color(0x800000ff, true) };
            plot.setDrawingSupplier(
                    new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
            panel = new ChartPanel(chart);
            panel.setMouseWheelEnabled(true);

            //CHART Red
            HistogramDataset datasetR = new HistogramDataset();
            r = raster.getSamples(0, 0, ancho, alto, 0, r);
            datasetR.addSeries("Red", r, BINS);
            JFreeChart chartR = ChartFactory.createHistogram("Histogram B", "Value", "Count", datasetR,
                    PlotOrientation.VERTICAL, true, true, false);
            XYPlot plotR = (XYPlot) chartR.getPlot();
            XYBarRenderer rendererR = (XYBarRenderer) plotR.getRenderer();
            rendererR.setBarPainter(new StandardXYBarPainter());
            // translucent red, green & blue
            Paint[] paintArrayR = { new Color(0x80ff0000, true)

            };
            plotR.setDrawingSupplier(
                    new DefaultDrawingSupplier(paintArrayR, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
            panelR = new ChartPanel(chartR);
            panelR.setMouseWheelEnabled(true);

            //CHART GREEN

            HistogramDataset datasetG = new HistogramDataset();
            r = raster.getSamples(0, 0, ancho, alto, 1, r);
            datasetG.addSeries("Green", r, BINS);
            JFreeChart chartG = ChartFactory.createHistogram("Histogram G ", "Value", "Count", datasetG,
                    PlotOrientation.VERTICAL, true, true, false);
            XYPlot plotG = (XYPlot) chartG.getPlot();
            XYBarRenderer rendererG = (XYBarRenderer) plotG.getRenderer();
            rendererG.setBarPainter(new StandardXYBarPainter());
            // translucent red, green & blue
            Paint[] paintArrayG = { new Color(0x8000ff00, true)

            };
            plotG.setDrawingSupplier(
                    new DefaultDrawingSupplier(paintArrayG, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
            panelG = new ChartPanel(chartG);
            panelG.setMouseWheelEnabled(true);

            //CHART BLUE

            HistogramDataset datasetB = new HistogramDataset();
            r = raster.getSamples(0, 0, ancho, alto, 2, r);
            datasetB.addSeries("Blue", r, BINS);
            JFreeChart chartB = ChartFactory.createHistogram("Histogram B ", "Value", "Count", datasetB,
                    PlotOrientation.VERTICAL, true, true, false);
            XYPlot plotB = (XYPlot) chartB.getPlot();
            XYBarRenderer rendererB = (XYBarRenderer) plotB.getRenderer();
            rendererB.setBarPainter(new StandardXYBarPainter());
            // translucent red, green & blue
            Paint[] paintArrayB = { new Color(0x800000ff, true)

            };
            plotB.setDrawingSupplier(
                    new DefaultDrawingSupplier(paintArrayB, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
            panelB = new ChartPanel(chartB);
            panelB.setMouseWheelEnabled(true);

        }

        //JTabbedPane jtp=new JTabbedPane();
        if (!viewH) {

            inicio.jTabbedPane1.addTab("Histogram", panel);
            inicio.jTabbedPane1.addTab("Histogram R", panelR);
            inicio.jTabbedPane1.addTab("Histogram G", panelG);
            inicio.jTabbedPane1.addTab("Histogram B", panelB);
            viewH = true;
        } else {
            inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram"));
            inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram R"));
            inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram G"));
            inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram B"));
            viewH = false;
        }

    }
        break;

    case 12: {
        //BRILLO
        int dif = inicio.brillo;

        if (brillos == false) {
            original = img;
        }
        int ancho = img.getWidth();
        int alto = img.getHeight();
        //se crea un buffer
        BufferedImage brillito = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);
        //se convierten los colores a negativo y se va guardando en el buffer
        for (int y = 0; y < alto; y++) {
            for (int x = 0; x < ancho; x++) {
                int p = original.getRGB(x, y);
                //obtenemos el valor r g b a de cada pixel
                int a = (p >> 24) & 0xff;
                int r = (p >> 16) & 0xff;
                int g = (p >> 8) & 0xff;
                int b = p & 0xff;
                //se resta el rbg
                r = truncate(r + dif);
                g = truncate(g + dif);
                b = truncate(b + dif);
                //se guarda el rgb
                p = (r << 16) | (g << 8) | b;
                brillito.setRGB(x, y, p);
            }
        }
        img = brillito;
        brillos = true;
        inicio.jLabel3.setBounds(0, 0, ancho, alto);
        ImageIcon icon = new ImageIcon(img);
        inicio.jLabel3.setIcon(icon);

    }
        break; //end case 12

    case 13: {
        //CONTRAST
        double dif = inicio.contraste;
        double level = Math.pow(((100.0 + dif) / 100.0), 2.0);

        if (contrastes == false) {
            original = img;
        }
        int ancho = original.getWidth();
        int alto = original.getHeight();
        BufferedImage contraste = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);

        for (int y = 0; y < alto; y++) {
            for (int x = 0; x < ancho; x++) {
                int p = original.getRGB(x, y);
                int a = (p >> 24) & 0xff;
                int r = (p >> 16) & 0xff;
                int g = (p >> 8) & 0xff;
                int b = p & 0xff;

                b = truncate((int) ((((((double) b / 255.0) - 0.5) * level) + 0.5) * 255.0));
                g = truncate((int) ((((((double) g / 255.0) - 0.5) * level) + 0.5) * 255.0));
                r = truncate((int) ((((((double) r / 255.0) - 0.5) * level) + 0.5) * 255.0));

                p = (r << 16) | (g << 8) | b;
                contraste.setRGB(x, y, p);
            }
        }
        img = contraste;
        contrastes = true;
        inicio.jLabel3.setBounds(0, 0, ancho, alto);
        ImageIcon icon = new ImageIcon(img);
        inicio.jLabel3.setIcon(icon);

    }
        break;// case 13

    case 14: {
        //UMBRALIZACION
        double u = inicio.umbral;
        if (inicio.jCheckBox1.isSelected()) {

            int ancho = img.getWidth();
            int alto = img.getHeight();

            BufferedImage contraste = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);

            for (int y = 0; y < alto; y++) {
                for (int x = 0; x < ancho; x++) {
                    int p = img.getRGB(x, y);

                    int a = (p >> 24) & 0xff;
                    int r = (p >> 16) & 0xff;
                    int g = (p >> 8) & 0xff;
                    int b = p & 0xff;

                    double mediana = (double) (r + b + g);
                    mediana /= 3;
                    int med = (int) Math.round(mediana);

                    b = med;
                    g = med;
                    r = med;

                    if (r <= u)
                        r = 0;
                    else
                        r = 255;

                    if (g <= u)
                        g = 0;
                    else
                        g = 255;

                    if (b <= u)
                        b = 0;
                    else
                        b = 255;

                    p = (r << 16) | (g << 8) | b;
                    contraste.setRGB(x, y, p);
                }
            }
            img = contraste;
            Change();
        }

    }
        break;

    case 15: {
        BufferedImage equalized = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);
        int r, g, b, a;
        int pixel = 0;

        //look up table rgb 
        int[] rhist = new int[256];
        int[] ghist = new int[256];
        int[] bhist = new int[256];

        for (int i = 0; i < rhist.length; i++)
            rhist[i] = 0;
        for (int i = 0; i < ghist.length; i++)
            ghist[i] = 0;
        for (int i = 0; i < bhist.length; i++)
            bhist[i] = 0;

        for (int i = 0; i < img.getWidth(); i++) {
            for (int j = 0; j < img.getHeight(); j++) {

                int red = new Color(img.getRGB(i, j)).getRed();
                int green = new Color(img.getRGB(i, j)).getGreen();
                int blue = new Color(img.getRGB(i, j)).getBlue();
                rhist[red]++;
                ghist[green]++;
                bhist[blue]++;

            }
        }

        //histograma color
        ArrayList<int[]> imageHist = new ArrayList<int[]>();
        imageHist.add(rhist);
        imageHist.add(ghist);
        imageHist.add(bhist);
        //lookup table
        ArrayList<int[]> imgLT = new ArrayList<int[]>();
        // llenar 
        rhist = new int[256];
        ghist = new int[256];
        bhist = new int[256];

        for (int i = 0; i < rhist.length; i++)
            rhist[i] = 0;
        for (int i = 0; i < ghist.length; i++)
            ghist[i] = 0;
        for (int i = 0; i < bhist.length; i++)
            bhist[i] = 0;

        long rojosT = 0;
        long verdesT = 0;
        long azulT = 0;

        // 
        float factorDeEscala = (float) (255.0 / (ancho * alto));

        for (int i = 0; i < rhist.length; i++) {
            rojosT += imageHist.get(0)[i];
            int valor = (int) (rojosT * factorDeEscala);
            if (valor > 255) {
                rhist[i] = 255;
            } else
                rhist[i] = valor;

            verdesT += imageHist.get(1)[i];
            int valg = (int) (verdesT * factorDeEscala);
            if (valg > 255) {
                ghist[i] = 255;
            } else
                ghist[i] = valg;

            azulT += imageHist.get(2)[i];
            int valb = (int) (azulT * factorDeEscala);
            if (valb > 255) {
                bhist[i] = 255;
            } else
                bhist[i] = valb;
        }

        imgLT.add(rhist);
        imgLT.add(ghist);
        imgLT.add(bhist);

        for (int i = 0; i < ancho; i++) {
            for (int j = 0; j < alto; j++) {

                // colores
                a = new Color(img.getRGB(i, j)).getAlpha();
                r = new Color(img.getRGB(i, j)).getRed();
                g = new Color(img.getRGB(i, j)).getGreen();
                b = new Color(img.getRGB(i, j)).getBlue();

                // nuevos valoooooores
                r = imgLT.get(0)[r];
                g = imgLT.get(1)[g];
                b = imgLT.get(2)[b];

                // rgb otra vez
                pixel = colorToRGB(a, r, g, b);

                //imagen final
                equalized.setRGB(i, j, pixel);

            }
        }

        img = equalized;
        Change();

    }
        break;

    case 16: {
        //zoom 
        double du = inicio.zoom;
        double u = du / 100;

        if (zoomv == false) {
            original = img;
        }
        BufferedImage zoom = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);

        for (int i = 0; i < zoom.getHeight(); ++i)
            for (int j = 0; j < zoom.getWidth(); ++j) {
                //nearest
                if (tipo == 1) {

                    int ax = (int) (Math.floor(i / u));
                    int ay = (int) (Math.floor(j / u));

                    int p = original.getRGB(ax, ay);
                    zoom.setRGB(i, j, p);
                }

                //bilinear
                if (tipo == 2) {

                }

                //no loss
                if (tipo == 0) {

                    int ax = (int) (i / u);
                    int ay = (int) (j / u);

                    int p = original.getRGB(ax, ay);
                    zoom.setRGB(i, j, p);
                }

            }
        img = zoom;
        zoomv = true;
        inicio.jLabel3.setBounds(0, 0, ancho, alto);
        ImageIcon icon = new ImageIcon(img);
        inicio.jLabel3.setIcon(icon);

    }
        break;

    case 17: {
        //escala
        double du = inicio.escala;
        double u = du / 100;

        if (escalav == false) {
            original = img;
        }
        int escalaX = (int) (ancho * u);
        int escalaY = (int) (alto * u);
        BufferedImage escala = new BufferedImage(escalaX, escalaY, BufferedImage.TYPE_INT_RGB);

        for (int i = 0; i < escala.getHeight(); ++i)
            for (int j = 0; j < escala.getWidth(); ++j) {
                //R(x,y):= A(x/ax, y/ay) 
                //R(x,y):= A(Floor x/10 ,Floor /10)

                //nearest
                if (tipo == 1) {

                    int ax = (int) (Math.floor(i / u));
                    int ay = (int) (Math.floor(j / u));

                    int p = original.getRGB(ax, ay);
                    escala.setRGB(i, j, p);
                }

                //bilinear
                if (tipo == 2) {

                }

                //no loss
                if (tipo == 0) {

                    int ax = (int) (i / u);
                    int ay = (int) (j / u);

                    int p = original.getRGB(ax, ay);
                    escala.setRGB(i, j, p);
                }

            }

        img = escala;
        escalav = true;
        inicio.jLabel3.setBounds(0, 0, ancho, alto);
        ImageIcon icon = new ImageIcon(img);
        inicio.jLabel3.setIcon(icon);
        content = ("Dimension: " + img.getWidth() + " x " + img.getHeight() + "\nBpp: " + bmp.bitsPorPixel
                + "bits");

    }
        break;

    case 18://prewitt both
    {

        BufferedImage aux = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);
        aux = img;
        BufferedImage y, x;

        float[][] arraya = { { -1, 0, 1 }, { -1, 0, 1 }, { -1, 0, 1 } };
        float[][] arrayb = { { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 },
                { -2, -1, 0, 1, 2 }, };

        float[][] arrayc = { { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 },
                { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 },
                { -3, -2, -1, 0, 1, 2, 3 }, };

        float[][] array = { { -1, -1, -1 }, { 0, 0, 0 }, { 1, 1, 1 } };
        float[][] array2 = { { -2, -2, -2, -2, -2 }, { -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2 }, };
        float[][] array3 = { { -3, -3, -3, -3, -3, -3, -3 }, { -2, -2, -2, -2, -2, -2, -2 },
                { -1, -1, -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1 },
                { 2, 2, 2, 2, 2, 2, 2 }, { 3, 3, 3, 3, 3, 3, 3 }, };
        if (inicio.size == 7) {
            y = generalKernel(array3, 7);
            img = aux;
            x = generalKernel(arrayc, 7);
        } else if (inicio.size == 5) {
            y = generalKernel(array2, 5);
            img = aux;
            x = generalKernel(arrayb, 5);
        } else {
            y = generalKernel(array, 3);
            img = aux;
            x = generalKernel(arraya, 3);
        }

        for (int i = 0; i < ancho; i++) {
            for (int j = 0; j < alto; j++) {

                int p = x.getRGB(i, j);
                int p2 = y.getRGB(i, j);
                //obtenemos el valor r g b a de cada pixel

                int r = (p >> 16) & 0xff;
                int g = (p >> 8) & 0xff;
                int b = p & 0xff;

                int r2 = (p2 >> 16) & 0xff;
                int g2 = (p2 >> 8) & 0xff;
                int b2 = p2 & 0xff;
                //process
                int resR = truncate(Math.sqrt(Math.pow(r, 2) + Math.pow(r2, 2)));
                int resG = truncate(Math.sqrt(Math.pow(g, 2) + Math.pow(g2, 2)));
                int resB = truncate(Math.sqrt(Math.pow(b, 2) + Math.pow(b2, 2)));

                //se guarda el rgb
                p = (resR << 16) | (resG << 8) | resB;
                img.setRGB(i, j, p);

            }
            Change();
        }
    }
        break;

    case 19://prewitt x
    {

        BufferedImage x;

        float[][] arraya = { { -1, 0, 1 }, { -1, 0, 1 }, { -1, 0, 1 } };
        float[][] arrayb = { { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 },
                { -2, -1, 0, 1, 2 }, };

        float[][] arrayc = { { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 },
                { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 },
                { -3, -2, -1, 0, 1, 2, 3 }, };

        if (inicio.size == 7) {
            x = generalKernel(arrayc, 7);
        } else if (inicio.size == 5) {
            x = generalKernel(arrayb, 5);
        } else {
            x = generalKernel(arraya, 3);
        }
        img = x;
        Change();

    }
        break;

    case 20://prewitt y
    {

        BufferedImage y;

        float[][] array = { { -1, -1, -1 }, { 0, 0, 0 }, { 1, 1, 1 } };
        float[][] array2 = { { -2, -2, -2, -2, -2 }, { -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2 }, };
        float[][] array3 = { { -3, -3, -3, -3, -3, -3, -3 }, { -2, -2, -2, -2, -2, -2, -2 },
                { -1, -1, -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1 },
                { 2, 2, 2, 2, 2, 2, 2 }, { 3, 3, 3, 3, 3, 3, 3 }, };

        if (inicio.size == 7) {
            y = generalKernel(array3, 7);
        } else if (inicio.size == 5) {
            y = generalKernel(array2, 5);
        } else {
            y = generalKernel(array, 3);
        }

        img = y;
        Change();

    }
        break;

    case 21://Sobel x
    {

        BufferedImage x;
        float[][] arraya = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } };

        float[][] arrayb = { { -5, -4, 0, 4, 5 }, { -8, -10, 0, 10, 8 }, { -10, -20, 0, 20, 10 },
                { -8, -10, 0, 10, 8 }, { -5, -4, 0, 4, 5 }, };

        float[][] arrayc = { { 3, 2, 1, 0, -1, -2, -3 }, { 4, 3, 2, 0, -2, -3, -4 }, { 5, 4, 3, 0, -3, -4, -5 },
                { 6, 5, 4, 0, -4, -5, -6 }, { 5, 4, 3, 0, -3, -4, -5 }, { 4, 3, 2, 0, -2, -3, -4 },
                { 3, 2, 1, 0, -1, -2, -3 }, };

        if (inicio.size == 7) {
            x = generalKernel(arrayc, 7);
        } else if (inicio.size == 5) {
            x = generalKernel(arrayb, 5);
        } else {
            x = generalKernel(arraya, 3);
        }
        img = x;
        Change();

    }
        break;

    case 22://sobel y
    {

        BufferedImage y;

        float[][] array1 = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } };

        float[][] array2 = { { 5, 8, 10, 8, 5 }, { 4, 10, 20, 10, 4 }, { 0, 0, 0, 0, 0 },
                { -4, -10, -20, -10, -4 }, { -5, -8, -10, -8, -5 }, };

        float[][] array3 = { { 3, 4, 5, 6, 5, 4, 3 }, { 2, 3, 4, 5, 4, 3, 2 }, { 1, 2, 3, 4, 3, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 0 }, { -1, -2, -3, -4, -3, -2, -1 }, { -2, -3, -4, -5, -4, -3, -2 },
                { -3, -4, -5, -6, -5, -4, -3 }, };

        if (inicio.size == 7) {
            y = generalKernel(array3, 7);
        } else if (inicio.size == 5) {
            y = generalKernel(array2, 5);
        } else {
            y = generalKernel(array1, 3);
        }

        img = y;
        Change();

    }
        break;

    case 23://sobel both
    {

        BufferedImage aux = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB);
        aux = img;
        BufferedImage y, x;

        float[][] arraya = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } };

        float[][] arrayb = { { -5, -4, 0, 4, 5 }, { -8, -10, 0, 10, 8 }, { -10, -20, 0, 20, 10 },
                { -8, -10, 0, 10, 8 }, { -5, -4, 0, 4, 5 }, };

        float[][] arrayc = { { 3, 2, 1, 0, -1, -2, -3 }, { 4, 3, 2, 0, -2, -3, -4 }, { 5, 4, 3, 0, -3, -4, -5 },
                { 6, 5, 4, 0, -4, -5, -6 }, { 5, 4, 3, 0, -3, -4, -5 }, { 4, 3, 2, 0, -2, -3, -4 },
                { 3, 2, 1, 0, -1, -2, -3 }, };

        float[][] array1 = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } };

        float[][] array2 = { { 5, 8, 10, 8, 5 }, { 4, 10, 20, 10, 4 }, { 0, 0, 0, 0, 0 },
                { -4, -10, -20, -10, -4 }, { -5, -8, -10, -8, -5 }, };

        float[][] array3 = { { 3, 4, 5, 6, 5, 4, 3 }, { 2, 3, 4, 5, 4, 3, 2 }, { 1, 2, 3, 4, 3, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 0 }, { -1, -2, -3, -4, -3, -2, -1 }, { -2, -3, -4, -5, -4, -3, -2 },
                { -3, -4, -5, -6, -5, -4, -3 }, };
        if (inicio.size == 7) {
            y = generalKernel(array3, 7);
            img = aux;
            x = generalKernel(arrayc, 7);
        } else if (inicio.size == 5) {
            y = generalKernel(array2, 5);
            img = aux;
            x = generalKernel(arrayb, 5);
        } else {
            y = generalKernel(array1, 3);
            img = aux;
            x = generalKernel(arraya, 3);
        }

        for (int i = 0; i < ancho; i++) {
            for (int j = 0; j < alto; j++) {

                int p = x.getRGB(i, j);
                int p2 = y.getRGB(i, j);
                //obtenermos el valor r g b a de cada pixel

                int r = (p >> 16) & 0xff;
                int g = (p >> 8) & 0xff;
                int b = p & 0xff;

                int r2 = (p2 >> 16) & 0xff;
                int g2 = (p2 >> 8) & 0xff;
                int b2 = p2 & 0xff;
                //process
                int resR = truncate(Math.sqrt(Math.pow(r, 2) + Math.pow(r2, 2)));
                int resG = truncate(Math.sqrt(Math.pow(g, 2) + Math.pow(g2, 2)));
                int resB = truncate(Math.sqrt(Math.pow(b, 2) + Math.pow(b2, 2)));

                //se guarda el rgb
                p = (resR << 16) | (resG << 8) | resB;
                img.setRGB(i, j, p);

            }
            Change();
        }
    }
        break;

    case 24://Gauss 
    {

        BufferedImage y;

        float[][] arraya = { { 1 / 16f, 1 / 8f, 1 / 16f }, { 1 / 8f, 1 / 4f, 1 / 8f },
                { 1 / 16f, 1 / 8f, 1 / 16f }, };
        float[][] arrayb = { { 1 / 273f, 4 / 273f, 7 / 273f, 4 / 273f, 1 / 273f },
                { 4 / 273f, 16 / 273f, 26 / 273f, 16 / 273f, 4 / 273f },
                { 7 / 273f, 26 / 273f, 41 / 273f, 26 / 273f, 7 / 273f },
                { 4 / 273f, 16 / 273f, 26 / 273f, 16 / 273f, 4 / 273f },
                { 1 / 273f, 4 / 273f, 7 / 273f, 4 / 273f, 1 / 273f }, };

        float[][] arrayc = {
                { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f },
                { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f },
                { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f },
                { 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f },
                { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f },
                { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f },
                { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f } };

        if (inicio.size == 7) {
            y = generalKernel(arrayc, 7);
        } else if (inicio.size == 5) {
            y = generalKernel(arrayb, 5);
        } else {
            y = generalKernel(arraya, 3);
        }

        img = y;
        Change();

    }
        break;

    case 25: {

        BufferedImage y;

        float[][] arraya = { { 1 / 9f, 1 / 9f, 1 / 9f }, { 1 / 9f, 1 / 9f, 1 / 9f },
                { 1 / 9f, 1 / 9f, 1 / 9f }, };
        float[][] arrayb = { { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f },
                { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f },
                { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f },
                { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f },
                { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f }, };
        float[][] arrayc = { { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f },
                { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f },
                { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f },
                { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f },
                { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f },
                { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f },
                { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, };
        if (inicio.size == 7) {
            y = generalKernel(arrayc, 7);
        } else if (inicio.size == 5) {
            y = generalKernel(arrayb, 5);
        } else {
            y = generalKernel(arraya, 3);
        }

        img = y;
        Change();

    }
        break;

    case 26://sharpen 
    {

        BufferedImage y;

        float[][] arraya = { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 }, };
        float[][] arrayb = { { -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 }, { -1, -1, 26, -1, -1 },
                { -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 }, };
        float[][] arrayc = { { -1, -1, -1, -1, -1, -1, -1 }, { -1, -2, -2, -2, -2, -2, -1 },
                { -1, -2, -3, -3, -3, -2, -1 }, { -1, -2, -3, 81, -3, -2, -1 }, { -1, -2, -3, -3, -3, -2, -1 },
                { -1, -2, -2, -2, -2, -2, -1 }, { -1, -1, -1, -1, -1, -1, -1 }, };
        if (inicio.size == 7) {
            y = generalKernel(arrayc, 7);
        } else if (inicio.size == 5) {
            y = generalKernel(arrayb, 5);
        } else {
            y = generalKernel(arraya, 3);
        }

        img = y;
        Change();

    }
        break;
    case 27: {

        kernel = new Kernel();
        kernel.show();
        kernel.setTitle("Kernel");
        kernel.setVisible(true);
        kernel.setLocationRelativeTo(null);
        kernel.setResizable(false);
        kernel.pack();

    }
        break;

    case 28: //valores
    {

        float[][] floatdata = new float[kernel.dim][kernel.dim];
        for (int i = 0; i < kernel.dim; i++) {
            for (int j = 0; j < kernel.dim; j++) {
                floatdata[i][j] = floatValue(kernel.tableData[i][j]);
            }
        }
        kernel.dispose();
        BufferedImage y;
        y = generalKernel(floatdata, kernel.dim);
        img = y;

        Change();

    }
        break;

    case 29://motion blur
    {
        BufferedImage y;

        float[][] array = { { 1 / 9f, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1 / 9f, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 1 / 9f, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1 / 9f, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1 / 9f, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1 / 9f, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 1 / 9f, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 1 / 9f, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 1 / 9f }, };

        /*
        float[][] arrayb = {
            {1/3f, 0, 0},
            {0, 1/3f, 0},
            {0, 0, 1/3f},
         };*/

        y = generalKernel(array, 9);

        img = y;
        Change();

    }
        break;

    } //end switch

}

From source file:processing.app.Base.java

/**
 * Show the About box.//  w  ww  . ja  v  a 2 s .  c  om
 */
@SuppressWarnings("serial")
public void handleAbout() {
    final Image image = Theme.getLibImage("about", activeEditor, Theme.scale(475), Theme.scale(300));
    final Window window = new Window(activeEditor) {
        public void paint(Graphics graphics) {
            Graphics2D g = Theme.setupGraphics2D(graphics);
            g.drawImage(image, 0, 0, null);

            Font f = new Font("SansSerif", Font.PLAIN, Theme.scale(11));
            g.setFont(f);
            g.setColor(new Color(0, 151, 156));
            g.drawString(BaseNoGui.VERSION_NAME_LONG, Theme.scale(33), Theme.scale(20));
        }
    };
    window.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            window.dispose();
        }
    });
    int w = image.getWidth(activeEditor);
    int h = image.getHeight(activeEditor);
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    window.setBounds((screen.width - w) / 2, (screen.height - h) / 2, w, h);
    window.setLocationRelativeTo(activeEditor);
    window.setVisible(true);
}

From source file:DefaultGraphics2D.java

/**
 * Draws as much of the specified image as is currently available. The image
 * is drawn with its top-left corner at (<i>x</i>,&nbsp;<i>y</i>) in this
 * graphics context's coordinate space. Transparent pixels are drawn in the
 * specified background color.//from  w w w .  jav a 2 s  .  com
 * <p>
 * This operation is equivalent to filling a rectangle of the width and height
 * of the specified image with the given color and then drawing the image on
 * top of it, but possibly more efficient.
 * <p>
 * This method returns immediately in all cases, even if the complete image
 * has not yet been loaded, and it has not been dithered and converted for the
 * current output device.
 * <p>
 * If the image has not yet been completely loaded, then
 * <code>drawImage</code> returns <code>false</code>. As more of the
 * image becomes available, the process that draws the image notifies the
 * specified image observer.
 * 
 * @param img
 *          the specified image to be drawn.
 * @param x
 *          the <i>x</i> coordinate.
 * @param y
 *          the <i>y</i> coordinate.
 * @param bgcolor
 *          the background color to paint under the non-opaque portions of the
 *          image.
 * @param observer
 *          object to be notified as more of the image is converted.
 * @see java.awt.Image
 * @see java.awt.image.ImageObserver
 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int,
 *      int, int, int)
 */
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
    return drawImage(img, x, y, img.getWidth(null), img.getHeight(null), bgcolor, observer);
}

From source file:DefaultGraphics2D.java

/**
 * Draws as much of the specified area of the specified image as is currently
 * available, scaling it on the fly to fit inside the specified area of the
 * destination drawable surface. Transparent pixels do not affect whatever
 * pixels are already there.//  www .  j  ava 2s. co m
 * <p>
 * This method returns immediately in all cases, even if the image area to be
 * drawn has not yet been scaled, dithered, and converted for the current
 * output device. If the current output representation is not yet complete
 * then <code>drawImage</code> returns <code>false</code>. As more of the
 * image becomes available, the process that draws the image notifies the
 * specified image observer.
 * <p>
 * This method always uses the unscaled version of the image to render the
 * scaled rectangle and performs the required scaling on the fly. It does not
 * use a cached, scaled version of the image for this operation. Scaling of
 * the image from source to destination is performed such that the first
 * coordinate of the source rectangle is mapped to the first coordinate of the
 * destination rectangle, and the second source coordinate is mapped to the
 * second destination coordinate. The subimage is scaled and flipped as needed
 * to preserve those mappings.
 * 
 * @param img
 *          the specified image to be drawn
 * @param dx1
 *          the <i>x</i> coordinate of the first corner of the destination
 *          rectangle.
 * @param dy1
 *          the <i>y</i> coordinate of the first corner of the destination
 *          rectangle.
 * @param dx2
 *          the <i>x</i> coordinate of the second corner of the destination
 *          rectangle.
 * @param dy2
 *          the <i>y</i> coordinate of the second corner of the destination
 *          rectangle.
 * @param sx1
 *          the <i>x</i> coordinate of the first corner of the source
 *          rectangle.
 * @param sy1
 *          the <i>y</i> coordinate of the first corner of the source
 *          rectangle.
 * @param sx2
 *          the <i>x</i> coordinate of the second corner of the source
 *          rectangle.
 * @param sy2
 *          the <i>y</i> coordinate of the second corner of the source
 *          rectangle.
 * @param observer
 *          object to be notified as more of the image is scaled and
 *          converted.
 * @see java.awt.Image
 * @see java.awt.image.ImageObserver
 * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int,
 *      int, int, int)
 * @since JDK1.1
 */
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
        ImageObserver observer) {
    BufferedImage src = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = src.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();

    src = src.getSubimage(sx1, sy1, sx2 - sx1, sy2 - sy1);

    return drawImage(src, dx1, dy1, dx2 - dx1, dy2 - dy1, observer);
}