00001 /*-----------------------------------------------------------------------* 00002 Project: Nintendo Augmented Reality Library. 00003 File: narImage.h 00004 00005 Copyright (C)2011-2012 Nintendo Co., Ltd. All rights reserved. 00006 00007 These coded instructions, statements, and computer programs contain 00008 proprietary information of Nintendo and/or its licensed developers 00009 and are protected by national and international copyright laws. They 00010 may not be disclosed to third parties or copied or duplicated in any 00011 form, in whole or in part, without the prior written consent of 00012 Nintendo. 00013 The content herein is highly confidential and should be handled 00014 accordingly. 00015 *-----------------------------------------------------------------------*/ 00016 00022 #ifndef NAR_IMAGE_H__ 00023 #define NAR_IMAGE_H__ 00024 00025 #include "narPort.h" 00026 #include "narMarkerTemplate.h" 00027 #include "narMesh.h" 00028 00029 namespace mw { namespace nar 00030 { 00031 struct Color_st; 00032 00035 enum Border_en 00036 { 00037 e_BorderWhiteBlack, 00038 e_BorderBlackWhite, 00039 e_BorderEnd 00040 }; 00041 00044 class Image_cl 00045 { 00046 public: 00048 static const u8 msc_DefaultXStep = 8; 00050 static const u8 msc_DefaultYStep = 16; 00051 00058 Image_cl( u16 w, u16 h, u32 * p_Work, u16 * p_DebugImg = 0 ) 00059 : m_Width( w ), m_Height( h ), m_XStep( msc_DefaultXStep ), m_YStep( ">msc_DefaultYStep ), m_Border( 0 ), mcp_Image( 0 ), mp_CheckFlags( p_Work ) 00060 #if NAR_DEBUG__ 00061 , mp_DebugImage( p_DebugImg ) 00062 #endif 00063 { 00064 NAR_NULL_TASSERT( p_Work ); 00065 #if ! NAR_DEBUG__ 00066 ( ( void )&p_DebugImg ); 00067 #endif 00068 } 00069 00074 void SetImage( const u16 * cp_Image ) { mcp_Image = cp_Image; } 00075 { 00076 NAR_NULL_TASSERT( cp_Image ); 00077 mcp_Image = cp_Image; 00078 } 00079 00083 u16 GetHeight() const { return m_Height; } 00084 00088 u16 GetWidth() const { return m_Width; } 00089 00094 u8 GetXStep() const { return m_XStep; } 00095 00100 u8 GetYStep() const { return m_YStep; } 00101 00110 void SetXStep( u8 x ) 00111 { 00112 NAR_MIN_TASSERT( x, 1 ); 00113 m_XStep = x; 00114 } 00115 00124 void SetYStep( u8 y ) 00125 { 00126 NAR_MIN_TASSERT( y, 1 ); 00127 m_YStep = y; 00128 } 00129 00135 u16 GetColor( u32 x, u32 y ) const 00136 { 00137 #if NAR_PIXEL_FMT == NAR_PIXEL_FMT_RGB555 00138 return static_cast< u16 >( mcp_Image[ y * m_Width + x ] ); 00139 #endif 00140 #if NAR_PIXEL_FMT == NAR_PIXEL_FMT_YUV422_BATCH 00141 int pos = y * m_Width + x; 00142 u8 Y = static_cast< u8 >( mcp_Image[ pos ] & 0xff ); 00143 u8 U = static_cast< u8 >( mcp_Image[ pos & ~1 ] >> 8 & 0xff ); 00144 u8 V = static_cast< u8 >( mcp_Image[ ( pos & ~1 ) + 1 ] >> 8 & 0xff ); 00145 return ConvYUVtoRGB5551( Y, U, V ); 00146 #endif 00147 } 00148 00151 void SetBorder( Border_en b ) 00152 { 00153 m_Border = b; 00154 } 00155 00158 Border_en GetBorder() 00159 { 00160 return static_cast< Border_en >( m_Border ); 00161 } 00162 00168 template< MeshDiv_e N > 00169 void PickupMeshData( const Vec2F_st * cap_Points, MeshColorData_tc< N > & r_MeshColorData ) const 00170 { 00171 // Calculates the mesh from 4 points 00172 MeshStrictWork_tc< N > work; 00173 MeshStrict_cl mesh( work ); 00174 mesh.precalc( cap_Points ); 00175 #if NAR_DEBUG__ 00176 // Display information for debugging 00177 mesh.drawInfo( *this, cap_Points, false ); 00178 #endif 00179 mesh.pickupFast( *this, r_MeshColorData ); 00180 } 00181 00188 template< MeshDiv_e N > 00189 void PickupMeshData( const Vec2F_st * cap_Points, MeshColorData_tc< N > & r_MeshColorData, MeshVtxData_tc< N > & r_MeshVtxData ) const 00190 { 00191 // Calculates the mesh from 4 points 00192 MeshStrictWork_tc< N > work; 00193 MeshStrict_cl mesh( work ); 00194 mesh.precalc( cap_Points ); 00195 #if NAR_DEBUG__ 00196 // Display information for debugging 00197 mesh.drawInfo( *this, cap_Points, false ); 00198 #endif 00199 mesh.pickupFast( *this, r_MeshColorData, r_MeshVtxData ); 00200 } 00201 00203 00207 void GetAvgColor( u32 x, u32 y, Color_st * p_Color ) const; 00208 00213 void GetAvgColorFast( u32 x, u32 y, Color_st * p_Color ) const; 00214 00218 static u8 GetR( u16 color ) 00219 { 00220 return static_cast< u8 >( color >> NAR_RGB5A1_R_SHIFT & 0x1f ); 00221 } 00222 00226 static u8 GetG( u16 color ) 00227 { 00228 return static_cast< u8 >( color >> NAR_RGB5A1_G_SHIFT & 0x1f ); 00229 } 00230 00234 static u8 GetB( u16 color ) 00235 { 00236 return static_cast< u8 >( color >> NAR_RGB5A1_B_SHIFT & 0x1f ); 00237 } 00238 00241 static u8 GetSimpleYRaw( u8 r, u8 g, u8 b ) 00242 { 00243 return static_cast< u8 >( r + ( g << 1 ) + b ); 00244 } 00245 00248 u8 GetSimpleYRaw( u32 x, u32 y ) const 00249 { 00250 #if NAR_PIXEL_FMT == NAR_PIXEL_FMT_RGB555 00251 u16 color = GetColor( x, y ); 00252 return GetSimpleYRaw( GetR( color ), GetG( color ), GetB( color ) ); 00253 #endif 00254 #if NAR_PIXEL_FMT == NAR_PIXEL_FMT_YUV422_BATCH 00255 u8 ret = static_cast< u8 >( mcp_Image[ y * m_Width + x ] & 0xff ); 00256 if ( m_Border ) 00257 return ~ret; 00258 else 00259 return ret; 00260 #endif 00261 } 00262 00265 void Checked( u32 x, u32 y ) 00266 { 00267 register u32 pixelNo = y * m_Width + x; 00268 register u32 flagNo = pixelNo >> 5; 00269 register u32 bitNo = pixelNo & 0x1f; 00270 mp_CheckFlags[ flagNo ] |= ( 1 << bitNo ); 00271 } 00272 00275 bool IsChecked( u32 x, u32 y ) const 00276 { 00277 register u32 pixelNo = y * m_Width + x; 00278 register u32 flagNo = pixelNo >> 5; 00279 register u32 bitNo = pixelNo & 0x1f; 00280 return 0 != ( mp_CheckFlags[ flagNo ] & ( 1 << bitNo ) ); 00281 } 00282 00285 void ClearChecked() 00286 { 00287 ClearFast( mp_CheckFlags, static_cast< u32 >( (( m_Width * m_Height + 31 ) & ~31) >> 3 ) ); 00288 } 00289 00292 static u16 ConvYUVtoRGB5551( u8 y, u8 u, u8 v ); 00293 00294 00295 #if NAR_DEBUG__ 00296 #if NAR_CTR_NATIVE_DEBUG_IMAGE 00297 00300 u32 GetDmpNativeTexelPos( u32 x, u32 y ) const; 00301 #endif 00302 00303 00308 void SetColorDebug( u32 x, u32 y, u16 color ) const 00309 { 00310 if ( mp_DebugImage && x < m_Width && y < m_Height ) 00311 { 00312 #if NAR_CTR_NATIVE_DEBUG_IMAGE 00313 int idx = GetDmpNativeTexelPos( x, y ); 00314 #else 00315 int idx = y * m_Width + x; 00316 #endif 00317 if ( 0 == mp_DebugImage[ idx ] ) 00318 mp_DebugImage[ idx ] = color; 00319 } 00320 } 00321 00324 void ClearDebugImage() 00325 { 00326 if ( mp_DebugImage ) 00327 ClearFast( mp_DebugImage, m_Width * m_Height * sizeof( u16 ) ); 00328 } 00329 00332 void DrawLineSegmentOnDebug( const Vec2F_st & cr_Start, const Vec2F_st & cr_End, u16 color ) const; 00333 00336 void DrawLineOnDebug( f32 a, f32 b, f32 c, u16 color ) const; 00337 00340 void DrawArrowOnDebug( const Vec2I_st & cr_Start, const Vec2I_st & cr_End, u16 color ) const; 00341 00344 void DrawPlusMarkOnDebug( const Vec2I_st & r_Point, u16 color ) const; 00345 00346 #endif 00347 00348 00350 void SetDebugImage( u16 * p_Image) 00351 { 00352 #if NAR_DEBUG__ 00353 mp_DebugImage = p_Image; 00354 #else 00355 ((void)&p_Image); 00356 #endif 00357 } 00358 private: 00360 u16 m_Width; 00362 u16 m_Height; 00365 u8 m_XStep; 00368 u8 m_YStep; 00369 00371 u8 m_Border; 00372 00373 u8 pad; 00374 00376 const u16 * mcp_Image; 00378 u32 * mp_CheckFlags; 00379 #if NAR_DEBUG__ 00380 u16 * mp_DebugImage; 00381 #endif 00382 }; 00383 00387 #define NAR_IMAGE_WORK_SIZE_4TH( w, h ) (((w)*(h)+31)>>5) 00388 } 00389 } 00390 00391 #endif
© 2011-2012 Nintendo. All rights reserved.
CONFIDENTIAL