• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2007-2008 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 #ifndef _ANDROID_SKIN_IMAGE_H
13 #define _ANDROID_SKIN_IMAGE_H
14 
15 #include "android/android.h"
16 #include <SDL.h>
17 #include "android/skin/rect.h"
18 
19 /* helper functions */
20 
21 extern SDL_Surface*    sdl_surface_from_argb32( void*  base, int  w, int  h );
22 
23 /* skin image file objects */
24 
25 /* opaque skin image type. all skin images are placed in a simple MRU cache
26  * to limit the emulator's memory usage, with the exception of 'clones' created
27  * with skin_image_clone() or skin_image_clone_blend()
28  */
29 typedef struct SkinImage   SkinImage;
30 
31 /* a descriptor for a given skin image */
32 typedef struct SkinImageDesc {
33     const char*      path;      /* image file path (must be .png) */
34     AndroidRotation  rotation;  /* rotation */
35     int              blend;     /* blending, 0..256 value */
36 } SkinImageDesc;
37 
38 #define  SKIN_BLEND_NONE   0
39 #define  SKIN_BLEND_HALF   128
40 #define  SKIN_BLEND_FULL   256
41 
42 /* a special value returned when an image cannot be properly loaded */
43 extern SkinImage*    SKIN_IMAGE_NONE;
44 
45 /* return the SDL_Surface* pointer of a given skin image */
46 extern SDL_Surface*  skin_image_surface( SkinImage*  image );
47 extern int           skin_image_w      ( SkinImage*  image );
48 extern int           skin_image_h      ( SkinImage*  image );
49 extern int           skin_image_org_w  ( SkinImage*  image );
50 extern int           skin_image_org_h  ( SkinImage*  image );
51 
52 /* get an image from the cache (load it from the file if necessary).
53  * returns SKIN_IMAGE_NONE in case of error. cannot return NULL
54  * this function also increments the reference count of the skin image,
55  * use "skin_image_unref()" when you don't need it anymore
56  */
57 extern SkinImage*    skin_image_find( SkinImageDesc*  desc );
58 
59 extern SkinImage*    skin_image_find_simple( const char*  path );
60 
61 /* increment the reference count of a given skin image,
62  * don't do anything if 'image' is NULL */
63 extern SkinImage*    skin_image_ref( SkinImage*  image );
64 
65 /* decrement the reference count of a given skin image. if
66  * the count reaches 0, the image becomes eligible for cache flushing.
67  * unless it was created through a skin_image_clone... function, where
68  * it is immediately discarded...
69  */
70 extern void          skin_image_unref( SkinImage**  pimage );
71 
72 /* get the rotation of a given image. this decrements the reference count
73  * of the source after returning the target, whose reference count is incremented
74  */
75 extern SkinImage*    skin_image_rotate( SkinImage*  source, SkinRotation  rotation );
76 
77 /* create a skin image clone. the clone is not part of the cache and will
78  * be destroyed immediately when its reference count reaches 0. this is useful
79  * if you need to modify the content of the clone (e.g. blending)
80  */
81 extern SkinImage*    skin_image_clone( SkinImage*  source );
82 
83 /* create a skin image clone, the clone is a rotated version of a source image
84  */
85 extern SkinImage*    skin_image_clone_full( SkinImage*       source,
86                                             SkinRotation     rotation,
87                                             int              blend );
88 
89 /* apply blending to a source skin image and copy the result to a target clone image */
90 extern void          skin_image_blend_clone( SkinImage*  clone, SkinImage*  source, int  blend );
91 
92 #endif /* _ANDROID_SKIN_IMAGE_H */
93