harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r592855 - in /harmony/enhanced/classlib/trunk/modules/awt/src/main: java/common/java/awt/image/Raster.java java/unix/org/apache/harmony/awt/wtk/linux/LinuxCursorFactory.java native/gl/shared/SurfaceDataStructure.cpp
Date Wed, 07 Nov 2007 19:08:40 GMT
Author: apetrenko
Date: Wed Nov  7 11:08:39 2007
New Revision: 592855

URL: http://svn.apache.org/viewvc?rev=592855&view=rev
Log:
Patch for HARMONY-5066 "[classlib][awt] Harmony crashes when 
LinuxCursorFactory.createCustomCursor"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxCursorFactory.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java?rev=592855&r1=592854&r2=592855&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
Wed Nov  7 11:08:39 2007
@@ -602,18 +602,8 @@
             throw new RasterFormatException(Messages.getString("awt.284")); //$NON-NLS-1$
         }
         
-        if (sampleModel instanceof ComponentSampleModel) {
-            validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
-                    ((ComponentSampleModel) sampleModel).getScanlineStride());
-        } else if (sampleModel instanceof MultiPixelPackedSampleModel) {
-            validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
-                    ((MultiPixelPackedSampleModel) sampleModel)
-                            .getScanlineStride());
-        } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
-            validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
-                    ((SinglePixelPackedSampleModel) sampleModel)
-                            .getScanlineStride());
-        }
+        validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
+                sampleModel);
 
         this.sampleModel = sampleModel;
         this.dataBuffer = dataBuffer;
@@ -853,8 +843,54 @@
     }
 
     private static void validateDataBuffer(final DataBuffer dataBuffer, final int w,
-            final int h, final int scanlineStride) {
-        if (dataBuffer.getSize() < (scanlineStride * (h - 1) + w - 1)) {
+            final int h, final SampleModel sampleModel) {
+
+        int size = 0;
+        
+        if (sampleModel instanceof ComponentSampleModel) {
+            ComponentSampleModel csm = (ComponentSampleModel) sampleModel;
+            int offsets[] = csm.getBandOffsets();
+            int maxOffset = offsets[0];
+            for (int i = 1; i < offsets.length; i++) {
+                if (offsets[i] > maxOffset) {
+                    maxOffset = offsets[i];
+                }
+            }
+            int scanlineStride = csm.getScanlineStride();
+            int pixelStride = csm.getPixelStride();
+            
+            size = (h - 1) * scanlineStride +
+            (w - 1) * pixelStride + maxOffset + 1;
+
+        } else if (sampleModel instanceof MultiPixelPackedSampleModel) {
+            MultiPixelPackedSampleModel mppsm = 
+                (MultiPixelPackedSampleModel) sampleModel;
+            
+            int scanlineStride = mppsm.getScanlineStride();
+            int dataBitOffset = mppsm.getDataBitOffset();
+            int dataType = dataBuffer.getDataType();
+            
+            size = scanlineStride * h;
+
+            switch (dataType) {
+            case DataBuffer.TYPE_BYTE:
+                size += (dataBitOffset + 7) / 8;
+                break;
+            case DataBuffer.TYPE_USHORT:
+                size += (dataBitOffset + 15) / 16;
+                break;
+            case DataBuffer.TYPE_INT:
+                size += (dataBitOffset + 31) / 32;
+                break;
+            }
+        } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
+            SinglePixelPackedSampleModel sppsm = 
+                (SinglePixelPackedSampleModel) sampleModel;
+            
+            int scanlineStride = sppsm.getScanlineStride();
+            size = (h - 1) * scanlineStride + w;
+        }
+        if (dataBuffer.getSize() < size) {
             // awt.298=dataBuffer is too small
             throw new RasterFormatException(Messages.getString("awt.298")); //$NON-NLS-1$
         }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxCursorFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxCursorFactory.java?rev=592855&r1=592854&r2=592855&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxCursorFactory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxCursorFactory.java
Wed Nov  7 11:08:39 2007
@@ -26,6 +26,7 @@
 import java.awt.color.ColorSpace;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBufferByte;
+import java.awt.image.MultiPixelPackedSampleModel;
 import java.awt.image.WritableRaster;
 
 import org.apache.harmony.awt.gl.Utils;
@@ -95,23 +96,27 @@
         int width = img.getWidth(null);
         int height = img.getHeight(null);
         BufferedImage bufImg = Utils.getBufferedImage(img);
+        if(bufImg == null) throw new NullPointerException("Cursor Image is null");
+
         //must convert image into TYPE_BYTE_BINARY format of depth 1
-        BufferedImage bmpSrc = convertTo1Bit(/*bufImg*/img);
+        BufferedImage bmpSrc = convertTo1Bit(bufImg);
         BufferedImage bmpMask = getMask(bufImg);
         //get pixel data from bufImg & create X11 pixmap
         byte[] bmpSrcData = ((DataBufferByte) bmpSrc.getData().getDataBuffer()).getData();
+        byte[] rSrcData = convertToLSBFirst(bmpSrcData);
         byte[] bmpMaskData = ((DataBufferByte) bmpMask.getData().getDataBuffer()).getData();
+        byte[] rMaskData = convertToLSBFirst(bmpMaskData);
 
         ArrayAccessor arrayAccess = AccessorFactory.getArrayAccessor();
         long wnd = factory.getRootWindow();
-        LockedArray larr = arrayAccess.lockArrayShort(bmpSrcData);
+        LockedArray larr = arrayAccess.lockArrayShort(rSrcData);
         long dataPtr = larr.getAddress();
         long pixmap = x11.XCreateBitmapFromData(display, wnd,
                 dataPtr, width, height);
         //System.out.println("source pixmap=" + pixmap);
         larr.release();
 
-        larr = arrayAccess.lockArrayShort(bmpMaskData);
+        larr = arrayAccess.lockArrayShort(rMaskData);
         dataPtr = larr.getAddress();
         long pixmapMask = x11.XCreateBitmapFromData(display, wnd, dataPtr,
                 width, height);
@@ -132,6 +137,24 @@
         return new LinuxCursor(cursor, display);
     }
 
+    // Convert Bitmap bits to LSBFirst
+    private byte[] convertToLSBFirst(byte[] src){
+        int len = src.length;
+        byte[] dst = new byte[len];
+
+        for(int i = 0; i < len; i++){
+            int pix = src[i] & 0xff;
+            int rpix = pix & 0x1;
+            for( int j = 1; j < 8; j++){
+                pix >>= 1;
+                rpix <<= 1;
+                rpix |= (pix & 0x1) ;
+            }
+            dst[i] = (byte)rpix;
+        }
+        return dst;
+    }
+
     /**
      * Select one of bufImg pixel colors as background color
      * when foreground color is fgColor.
@@ -273,7 +296,11 @@
      * @param src Image to convert
      * @return new Buffered image containing 1-bit bitmap
      */
-    static BufferedImage convertTo1Bit(Image src) {
+    static BufferedImage convertTo1Bit(BufferedImage src) {
+        if(src.getType() == BufferedImage.TYPE_BYTE_BINARY){
+            MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel) src.getRaster().getSampleModel();
+            if(mppsm.getPixelBitStride() == 1) return src;
+        }
         int w = src.getWidth(null);
         int h = src.getHeight(null);
 

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp?rev=592855&r1=592854&r2=592855&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/shared/SurfaceDataStructure.cpp
Wed Nov  7 11:08:39 2007
@@ -461,10 +461,10 @@
                 src = (unsigned char *)srcDataPtr + src_offset;
                 dst = (unsigned int *)bmpDataPtr + dst_offset;
 
-                for(int _y = h; _y > 0; _y--, src += src_stride, dst += dst_stride){
+                for(int y = h; y > 0; y--, src += src_stride, dst += dst_stride){
                     d = dst;
 
-                    for(int _x = 0; _x < w; _x++){
+                    for(int x = 0; x < w; x++){
                         bitnum = x * pixelBits;
                         s = src + bitnum / 8;
                         elem = *s;



Mime
View raw message