Project

General

Profile

caching_images_20151010.txt

Sergey Ivanovskiy, 10/10/2015 05:40 AM

Download (15 KB)

 
1
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/BufferedImageDrawHelper.java'
2
--- src/com/goldencode/p2j/ui/client/gui/driver/BufferedImageDrawHelper.java	2015-08-13 14:51:06 +0000
3
+++ src/com/goldencode/p2j/ui/client/gui/driver/BufferedImageDrawHelper.java	2015-10-10 08:29:27 +0000
4
@@ -30,11 +30,16 @@
5
     * 
6
     * @param    ps
7
     *           The holder for images parameters.
8
+    * @param    transformImage
9
+    *           The transform image flag that indicates the original image must be transformed
10
+    *           iff this boolean flag is true, otherwise the method returns the unchanged image
11
+    *           with new calculated bounds. 
12
     * 
13
     * @return The wrapped image with its with and its height.
14
     */
15
    @Override
16
-   public ImageWrapper<BufferedImage> processImage(PaintStructure<?, BufferedImage> ps)
17
+   public ImageWrapper<BufferedImage> processImage(PaintStructure<?, BufferedImage> ps,
18
+            boolean transformImage)
19
    {
20
       BufferedImage img2draw = null;
21
       int width  = 0;
22
@@ -65,12 +70,21 @@
23
          {
24
             heightToCut = ps.height;
25
          }
26
+
27
+         BufferedImage fullImg = ((ImageWrapper<BufferedImage>)ps.img).getImage();
28
+         BufferedImage bimg;
29
          // partial image, get subimage
30
-         BufferedImage fullImg = ((ImageWrapper<BufferedImage>)ps.img).getImage();
31
-         BufferedImage bimg = fullImg.getSubimage(ps.xOffset,
32
-                                                  ps.yOffset,
33
-                                                  widthToCut,
34
-                                                  heightToCut);
35
+         if (transformImage)
36
+         {
37
+            bimg = fullImg.getSubimage(ps.xOffset,
38
+                                       ps.yOffset,
39
+                                       widthToCut,
40
+                                       heightToCut);
41
+         }
42
+         else
43
+         {
44
+            bimg = fullImg;
45
+         }
46
          
47
          if (bimg != null)
48
          {
49
@@ -86,12 +100,12 @@
50
       {
51
          // check binary image options
52
          // 3D color conversions
53
-         if (ps.convert3D)
54
+         if (ps.convert3D && transformImage)
55
          {
56
             img2draw = get3DColorsConvertedImage((BufferedImage)img2draw);
57
          }
58
          // transparency
59
-         if (ps.transparent)
60
+         if (ps.transparent && transformImage)
61
          {
62
             int pixTrans = img2draw.getRGB(0, height - 1);
63
             img2draw = getTransparentImage(img2draw, pixTrans);
64

    
65
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/ClientImageDrawHelper.java'
66
--- src/com/goldencode/p2j/ui/client/gui/driver/ClientImageDrawHelper.java	2015-08-13 14:51:06 +0000
67
+++ src/com/goldencode/p2j/ui/client/gui/driver/ClientImageDrawHelper.java	2015-10-10 08:24:45 +0000
68
@@ -27,8 +27,12 @@
69
     * 
70
     * @param    ps
71
     *           The holder for images parameters.
72
+    * @param    transformImage
73
+    *           The transform image flag that indicates the original image must be transformed
74
+    *           iff this boolean flag is true, otherwise the method returns the unchanged image
75
+    *           with new calculated bounds. 
76
     * 
77
     * @return The wrapped image with its with and its height.
78
     */
79
-   public ImageWrapper<I> processImage(PaintStructure<?, I> ps);
80
+   public ImageWrapper<I> processImage(PaintStructure<?, I> ps, boolean transformImage);
81
 }
82

    
83
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/ImageWrapper.java'
84
--- src/com/goldencode/p2j/ui/client/gui/driver/ImageWrapper.java	2015-05-18 20:48:28 +0000
85
+++ src/com/goldencode/p2j/ui/client/gui/driver/ImageWrapper.java	2015-10-10 08:52:50 +0000
86
@@ -74,4 +74,45 @@
87
    {
88
       return width;
89
    }
90
+
91
+   /* (non-Javadoc)
92
+    * @see java.lang.Object#hashCode()
93
+    */
94
+   @Override
95
+   public int hashCode()
96
+   {
97
+      final int prime = 31;
98
+      int result = 1;
99
+      result = prime * result + height;
100
+      result = prime * result + ((image == null) ? 0 : image.hashCode());
101
+      result = prime * result + width;
102
+      return result;
103
+   }
104
+
105
+   /* (non-Javadoc)
106
+    * @see java.lang.Object#equals(java.lang.Object)
107
+    */
108
+   @Override
109
+   public boolean equals(Object obj)
110
+   {
111
+      if (this == obj)
112
+         return true;
113
+      if (obj == null)
114
+         return false;
115
+      if (getClass() != obj.getClass())
116
+         return false;
117
+      ImageWrapper other = (ImageWrapper) obj;
118
+      if (height != other.height)
119
+         return false;
120
+      if (image == null)
121
+      {
122
+         if (other.image != null)
123
+            return false;
124
+      }
125
+      else if (!image.equals(other.image))
126
+         return false;
127
+      if (width != other.width)
128
+         return false;
129
+      return true;
130
+   }
131
 }
132

    
133
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/PaintStructure.java'
134
--- src/com/goldencode/p2j/ui/client/gui/driver/PaintStructure.java	2015-09-16 16:53:54 +0000
135
+++ src/com/goldencode/p2j/ui/client/gui/driver/PaintStructure.java	2015-10-10 09:14:46 +0000
136
@@ -34,6 +34,18 @@
137
  */
138
 public class PaintStructure<F, I>
139
 {
140
+   /** convert 3d image bit mask */
141
+   private static final int CONVERT_3D_MASK  = 1;
142
+
143
+   /** transparent image bit mask */
144
+   private static final int TRANSPARENT_MASK = 2;
145
+
146
+   /** stretch to fit image bit mask */
147
+   private static final int STRETCH_TO_FIT_MASK = 4;
148
+
149
+   /** retain shape image bit mask */
150
+   private static final int RETAIN_SHAPE_MASK   = 8;
151
+
152
    /** Paint operation */
153
    public PaintPrimitives id;
154
    
155
@@ -119,4 +131,169 @@
156
    {
157
       this.id = id;
158
    }
159
+   
160
+   /**
161
+    * Return the embedded image structure filled with the required parameters to draw the target.
162
+    * 
163
+    * @return   The embedded image structure.
164
+    */
165
+   public EmbeddedImageStructure getEmbeddedImageStructure()
166
+   {
167
+      return new EmbeddedImageStructure();
168
+   }
169
+   
170
+   /**
171
+    * Encapsulates the image drawing parameters and the image caching hash code. 
172
+    */
173
+   public class EmbeddedImageStructure
174
+   {
175
+      /**
176
+       * Returns the image canvas width.
177
+       * 
178
+       * @return   The width.
179
+       */
180
+      public int getWidth()
181
+      {
182
+         return width;
183
+      }
184
+
185
+      /**
186
+       * Returns the image canvas height.
187
+       * 
188
+       * @return The canvas height.
189
+       */
190
+      public int getHeight()
191
+      {
192
+         return height;
193
+      }
194
+
195
+      /**
196
+       * The image drawing offset along x-axis.
197
+       * 
198
+       * @return   The xOffset
199
+       */
200
+      public int getxOffset()
201
+      {
202
+         return xOffset;
203
+      }
204
+
205
+      /**
206
+       * The image drawing offset along y-axis.
207
+       * 
208
+       * @return   The yOffset.
209
+       */
210
+      public int getyOffset()
211
+      {
212
+         return yOffset;
213
+      }
214
+
215
+      /**
216
+       * Returns the wrapped image to draw.
217
+       * 
218
+       * @return   The wrapped image.
219
+       */
220
+      public ImageWrapper<I> getImage()
221
+      {
222
+         return img;
223
+      }
224
+
225
+      /**
226
+       * Encodes image conversions: 3d, transparent, stretch, retain.
227
+       * 
228
+       * @return   The bits mask that encodes image conversions.
229
+       */
230
+      public int getImageConversionMask()
231
+      {
232
+         int mask = 0;
233
+         if (convert3D)
234
+         {
235
+            mask |= CONVERT_3D_MASK;
236
+         }
237
+         if (transparent)
238
+         {
239
+            mask |= TRANSPARENT_MASK;
240
+         }
241
+         if (stretchToFit)
242
+         {
243
+            mask |= STRETCH_TO_FIT_MASK;
244
+         }
245
+         if (retainShape)
246
+         {
247
+            mask |= RETAIN_SHAPE_MASK;
248
+         }
249
+
250
+         return mask;
251
+      }
252
+
253
+      /* (non-Javadoc)
254
+       * @see java.lang.Object#hashCode()
255
+       */
256
+      @Override
257
+      public int hashCode()
258
+      {
259
+         final int prime = 31;
260
+         int result = 1;
261
+         result = prime * result + getImageConversionMask();
262
+         result = prime * result + ((img == null) ? 0 : img.hashCode());
263
+         result = prime * result + height;
264
+         result = prime * result + width;
265
+         result = prime * result + xOffset;
266
+         result = prime * result + yOffset;
267
+         return result;
268
+      }
269
+
270
+      /* (non-Javadoc)
271
+       * @see java.lang.Object#equals(java.lang.Object)
272
+       */
273
+      @Override
274
+      public boolean equals(Object obj)
275
+      {
276
+         if (this == obj)
277
+         {
278
+            return true;
279
+         }
280
+         if (obj == null)
281
+         {
282
+            return false;
283
+         }
284
+         if (getClass() != obj.getClass())
285
+         {
286
+            return false;
287
+         }
288
+         EmbeddedImageStructure other = (EmbeddedImageStructure) obj;
289
+         
290
+         if (getImageConversionMask() != other.getImageConversionMask())
291
+         {
292
+            return false;
293
+         }
294
+         if (getImage() == null)
295
+         {
296
+            if (other.getImage() != null)
297
+            {
298
+               return false;
299
+            }
300
+         }
301
+         else if (!getImage().equals(other.getImage()))
302
+         {
303
+            return false;
304
+         }
305
+         if (width != other.getWidth())
306
+         {
307
+            return false;
308
+         }
309
+         if (height != other.getHeight())
310
+         {
311
+            return false;
312
+         }
313
+         if (xOffset != other.getxOffset())
314
+         {
315
+            return false;
316
+         }
317
+         if (yOffset != other.getyOffset())
318
+         {
319
+            return false;
320
+         }
321
+         return true;
322
+      }
323
+   }
324
 }
325

    
326
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingEmulatedWindow.java'
327
--- src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingEmulatedWindow.java	2015-10-06 19:09:18 +0000
328
+++ src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingEmulatedWindow.java	2015-10-10 09:18:27 +0000
329
@@ -716,7 +716,7 @@
330
             g2.drawRoundRect(ps.x, ps.y, ps.width, ps.height, ps.arcDiameter, ps.arcDiameter);
331
             break;
332
          case DRAW_IMAGE:
333
-            ImageWrapper<BufferedImage> preparedImage = drawHelper.processImage(ps);
334
+            ImageWrapper<BufferedImage> preparedImage = drawHelper.processImage(ps, true);
335
             if (preparedImage.getImage() != null) {
336
                g2.drawImage(preparedImage.getImage(), ps.x, ps.y, preparedImage.getWidth(), preparedImage.getHeight(), pane);
337
             }
338

    
339
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebEmulatedWindow.java'
340
--- src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebEmulatedWindow.java	2015-09-29 14:43:06 +0000
341
+++ src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebEmulatedWindow.java	2015-10-10 09:15:46 +0000
342
@@ -320,12 +320,13 @@
343
             break;
344
          case DRAW_IMAGE:
345
             {
346
-               ImageWrapper wrappedImage = drawHelper.processImage(ps);
347
-               Object[] imageEncodedPacket = encodeImage(ps.x, ps.y, wrappedImage);
348
+               int hashCode = ps.getEmbeddedImageStructure().hashCode();
349
+               Object[] imageEncodedPacket = encodeImage(ps, hashCode);
350
                int imageHash = (Integer) imageEncodedPacket[0];
351
                ImageEncoding encoding = (ImageEncoding) imageEncodedPacket[1];
352
                byte[] encodedImage = (byte[]) imageEncodedPacket[2];
353
-               websock.drawImage(ps.x, ps.y, wrappedImage.getWidth(), wrappedImage.getHeight(),
354
+               ImageWrapper embeddedImage = (ImageWrapper) imageEncodedPacket[3];
355
+               websock.drawImage(ps.x, ps.y, embeddedImage.getWidth(), embeddedImage.getHeight(),
356
                         encoding, imageHash, encodedImage);
357
             }
358
             break;
359
@@ -417,12 +418,13 @@
360
             break;
361
          case SET_ICON:
362
             {
363
-               ImageWrapper wrappedImage = drawHelper.processImage(ps);
364
-               Object[] imageEncodedPacket = encodeImage(ps.x, ps.y, wrappedImage);
365
+               int hashCode = ps.getEmbeddedImageStructure().hashCode();
366
+               Object[] imageEncodedPacket = encodeImage(ps, hashCode);
367
                int imageHash = (Integer) imageEncodedPacket[0];
368
                ImageEncoding encoding = (ImageEncoding) imageEncodedPacket[1];
369
                byte[] encodedImage = (byte[]) imageEncodedPacket[2];
370
-               websock.setIconImage(wrappedImage.getWidth(), wrappedImage.getHeight(), encoding,
371
+               ImageWrapper embeddedImage = (ImageWrapper) imageEncodedPacket[3];
372
+               websock.setIconImage(embeddedImage.getWidth(), embeddedImage.getHeight(), encoding,
373
                         imageHash, encodedImage);
374
             }
375
             break;
376
@@ -436,37 +438,39 @@
377
     * the image hash in its first element, the image encoding in its second element
378
     * and the encoded image or null in its third element depending on its loaded state.
379
     * 
380
-    * @param    x
381
-    *           The x-coordinate of the target image position. 
382
-    * @param    y
383
-    *           The y-coordinate of the target image position.
384
-    * @param    wrappedImage
385
-    *           The wrapped image.
386
+    * @param    ps
387
+    *           The paint structure filled with the target image parameters. 
388
+    * @param    imageHash
389
+    *           The image unique id.
390
     * 
391
-    * @return   The 3-elements array that holds the image hash in its first element,
392
-    *           the image encoding in its second element and the bytes array of the encoded image
393
-    *           or null in its third element. 
394
+    * @return   The 4-elements array that holds the image hash in its first element, the image
395
+    *           encoding in its second element, the bytes array of the encoded image or null
396
+    *           in its third element and the embedded image in its forth element.
397
     */
398
-   private final Object[] encodeImage(int x, int y, ImageWrapper wrappedImage)
399
+   private final Object[] encodeImage(PaintStructure<Integer, BufferedImage> ps, int imageHash)
400
    {
401
       VirtualScreen virtualScreen = webdriver.getVirtualScreen();
402
-      int imageHash = wrappedImage.getImage().hashCode();
403
       ImageEncoding encoding;
404
       byte[] encodedImage;
405
+      ImageWrapper embeddedImage;
406
       if (webdriver.addImageUsage(imageHash, windowId))
407
       {
408
+         int x = ps.x;
409
+         int y = ps.y;
410
+         embeddedImage = drawHelper.processImage(ps, true);
411
          encoding = ImageEncoding.RAW;
412
-         virtualScreen.drawImage(wrappedImage, x, y);
413
+         virtualScreen.drawImage(embeddedImage, x, y);
414
          encodedImage = new RawEncoder().packToBinaries(virtualScreen, x, y,
415
-                  wrappedImage.getWidth(), wrappedImage.getHeight());
416
+                  embeddedImage.getWidth(), embeddedImage.getHeight());
417
       }
418
       else
419
       {
420
          encoding = ImageEncoding.HASH;
421
          encodedImage = null;
422
+         embeddedImage = drawHelper.processImage(ps, false);
423
       }
424
       
425
-      return new Object[] {imageHash, encoding, encodedImage};
426
+      return new Object[] {imageHash, encoding, encodedImage, embeddedImage};
427
    }
428
    
429
    /**
430