1 7 8 package java.awt.image; 9 10 import java.awt.Transparency ; 11 import java.awt.color.ColorSpace ; 12 import java.awt.Graphics2D ; 13 import java.awt.GraphicsConfiguration ; 14 import java.awt.GraphicsEnvironment ; 15 import java.awt.ImageCapabilities ; 16 import java.awt.geom.Rectangle2D ; 17 import java.awt.geom.Point2D ; 18 import java.awt.Point ; 19 import java.awt.Rectangle ; 20 import java.util.Hashtable ; 21 import java.util.Vector ; 22 23 import sun.awt.image.BytePackedRaster; 24 import sun.awt.image.ShortComponentRaster; 25 import sun.awt.image.ByteComponentRaster; 26 import sun.awt.image.IntegerComponentRaster; 27 import sun.awt.image.OffScreenImageSource; 28 29 52 53 public class BufferedImage extends java.awt.Image 54 implements WritableRenderedImage , Transparency 55 { 56 int imageType = TYPE_CUSTOM; 57 ColorModel colorModel; 58 WritableRaster raster; 59 OffScreenImageSource osis; 60 Hashtable properties; 61 62 boolean isAlphaPremultiplied; 65 sun.awt.image.SurfaceManager surfaceManager; 66 67 70 71 76 public static final int TYPE_CUSTOM = 0; 77 78 89 public static final int TYPE_INT_RGB = 1; 90 91 100 public static final int TYPE_INT_ARGB = 2; 101 102 108 public static final int TYPE_INT_ARGB_PRE = 3; 109 110 122 public static final int TYPE_INT_BGR = 4; 123 124 136 public static final int TYPE_3BYTE_BGR = 5; 137 138 147 public static final int TYPE_4BYTE_ABGR = 6; 148 149 157 public static final int TYPE_4BYTE_ABGR_PRE = 7; 158 159 170 public static final int TYPE_USHORT_565_RGB = 8; 171 172 183 public static final int TYPE_USHORT_555_RGB = 9; 184 185 196 public static final int TYPE_BYTE_GRAY = 10; 197 198 209 public static final int TYPE_USHORT_GRAY = 11; 210 211 238 public static final int TYPE_BYTE_BINARY = 12; 239 240 257 public static final int TYPE_BYTE_INDEXED = 13; 258 259 private static final int DCM_RED_MASK = 0x00ff0000; 260 private static final int DCM_GREEN_MASK = 0x0000ff00; 261 private static final int DCM_BLUE_MASK = 0x000000ff; 262 private static final int DCM_ALPHA_MASK = 0xff000000; 263 private static final int DCM_565_RED_MASK = 0xf800; 264 private static final int DCM_565_GRN_MASK = 0x07E0; 265 private static final int DCM_565_BLU_MASK = 0x001F; 266 private static final int DCM_555_RED_MASK = 0x7C00; 267 private static final int DCM_555_GRN_MASK = 0x03E0; 268 private static final int DCM_555_BLU_MASK = 0x001F; 269 private static final int DCM_BGR_RED_MASK = 0x0000ff; 270 private static final int DCM_BGR_GRN_MASK = 0x00ff00; 271 private static final int DCM_BGR_BLU_MASK = 0xff0000; 272 273 274 static private native void initIDs(); 275 static { 276 ColorModel.loadLibraries(); 277 initIDs(); 278 } 279 280 302 public BufferedImage(int width, 303 int height, 304 int imageType) { 305 switch (imageType) { 306 case TYPE_INT_RGB: 307 { 308 colorModel = new DirectColorModel (24, 309 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0 ); 314 raster = colorModel.createCompatibleWritableRaster(width, 315 height); 316 } 317 break; 318 319 case TYPE_INT_ARGB: 320 { 321 colorModel = ColorModel.getRGBdefault(); 322 323 raster = colorModel.createCompatibleWritableRaster(width, 324 height); 325 } 326 break; 327 328 case TYPE_INT_ARGB_PRE: 329 { 330 colorModel = new 331 DirectColorModel ( 332 ColorSpace.getInstance(ColorSpace.CS_sRGB), 333 32, 334 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, true, DataBuffer.TYPE_INT 340 ); 341 342 raster = colorModel.createCompatibleWritableRaster(width, 343 height); 344 } 345 break; 346 347 case TYPE_INT_BGR: 348 { 349 colorModel = new DirectColorModel (24, 350 0x000000ff, 0x0000ff00, 0x00ff0000 ); 354 raster = colorModel.createCompatibleWritableRaster(width, 355 height); 356 } 357 break; 358 359 case TYPE_3BYTE_BGR: 360 { 361 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); 362 int[] nBits = {8, 8, 8}; 363 int[] bOffs = {2, 1, 0}; 364 colorModel = new ComponentColorModel (cs, nBits, false, false, 365 Transparency.OPAQUE, 366 DataBuffer.TYPE_BYTE); 367 raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 368 width, height, 369 width*3, 3, 370 bOffs, null); 371 } 372 break; 373 374 case TYPE_4BYTE_ABGR: 375 { 376 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); 377 int[] nBits = {8, 8, 8, 8}; 378 int[] bOffs = {3, 2, 1, 0}; 379 colorModel = new ComponentColorModel (cs, nBits, true, false, 380 Transparency.TRANSLUCENT, 381 DataBuffer.TYPE_BYTE); 382 raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 383 width, height, 384 width*4, 4, 385 bOffs, null); 386 } 387 break; 388 389 case TYPE_4BYTE_ABGR_PRE: 390 { 391 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); 392 int[] nBits = {8, 8, 8, 8}; 393 int[] bOffs = {3, 2, 1, 0}; 394 colorModel = new ComponentColorModel (cs, nBits, true, true, 395 Transparency.TRANSLUCENT, 396 DataBuffer.TYPE_BYTE); 397 raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 398 width, height, 399 width*4, 4, 400 bOffs, null); 401 } 402 break; 403 404 case TYPE_BYTE_GRAY: 405 { 406 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); 407 int[] nBits = {8}; 408 colorModel = new ComponentColorModel (cs, nBits, false, true, 409 Transparency.OPAQUE, 410 DataBuffer.TYPE_BYTE); 411 raster = colorModel.createCompatibleWritableRaster(width, 412 height); 413 } 414 break; 415 416 case TYPE_USHORT_GRAY: 417 { 418 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); 419 int[] nBits = {16}; 420 colorModel = new ComponentColorModel (cs, nBits, false, true, 421 Transparency.OPAQUE, 422 DataBuffer.TYPE_USHORT); 423 raster = colorModel.createCompatibleWritableRaster(width, 424 height); 425 } 426 break; 427 428 case TYPE_BYTE_BINARY: 429 { 430 byte[] arr = {(byte)0, (byte)0xff}; 431 432 colorModel = new IndexColorModel (1, 2, arr, arr, arr); 433 raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE, 434 width, height, 1, 1, null); 435 } 436 break; 437 438 case TYPE_BYTE_INDEXED: 439 { 440 int[] cmap = new int[256]; 442 int i=0; 443 for (int r=0; r < 256; r += 51) { 444 for (int g=0; g < 256; g += 51) { 445 for (int b=0; b < 256; b += 51) { 446 cmap[i++] = (r<<16)|(g<<8)|b; 447 } 448 } 449 } 450 int grayIncr = 256/(256-i); 452 453 int gray = grayIncr*3; 455 for (; i < 256; i++) { 456 cmap[i] = (gray<<16)|(gray<<8)|gray; 457 gray += grayIncr; 458 } 459 460 colorModel = new IndexColorModel (8, 256, cmap, 0, false, -1, 461 DataBuffer.TYPE_BYTE); 462 raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 463 width, height, 1, null); 464 } 465 break; 466 467 case TYPE_USHORT_565_RGB: 468 { 469 colorModel = new DirectColorModel (16, 470 DCM_565_RED_MASK, 471 DCM_565_GRN_MASK, 472 DCM_565_BLU_MASK 473 ); 474 raster = colorModel.createCompatibleWritableRaster(width, 475 height); 476 } 477 break; 478 479 case TYPE_USHORT_555_RGB: 480 { 481 colorModel = new DirectColorModel (15, 482 DCM_555_RED_MASK, 483 DCM_555_GRN_MASK, 484 DCM_555_BLU_MASK 485 ); 486 raster = colorModel.createCompatibleWritableRaster(width, 487 height); 488 } 489 break; 490 491 default: 492 throw new IllegalArgumentException ("Unknown image type " + 493 imageType); 494 } 495 496 this.imageType = imageType; 497 } 498 499 522 public BufferedImage (int width, 523 int height, 524 int imageType, 525 IndexColorModel cm) { 526 if (cm.hasAlpha() && cm.isAlphaPremultiplied()) { 527 throw new IllegalArgumentException ("This image types do not have "+ 528 "premultiplied alpha."); 529 } 530 531 switch(imageType) { 532 case TYPE_BYTE_BINARY: 533 int bits; int mapSize = cm.getMapSize(); 535 if (mapSize <= 2) { 536 bits = 1; 537 } else if (mapSize <= 4) { 538 bits = 2; 539 } else if (mapSize <= 16) { 540 bits = 4; 541 } else { 542 throw new IllegalArgumentException 543 ("Color map for TYPE_BYTE_BINARY " + 544 "must have no more than 16 entries"); 545 } 546 raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE, 547 width, height, 1, bits, null); 548 break; 549 550 case TYPE_BYTE_INDEXED: 551 raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, 552 width, height, 1, null); 553 break; 554 default: 555 throw new IllegalArgumentException ("Invalid image type (" + 556 imageType+"). Image type must"+ 557 " be either TYPE_BYTE_BINARY or "+ 558 " TYPE_BYTE_INDEXED"); 559 } 560 561 if (!cm.isCompatibleRaster(raster)) { 562 throw new IllegalArgumentException ("Incompatible image type and IndexColorModel"); 563 } 564 565 colorModel = cm; 566 this.imageType = imageType; 567 } 568 569 599 600 601 607 public BufferedImage (ColorModel cm, 608 WritableRaster raster, 609 boolean isRasterPremultiplied, 610 Hashtable <?,?> properties) { 611 612 if (!cm.isCompatibleRaster(raster)) { 613 throw new 614 IllegalArgumentException ("Raster "+raster+ 615 " is incompatible with ColorModel "+ 616 cm); 617 } 618 619 if ((raster.minX != 0) || (raster.minY != 0)) { 620 throw new 621 IllegalArgumentException ("Raster "+raster+ 622 " has minX or minY not equal to zero: " 623 + raster.minX + " " + raster.minY); 624 } 625 626 colorModel = cm; 627 this.raster = raster; 628 this.properties = properties; 629 int numBands = raster.getNumBands(); 630 boolean isAlphaPre = cm.isAlphaPremultiplied(); 631 ColorSpace cs; 632 633 coerceData(isRasterPremultiplied); 636 637 SampleModel sm = raster.getSampleModel(); 638 cs = cm.getColorSpace(); 639 int csType = cs.getType(); 640 if (csType != ColorSpace.TYPE_RGB) { 641 if (csType == ColorSpace.TYPE_GRAY 642 && cm instanceof ComponentColorModel ) { 643 if (sm instanceof ComponentSampleModel && 645 ((ComponentSampleModel )sm).getPixelStride() != numBands) { 646 imageType = TYPE_CUSTOM; 647 } else if (raster instanceof ByteComponentRaster && 648 raster.getNumBands() == 1 && 649 cm.getComponentSize(0) == 8 && 650 ((ByteComponentRaster)raster).getPixelStride() == 1) { 651 imageType = TYPE_BYTE_GRAY; 652 } else if (raster instanceof ShortComponentRaster && 653 raster.getNumBands() == 1 && 654 cm.getComponentSize(0) == 16 && 655 ((ShortComponentRaster)raster).getPixelStride() == 1) { 656 imageType = TYPE_USHORT_GRAY; 657 } 658 } else { 659 imageType = TYPE_CUSTOM; 660 } 661 return; 662 } 663 664 if ((raster instanceof IntegerComponentRaster) && 665 (numBands == 3 || numBands == 4)) { 666 IntegerComponentRaster iraster = 667 (IntegerComponentRaster) raster; 668 int pixSize = cm.getPixelSize(); 671 if (iraster.getPixelStride() == 1 && 672 cm instanceof DirectColorModel && 673 (pixSize == 32 || pixSize == 24)) 674 { 675 DirectColorModel dcm = (DirectColorModel ) cm; 677 int rmask = dcm.getRedMask(); 678 int gmask = dcm.getGreenMask(); 679 int bmask = dcm.getBlueMask(); 680 if (rmask == DCM_RED_MASK && gmask == DCM_GREEN_MASK && 681 bmask == DCM_BLUE_MASK) 682 { 683 if (dcm.getAlphaMask() == DCM_ALPHA_MASK) { 684 imageType = (isAlphaPre 685 ? TYPE_INT_ARGB_PRE 686 : TYPE_INT_ARGB); 687 } 688 else { 689 if (!dcm.hasAlpha()) { 691 imageType = TYPE_INT_RGB; 692 } 693 } 694 } else if (rmask == DCM_BGR_RED_MASK && gmask == DCM_BGR_GRN_MASK 696 && bmask == DCM_BGR_BLU_MASK) { 697 if (!dcm.hasAlpha()) { 698 imageType = TYPE_INT_BGR; 699 } 700 } } } else if ((cm instanceof IndexColorModel ) && (numBands == 1) && 704 (!cm.hasAlpha() || !isAlphaPre)) 705 { 706 IndexColorModel icm = (IndexColorModel ) cm; 707 int pixSize = icm.getPixelSize(); 708 709 if (raster instanceof BytePackedRaster) { 710 imageType = TYPE_BYTE_BINARY; 711 } else if (raster instanceof ByteComponentRaster) { 713 ByteComponentRaster braster = (ByteComponentRaster) raster; 714 if (braster.getPixelStride() == 1 && pixSize <= 8) { 715 imageType = TYPE_BYTE_INDEXED; 716 } 717 } 718 } else if ((raster instanceof ShortComponentRaster) 720 && (cm instanceof DirectColorModel ) 721 && (numBands == 3) 722 && !cm.hasAlpha()) 723 { 724 DirectColorModel dcm = (DirectColorModel ) cm; 725 if (dcm.getRedMask() == DCM_565_RED_MASK) { 726 if (dcm.getGreenMask() == DCM_565_GRN_MASK && 727 dcm.getBlueMask() == DCM_565_BLU_MASK) { 728 imageType = TYPE_USHORT_565_RGB; 729 } 730 } 731 else if (dcm.getRedMask() == DCM_555_RED_MASK) { 732 if (dcm.getGreenMask() == DCM_555_GRN_MASK && 733 dcm.getBlueMask() == DCM_555_BLU_MASK) { 734 imageType = TYPE_USHORT_555_RGB; 735 } 736 } 737 } else if ((raster instanceof ByteComponentRaster) 739 && (cm instanceof ComponentColorModel ) 740 && (raster.getSampleModel() instanceof PixelInterleavedSampleModel ) 741 && (numBands == 3 || numBands == 4)) 742 { 743 ComponentColorModel ccm = (ComponentColorModel ) cm; 744 PixelInterleavedSampleModel csm = 745 (PixelInterleavedSampleModel )raster.getSampleModel(); 746 ByteComponentRaster braster = (ByteComponentRaster) raster; 747 int[] offs = csm.getBandOffsets(); 748 if (ccm.getNumComponents() != numBands) { 749 throw new RasterFormatException ("Number of components in "+ 750 "ColorModel ("+ 751 ccm.getNumComponents()+ 752 ") does not match # in "+ 753 " Raster ("+numBands+")"); 754 } 755 int[] nBits = ccm.getComponentSize(); 756 boolean is8bit = true; 757 for (int i=0; i < numBands; i++) { 758 if (nBits[i] != 8) { 759 is8bit = false; 760 break; 761 } 762 } 763 if (is8bit && 764 offs[0] == numBands-1 && 765 offs[1] == numBands-2 && 766 offs[2] == numBands-3) 767 { 768 if (numBands == 3) { 769 imageType = TYPE_3BYTE_BGR; 770 } 771 else if (offs[3] == 0) { 772 imageType = (isAlphaPre 773 ? TYPE_4BYTE_ABGR_PRE 774 : TYPE_4BYTE_ABGR); 775 } 776 } 777 } } 779 780 799 public int getType() { 800 return imageType; 801 } 802 803 808 public ColorModel getColorModel() { 809 return colorModel; 810 } 811 812 817 public WritableRaster getRaster() { 818 return raster; 819 } 820 821 822 843 public WritableRaster getAlphaRaster() { 844 return colorModel.getAlphaRaster(raster); 845 } 846 847 869 public int getRGB(int x, int y) { 870 return colorModel.getRGB(raster.getDataElements(x, y, null)); 871 } 872 873 904 public int[] getRGB(int startX, int startY, int w, int h, 905 int[] rgbArray, int offset, int scansize) { 906 int yoff = offset; 907 int off; 908 Object data; 909 int nbands = raster.getNumBands(); 910 int dataType = raster.getDataBuffer().getDataType(); 911 switch (dataType) { 912 case DataBuffer.TYPE_BYTE: 913 data = new byte[nbands]; 914 break; 915 case DataBuffer.TYPE_USHORT: 916 data = new short[nbands]; 917 break; 918 case DataBuffer.TYPE_INT: 919 data = new int[nbands]; 920 break; 921 case DataBuffer.TYPE_FLOAT: 922 data = new float[nbands]; 923 break; 924 case DataBuffer.TYPE_DOUBLE: 925 data = new double[nbands]; 926 break; 927 default: 928 throw new IllegalArgumentException ("Unknown data buffer type: "+ 929 dataType); 930 } 931 932 if (rgbArray == null) { 933 rgbArray = new int[offset+h*scansize]; 934 } 935 936 for (int y = startY; y < startY+h; y++, yoff+=scansize) { 937 off = yoff; 938 for (int x = startX; x < startX+w; x++) { 939 rgbArray[off++] = colorModel.getRGB(raster.getDataElements(x, 940 y, 941 data)); 942 } 943 } 944 945 return rgbArray; 946 } 947 948 949 967 public synchronized void setRGB(int x, int y, int rgb) { 968 raster.setDataElements(x, y, colorModel.getDataElements(rgb, null)); 969 } 970 971 1000 public void setRGB(int startX, int startY, int w, int h, 1001 int[] rgbArray, int offset, int scansize) { 1002 int yoff = offset; 1003 int off; 1004 Object pixel = null; 1005 1006 for (int y = startY; y < startY+h; y++, yoff+=scansize) { 1007 off = yoff; 1008 for (int x = startX; x < startX+w; x++) { 1009 pixel = colorModel.getDataElements(rgbArray[off++], pixel); 1010 raster.setDataElements(x, y, pixel); 1011 } 1012 } 1013 } 1014 1015 1016 1020 public int getWidth() { 1021 return raster.getWidth(); 1022 } 1023 1024 1028 public int getHeight() { 1029 return raster.getHeight(); 1030 } 1031 1032 1037 public int getWidth(ImageObserver observer) { 1038 return raster.getWidth(); 1039 } 1040 1041 1046 public int getHeight(ImageObserver observer) { 1047 return raster.getHeight(); 1048 } 1049 1050 1056 public ImageProducer getSource() { 1057 if (osis == null) { 1058 if (properties == null) { 1059 properties = new Hashtable (); 1060 } 1061 osis = new OffScreenImageSource(this, properties); 1062 } 1063 return osis; 1064 } 1065 1066 1067 1087 public Object getProperty(String name, ImageObserver observer) { 1088 return getProperty(name); 1089 } 1090 1091 1098 public Object getProperty(String name) { 1099 if (name == null) { 1100 throw new NullPointerException ("null property name is not allowed"); 1101 } 1102 if (properties == null) { 1103 properties = new Hashtable (); 1104 } 1105 Object o = properties.get(name); 1106 if (o == null) { 1107 o = java.awt.Image.UndefinedProperty; 1108 } 1109 return o; 1110 } 1111 1112 1116 public void flush() { 1117 if (surfaceManager != null) { 1118 surfaceManager.flush(); 1119 } 1120 } 1121 1122 1130 public java.awt.Graphics getGraphics() { 1131 return createGraphics(); 1132 } 1133 1134 1140 public Graphics2D createGraphics() { 1141 GraphicsEnvironment env = 1142 GraphicsEnvironment.getLocalGraphicsEnvironment(); 1143 return env.createGraphics(this); 1144 } 1145 1146 1159 public BufferedImage getSubimage (int x, int y, int w, int h) { 1160 return new BufferedImage (colorModel, 1161 raster.createWritableChild(x, y, w, h, 1162 0, 0, null), 1163 colorModel.isAlphaPremultiplied(), 1164 properties); 1165 } 1166 1167 1173 public boolean isAlphaPremultiplied() { 1174 return colorModel.isAlphaPremultiplied(); 1175 } 1176 1177 1185 public void coerceData (boolean isAlphaPremultiplied) { 1186 if (colorModel.hasAlpha() && 1187 colorModel.isAlphaPremultiplied() != isAlphaPremultiplied) { 1188 colorModel = colorModel.coerceData (raster, isAlphaPremultiplied); 1190 } 1191 } 1192 1193 1199 public String toString() { 1200 return new String ("BufferedImage@"+Integer.toHexString(hashCode()) 1201 +": type = "+imageType 1202 +" "+colorModel+" "+raster); 1203 } 1204 1205 1220 public Vector <RenderedImage > getSources() { 1221 return null; 1222 } 1223 1224 1232 public String [] getPropertyNames() { 1233 return null; 1234 } 1235 1236 1242 public int getMinX() { 1243 return raster.getMinX(); 1244 } 1245 1246 1252 public int getMinY() { 1253 return raster.getMinY(); 1254 } 1255 1256 1262 public SampleModel getSampleModel() { 1263 return raster.getSampleModel(); 1264 } 1265 1266 1271 public int getNumXTiles() { 1272 return 1; 1273 } 1274 1275 1280 public int getNumYTiles() { 1281 return 1; 1282 } 1283 1284 1289 public int getMinTileX() { 1290 return 0; 1291 } 1292 1293 1298 public int getMinTileY() { 1299 return 0; 1300 } 1301 1302 1306 public int getTileWidth() { 1307 return raster.getWidth(); 1308 } 1309 1310 1314 public int getTileHeight() { 1315 return raster.getHeight(); 1316 } 1317 1318 1324 public int getTileGridXOffset() { 1325 return raster.getSampleModelTranslateX(); 1326 } 1327 1328 1334 public int getTileGridYOffset() { 1335 return raster.getSampleModelTranslateY(); 1336 } 1337 1338 1352 public Raster getTile(int tileX, int tileY) { 1353 if (tileX == 0 && tileY == 0) { 1354 return raster; 1355 } 1356 throw new ArrayIndexOutOfBoundsException ("BufferedImages only have"+ 1357 " one tile with index 0,0"); 1358 } 1359 1360 1367 public Raster getData() { 1368 1369 int width = raster.getWidth(); 1373 int height = raster.getHeight(); 1374 int startX = raster.getMinX(); 1375 int startY = raster.getMinY(); 1376 WritableRaster wr = 1377 Raster.createWritableRaster(raster.getSampleModel(), 1378 new Point (raster.getSampleModelTranslateX(), 1379 raster.getSampleModelTranslateY())); 1380 1381 Object tdata = null; 1382 1383 for (int i = startY; i < startY+height; i++) { 1384 tdata = raster.getDataElements(startX,i,width,1,tdata); 1385 wr.setDataElements(startX,i,width,1, tdata); 1386 } 1387 return wr; 1388 } 1389 1390 1401 public Raster getData(Rectangle rect) { 1402 SampleModel sm = raster.getSampleModel(); 1403 SampleModel nsm = sm.createCompatibleSampleModel(rect.width, 1404 rect.height); 1405 WritableRaster wr = Raster.createWritableRaster(nsm, 1406 rect.getLocation()); 1407 int width = rect.width; 1408 int height = rect.height; 1409 int startX = rect.x; 1410 int startY = rect.y; 1411 1412 Object tdata = null; 1413 1414 for (int i = startY; i < startY+height; i++) { 1415 tdata = raster.getDataElements(startX,i,width,1,tdata); 1416 wr.setDataElements(startX,i,width,1, tdata); 1417 } 1418 return wr; 1419 } 1420 1421 1436 public WritableRaster copyData(WritableRaster outRaster) { 1437 if (outRaster == null) { 1438 return (WritableRaster ) getData(); 1439 } 1440 int width = outRaster.getWidth(); 1441 int height = outRaster.getHeight(); 1442 int startX = outRaster.getMinX(); 1443 int startY = outRaster.getMinY(); 1444 1445 Object tdata = null; 1446 1447 for (int i = startY; i < startY+height; i++) { 1448 tdata = raster.getDataElements(startX,i,width,1,tdata); 1449 outRaster.setDataElements(startX,i,width,1, tdata); 1450 } 1451 1452 return outRaster; 1453 } 1454 1455 1465 public void setData(Raster r) { 1466 int width = r.getWidth(); 1467 int height = r.getHeight(); 1468 int startX = r.getMinX(); 1469 int startY = r.getMinY(); 1470 1471 int[] tdata = null; 1472 1473 Rectangle rclip = new Rectangle (startX, startY, width, height); 1475 Rectangle bclip = new Rectangle (0, 0, raster.width, raster.height); 1476 Rectangle intersect = rclip.intersection(bclip); 1477 if (intersect.isEmpty()) { 1478 return; 1479 } 1480 width = intersect.width; 1481 height = intersect.height; 1482 startX = intersect.x; 1483 startY = intersect.y; 1484 1485 for (int i = startY; i < startY+height; i++) { 1488 tdata = r.getPixels(startX,i,width,1,tdata); 1489 raster.setPixels(startX,i,width,1, tdata); 1490 } 1491 } 1492 1493 1494 1499 public void addTileObserver (TileObserver to) { 1500 } 1501 1502 1508 public void removeTileObserver (TileObserver to) { 1509 } 1510 1511 1522 public boolean isTileWritable (int tileX, int tileY) { 1523 if (tileX == 0 && tileY == 0) { 1524 return true; 1525 } 1526 throw new IllegalArgumentException ("Only 1 tile in image"); 1527 } 1528 1529 1537 public Point [] getWritableTileIndices() { 1538 Point [] p = new Point [1]; 1539 p[0] = new Point (0, 0); 1540 1541 return p; 1542 } 1543 1544 1553 public boolean hasTileWriters () { 1554 return true; 1555 } 1556 1557 1566 public WritableRaster getWritableTile (int tileX, int tileY) { 1567 return raster; 1568 } 1569 1570 1581 public void releaseWritableTile (int tileX, int tileY) { 1582 } 1583 1584 1593 public int getTransparency() { 1594 return colorModel.getTransparency(); 1595 } 1596 1597 1603 public ImageCapabilities getCapabilities(GraphicsConfiguration gc) { 1604 if (surfaceManager != null) { 1605 return surfaceManager.getCapabilities(gc); 1606 } 1607 return super.getCapabilities(gc); 1610 } 1611} 1612 1613 1614 | Popular Tags |