Home | History | Annotate | Download | only in b_ImageEm
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef bim_UINT8_PYRAMIDAL_IMAGE_EM_H
     18 #define bim_UINT8_PYRAMIDAL_IMAGE_EM_H
     19 
     20 /* ---- includes ----------------------------------------------------------- */
     21 
     22 #include "b_BasicEm/Context.h"
     23 #include "b_ImageEm/UInt8Image.h"
     24 
     25 /* ---- related objects  --------------------------------------------------- */
     26 
     27 /* ---- typedefs ----------------------------------------------------------- */
     28 
     29 #define bim_PYRAMIDAL_IMAGE_STANDARD_DEPTH 4
     30 
     31 /* ---- constants ---------------------------------------------------------- */
     32 
     33 /* data format version number */
     34 #define bim_UINT8_PYRAMIDAL_IMAGE_VERSION 100
     35 
     36 /* ---- object definition -------------------------------------------------- */
     37 
     38 /** Pyramidal image of uint8.
     39  *  The Pyramidal format is as follows
     40  *  widthE  specifies width of first image (image 0)
     41  *  heightE specifies height of first image (image 0)
     42  *  depthE  specifies the number of levels present
     43  *  image n has half of the width,heigth dimension of image n-1
     44  *  A pixel of in image n is the average of the corresponding 4
     45  *  covering pixels in image n-1
     46  *  Adresses of data relative to arrE.arrPtrE
     47  *  The address of image 0 is 0
     48  *  The address of image 1 is widthE * heightE
     49  *  The address of image n is widthE * heightE + widthE * heightE / 4 + ... + widthE * heightE * ( 2^-(2*n) )
     50  *  Use function uint8* bim_UInt8PyramidalImage_arrPtr( uint32 levelA ) to obtain adress of image at given depth level
     51  *  Use function bim_UInt8PyramidalImage_importUInt8 to create a pyramidal image from an uint8 image
     52 */
     53 struct bim_UInt8PyramidalImage
     54 {
     55 
     56 	/* ---- private data --------------------------------------------------- */
     57 
     58 	/* ---- public data ---------------------------------------------------- */
     59 
     60 	/** width of image */
     61 	uint32 widthE;
     62 
     63 	/** height of image */
     64 	uint32 heightE;
     65 
     66 	/** depth of image (number of layers) */
     67 	uint32 depthE;
     68 
     69 	/** pyramidal image type (temporary: until switch to 16-bit complete) */
     70 	uint32 typeE;
     71 
     72 	/** array of bytes */
     73 	struct bbs_UInt8Arr arrE;
     74 };
     75 
     76 /* ---- associated objects ------------------------------------------------- */
     77 
     78 /* ---- external functions ------------------------------------------------- */
     79 
     80 /* ---- \ghd{ constructor/destructor } ------------------------------------- */
     81 
     82 /** initializes bim_UInt8PyramidalImage  */
     83 void bim_UInt8PyramidalImage_init( struct bbs_Context* cpA,
     84 								   struct bim_UInt8PyramidalImage* ptrA );
     85 
     86 /** allocates memory for bim_UInt8PyramidalImage  */
     87 void bim_UInt8PyramidalImage_create( struct bbs_Context* cpA,
     88 									 struct bim_UInt8PyramidalImage* ptrA,
     89 									 uint32 widthA, uint32 heightA,
     90 									 uint32 depthA,
     91  									 struct bbs_MemSeg* mspA );
     92 
     93 /** frees bim_UInt8PyramidalImage  */
     94 void bim_UInt8PyramidalImage_exit( struct bbs_Context* cpA,
     95 								   struct bim_UInt8PyramidalImage* ptrA );
     96 
     97 /* ---- \ghd{ operators } -------------------------------------------------- */
     98 
     99 /** copy operator */
    100 void bim_UInt8PyramidalImage_copy( struct bbs_Context* cpA,
    101 								   struct bim_UInt8PyramidalImage* ptrA,
    102 								   const struct bim_UInt8PyramidalImage* srcPtrA );
    103 
    104 /** equal operator */
    105 flag bim_UInt8PyramidalImage_equal( struct bbs_Context* cpA,
    106 								    const struct bim_UInt8PyramidalImage* ptrA, const struct bim_UInt8PyramidalImage* srcPtrA );
    107 
    108 /* ---- \ghd{ query functions } -------------------------------------------- */
    109 
    110 /** returns adress of image at given depth level */
    111 uint8* bim_UInt8PyramidalImage_arrPtr( struct bbs_Context* cpA,
    112 									   const struct bim_UInt8PyramidalImage* ptrA,
    113 									   uint32 levelA );
    114 
    115 /** calculates the amount of heap memory needed (16bit words) if created with given parameters */
    116 uint32 bim_UInt8PyramidalImage_heapSize( struct bbs_Context* cpA,
    117 										 const struct bim_UInt8PyramidalImage* ptrA,
    118 										 uint32 widthA,
    119 										 uint32 heightA,
    120 										 uint32 depthA );
    121 
    122 /* ---- \ghd{ modify functions } ------------------------------------------- */
    123 
    124 /** sets image size */
    125 void bim_UInt8PyramidalImage_size( struct bbs_Context* cpA,
    126 								   struct bim_UInt8PyramidalImage* ptrA,
    127 								   uint32 widthA,
    128 								   uint32 heightA,
    129 								   uint32 depthA );
    130 
    131 /* ---- \ghd{ memory I/O } ------------------------------------------------- */
    132 
    133 /** size object needs when written to memory */
    134 uint32 bim_UInt8PyramidalImage_memSize( struct bbs_Context* cpA,
    135 									    const struct bim_UInt8PyramidalImage* ptrA );
    136 
    137 /** writes object to memory; returns number of words (16-bit) written */
    138 uint32 bim_UInt8PyramidalImage_memWrite( struct bbs_Context* cpA,
    139 										 const struct bim_UInt8PyramidalImage* ptrA, uint16* memPtrA );
    140 
    141 /** reads object from memory; returns number of words (16-bit) read */
    142 uint32 bim_UInt8PyramidalImage_memRead( struct bbs_Context* cpA,
    143 									    struct bim_UInt8PyramidalImage* ptrA,
    144 									    const uint16* memPtrA,
    145  									    struct bbs_MemSeg* mspA );
    146 
    147 /* ---- \ghd{ exec functions } --------------------------------------------- */
    148 
    149 /** create overlay bim_UInt8Image (does not own memory) */
    150 void bim_UInt8PyramidalImage_overlayUInt8( struct bbs_Context* cpA,
    151 										   const struct bim_UInt8PyramidalImage* ptrA,
    152 										   struct bim_UInt8Image* uint8ImageA );
    153 
    154 /** recompute pyramidal format with given depth from data in layer 0 */
    155 void bim_UInt8PyramidalImage_recompute( struct bbs_Context* cpA,
    156 									    struct bim_UInt8PyramidalImage* dstPtrA );
    157 
    158 /** import uint8image and creates pyramidal format with given depth */
    159 void bim_UInt8PyramidalImage_importUInt8( struct bbs_Context* cpA,
    160 										  struct bim_UInt8PyramidalImage* dstPtrA,
    161 									      const struct bim_UInt8Image* srcPtrA,
    162 										  uint32 depthA );
    163 
    164 #endif /* bim_UINT8_PYRAMIDAL_IMAGE_EM_H */
    165 
    166