javauis/m3g_qt/src/jni/image2d.inl
changeset 87 1627c337e51e
parent 35 85266cc22c7f
equal deleted inserted replaced
80:d6dafc5d983f 87:1627c337e51e
    63 {
    63 {
    64 
    64 
    65     if (aImageHandle != 0)
    65     if (aImageHandle != 0)
    66     {
    66     {
    67         Java::GFX::Image* cgfxImage = reinterpret_cast<Java::GFX::Image*>(aImageHandle);
    67         Java::GFX::Image* cgfxImage = reinterpret_cast<Java::GFX::Image*>(aImageHandle);
    68         QImage qtImage;
    68         QImage qtImage = cgfxImage->toImage();
    69 
    69         if (qtImage.isNull())
    70         if (!cgfxImage)
    70         {
    71         {
    71             return 0;
    72             return 0;
       
    73         }
       
    74         else
       
    75         {
       
    76             qtImage = cgfxImage->toImage();
       
    77             if (qtImage.isNull())
       
    78             {
       
    79                 return 0;
       
    80             }
       
    81         }
    72         }
    82 
    73 
    83         // m3g needs format in 32bpp, i.e. in RGB32 or ARGB32 so
    74         // m3g needs format in 32bpp, i.e. in RGB32 or ARGB32 so
    84         // if format is not one of those convert it here
    75         // if format is not one of those convert it here
    85         if ((qtImage.format() != QImage::Format_ARGB32) || (qtImage.format() != QImage::Format_RGB32))
    76         if ((qtImage.format() != QImage::Format_ARGB32) || (qtImage.format() != QImage::Format_RGB32))
   100         M3G_DO_LOCK
    91         M3G_DO_LOCK
   101 
    92 
   102         image = m3gCreateImage((M3GInterface)aHM3g, (M3GImageFormat)aFormat, width, height, 0);
    93         image = m3gCreateImage((M3GInterface)aHM3g, (M3GImageFormat)aFormat, width, height, 0);
   103         if (image == NULL)
    94         if (image == NULL)
   104         {
    95         {
       
    96             M3G_DO_UNLOCK(aEnv)
   105             return 0;    // exception automatically raised
    97             return 0;    // exception automatically raised
   106         }
    98         }
   107 
    99 
   108         M3Guint *tempPixels = (M3Guint *) malloc(width * 4);
   100         M3Guint *tempPixels = (M3Guint *) malloc(width * 4);
   109         if (tempPixels == NULL)
   101         if (tempPixels == NULL)
   110         {
   102         {
   111             m3gDeleteObject((M3GObject) image);
   103             m3gDeleteObject((M3GObject) image);
       
   104             M3G_DO_UNLOCK(aEnv)
   112             return 0;
   105             return 0;
   113         }
   106         }
   114 
   107 
   115         // read and write scanline by scanline
   108         // read and write scanline by scanline
   116         for (M3Gint y = 0; y < height; ++y)
   109         for (M3Gint y = 0; y < height; ++y)
   184 
   177 
   185                 jbyte* image = aEnv->GetByteArrayElements(aImage, NULL);
   178                 jbyte* image = aEnv->GetByteArrayElements(aImage, NULL);
   186                 if (image == NULL)
   179                 if (image == NULL)
   187                 {
   180                 {
   188                     M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
   181                     M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
   182                     M3G_DO_UNLOCK(aEnv)
   189                     return 0;
   183                     return 0;
   190                 }
   184                 }
   191 
   185 
   192                 m3gSetImage(hImg, image);
   186                 m3gSetImage(hImg, image);
   193 
   187 
   197                     if (image)
   191                     if (image)
   198                     {
   192                     {
   199                         aEnv->ReleaseByteArrayElements(aImage, image, JNI_ABORT);
   193                         aEnv->ReleaseByteArrayElements(aImage, image, JNI_ABORT);
   200                     }
   194                     }
   201                     M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
   195                     M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
   196                     M3G_DO_UNLOCK(aEnv)
   202                     return 0;
   197                     return 0;
   203                 }
   198                 }
   204 
   199 
   205                 m3gSetImagePalette(hImg, numEntries, palette);
   200                 m3gSetImagePalette(hImg, numEntries, palette);
   206                 m3gCommitImage(hImg);
   201                 m3gCommitImage(hImg);