1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     camera.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 46365 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_SAMPLE_DEMOS_DEMO1_CAMERA_H_
17 #define NN_SAMPLE_DEMOS_DEMO1_CAMERA_H_
18 
19 #include "device.h"
20 
21 // Camera image size
22 #define CAMERA_SIZE             nn::camera::SIZE_VGA
23 #define CAMERA_WIDTH            640
24 #define CAMERA_HEIGHT           480
25 
26 // Size of camera image after trimming
27 #define CAMERA_IMG_WIDTH        128
28 #define CAMERA_IMG_HEIGHT       128
29 
30 
31 // Camera configuration
32 #define CAMERA_SELECT           nn::camera::SELECT_OUT1
33 #define CAMERA_FRAME_RATE       nn::camera::FRAME_RATE_5
34 
35 // Set Y2R
36 #define Y2R_INPUT_FORMAT        nn::y2r::INPUT_YUV422_BATCH
37 #define Y2R_OUTPUT_FORMAT       nn::y2r::OUTPUT_RGB_16_565
38 #define Y2R_YUV_BYTES           2
39 #define Y2R_RGB_BYTES           2
40 #define Y2R_BLOCK_ALIGNMENT     nn::y2r::BLOCK_8_BY_8
41 #define Y2R_ROTATION            nn::y2r::ROTATION_NONE
42 
43 // Set GL
44 #define GL_IMG_FORMAT           GL_RGB_NATIVE_DMP
45 #define GL_IMG_TYPE             GL_UNSIGNED_SHORT_5_6_5
46 
47 // Camera event definition
48 enum
49 {
50     EVENT_CAMERA_TRANSFER = 0,
51     EVENT_CAMERA_ERROR,
52     EVENT_CAMERA_END,
53     EVENT_CAMERA_NUM
54 };
55 
56 // Progress status of camera initial setting
57 enum
58 {
59     CAMERA_STATE_NONE = 0,
60     CAMERA_STATE_INITIALIZED,
61     CAMERA_STATE_SET,
62     CAMERA_STATE_STARTED
63 };
64 
65 class CameraDemo : public Device
66 {
67 public:
CameraDemo()68     CameraDemo()
69     {
70         m_EndEvent.Initialize(false);
71         m_InitializeState = CAMERA_STATE_NONE;
72     }
73 
~CameraDemo()74     ~CameraDemo()
75     {
76         m_EndEvent.Finalize();
77     }
78 
Initialize(demo::RenderSystemDrawing * p_RenderSystem)79     virtual void Initialize(demo::RenderSystemDrawing* p_RenderSystem) { Device::Initialize(p_RenderSystem); }
80     void Initialize(demo::RenderSystemDrawing* p_RenderSystem, nn::fnd::ExpHeap* p_AppHeap);
81     virtual void Finalize(void);
82 
83     virtual void Start(void);
84     virtual void End(void);
85 
86     void TransferThreadFuncImpl(void);
87 
88     virtual void DrawFrame(void);
89 
90 private:
91     void CameraInitialize();
92     void CameraSetting();
93     bool CheckCameraResult( nn::Result result );
94     void CameraInitialSequence();
95 
96     size_t m_CameraOutputSize;
97     size_t m_TransferUnit;
98     u32 m_Y2rOutputSize;
99 
100     nn::fnd::ExpHeap* mp_AppHeap;
101     nn::os::Thread m_TransferThread;
102     nn::os::Event m_TransferEvent;
103     nn::os::Event m_ErrorEvent;
104     nn::os::Event m_EndEvent;
105 
106     int m_InitializeState;
107 };
108 
109 
110 /* NN_SAMPLE_DEMOS_DEMO1_CAMERA_H_ */
111 #endif
112 
113 /*---------------------------------------------------------------------------*
114   End of file
115  *---------------------------------------------------------------------------*/
116