javauis/m3g_qt/src/m3g_jsr184.inl
changeset 35 85266cc22c7f
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /*!
       
    20  * \file \brief Global methods for JSR-184
       
    21  *
       
    22  * This file is <em>included</em>, not linked, by specific VM bindings.
       
    23  *
       
    24  */
       
    25 
       
    26 #ifndef M3G_JAVA_INCLUDE
       
    27 #   error included by m3g_<platform>_java_api.c; do not compile separately.
       
    28 #endif
       
    29 
       
    30 #include <m3g/m3g_core.h>
       
    31 #include "m3g_jsr184.h"
       
    32 
       
    33 /*----------------------------------------------------------------------
       
    34  * Internal functions
       
    35  *--------------------------------------------------------------------*/
       
    36 
       
    37 /*!
       
    38  * \brief Returns the number of bytes per pixel for a JSR-184 pixel
       
    39  * format
       
    40  *
       
    41  * \note Dependent on constants in Image2D.java
       
    42  */
       
    43 static M3Guint jsr184BytesPerPixel(int jsrFormat)
       
    44 {
       
    45     switch (jsrFormat)
       
    46     {
       
    47     case M3G_ALPHA:
       
    48         return 1;
       
    49     case M3G_LUMINANCE:
       
    50         return 1;
       
    51     case M3G_LUMINANCE_ALPHA:
       
    52         return 2;
       
    53     case M3G_RGB:
       
    54         return 3;
       
    55     case M3G_RGBA:
       
    56         return 4;
       
    57     default:
       
    58         return 0;
       
    59     }
       
    60 }
       
    61 
       
    62 /*!
       
    63  * \brief Returns m3g core pixel format for qiven Qt based pixel format
       
    64  *
       
    65  */
       
    66 static M3GPixelFormat mapQtPixelformat(int qtFormat)
       
    67 {
       
    68     switch (qtFormat)
       
    69     {
       
    70     case QImage::Format_RGB32:
       
    71     case QImage::Format_ARGB32:
       
    72         return M3G_ARGB8;
       
    73     case QImage::Format_RGB888:
       
    74         return M3G_RGB8;
       
    75     case QImage::Format_RGB444:
       
    76         return M3G_RGB4;
       
    77     case QImage::Format_RGB16:
       
    78         return M3G_RGB565;
       
    79     default:
       
    80         return M3G_NO_FORMAT;
       
    81     }
       
    82 }
       
    83 
       
    84 
       
    85 /*!
       
    86  * \brief Return a MIDP exception string corresponding to an M3G error
       
    87  */
       
    88 static const char *jsr184Exception(M3Genum errorCode)
       
    89 {
       
    90     switch (errorCode)
       
    91     {
       
    92     case M3G_NO_ERROR:
       
    93         return NULL;
       
    94     case M3G_OUT_OF_MEMORY:
       
    95         return "java/lang/OutOfMemoryError";
       
    96     case M3G_INVALID_OPERATION:
       
    97         return "java/lang/IllegalStateException";
       
    98     case M3G_INVALID_INDEX:
       
    99         return "java/lang/IndexOutOfBoundsException";
       
   100     case M3G_NULL_POINTER:
       
   101         return "java/lang/NullPointerException";
       
   102     case M3G_ARITHMETIC_ERROR:
       
   103         return "java/lang/ArithmeticException";
       
   104     case M3G_IO_ERROR:
       
   105         return "java/io/IOException";
       
   106     default:
       
   107         return "java/lang/IllegalArgumentException";
       
   108     }
       
   109 }