os/graphics/m3g/m3gcore11/inc/m3g_image.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 the License "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: Image interface
    15 *
    16 */
    17 
    18 #ifndef __M3G_IMAGE_H__
    19 #define __M3G_IMAGE_H__
    20 
    21 /*!
    22  * \internal
    23  * \file
    24  * \brief Image interface
    25  */
    26 
    27 #include "m3g_object.h"
    28 #include "m3g_gl.h"
    29 
    30 #if !defined(M3G_NGL_TEXTURE_API)
    31 typedef struct LargeImageImpl LargeImage;
    32 #endif
    33 
    34 /*!
    35  * \internal
    36  * \brief Image object
    37  */
    38 struct M3GImageImpl
    39 {
    40     Object object;
    41 
    42     M3Gint width, height;
    43     M3GImageFormat format;
    44     M3GPixelFormat internalFormat;
    45 
    46     Image *powerOfTwo;
    47 
    48     GLenum glFormat;
    49 #   if !defined(M3G_NGL_TEXTURE_API)
    50     GLuint texObject;
    51     LargeImage *large;  /*! \internal \ */
    52 #   endif
    53 
    54     M3GMemObject data;
    55     M3GMemObject mipData;
    56     M3Gsizei paletteBytes;
    57 
    58     M3Gbitmask flags            : 8; /* flags defined in m3g_core.h */
    59     M3Gbitmask special          : 8; /* flags defined below */
    60     
    61     M3Gbool pinned              : 1; /* image can not be deleted */
    62     M3Gbool dirty               : 1;
    63     M3Gbool powerOfTwoDirty     : 1;
    64     M3Gbool mipDataMapCount     : 4; /* max. 16 concurrent uses */
    65 #   if !defined(M3G_NGL_TEXTURE_API)
    66     M3Gbool mipmapsDirty        : 1; /*!< \internal 'dirty' overrides this */
    67 #   endif
    68 
    69     /* For easy cloning of immutable images without replicating the
    70      * data, we must keep a reference to the original so that it isn't
    71      * deleted until we are */
    72     
    73     Image *copyOf;
    74 };
    75 
    76 /*!
    77  * \internal \brief "special" flag bits */
    78 #define IMG_NPOT        0x01
    79 #define IMG_LARGE       0x02
    80 
    81 /*----------------------------------------------------------------------
    82  * Internal functions
    83  *--------------------------------------------------------------------*/
    84 
    85 static void m3gBindTextureImage(Image *img, M3Genum levelFilter, M3Genum imageFilter);
    86 static void m3gReleaseTextureImage(Image *img);
    87 
    88 static Image *m3gGetPowerOfTwoImage(Image *img);
    89 
    90 static M3GPixelFormat m3gPixelFormat  (M3GImageFormat format);
    91 static M3Gint         m3gBytesPerPixel(M3GPixelFormat format);
    92 
    93 static void m3gConvertPixels(M3GPixelFormat srcFormat, const M3Gubyte *src,
    94                              M3GPixelFormat dstFormat, M3Gubyte *dst,
    95                              M3Gsizei count);
    96 
    97 static void m3gConvertPixelRect(
    98     M3GPixelFormat srcFormat, const M3Gubyte *src, M3Gsizei srcStride,
    99     M3Gsizei width, M3Gsizei height,
   100     M3GPixelFormat dstFormat, M3Gubyte *dst, M3Gsizei dstStride);
   101 
   102 static void m3gCopyImagePixels(Image *dst, const Image *src);
   103 #if !defined(M3G_NGL_TEXTURE_API)
   104 static void m3gCopyFrameBufferImage(Image *dst);
   105 static void m3gDrawFrameBufferImage(RenderContext *ctx, const Image *src);
   106 #endif /* !defined(M3G_NGL_TEXTURE_API)*/
   107 
   108 static void m3gInvalidateImage(Image *img);
   109 
   110 #if defined(M3G_NGL_TEXTURE_API)
   111 static M3Gbool m3gValidateMipmapMemory(Image *img);
   112 #endif
   113 
   114 /*! \internal */
   115 static M3Gsizei m3gGetImageStride(const Image *img);
   116 
   117 static M3Gint m3gGetAlpha(Image *image, M3Gint x, M3Gint y);
   118 
   119 static M3G_INLINE M3Gbool m3gIsInternallyPaletted(const Image *img)
   120 {
   121     return (img->paletteBytes > 0);
   122 }
   123 
   124 #if 0
   125 /*!
   126  * \internal
   127  * \brief Type-safe helper function
   128  */
   129 static M3G_INLINE void m3gDeleteImage(Image *img)
   130 {
   131     m3gDeleteObject((Object*) img);
   132 }
   133 #endif
   134 
   135 #endif /*__M3G_IMAGE_H__*/