KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > renderable > TileRable8Bit


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image.renderable;
19
20 import java.awt.Graphics2D JavaDoc;
21 import java.awt.Rectangle JavaDoc;
22 import java.awt.RenderingHints JavaDoc;
23 import java.awt.Shape JavaDoc;
24 import java.awt.geom.AffineTransform JavaDoc;
25 import java.awt.geom.Point2D JavaDoc;
26 import java.awt.geom.Rectangle2D JavaDoc;
27 import java.awt.image.BufferedImage JavaDoc;
28 import java.awt.image.RenderedImage JavaDoc;
29 import java.awt.image.renderable.RenderContext JavaDoc;
30
31 import org.apache.batik.ext.awt.RenderingHintsKeyExt;
32 import org.apache.batik.ext.awt.image.GraphicsUtil;
33 import org.apache.batik.ext.awt.image.rendered.AffineRed;
34 import org.apache.batik.ext.awt.image.rendered.BufferedImageCachableRed;
35 import org.apache.batik.ext.awt.image.rendered.CachableRed;
36 import org.apache.batik.ext.awt.image.rendered.TileRed;
37
38 /**
39  * 8 bit TileRable implementation
40  *
41  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
42  * @version $Id: TileRable8Bit.java,v 1.9 2004/08/18 07:14:00 vhardy Exp $
43  */

44 public class TileRable8Bit
45     extends AbstractColorInterpolationRable
46     implements TileRable{
47     /**
48      * Tile region
49      */

50     private Rectangle2D JavaDoc tileRegion;
51
52     /**
53      * Tiled region
54      */

55     private Rectangle2D JavaDoc tiledRegion;
56
57     /**
58      * Controls whether the tileRegion clips the source
59      * or not
60      */

61     private boolean overflow;
62
63     /**
64      * Returns the tile region
65      */

66     public Rectangle2D JavaDoc getTileRegion(){
67         return tileRegion;
68     }
69
70     /**
71      * Sets the tile region
72      */

73     public void setTileRegion(Rectangle2D JavaDoc tileRegion){
74         if(tileRegion == null){
75             throw new IllegalArgumentException JavaDoc();
76         }
77         touch();
78         this.tileRegion = tileRegion;
79     }
80
81     /**
82      * Returns the tiled region
83      */

84     public Rectangle2D JavaDoc getTiledRegion(){
85         return tiledRegion;
86     }
87
88     /**
89      * Sets the tiled region
90      */

91     public void setTiledRegion(Rectangle2D JavaDoc tiledRegion){
92         if(tiledRegion == null){
93             throw new IllegalArgumentException JavaDoc();
94         }
95         touch();
96         this.tiledRegion = tiledRegion;
97     }
98
99     /**
100      * Returns the overflow strategy
101      */

102     public boolean isOverflow(){
103         return overflow;
104     }
105
106     /**
107      * Sets the overflow strategy
108      */

109     public void setOverflow(boolean overflow){
110         touch();
111         this.overflow = overflow;
112     }
113
114     /**
115      * Default constructor
116      */

117     public TileRable8Bit(Filter source,
118                          Rectangle2D JavaDoc tiledRegion,
119                          Rectangle2D JavaDoc tileRegion,
120                          boolean overflow){
121         super(source);
122
123         setTileRegion(tileRegion);
124         setTiledRegion(tiledRegion);
125         setOverflow(overflow);
126     }
127
128     /**
129      * Sets the filter source
130      */

131     public void setSource(Filter src){
132         init(src);
133     }
134
135     /**
136      * Return's the tile source
137      */

138     public Filter getSource(){
139         return (Filter)srcs.get(0);
140     }
141
142     /**
143      * Returns this filter's bounds
144      */

145     public Rectangle2D JavaDoc getBounds2D(){
146         return (Rectangle2D JavaDoc)tiledRegion.clone();
147     }
148
149     public RenderedImage JavaDoc createRendering(RenderContext JavaDoc rc){
150         // Just copy over the rendering hints.
151
RenderingHints JavaDoc rh = rc.getRenderingHints();
152         if (rh == null) rh = new RenderingHints JavaDoc(null);
153
154         // update the current affine transform
155
AffineTransform JavaDoc at = rc.getTransform();
156
157         double sx = at.getScaleX();
158         double sy = at.getScaleY();
159
160         double shx = at.getShearX();
161         double shy = at.getShearY();
162
163         double tx = at.getTranslateX();
164         double ty = at.getTranslateY();
165
166         // The Scale is the "hypotonose" of the matrix vectors.
167
double scaleX = Math.sqrt(sx*sx + shy*shy);
168         double scaleY = Math.sqrt(sy*sy + shx*shx);
169
170         // System.out.println("AT: " + at);
171
// System.out.println("Scale: " + scaleX + "x" + scaleY);
172

173         //
174
// Compute the actual tiled area (intersection of AOI
175
// and bounds) and the actual tile (anchored in the
176
// upper left corner of the tiled area
177
//
178

179         // tiledRect
180
Rectangle2D JavaDoc tiledRect = getBounds2D();
181         Rectangle2D JavaDoc aoiRect;
182         Shape JavaDoc aoiShape = rc.getAreaOfInterest();
183         if (aoiShape == null)
184             aoiRect = tiledRect;
185         else {
186             aoiRect = aoiShape.getBounds2D();
187
188             if (tiledRect.intersects(aoiRect) == false)
189                 return null;
190             Rectangle2D.intersect(tiledRect, aoiRect, tiledRect);
191         }
192
193         // tileRect
194
Rectangle2D JavaDoc tileRect = tileRegion;
195         
196         // Adjust the scale so that the tiling happens on pixel
197
// boundaries on both axis.
198
// Desired pixel rect width
199
int dw = (int)(Math.ceil(tileRect.getWidth() *scaleX));
200         int dh = (int)(Math.ceil(tileRect.getHeight()*scaleY));
201
202         double tileScaleX = dw/tileRect.getWidth();
203         double tileScaleY = dh/tileRect.getHeight();
204
205         // System.out.println("scaleX/scaleY : " + scaleX + " / " + scaleY);
206
// System.out.println("tileScaleX/tileScaleY : " + tileScaleX + " / " + tileScaleY);
207

208         // Adjust the translation so that the tile's origin falls on
209
// pixel boundary
210
int dx = (int)Math.floor(tileRect.getX()*tileScaleX);
211         int dy = (int)Math.floor(tileRect.getY()*tileScaleY);
212
213         double ttx = dx - (tileRect.getX()*tileScaleX);
214         double tty = dy - (tileRect.getY()*tileScaleY);
215
216         // System.out.println("ttx/tty : " + ttx + " / " + tty);
217

218         // Get result unsheared or rotated
219
AffineTransform JavaDoc tileAt;
220         // tileAt = AffineTransform.getScaleInstance(tileScaleX, tileScaleY);
221
// tileAt.translate(ttx, tty);
222
// System.out.println("Pt: " + tileAt.transform
223
// (new Point2D.Double(aoiRect.getX(),
224
// aoiRect.getY()), null));
225

226
227         tileAt = AffineTransform.getTranslateInstance(ttx, tty);
228         tileAt.scale(tileScaleX, tileScaleY);
229
230         // System.out.println("Pt: " + tileAt.transform
231
// (new Point2D.Double(aoiRect.getX(),
232
// aoiRect.getY()), null));
233

234         // System.out.println("tileRect in userSpace : " + tileRect);
235
// System.out.println("tileRect in deviceSpace : " +
236
// tileAt.createTransformedShape(tileRect).
237
// getBounds2D());
238
Filter source = getSource();
239
240         Rectangle2D JavaDoc srcRect;
241         if (overflow)
242             srcRect = source.getBounds2D();
243         else
244             srcRect = tileRect;
245
246         // System.out.println("SrcRect: " + srcRect);
247

248         RenderContext JavaDoc tileRc = new RenderContext JavaDoc(tileAt, srcRect, rh);
249         // RenderedImage tileRed = new DemandRed(source, tileRc);
250
RenderedImage JavaDoc tileRed = source.createRendering(tileRc);
251         
252         // System.out.println("TileRed: " +
253
// GraphicsUtil.wrap(tileRed).getBounds());
254

255         // RenderedImage tileRed = createTile(tileRc);
256
// System.out.println("tileRed : " + tileRed.getMinX() + "/" + tileRed.getMinY() + "/"
257
// + tileRed.getWidth() + "/" + tileRed.getHeight());
258
if(tileRed == null)
259             return null;
260
261
262         // System.out.println("aoiRect: " + aoiRect);
263

264         Rectangle JavaDoc tiledArea = tileAt.createTransformedShape
265             (aoiRect).getBounds();
266
267         // Serious hack alert!!!
268
// In some cases the bounds are set to cover the whole area.
269
// when they get scaled up sometimes the lower bounds go
270
// to Integer.MIN_VALUE, and width/height to Integer.MAX_VALUE,
271
// but this only covers the negative quarter of the canvas!!!
272
// So if width and height are MAX_VALUE then we assume this
273
// clipping has happened and we recenter the range.
274
// Yes this is a serious hack and I appologies for it.
275
// I wouldn't need to do this if PatternPaintContext knew
276
// what it's bounds were going to be....
277
if ((tiledArea.width == Integer.MAX_VALUE)||
278             (tiledArea.height == Integer.MAX_VALUE)) {
279             tiledArea = new Rectangle JavaDoc(Integer.MIN_VALUE/4,
280                                       Integer.MIN_VALUE/4,
281                                       Integer.MAX_VALUE/2,
282                                       Integer.MAX_VALUE/2);
283         }
284         // System.out.println("tiledArea: " + tiledArea);
285
tileRed = convertSourceCS(tileRed);
286         TileRed tiledRed = new TileRed(tileRed, tiledArea, dw, dh);
287
288         // org.apache.batik.test.gvt.ImageDisplay.showImage("Tile", tiledRed);
289
// System.out.println("TileR: " + tiledRed.getBounds());
290

291         // Return sheared/rotated tiled image
292
AffineTransform JavaDoc shearAt =
293             new AffineTransform JavaDoc(sx/scaleX, shy/scaleX,
294                                 shx/scaleY, sy/scaleY,
295                                 tx, ty);
296         shearAt.scale(scaleX/tileScaleX, scaleY/tileScaleY);
297         
298         shearAt.translate(-ttx, -tty);
299
300         CachableRed cr = tiledRed;
301         if(!shearAt.isIdentity())
302             cr = new AffineRed(tiledRed, shearAt, rh);
303
304         // System.out.println("AffineR: " + cr.getBounds());
305

306         return cr;
307     }
308
309     public Rectangle2D JavaDoc getActualTileBounds(Rectangle2D JavaDoc tiledRect){
310         // Get the tile rectangle in user space
311
Rectangle2D JavaDoc tileRect = (Rectangle2D JavaDoc)tileRegion.clone();
312
313         // System.out.println("tileRect : " + tileRect);
314
// System.out.println("tiledRect: " + tiledRect);
315

316         if ((tileRect.getWidth() <= 0)
317             || (tileRect.getHeight() <= 0)
318             || (tiledRect.getWidth() <= 0)
319             || (tiledRect.getHeight() <= 0))
320             return null;
321
322
323         double tileWidth = tileRect.getWidth();
324         double tileHeight = tileRect.getHeight();
325         
326         double tiledWidth = tiledRect.getWidth();
327         double tiledHeight = tiledRect.getHeight();
328
329         double w = Math.min(tileWidth, tiledWidth);
330         double h = Math.min(tileHeight, tiledHeight);
331
332         Rectangle2D JavaDoc realTileRect
333             = new Rectangle2D.Double JavaDoc(tileRect.getX(),
334                                      tileRect.getY(),
335                                      w, h);
336
337         return realTileRect;
338     }
339
340     /**
341      * Computes the tile to use for the tiling operation.
342      *
343      * The tile has its origin in the upper left
344      * corner of the tiled region. That tile is separated
345      * into 4 areas: top-left, top-right, bottom-left and
346      * bottom-right. Each of these areas is mapped to
347      * some input area from the source.
348      * If the source is smaller than the tiled area, then
349      * a single rendering is requested from the source.
350      * If the source's width or height is bigger than that
351      * of the tiled area, then separate renderings are
352      * requested from the source.
353      *
354      */

355     public RenderedImage JavaDoc createTile(RenderContext JavaDoc rc){
356         AffineTransform JavaDoc usr2dev = rc.getTransform();
357
358         // Hints
359
RenderingHints JavaDoc hints = rc.getRenderingHints();
360         if(hints == null){
361             hints = new RenderingHints JavaDoc(null);
362         } else {
363             hints = new RenderingHints JavaDoc(hints);
364         }
365
366         // The region actually tiles is the intersection
367
// of the tiledRegion and the area of interest
368
Rectangle2D JavaDoc tiledRect = getBounds2D();
369         Shape JavaDoc aoiShape = rc.getAreaOfInterest();
370         Rectangle2D JavaDoc aoiRect = aoiShape.getBounds2D();
371         if (tiledRect.intersects(aoiRect) == false)
372             return null;
373         Rectangle2D.intersect(tiledRect, aoiRect, tiledRect);
374
375         // Get the tile rectangle in user space
376
Rectangle2D JavaDoc tileRect = (Rectangle2D JavaDoc)tileRegion.clone();
377
378         // System.out.println("tileRect : " + tileRect);
379
// System.out.println("tiledRect: " + tiledRect);
380

381         if ((tileRect.getWidth() <= 0)
382             || (tileRect.getHeight() <= 0)
383             || (tiledRect.getWidth() <= 0)
384             || (tiledRect.getHeight() <= 0))
385             return null;
386
387         //
388
// (tiledX, tiledY)
389
// <------- min(tileWidth, tiledWidth) ----------->
390
// ^ +------+-------------------------------------+
391
// | + A' + B' +
392
// | +------+-------------------------------------+
393
// min(tileHeight, | + + +
394
// tiledHeight) | + + +
395
// | + C' + D' +
396
// | + + +
397
// ^ +------+-------------------------------------+
398
//
399
// Maps to, in the tile:
400
//
401
// (tileX, tileY)
402
//
403
// <----------- tileWidth --------------->
404
// ^ +-----------------------------+------+-------+
405
// | + + + |
406
// tiledHeight | + + + |
407
// | + D + + C |
408
// | + + + |
409
// | +-----------------------------+------+-------|
410
// | + | | |
411
// | + | | |
412
// | +-----------------------------+------+-------+
413
// | | B + + A |
414
// ^ +-----------------------------+------+-------+
415

416         // w = min(tileWidth, tiledWidth)
417
// h = min(tileHeight, tiledHeight)
418
// dx = tileWidth - (tiledX - tileX)%tileWidth;
419
// dy = tileHeight - (tiledY - tileY)%tileHeight;
420
//
421
// A = (tileX + tileWidth - dx, tileY + tileHeight - dy, dx, dy)
422
// B = (tileX, tileY + tileHeight - dy, w - dx, dy)
423
// C = (tileX + tileWidth - dx, tileY, dx, h - dy)
424
// D = (tileX, tileY, w - dx, h - dy)
425

426         double tileX = tileRect.getX();
427         double tileY = tileRect.getY();
428         double tileWidth = tileRect.getWidth();
429         double tileHeight = tileRect.getHeight();
430         
431         double tiledX = tiledRect.getX();
432         double tiledY = tiledRect.getY();
433         double tiledWidth = tiledRect.getWidth();
434         double tiledHeight = tiledRect.getHeight();
435
436         double w = Math.min(tileWidth, tiledWidth);
437         double h = Math.min(tileHeight, tiledHeight);
438         double dx = (tiledX - tileX)%tileWidth;
439         double dy = (tiledY - tileY)%tileHeight;
440
441         if(dx > 0){
442             dx = tileWidth - dx;
443         }
444         else{
445             dx *= -1;
446         }
447
448         if(dy > 0){
449             dy = tileHeight - dy;
450         }
451         else{
452             dy *= -1;
453         }
454
455         //
456
// Adjust dx and dy so that they fall on a pixel boundary
457
//
458
double scaleX = usr2dev.getScaleX();
459         double scaleY = usr2dev.getScaleY();
460         double tdx = Math.floor(scaleX*dx);
461         double tdy = Math.floor(scaleY*dy);
462
463         dx = tdx/scaleX;
464         dy = tdy/scaleY;
465
466         // System.out.println("dx / dy / w / h : " + dx + " / " + dy + " / " + w + " / " + h);
467

468         Rectangle2D.Double JavaDoc A = new Rectangle2D.Double JavaDoc
469             (tileX + tileWidth - dx, tileY + tileHeight - dy, dx, dy);
470         Rectangle2D.Double JavaDoc B = new Rectangle2D.Double JavaDoc
471             (tileX, tileY + tileHeight - dy, w - dx, dy);
472         Rectangle2D.Double JavaDoc C = new Rectangle2D.Double JavaDoc
473             (tileX + tileWidth - dx, tileY, dx, h - dy);
474         Rectangle2D.Double JavaDoc D = new Rectangle2D.Double JavaDoc
475             (tileX, tileY, w - dx, h - dy);
476
477         Rectangle2D JavaDoc realTileRect
478             = new Rectangle2D.Double JavaDoc(tiledRect.getX(),
479                                      tiledRect.getY(),
480                                      w, h);
481
482         // System.out.println("A rect : " + A);
483
// System.out.println("B rect : " + B);
484
// System.out.println("C rect : " + C);
485
// System.out.println("D rect : " + D);
486
// System.out.println("realTileR : " + realTileRect);
487

488         // A, B, C and D are the four user space are that make the
489
// tile that will be used. We create a rendering for each of
490
// these areas that i s not empty (i.e., with either width or
491
// height equal to zero)
492
RenderedImage JavaDoc ARed = null, BRed = null, CRed = null, DRed = null;
493         Filter source = getSource();
494         
495         if (A.getWidth() > 0 && A.getHeight() > 0){
496             // System.out.println("Rendering A");
497
Rectangle JavaDoc devA = usr2dev.createTransformedShape(A).getBounds();
498             if(devA.width > 0 && devA.height > 0){
499                 AffineTransform JavaDoc ATxf = new AffineTransform JavaDoc(usr2dev);
500                 ATxf.translate(-A.x + tiledX,
501                                -A.y + tiledY);
502
503                 Shape JavaDoc aoi = A;
504                 if(overflow){
505                     aoi = new Rectangle2D.Double JavaDoc(A.x,
506                                                  A.y,
507                                                  tiledWidth,
508                                                  tiledHeight);
509                 }
510
511                 hints.put(RenderingHintsKeyExt.KEY_AREA_OF_INTEREST,
512                           aoi);
513
514                 RenderContext JavaDoc arc
515                     = new RenderContext JavaDoc(ATxf, aoi, hints);
516
517                 ARed = source.createRendering(arc);
518                 
519                 //System.out.println("ARed : " + ARed.getMinX() + " / " +
520
// ARed.getMinY() + " / " +
521
// ARed.getWidth() + " / " +
522
// ARed.getHeight());
523
}
524         }
525
526         if(B.getWidth() > 0 && B.getHeight() > 0){
527             // System.out.println("Rendering B");
528
Rectangle JavaDoc devB = usr2dev.createTransformedShape(B).getBounds();
529             if(devB.width > 0 && devB.height > 0){
530                 AffineTransform JavaDoc BTxf = new AffineTransform JavaDoc(usr2dev);
531                 BTxf.translate(-B.x + (tiledX + dx),
532                                -B.y + tiledY);
533
534                 Shape JavaDoc aoi = B;
535                 if(overflow){
536                     aoi = new Rectangle2D.Double JavaDoc(B.x - tiledWidth + w - dx,
537                                                  B.y,
538                                                  tiledWidth,
539                                                  tiledHeight);
540                 }
541
542                 hints.put(RenderingHintsKeyExt.KEY_AREA_OF_INTEREST,
543                           aoi);
544
545                 RenderContext JavaDoc brc
546                     = new RenderContext JavaDoc(BTxf, aoi, hints);
547
548                 BRed = source.createRendering(brc);
549                 // System.out.println("BRed : " + BRed.getMinX() + " / " + BRed.getMinY() + " / " + BRed.getWidth() + " / " + BRed.getHeight());
550
}
551         }
552
553         if(C.getWidth() > 0 && C.getHeight() > 0){
554             // System.out.println("Rendering C");
555
Rectangle JavaDoc devC = usr2dev.createTransformedShape(C).getBounds();
556             if(devC.width > 0 && devC.height > 0){
557                 AffineTransform JavaDoc CTxf = new AffineTransform JavaDoc(usr2dev);
558                 CTxf.translate(-C.x + tiledX,
559                                -C.y + (tiledY + dy));
560
561                 Shape JavaDoc aoi = C;
562                 if(overflow){
563                     aoi = new Rectangle2D.Double JavaDoc(C.x,
564                                                  C.y - tileHeight + h - dy,
565                                                  tiledWidth,
566                                                  tiledHeight);
567                 }
568
569                 hints.put(RenderingHintsKeyExt.KEY_AREA_OF_INTEREST,
570                           aoi);
571
572                 RenderContext JavaDoc crc
573                     = new RenderContext JavaDoc(CTxf, aoi, hints);
574
575                 CRed = source.createRendering(crc);
576                 // System.out.println("CRed : " + CRed.getMinX() + " / " + CRed.getMinY() + " / " + CRed.getWidth() + " / " + CRed.getHeight());
577
}
578         }
579
580         if(D.getWidth() > 0 && D.getHeight() > 0){
581             // System.out.println("Rendering D");
582
Rectangle JavaDoc devD = usr2dev.createTransformedShape(D).getBounds();
583             if(devD.width > 0 && devD.height > 0){
584                 AffineTransform JavaDoc DTxf = new AffineTransform JavaDoc(usr2dev);
585                 DTxf.translate(-D.x + (tiledX + dx),
586                                -D.y + (tiledY + dy));
587
588                 Shape JavaDoc aoi = D;
589                 if(overflow){
590                     aoi = new Rectangle2D.Double JavaDoc(D.x - tileWidth + w - dx,
591                                                  D.y - tileHeight + h - dy,
592                                                  tiledWidth,
593                                                  tiledHeight);
594                 }
595
596                 hints.put(RenderingHintsKeyExt.KEY_AREA_OF_INTEREST,
597                           aoi);
598
599                 RenderContext JavaDoc drc
600                     = new RenderContext JavaDoc(DTxf, aoi, hints);
601
602                 DRed = source.createRendering(drc);
603                 // System.out.println("DRed : " + DRed.getMinX() + " / " + DRed.getMinY() + " / " + DRed.getWidth() + " / " + DRed.getHeight());
604
}
605         }
606
607         //
608
// Now, combine ARed, BRed, CRed and DRed into a single
609
// RenderedImage that will be tiled
610
//
611
final Rectangle JavaDoc realTileRectDev
612             = usr2dev.createTransformedShape(realTileRect).getBounds();
613         
614         if(realTileRectDev.width == 0 || realTileRectDev.height == 0){
615             return null;
616         }
617
618         BufferedImage JavaDoc realTileBI
619             = new BufferedImage JavaDoc(realTileRectDev.width,
620                                 realTileRectDev.height,
621                                 BufferedImage.TYPE_INT_ARGB);
622         
623         Graphics2D JavaDoc g = GraphicsUtil.createGraphics(realTileBI,
624                                                    rc.getRenderingHints());
625         // g.setPaint(new java.awt.Color(0, 255, 0, 64));
626
// g.fillRect(0, 0, realTileBI.getWidth(), realTileBI.getHeight());
627
g.translate(-realTileRectDev.x,
628                     -realTileRectDev.y);
629
630         // System.out.println("realTileRectDev " + realTileRectDev);
631

632         AffineTransform JavaDoc redTxf = new AffineTransform JavaDoc();
633         Point2D.Double JavaDoc redVec = new Point2D.Double JavaDoc();
634         RenderedImage JavaDoc refRed = null;
635         if(ARed != null){
636             // System.out.println("Drawing A");
637
g.drawRenderedImage(ARed, redTxf);
638             refRed = ARed;
639         }
640         if(BRed != null){
641             // System.out.println("Drawing B");
642

643             if(refRed == null){
644                 refRed = BRed;
645             }
646
647             // Adjust B's coordinates
648
redVec.x = dx;
649             redVec.y = 0;
650             usr2dev.deltaTransform(redVec, redVec);
651             redVec.x = Math.floor(redVec.x) - (BRed.getMinX() - refRed.getMinX());
652             redVec.y = Math.floor(redVec.y) - (BRed.getMinY() - refRed.getMinY());
653
654             // System.out.println("BRed adjust : " + redVec);
655

656                 // redTxf.setToTranslation(redVec.x, redVec.y);
657
g.drawRenderedImage(BRed, redTxf);
658         }
659         if(CRed != null){
660             // System.out.println("Drawing C");
661

662             if(refRed == null){
663                 refRed = CRed;
664             }
665
666             // Adjust C's coordinates
667
redVec.x = 0;
668             redVec.y = dy;
669             usr2dev.deltaTransform(redVec, redVec);
670             redVec.x = Math.floor(redVec.x) - (CRed.getMinX() - refRed.getMinX());
671             redVec.y = Math.floor(redVec.y) - (CRed.getMinY() - refRed.getMinY());
672
673             // System.out.println("CRed adjust : " + redVec);
674

675                 // redTxf.setToTranslation(redVec.x, redVec.y);
676
g.drawRenderedImage(CRed, redTxf);
677         }
678         if(DRed != null){
679             // System.out.println("Drawing D");
680

681             if(refRed == null){
682                 refRed = DRed;
683             }
684
685             // Adjust D's coordinates
686
redVec.x = dx;
687             redVec.y = dy;
688             usr2dev.deltaTransform(redVec, redVec);
689             redVec.x = Math.floor(redVec.x) - (DRed.getMinX() - refRed.getMinX());
690             redVec.y = Math.floor(redVec.y) - (DRed.getMinY() - refRed.getMinY());
691
692             // System.out.println("DRed adjust : " + redVec);
693

694                 // redTxf.setToTranslation(redVec.x, redVec.y);
695
g.drawRenderedImage(DRed, redTxf);
696         }
697
698         CachableRed realTile;
699         realTile = new BufferedImageCachableRed(realTileBI,
700                                                 realTileRectDev.x,
701                                                 realTileRectDev.y);
702
703         return realTile;
704     }
705 }
706
Popular Tags