< prev index next >

src/java.desktop/share/classes/sun/awt/image/ImageRepresentation.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 267             isDefaultBI = true;
 268         }
 269         else if (cmodel instanceof DirectColorModel) {
 270             DirectColorModel dcm = (DirectColorModel) cmodel;
 271             if (dcm.getRedMask() == 0xff0000 &&
 272                 dcm.getGreenMask() == 0xff00 &&
 273                 dcm.getBlueMask()  == 0xff) {
 274                 isDefaultBI = true;
 275             }
 276         }
 277     }
 278 
 279     private void convertToRGB() {
 280         int w = bimage.getWidth();
 281         int h = bimage.getHeight();
 282         int size = w*h;
 283 
 284         DataBufferInt dbi = new DataBufferInt(size);
 285         // Note that stealData() requires a markDirty() afterwards
 286         // since we modify the data in it.
 287         int newpixels[] = SunWritableRaster.stealData(dbi, 0);
 288         if (cmodel instanceof IndexColorModel &&
 289             biRaster instanceof ByteComponentRaster &&
 290             biRaster.getNumDataElements() == 1)
 291         {
 292             ByteComponentRaster bct = (ByteComponentRaster) biRaster;
 293             byte[] data = bct.getDataStorage();
 294             int coff = bct.getDataOffset(0);
 295             for (int i=0; i < size; i++) {
 296                 newpixels[i] = srcLUT[data[coff+i]&0xff];
 297             }
 298         }
 299         else {
 300             Object srcpixels = null;
 301             int off=0;
 302             for (int y=0; y < h; y++) {
 303                 for (int x=0; x < w; x++) {
 304                     srcpixels=biRaster.getDataElements(x, y, srcpixels);
 305                     newpixels[off++] = cmodel.getRGB(srcpixels);
 306                 }
 307             }
 308         }
 309         // We modified the data array directly above so mark it as dirty now...
 310         SunWritableRaster.markDirty(dbi);
 311 
 312         isSameCM = false;
 313         cmodel = ColorModel.getRGBdefault();
 314 
 315         int bandMasks[] = {0x00ff0000,
 316                            0x0000ff00,
 317                            0x000000ff,
 318                            0xff000000};
 319 
 320         biRaster = Raster.createPackedRaster(dbi,w,h,w,
 321                                              bandMasks,null);
 322 
 323         bimage = createImage(cmodel, biRaster,
 324                              cmodel.isAlphaPremultiplied(), null);
 325         srcLUT = null;
 326         isDefaultBI = true;
 327     }
 328 
 329     public void setHints(int h) {
 330         if (src != null) {
 331             src.checkSecurity(null, false);
 332         }
 333         hints = h;
 334     }
 335 
 336     private native boolean setICMpixels(int x, int y, int w, int h, int[] lut,
 337                                     byte[] pix, int off, int scansize,
 338                                     IntegerComponentRaster ict);
 339     private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
 340                                  int transPix, int numLut, IndexColorModel icm,
 341                                  byte[] pix, int off, int scansize,
 342                                  ByteComponentRaster bct, int chanOff);
 343     static boolean s_useNative = true;
 344 
 345     public void setPixels(int x, int y, int w, int h,
 346                           ColorModel model,
 347                           byte pix[], int off, int scansize) {
 348         int lineOff=off;
 349         int poff;
 350         int[] newLUT=null;
 351 
 352         if (src != null) {
 353             src.checkSecurity(null, false);
 354         }
 355 
 356         // REMIND: What if the model doesn't fit in default color model?
 357         synchronized (this) {
 358             if (bimage == null) {
 359                 if (cmodel == null) {
 360                     cmodel = model;
 361                 }
 362                 createBufferedImage();
 363             }
 364 
 365             if (w <= 0 || h <= 0) {
 366                 return;
 367             }


 524             }
 525             else {
 526                 for (int yoff=y; yoff < y+h; yoff++, lineOff += scansize) {
 527                     poff = lineOff;
 528                     for (int xoff=x; xoff < x+w; xoff++) {
 529                         bimage.setRGB(xoff, yoff,
 530                                       model.getRGB(pix[poff++]&0xff));
 531                     }
 532                 }
 533                 availinfo |= ImageObserver.SOMEBITS;
 534             }
 535         }
 536 
 537         if ((availinfo & ImageObserver.FRAMEBITS) == 0) {
 538             newInfo(image, ImageObserver.SOMEBITS, x, y, w, h);
 539         }
 540     }
 541 
 542 
 543     public void setPixels(int x, int y, int w, int h, ColorModel model,
 544                           int pix[], int off, int scansize)
 545     {
 546         int lineOff=off;
 547         int poff;
 548 
 549         if (src != null) {
 550             src.checkSecurity(null, false);
 551         }
 552 
 553         // REMIND: What if the model doesn't fit in default color model?
 554         synchronized (this) {
 555             if (bimage == null) {
 556                 if (cmodel == null) {
 557                     cmodel = model;
 558                 }
 559                 createBufferedImage();
 560             }
 561 
 562             int[] storage = new int[w];
 563             int yoff;
 564             int pixel;


 645         if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
 646             int w = bimage.getWidth();
 647             int h = bimage.getHeight();
 648             int size = w * h;
 649 
 650             // Note that we steal the data array here, but only for reading...
 651             DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer();
 652             int[] pixels = SunWritableRaster.stealData(db, 0);
 653 
 654             for (int i = 0; i < size; i++) {
 655                 if ((pixels[i] >>> 24) != 0xff) {
 656                     return bimage;
 657                 }
 658             }
 659 
 660             ColorModel opModel = new DirectColorModel(24,
 661                                                       0x00ff0000,
 662                                                       0x0000ff00,
 663                                                       0x000000ff);
 664 
 665             int bandmasks[] = {0x00ff0000, 0x0000ff00, 0x000000ff};
 666             WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w,
 667                                                                 bandmasks,
 668                                                                 null);
 669 
 670             try {
 671                 BufferedImage opImage = createImage(opModel, opRaster,
 672                                                     false, null);
 673                 return opImage;
 674             } catch (Exception e) {
 675                 return bimage;
 676             }
 677         }
 678         return bimage;
 679     }
 680 
 681     private boolean consuming = false;
 682 
 683     public void imageComplete(int status) {
 684         if (src != null) {
 685             src.checkSecurity(null, false);


   1 /*
   2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 267             isDefaultBI = true;
 268         }
 269         else if (cmodel instanceof DirectColorModel) {
 270             DirectColorModel dcm = (DirectColorModel) cmodel;
 271             if (dcm.getRedMask() == 0xff0000 &&
 272                 dcm.getGreenMask() == 0xff00 &&
 273                 dcm.getBlueMask()  == 0xff) {
 274                 isDefaultBI = true;
 275             }
 276         }
 277     }
 278 
 279     private void convertToRGB() {
 280         int w = bimage.getWidth();
 281         int h = bimage.getHeight();
 282         int size = w*h;
 283 
 284         DataBufferInt dbi = new DataBufferInt(size);
 285         // Note that stealData() requires a markDirty() afterwards
 286         // since we modify the data in it.
 287         int[] newpixels = SunWritableRaster.stealData(dbi, 0);
 288         if (cmodel instanceof IndexColorModel &&
 289             biRaster instanceof ByteComponentRaster &&
 290             biRaster.getNumDataElements() == 1)
 291         {
 292             ByteComponentRaster bct = (ByteComponentRaster) biRaster;
 293             byte[] data = bct.getDataStorage();
 294             int coff = bct.getDataOffset(0);
 295             for (int i=0; i < size; i++) {
 296                 newpixels[i] = srcLUT[data[coff+i]&0xff];
 297             }
 298         }
 299         else {
 300             Object srcpixels = null;
 301             int off=0;
 302             for (int y=0; y < h; y++) {
 303                 for (int x=0; x < w; x++) {
 304                     srcpixels=biRaster.getDataElements(x, y, srcpixels);
 305                     newpixels[off++] = cmodel.getRGB(srcpixels);
 306                 }
 307             }
 308         }
 309         // We modified the data array directly above so mark it as dirty now...
 310         SunWritableRaster.markDirty(dbi);
 311 
 312         isSameCM = false;
 313         cmodel = ColorModel.getRGBdefault();
 314 
 315         int[] bandMasks = {0x00ff0000,
 316                            0x0000ff00,
 317                            0x000000ff,
 318                            0xff000000};
 319 
 320         biRaster = Raster.createPackedRaster(dbi,w,h,w,
 321                                              bandMasks,null);
 322 
 323         bimage = createImage(cmodel, biRaster,
 324                              cmodel.isAlphaPremultiplied(), null);
 325         srcLUT = null;
 326         isDefaultBI = true;
 327     }
 328 
 329     public void setHints(int h) {
 330         if (src != null) {
 331             src.checkSecurity(null, false);
 332         }
 333         hints = h;
 334     }
 335 
 336     private native boolean setICMpixels(int x, int y, int w, int h, int[] lut,
 337                                     byte[] pix, int off, int scansize,
 338                                     IntegerComponentRaster ict);
 339     private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
 340                                  int transPix, int numLut, IndexColorModel icm,
 341                                  byte[] pix, int off, int scansize,
 342                                  ByteComponentRaster bct, int chanOff);
 343     static boolean s_useNative = true;
 344 
 345     public void setPixels(int x, int y, int w, int h,
 346                           ColorModel model,
 347                           byte[] pix, int off, int scansize) {
 348         int lineOff=off;
 349         int poff;
 350         int[] newLUT=null;
 351 
 352         if (src != null) {
 353             src.checkSecurity(null, false);
 354         }
 355 
 356         // REMIND: What if the model doesn't fit in default color model?
 357         synchronized (this) {
 358             if (bimage == null) {
 359                 if (cmodel == null) {
 360                     cmodel = model;
 361                 }
 362                 createBufferedImage();
 363             }
 364 
 365             if (w <= 0 || h <= 0) {
 366                 return;
 367             }


 524             }
 525             else {
 526                 for (int yoff=y; yoff < y+h; yoff++, lineOff += scansize) {
 527                     poff = lineOff;
 528                     for (int xoff=x; xoff < x+w; xoff++) {
 529                         bimage.setRGB(xoff, yoff,
 530                                       model.getRGB(pix[poff++]&0xff));
 531                     }
 532                 }
 533                 availinfo |= ImageObserver.SOMEBITS;
 534             }
 535         }
 536 
 537         if ((availinfo & ImageObserver.FRAMEBITS) == 0) {
 538             newInfo(image, ImageObserver.SOMEBITS, x, y, w, h);
 539         }
 540     }
 541 
 542 
 543     public void setPixels(int x, int y, int w, int h, ColorModel model,
 544                           int[] pix, int off, int scansize)
 545     {
 546         int lineOff=off;
 547         int poff;
 548 
 549         if (src != null) {
 550             src.checkSecurity(null, false);
 551         }
 552 
 553         // REMIND: What if the model doesn't fit in default color model?
 554         synchronized (this) {
 555             if (bimage == null) {
 556                 if (cmodel == null) {
 557                     cmodel = model;
 558                 }
 559                 createBufferedImage();
 560             }
 561 
 562             int[] storage = new int[w];
 563             int yoff;
 564             int pixel;


 645         if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
 646             int w = bimage.getWidth();
 647             int h = bimage.getHeight();
 648             int size = w * h;
 649 
 650             // Note that we steal the data array here, but only for reading...
 651             DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer();
 652             int[] pixels = SunWritableRaster.stealData(db, 0);
 653 
 654             for (int i = 0; i < size; i++) {
 655                 if ((pixels[i] >>> 24) != 0xff) {
 656                     return bimage;
 657                 }
 658             }
 659 
 660             ColorModel opModel = new DirectColorModel(24,
 661                                                       0x00ff0000,
 662                                                       0x0000ff00,
 663                                                       0x000000ff);
 664 
 665             int[] bandmasks = {0x00ff0000, 0x0000ff00, 0x000000ff};
 666             WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w,
 667                                                                 bandmasks,
 668                                                                 null);
 669 
 670             try {
 671                 BufferedImage opImage = createImage(opModel, opRaster,
 672                                                     false, null);
 673                 return opImage;
 674             } catch (Exception e) {
 675                 return bimage;
 676             }
 677         }
 678         return bimage;
 679     }
 680 
 681     private boolean consuming = false;
 682 
 683     public void imageComplete(int status) {
 684         if (src != null) {
 685             src.checkSecurity(null, false);


< prev index next >