Xbee CountUp

Dependencies:   mbed

Fork of HeptaXbee_CountUp by 智也 大野

Committer:
tomoya123
Date:
Fri Dec 09 04:58:00 2016 +0000
Revision:
0:0a7fa0911e6c
Xbee CountUP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomoya123 0:0a7fa0911e6c 1 #include "HeptaCamera.h"
tomoya123 0:0a7fa0911e6c 2 #include "mbed.h"
tomoya123 0:0a7fa0911e6c 3
tomoya123 0:0a7fa0911e6c 4 int sizex = 0;
tomoya123 0:0a7fa0911e6c 5 int sizey = 0;
tomoya123 0:0a7fa0911e6c 6
tomoya123 0:0a7fa0911e6c 7 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:0a7fa0911e6c 8
tomoya123 0:0a7fa0911e6c 9 #define FILEHEADERSIZE 14 //ファイルヘッダのサイズ
tomoya123 0:0a7fa0911e6c 10 #define INFOHEADERSIZE 40 //情報ヘッダのサイズ
tomoya123 0:0a7fa0911e6c 11 #define HEADERSIZE (FILEHEADERSIZE+INFOHEADERSIZE)
tomoya123 0:0a7fa0911e6c 12
tomoya123 0:0a7fa0911e6c 13 int create_header(FILE *fp, int width, int height) {
tomoya123 0:0a7fa0911e6c 14 int real_width;
tomoya123 0:0a7fa0911e6c 15 unsigned char header_buf[HEADERSIZE]; //ヘッダを格納する
tomoya123 0:0a7fa0911e6c 16 unsigned int file_size;
tomoya123 0:0a7fa0911e6c 17 unsigned int offset_to_data;
tomoya123 0:0a7fa0911e6c 18 unsigned long info_header_size;
tomoya123 0:0a7fa0911e6c 19 unsigned int planes;
tomoya123 0:0a7fa0911e6c 20 unsigned int color;
tomoya123 0:0a7fa0911e6c 21 unsigned long compress;
tomoya123 0:0a7fa0911e6c 22 unsigned long data_size;
tomoya123 0:0a7fa0911e6c 23 long xppm;
tomoya123 0:0a7fa0911e6c 24 long yppm;
tomoya123 0:0a7fa0911e6c 25
tomoya123 0:0a7fa0911e6c 26 real_width = width*3 + width%4;
tomoya123 0:0a7fa0911e6c 27
tomoya123 0:0a7fa0911e6c 28 //ここからヘッダ作成
tomoya123 0:0a7fa0911e6c 29 file_size = height * real_width + HEADERSIZE;
tomoya123 0:0a7fa0911e6c 30 offset_to_data = HEADERSIZE;
tomoya123 0:0a7fa0911e6c 31 info_header_size = INFOHEADERSIZE;
tomoya123 0:0a7fa0911e6c 32 planes = 1;
tomoya123 0:0a7fa0911e6c 33 color = 24;
tomoya123 0:0a7fa0911e6c 34 compress = 0;
tomoya123 0:0a7fa0911e6c 35 data_size = height * real_width;
tomoya123 0:0a7fa0911e6c 36 xppm = 1;
tomoya123 0:0a7fa0911e6c 37 yppm = 1;
tomoya123 0:0a7fa0911e6c 38
tomoya123 0:0a7fa0911e6c 39 header_buf[0] = 'B';
tomoya123 0:0a7fa0911e6c 40 header_buf[1] = 'M';
tomoya123 0:0a7fa0911e6c 41 memcpy(header_buf + 2, &file_size, sizeof(file_size));
tomoya123 0:0a7fa0911e6c 42 header_buf[6] = 0;
tomoya123 0:0a7fa0911e6c 43 header_buf[7] = 0;
tomoya123 0:0a7fa0911e6c 44 header_buf[8] = 0;
tomoya123 0:0a7fa0911e6c 45 header_buf[9] = 0;
tomoya123 0:0a7fa0911e6c 46 memcpy(header_buf + 10, &offset_to_data, sizeof(offset_to_data));
tomoya123 0:0a7fa0911e6c 47 memcpy(header_buf + 14, &info_header_size, sizeof(info_header_size));
tomoya123 0:0a7fa0911e6c 48 memcpy(header_buf + 18, &width, sizeof(width));
tomoya123 0:0a7fa0911e6c 49 height = height * -1; // データ格納順が逆なので、高さをマイナスとしている
tomoya123 0:0a7fa0911e6c 50 memcpy(header_buf + 22, &height, sizeof(height));
tomoya123 0:0a7fa0911e6c 51 memcpy(header_buf + 26, &planes, sizeof(planes));
tomoya123 0:0a7fa0911e6c 52 memcpy(header_buf + 28, &color, sizeof(color));
tomoya123 0:0a7fa0911e6c 53 memcpy(header_buf + 30, &compress, sizeof(compress));
tomoya123 0:0a7fa0911e6c 54 memcpy(header_buf + 34, &data_size, sizeof(data_size));
tomoya123 0:0a7fa0911e6c 55 memcpy(header_buf + 38, &xppm, sizeof(xppm));
tomoya123 0:0a7fa0911e6c 56 memcpy(header_buf + 42, &yppm, sizeof(yppm));
tomoya123 0:0a7fa0911e6c 57 header_buf[46] = 0;
tomoya123 0:0a7fa0911e6c 58 header_buf[47] = 0;
tomoya123 0:0a7fa0911e6c 59 header_buf[48] = 0;
tomoya123 0:0a7fa0911e6c 60 header_buf[49] = 0;
tomoya123 0:0a7fa0911e6c 61 header_buf[50] = 0;
tomoya123 0:0a7fa0911e6c 62 header_buf[51] = 0;
tomoya123 0:0a7fa0911e6c 63 header_buf[52] = 0;
tomoya123 0:0a7fa0911e6c 64 header_buf[53] = 0;
tomoya123 0:0a7fa0911e6c 65
tomoya123 0:0a7fa0911e6c 66 //ヘッダの書き込み
tomoya123 0:0a7fa0911e6c 67 fwrite(header_buf, sizeof(unsigned char), HEADERSIZE, fp);
tomoya123 0:0a7fa0911e6c 68
tomoya123 0:0a7fa0911e6c 69 return 0;
tomoya123 0:0a7fa0911e6c 70 }
tomoya123 0:0a7fa0911e6c 71 #endif
tomoya123 0:0a7fa0911e6c 72
tomoya123 0:0a7fa0911e6c 73 HeptaCamera::HeptaCamera(PinName sda, PinName scl, PinName vs, PinName hr,PinName we, PinName d7, PinName d6, PinName d5, PinName d4,
tomoya123 0:0a7fa0911e6c 74 PinName d3, PinName d2, PinName d1, PinName d0, PinName rt, PinName o, PinName rc ) : camera(sda,scl),vsync(vs),href(hr),wen(we),data(d0,d1,d2,d3,d4,d5,d6,d7),rrst(rt),oe(o),rclk(rc)
tomoya123 0:0a7fa0911e6c 75 {
tomoya123 0:0a7fa0911e6c 76 camera.stop();
tomoya123 0:0a7fa0911e6c 77 camera.frequency(OV7670_I2CFREQ);
tomoya123 0:0a7fa0911e6c 78 vsync.fall(this,&HeptaCamera::VsyncHandler);
tomoya123 0:0a7fa0911e6c 79 href.rise(this,&HeptaCamera::HrefHandler);
tomoya123 0:0a7fa0911e6c 80 CaptureReq = false;
tomoya123 0:0a7fa0911e6c 81 Busy = false;
tomoya123 0:0a7fa0911e6c 82 Done = false;
tomoya123 0:0a7fa0911e6c 83 LineCounter = 0;
tomoya123 0:0a7fa0911e6c 84 rrst = 1;
tomoya123 0:0a7fa0911e6c 85 oe = 1;
tomoya123 0:0a7fa0911e6c 86 rclk = 1;
tomoya123 0:0a7fa0911e6c 87 wen = 0;
tomoya123 0:0a7fa0911e6c 88 }
tomoya123 0:0a7fa0911e6c 89 // capture request
tomoya123 0:0a7fa0911e6c 90 void HeptaCamera::CaptureNext(void)
tomoya123 0:0a7fa0911e6c 91 {
tomoya123 0:0a7fa0911e6c 92 CaptureReq = true;
tomoya123 0:0a7fa0911e6c 93 Busy = true;
tomoya123 0:0a7fa0911e6c 94 }
tomoya123 0:0a7fa0911e6c 95
tomoya123 0:0a7fa0911e6c 96 // capture done? (with clear)
tomoya123 0:0a7fa0911e6c 97 bool HeptaCamera::CaptureDone(void)
tomoya123 0:0a7fa0911e6c 98 {
tomoya123 0:0a7fa0911e6c 99 bool result;
tomoya123 0:0a7fa0911e6c 100 if (Busy) {
tomoya123 0:0a7fa0911e6c 101 result = false;
tomoya123 0:0a7fa0911e6c 102 } else {
tomoya123 0:0a7fa0911e6c 103 result = Done;
tomoya123 0:0a7fa0911e6c 104 Done = false;
tomoya123 0:0a7fa0911e6c 105 }
tomoya123 0:0a7fa0911e6c 106 return result;
tomoya123 0:0a7fa0911e6c 107 }
tomoya123 0:0a7fa0911e6c 108
tomoya123 0:0a7fa0911e6c 109 // write to camera
tomoya123 0:0a7fa0911e6c 110 void HeptaCamera::WriteReg(int addr,int data)
tomoya123 0:0a7fa0911e6c 111 {
tomoya123 0:0a7fa0911e6c 112 // WRITE 0x42,ADDR,DATA
tomoya123 0:0a7fa0911e6c 113 camera.start();
tomoya123 0:0a7fa0911e6c 114 camera.write(OV7670_WRITE);
tomoya123 0:0a7fa0911e6c 115 wait_us(OV7670_WRITEWAIT);
tomoya123 0:0a7fa0911e6c 116 camera.write(addr);
tomoya123 0:0a7fa0911e6c 117 wait_us(OV7670_WRITEWAIT);
tomoya123 0:0a7fa0911e6c 118 camera.write(data);
tomoya123 0:0a7fa0911e6c 119 camera.stop();
tomoya123 0:0a7fa0911e6c 120 }
tomoya123 0:0a7fa0911e6c 121
tomoya123 0:0a7fa0911e6c 122 // read from camera
tomoya123 0:0a7fa0911e6c 123 int HeptaCamera::ReadReg(int addr)
tomoya123 0:0a7fa0911e6c 124 {
tomoya123 0:0a7fa0911e6c 125 int data;
tomoya123 0:0a7fa0911e6c 126
tomoya123 0:0a7fa0911e6c 127 // WRITE 0x42,ADDR
tomoya123 0:0a7fa0911e6c 128 camera.start();
tomoya123 0:0a7fa0911e6c 129 camera.write(OV7670_WRITE);
tomoya123 0:0a7fa0911e6c 130 wait_us(OV7670_WRITEWAIT);
tomoya123 0:0a7fa0911e6c 131 camera.write(addr);
tomoya123 0:0a7fa0911e6c 132 camera.stop();
tomoya123 0:0a7fa0911e6c 133 wait_us(OV7670_WRITEWAIT);
tomoya123 0:0a7fa0911e6c 134
tomoya123 0:0a7fa0911e6c 135 // WRITE 0x43,READ
tomoya123 0:0a7fa0911e6c 136 camera.start();
tomoya123 0:0a7fa0911e6c 137 camera.write(OV7670_READ);
tomoya123 0:0a7fa0911e6c 138 wait_us(OV7670_WRITEWAIT);
tomoya123 0:0a7fa0911e6c 139 data = camera.read(OV7670_NOACK);
tomoya123 0:0a7fa0911e6c 140 camera.stop();
tomoya123 0:0a7fa0911e6c 141
tomoya123 0:0a7fa0911e6c 142 return data;
tomoya123 0:0a7fa0911e6c 143 }
tomoya123 0:0a7fa0911e6c 144
tomoya123 0:0a7fa0911e6c 145 // print register
tomoya123 0:0a7fa0911e6c 146 void HeptaCamera::PrintRegister(void) {
tomoya123 0:0a7fa0911e6c 147 printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F");
tomoya123 0:0a7fa0911e6c 148 for (int i=0;i<OV7670_REGMAX;i++) {
tomoya123 0:0a7fa0911e6c 149 int data;
tomoya123 0:0a7fa0911e6c 150 data = ReadReg(i); // READ REG
tomoya123 0:0a7fa0911e6c 151 if ((i & 0x0F) == 0) {
tomoya123 0:0a7fa0911e6c 152 printf("\r\n%02X : ",i);
tomoya123 0:0a7fa0911e6c 153 }
tomoya123 0:0a7fa0911e6c 154 printf("%02X ",data);
tomoya123 0:0a7fa0911e6c 155 }
tomoya123 0:0a7fa0911e6c 156 printf("\r\n");
tomoya123 0:0a7fa0911e6c 157 }
tomoya123 0:0a7fa0911e6c 158
tomoya123 0:0a7fa0911e6c 159 void HeptaCamera::Reset(void) {
tomoya123 0:0a7fa0911e6c 160 WriteReg(REG_COM7,COM7_RESET); // RESET CAMERA
tomoya123 0:0a7fa0911e6c 161 wait_ms(200);
tomoya123 0:0a7fa0911e6c 162 }
tomoya123 0:0a7fa0911e6c 163
tomoya123 0:0a7fa0911e6c 164 void HeptaCamera::InitForFIFOWriteReset(void) {
tomoya123 0:0a7fa0911e6c 165 WriteReg(REG_COM10, COM10_VS_NEG);
tomoya123 0:0a7fa0911e6c 166 }
tomoya123 0:0a7fa0911e6c 167
tomoya123 0:0a7fa0911e6c 168 void HeptaCamera::InitSetColorbar(void) {
tomoya123 0:0a7fa0911e6c 169 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 170 // color bar
tomoya123 0:0a7fa0911e6c 171 WriteReg(REG_COM17, reg_com7|COM17_CBAR);
tomoya123 0:0a7fa0911e6c 172 }
tomoya123 0:0a7fa0911e6c 173
tomoya123 0:0a7fa0911e6c 174 void HeptaCamera::InitDefaultReg(void) {
tomoya123 0:0a7fa0911e6c 175 // Gamma curve values
tomoya123 0:0a7fa0911e6c 176 WriteReg(0x7a, 0x20);
tomoya123 0:0a7fa0911e6c 177 WriteReg(0x7b, 0x10);
tomoya123 0:0a7fa0911e6c 178 WriteReg(0x7c, 0x1e);
tomoya123 0:0a7fa0911e6c 179 WriteReg(0x7d, 0x35);
tomoya123 0:0a7fa0911e6c 180 WriteReg(0x7e, 0x5a);
tomoya123 0:0a7fa0911e6c 181 WriteReg(0x7f, 0x69);
tomoya123 0:0a7fa0911e6c 182 WriteReg(0x80, 0x76);
tomoya123 0:0a7fa0911e6c 183 WriteReg(0x81, 0x80);
tomoya123 0:0a7fa0911e6c 184 WriteReg(0x82, 0x88);
tomoya123 0:0a7fa0911e6c 185 WriteReg(0x83, 0x8f);
tomoya123 0:0a7fa0911e6c 186 WriteReg(0x84, 0x96);
tomoya123 0:0a7fa0911e6c 187 WriteReg(0x85, 0xa3);
tomoya123 0:0a7fa0911e6c 188 WriteReg(0x86, 0xaf);
tomoya123 0:0a7fa0911e6c 189 WriteReg(0x87, 0xc4);
tomoya123 0:0a7fa0911e6c 190 WriteReg(0x88, 0xd7);
tomoya123 0:0a7fa0911e6c 191 WriteReg(0x89, 0xe8);
tomoya123 0:0a7fa0911e6c 192
tomoya123 0:0a7fa0911e6c 193 // AGC and AEC parameters. Note we start by disabling those features,
tomoya123 0:0a7fa0911e6c 194 //then turn them only after tweaking the values.
tomoya123 0:0a7fa0911e6c 195 WriteReg(REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT);
tomoya123 0:0a7fa0911e6c 196 WriteReg(REG_GAIN, 0);
tomoya123 0:0a7fa0911e6c 197 WriteReg(REG_AECH, 0);
tomoya123 0:0a7fa0911e6c 198 WriteReg(REG_COM4, 0x40);
tomoya123 0:0a7fa0911e6c 199 // magic reserved bit
tomoya123 0:0a7fa0911e6c 200 WriteReg(REG_COM9, 0x18);
tomoya123 0:0a7fa0911e6c 201 // 4x gain + magic rsvd bit
tomoya123 0:0a7fa0911e6c 202 WriteReg(REG_BD50MAX, 0x05);
tomoya123 0:0a7fa0911e6c 203 WriteReg(REG_BD60MAX, 0x07);
tomoya123 0:0a7fa0911e6c 204 WriteReg(REG_AEW, 0x95);
tomoya123 0:0a7fa0911e6c 205 WriteReg(REG_AEB, 0x33);
tomoya123 0:0a7fa0911e6c 206 WriteReg(REG_VPT, 0xe3);
tomoya123 0:0a7fa0911e6c 207 WriteReg(REG_HAECC1, 0x78);
tomoya123 0:0a7fa0911e6c 208 WriteReg(REG_HAECC2, 0x68);
tomoya123 0:0a7fa0911e6c 209 WriteReg(0xa1, 0x03);
tomoya123 0:0a7fa0911e6c 210 // magic
tomoya123 0:0a7fa0911e6c 211 WriteReg(REG_HAECC3, 0xd8);
tomoya123 0:0a7fa0911e6c 212 WriteReg(REG_HAECC4, 0xd8);
tomoya123 0:0a7fa0911e6c 213 WriteReg(REG_HAECC5, 0xf0);
tomoya123 0:0a7fa0911e6c 214 WriteReg(REG_HAECC6, 0x90);
tomoya123 0:0a7fa0911e6c 215 WriteReg(REG_HAECC7, 0x94);
tomoya123 0:0a7fa0911e6c 216 WriteReg(REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC);
tomoya123 0:0a7fa0911e6c 217
tomoya123 0:0a7fa0911e6c 218 // Almost all of these are magic "reserved" values.
tomoya123 0:0a7fa0911e6c 219 WriteReg(REG_COM5, 0x61);
tomoya123 0:0a7fa0911e6c 220 WriteReg(REG_COM6, 0x4b);
tomoya123 0:0a7fa0911e6c 221 WriteReg(0x16, 0x02);
tomoya123 0:0a7fa0911e6c 222 WriteReg(REG_MVFP, 0x07);
tomoya123 0:0a7fa0911e6c 223 WriteReg(0x21, 0x02);
tomoya123 0:0a7fa0911e6c 224 WriteReg(0x22, 0x91);
tomoya123 0:0a7fa0911e6c 225 WriteReg(0x29, 0x07);
tomoya123 0:0a7fa0911e6c 226 WriteReg(0x33, 0x0b);
tomoya123 0:0a7fa0911e6c 227 WriteReg(0x35, 0x0b);
tomoya123 0:0a7fa0911e6c 228 WriteReg(0x37, 0x1d);
tomoya123 0:0a7fa0911e6c 229 WriteReg(0x38, 0x71);
tomoya123 0:0a7fa0911e6c 230 WriteReg(0x39, 0x2a);
tomoya123 0:0a7fa0911e6c 231 WriteReg(REG_COM12, 0x78);
tomoya123 0:0a7fa0911e6c 232 WriteReg(0x4d, 0x40);
tomoya123 0:0a7fa0911e6c 233 WriteReg(0x4e, 0x20);
tomoya123 0:0a7fa0911e6c 234 WriteReg(REG_GFIX, 0);
tomoya123 0:0a7fa0911e6c 235 WriteReg(0x6b, 0x0a);
tomoya123 0:0a7fa0911e6c 236 WriteReg(0x74, 0x10);
tomoya123 0:0a7fa0911e6c 237 WriteReg(0x8d, 0x4f);
tomoya123 0:0a7fa0911e6c 238 WriteReg(0x8e, 0);
tomoya123 0:0a7fa0911e6c 239 WriteReg(0x8f, 0);
tomoya123 0:0a7fa0911e6c 240 WriteReg(0x90, 0);
tomoya123 0:0a7fa0911e6c 241 WriteReg(0x91, 0);
tomoya123 0:0a7fa0911e6c 242 WriteReg(0x96, 0);
tomoya123 0:0a7fa0911e6c 243 WriteReg(0x9a, 0);
tomoya123 0:0a7fa0911e6c 244 WriteReg(0xb0, 0x84);
tomoya123 0:0a7fa0911e6c 245 WriteReg(0xb1, 0x0c);
tomoya123 0:0a7fa0911e6c 246 WriteReg(0xb2, 0x0e);
tomoya123 0:0a7fa0911e6c 247 WriteReg(0xb3, 0x82);
tomoya123 0:0a7fa0911e6c 248 WriteReg(0xb8, 0x0a);
tomoya123 0:0a7fa0911e6c 249
tomoya123 0:0a7fa0911e6c 250 // More reserved magic, some of which tweaks white balance
tomoya123 0:0a7fa0911e6c 251 WriteReg(0x43, 0x0a);
tomoya123 0:0a7fa0911e6c 252 WriteReg(0x44, 0xf0);
tomoya123 0:0a7fa0911e6c 253 WriteReg(0x45, 0x34);
tomoya123 0:0a7fa0911e6c 254 WriteReg(0x46, 0x58);
tomoya123 0:0a7fa0911e6c 255 WriteReg(0x47, 0x28);
tomoya123 0:0a7fa0911e6c 256 WriteReg(0x48, 0x3a);
tomoya123 0:0a7fa0911e6c 257 WriteReg(0x59, 0x88);
tomoya123 0:0a7fa0911e6c 258 WriteReg(0x5a, 0x88);
tomoya123 0:0a7fa0911e6c 259 WriteReg(0x5b, 0x44);
tomoya123 0:0a7fa0911e6c 260 WriteReg(0x5c, 0x67);
tomoya123 0:0a7fa0911e6c 261 WriteReg(0x5d, 0x49);
tomoya123 0:0a7fa0911e6c 262 WriteReg(0x5e, 0x0e);
tomoya123 0:0a7fa0911e6c 263 WriteReg(0x6c, 0x0a);
tomoya123 0:0a7fa0911e6c 264 WriteReg(0x6d, 0x55);
tomoya123 0:0a7fa0911e6c 265 WriteReg(0x6e, 0x11);
tomoya123 0:0a7fa0911e6c 266 WriteReg(0x6f, 0x9f);
tomoya123 0:0a7fa0911e6c 267 // "9e for advance AWB"
tomoya123 0:0a7fa0911e6c 268 WriteReg(0x6a, 0x40);
tomoya123 0:0a7fa0911e6c 269 WriteReg(REG_BLUE, 0x40);
tomoya123 0:0a7fa0911e6c 270 WriteReg(REG_RED, 0x60);
tomoya123 0:0a7fa0911e6c 271 WriteReg(REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB);
tomoya123 0:0a7fa0911e6c 272
tomoya123 0:0a7fa0911e6c 273 // Matrix coefficients
tomoya123 0:0a7fa0911e6c 274 WriteReg(0x4f, 0x80);
tomoya123 0:0a7fa0911e6c 275 WriteReg(0x50, 0x80);
tomoya123 0:0a7fa0911e6c 276 WriteReg(0x51, 0);
tomoya123 0:0a7fa0911e6c 277 WriteReg(0x52, 0x22);
tomoya123 0:0a7fa0911e6c 278 WriteReg(0x53, 0x5e);
tomoya123 0:0a7fa0911e6c 279 WriteReg(0x54, 0x80);
tomoya123 0:0a7fa0911e6c 280 WriteReg(0x58, 0x9e);
tomoya123 0:0a7fa0911e6c 281
tomoya123 0:0a7fa0911e6c 282 WriteReg(REG_COM16, COM16_AWBGAIN);
tomoya123 0:0a7fa0911e6c 283 WriteReg(REG_EDGE, 0);
tomoya123 0:0a7fa0911e6c 284 WriteReg(0x75, 0x05);
tomoya123 0:0a7fa0911e6c 285 WriteReg(0x76, 0xe1);
tomoya123 0:0a7fa0911e6c 286 WriteReg(0x4c, 0);
tomoya123 0:0a7fa0911e6c 287 WriteReg(0x77, 0x01);
tomoya123 0:0a7fa0911e6c 288 WriteReg(0x4b, 0x09);
tomoya123 0:0a7fa0911e6c 289 WriteReg(0xc9, 0x60);
tomoya123 0:0a7fa0911e6c 290 WriteReg(REG_COM16, 0x38);
tomoya123 0:0a7fa0911e6c 291 WriteReg(0x56, 0x40);
tomoya123 0:0a7fa0911e6c 292
tomoya123 0:0a7fa0911e6c 293 WriteReg(0x34, 0x11);
tomoya123 0:0a7fa0911e6c 294 WriteReg(REG_COM11, COM11_EXP|COM11_HZAUTO_ON);
tomoya123 0:0a7fa0911e6c 295 WriteReg(0xa4, 0x88);
tomoya123 0:0a7fa0911e6c 296 WriteReg(0x96, 0);
tomoya123 0:0a7fa0911e6c 297 WriteReg(0x97, 0x30);
tomoya123 0:0a7fa0911e6c 298 WriteReg(0x98, 0x20);
tomoya123 0:0a7fa0911e6c 299 WriteReg(0x99, 0x30);
tomoya123 0:0a7fa0911e6c 300 WriteReg(0x9a, 0x84);
tomoya123 0:0a7fa0911e6c 301 WriteReg(0x9b, 0x29);
tomoya123 0:0a7fa0911e6c 302 WriteReg(0x9c, 0x03);
tomoya123 0:0a7fa0911e6c 303 WriteReg(0x9d, 0x4c);
tomoya123 0:0a7fa0911e6c 304 WriteReg(0x9e, 0x3f);
tomoya123 0:0a7fa0911e6c 305 WriteReg(0x78, 0x04);
tomoya123 0:0a7fa0911e6c 306
tomoya123 0:0a7fa0911e6c 307 // Extra-weird stuff. Some sort of multiplexor register
tomoya123 0:0a7fa0911e6c 308 WriteReg(0x79, 0x01);
tomoya123 0:0a7fa0911e6c 309 WriteReg(0xc8, 0xf0);
tomoya123 0:0a7fa0911e6c 310 WriteReg(0x79, 0x0f);
tomoya123 0:0a7fa0911e6c 311 WriteReg(0xc8, 0x00);
tomoya123 0:0a7fa0911e6c 312 WriteReg(0x79, 0x10);
tomoya123 0:0a7fa0911e6c 313 WriteReg(0xc8, 0x7e);
tomoya123 0:0a7fa0911e6c 314 WriteReg(0x79, 0x0a);
tomoya123 0:0a7fa0911e6c 315 WriteReg(0xc8, 0x80);
tomoya123 0:0a7fa0911e6c 316 WriteReg(0x79, 0x0b);
tomoya123 0:0a7fa0911e6c 317 WriteReg(0xc8, 0x01);
tomoya123 0:0a7fa0911e6c 318 WriteReg(0x79, 0x0c);
tomoya123 0:0a7fa0911e6c 319 WriteReg(0xc8, 0x0f);
tomoya123 0:0a7fa0911e6c 320 WriteReg(0x79, 0x0d);
tomoya123 0:0a7fa0911e6c 321 WriteReg(0xc8, 0x20);
tomoya123 0:0a7fa0911e6c 322 WriteReg(0x79, 0x09);
tomoya123 0:0a7fa0911e6c 323 WriteReg(0xc8, 0x80);
tomoya123 0:0a7fa0911e6c 324 WriteReg(0x79, 0x02);
tomoya123 0:0a7fa0911e6c 325 WriteReg(0xc8, 0xc0);
tomoya123 0:0a7fa0911e6c 326 WriteReg(0x79, 0x03);
tomoya123 0:0a7fa0911e6c 327 WriteReg(0xc8, 0x40);
tomoya123 0:0a7fa0911e6c 328 WriteReg(0x79, 0x05);
tomoya123 0:0a7fa0911e6c 329 WriteReg(0xc8, 0x30);
tomoya123 0:0a7fa0911e6c 330 WriteReg(0x79, 0x26);
tomoya123 0:0a7fa0911e6c 331 }
tomoya123 0:0a7fa0911e6c 332
tomoya123 0:0a7fa0911e6c 333 void HeptaCamera::InitRGB444(void){
tomoya123 0:0a7fa0911e6c 334 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 335
tomoya123 0:0a7fa0911e6c 336 WriteReg(REG_COM7, reg_com7|COM7_RGB);
tomoya123 0:0a7fa0911e6c 337 WriteReg(REG_RGB444, RGB444_ENABLE|RGB444_XBGR);
tomoya123 0:0a7fa0911e6c 338 WriteReg(REG_COM15, COM15_R01FE|COM15_RGB444);
tomoya123 0:0a7fa0911e6c 339
tomoya123 0:0a7fa0911e6c 340 WriteReg(REG_COM1, 0x40); // Magic reserved bit
tomoya123 0:0a7fa0911e6c 341 WriteReg(REG_COM9, 0x38); // 16x gain ceiling; 0x8 is reserved bit
tomoya123 0:0a7fa0911e6c 342 WriteReg(0x4f, 0xb3); // "matrix coefficient 1"
tomoya123 0:0a7fa0911e6c 343 WriteReg(0x50, 0xb3); // "matrix coefficient 2"
tomoya123 0:0a7fa0911e6c 344 WriteReg(0x51, 0x00); // vb
tomoya123 0:0a7fa0911e6c 345 WriteReg(0x52, 0x3d); // "matrix coefficient 4"
tomoya123 0:0a7fa0911e6c 346 WriteReg(0x53, 0xa7); // "matrix coefficient 5"
tomoya123 0:0a7fa0911e6c 347 WriteReg(0x54, 0xe4); // "matrix coefficient 6"
tomoya123 0:0a7fa0911e6c 348 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT|0x2); // Magic rsvd bit
tomoya123 0:0a7fa0911e6c 349
tomoya123 0:0a7fa0911e6c 350 WriteReg(REG_TSLB, 0x04);
tomoya123 0:0a7fa0911e6c 351 }
tomoya123 0:0a7fa0911e6c 352
tomoya123 0:0a7fa0911e6c 353 void HeptaCamera::InitRGB555(void){
tomoya123 0:0a7fa0911e6c 354 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 355
tomoya123 0:0a7fa0911e6c 356 WriteReg(REG_COM7, reg_com7|COM7_RGB);
tomoya123 0:0a7fa0911e6c 357 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:0a7fa0911e6c 358 WriteReg(REG_COM15, COM15_RGB555|COM15_R00FF);
tomoya123 0:0a7fa0911e6c 359
tomoya123 0:0a7fa0911e6c 360 WriteReg(REG_TSLB, 0x04);
tomoya123 0:0a7fa0911e6c 361
tomoya123 0:0a7fa0911e6c 362 WriteReg(REG_COM1, 0x00);
tomoya123 0:0a7fa0911e6c 363 WriteReg(REG_COM9, 0x38); // 16x gain ceiling; 0x8 is reserved bit
tomoya123 0:0a7fa0911e6c 364 WriteReg(0x4f, 0xb3); // "matrix coefficient 1"
tomoya123 0:0a7fa0911e6c 365 WriteReg(0x50, 0xb3); // "matrix coefficient 2"
tomoya123 0:0a7fa0911e6c 366 WriteReg(0x51, 0x00); // vb
tomoya123 0:0a7fa0911e6c 367 WriteReg(0x52, 0x3d); // "matrix coefficient 4"
tomoya123 0:0a7fa0911e6c 368 WriteReg(0x53, 0xa7); // "matrix coefficient 5"
tomoya123 0:0a7fa0911e6c 369 WriteReg(0x54, 0xe4); // "matrix coefficient 6"
tomoya123 0:0a7fa0911e6c 370 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT);
tomoya123 0:0a7fa0911e6c 371 }
tomoya123 0:0a7fa0911e6c 372
tomoya123 0:0a7fa0911e6c 373 void HeptaCamera::InitRGB565(void){
tomoya123 0:0a7fa0911e6c 374 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 375
tomoya123 0:0a7fa0911e6c 376 WriteReg(REG_COM7, reg_com7|COM7_RGB);
tomoya123 0:0a7fa0911e6c 377 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:0a7fa0911e6c 378 WriteReg(REG_COM15, COM15_R00FF|COM15_RGB565);
tomoya123 0:0a7fa0911e6c 379
tomoya123 0:0a7fa0911e6c 380 WriteReg(REG_TSLB, 0x04);
tomoya123 0:0a7fa0911e6c 381
tomoya123 0:0a7fa0911e6c 382 WriteReg(REG_COM1, 0x00);
tomoya123 0:0a7fa0911e6c 383 WriteReg(REG_COM9, 0x38); // 16x gain ceiling; 0x8 is reserved bit
tomoya123 0:0a7fa0911e6c 384 WriteReg(0x4f, 0xb3); // "matrix coefficient 1"
tomoya123 0:0a7fa0911e6c 385 WriteReg(0x50, 0xb3); // "matrix coefficient 2"
tomoya123 0:0a7fa0911e6c 386 WriteReg(0x51, 0x00); // vb
tomoya123 0:0a7fa0911e6c 387 WriteReg(0x52, 0x3d); // "matrix coefficient 4"
tomoya123 0:0a7fa0911e6c 388 WriteReg(0x53, 0xa7); // "matrix coefficient 5"
tomoya123 0:0a7fa0911e6c 389 WriteReg(0x54, 0xe4); // "matrix coefficient 6"
tomoya123 0:0a7fa0911e6c 390 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT);
tomoya123 0:0a7fa0911e6c 391 }
tomoya123 0:0a7fa0911e6c 392
tomoya123 0:0a7fa0911e6c 393 void HeptaCamera::InitYUV(void){
tomoya123 0:0a7fa0911e6c 394 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 395
tomoya123 0:0a7fa0911e6c 396 WriteReg(REG_COM7, reg_com7|COM7_YUV);
tomoya123 0:0a7fa0911e6c 397 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:0a7fa0911e6c 398 WriteReg(REG_COM15, COM15_R00FF);
tomoya123 0:0a7fa0911e6c 399
tomoya123 0:0a7fa0911e6c 400 WriteReg(REG_TSLB, 0x04);
tomoya123 0:0a7fa0911e6c 401 // WriteReg(REG_TSLB, 0x14);
tomoya123 0:0a7fa0911e6c 402 // WriteReg(REG_MANU, 0x00);
tomoya123 0:0a7fa0911e6c 403 // WriteReg(REG_MANV, 0x00);
tomoya123 0:0a7fa0911e6c 404
tomoya123 0:0a7fa0911e6c 405 WriteReg(REG_COM1, 0x00);
tomoya123 0:0a7fa0911e6c 406 WriteReg(REG_COM9, 0x18); // 4x gain ceiling; 0x8 is reserved bit
tomoya123 0:0a7fa0911e6c 407 WriteReg(0x4f, 0x80); // "matrix coefficient 1"
tomoya123 0:0a7fa0911e6c 408 WriteReg(0x50, 0x80); // "matrix coefficient 2"
tomoya123 0:0a7fa0911e6c 409 WriteReg(0x51, 0x00); // vb
tomoya123 0:0a7fa0911e6c 410 WriteReg(0x52, 0x22); // "matrix coefficient 4"
tomoya123 0:0a7fa0911e6c 411 WriteReg(0x53, 0x5e); // "matrix coefficient 5"
tomoya123 0:0a7fa0911e6c 412 WriteReg(0x54, 0x80); // "matrix coefficient 6"
tomoya123 0:0a7fa0911e6c 413 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT|COM13_UVSWAP);
tomoya123 0:0a7fa0911e6c 414 }
tomoya123 0:0a7fa0911e6c 415
tomoya123 0:0a7fa0911e6c 416 void HeptaCamera::InitBayerRGB(void){
tomoya123 0:0a7fa0911e6c 417 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 418
tomoya123 0:0a7fa0911e6c 419 // odd line BGBG... even line GRGR...
tomoya123 0:0a7fa0911e6c 420 WriteReg(REG_COM7, reg_com7|COM7_BAYER);
tomoya123 0:0a7fa0911e6c 421 // odd line GBGB... even line RGRG...
tomoya123 0:0a7fa0911e6c 422 //WriteReg(REG_COM7, reg_com7|COM7_PBAYER);
tomoya123 0:0a7fa0911e6c 423
tomoya123 0:0a7fa0911e6c 424 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:0a7fa0911e6c 425 WriteReg(REG_COM15, COM15_R00FF);
tomoya123 0:0a7fa0911e6c 426
tomoya123 0:0a7fa0911e6c 427 WriteReg(REG_COM13, 0x08); /* No gamma, magic rsvd bit */
tomoya123 0:0a7fa0911e6c 428 WriteReg(REG_COM16, 0x3d); /* Edge enhancement, denoise */
tomoya123 0:0a7fa0911e6c 429 WriteReg(REG_REG76, 0xe1); /* Pix correction, magic rsvd */
tomoya123 0:0a7fa0911e6c 430
tomoya123 0:0a7fa0911e6c 431 WriteReg(REG_TSLB, 0x04);
tomoya123 0:0a7fa0911e6c 432 }
tomoya123 0:0a7fa0911e6c 433
tomoya123 0:0a7fa0911e6c 434 void HeptaCamera::InitVGA(void) {
tomoya123 0:0a7fa0911e6c 435 // VGA
tomoya123 0:0a7fa0911e6c 436 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 437
tomoya123 0:0a7fa0911e6c 438 WriteReg(REG_COM7,reg_com7|COM7_VGA);
tomoya123 0:0a7fa0911e6c 439
tomoya123 0:0a7fa0911e6c 440 WriteReg(REG_HSTART,HSTART_VGA);
tomoya123 0:0a7fa0911e6c 441 WriteReg(REG_HSTOP,HSTOP_VGA);
tomoya123 0:0a7fa0911e6c 442 WriteReg(REG_HREF,HREF_VGA);
tomoya123 0:0a7fa0911e6c 443 WriteReg(REG_VSTART,VSTART_VGA);
tomoya123 0:0a7fa0911e6c 444 WriteReg(REG_VSTOP,VSTOP_VGA);
tomoya123 0:0a7fa0911e6c 445 WriteReg(REG_VREF,VREF_VGA);
tomoya123 0:0a7fa0911e6c 446 WriteReg(REG_COM3, COM3_VGA);
tomoya123 0:0a7fa0911e6c 447 WriteReg(REG_COM14, COM14_VGA);
tomoya123 0:0a7fa0911e6c 448 WriteReg(REG_SCALING_XSC, SCALING_XSC_VGA);
tomoya123 0:0a7fa0911e6c 449 WriteReg(REG_SCALING_YSC, SCALING_YSC_VGA);
tomoya123 0:0a7fa0911e6c 450 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_VGA);
tomoya123 0:0a7fa0911e6c 451 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_VGA);
tomoya123 0:0a7fa0911e6c 452 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_VGA);
tomoya123 0:0a7fa0911e6c 453 }
tomoya123 0:0a7fa0911e6c 454
tomoya123 0:0a7fa0911e6c 455 void HeptaCamera::InitFIFO_2bytes_color_nealy_limit_size(void) {
tomoya123 0:0a7fa0911e6c 456 // nealy FIFO limit 544x360
tomoya123 0:0a7fa0911e6c 457 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 458
tomoya123 0:0a7fa0911e6c 459 WriteReg(REG_COM7,reg_com7|COM7_VGA);
tomoya123 0:0a7fa0911e6c 460
tomoya123 0:0a7fa0911e6c 461 WriteReg(REG_HSTART,HSTART_VGA);
tomoya123 0:0a7fa0911e6c 462 WriteReg(REG_HSTOP,HSTOP_VGA);
tomoya123 0:0a7fa0911e6c 463 WriteReg(REG_HREF,HREF_VGA);
tomoya123 0:0a7fa0911e6c 464 WriteReg(REG_VSTART,VSTART_VGA);
tomoya123 0:0a7fa0911e6c 465 WriteReg(REG_VSTOP,VSTOP_VGA);
tomoya123 0:0a7fa0911e6c 466 WriteReg(REG_VREF,VREF_VGA);
tomoya123 0:0a7fa0911e6c 467 WriteReg(REG_COM3, COM3_VGA);
tomoya123 0:0a7fa0911e6c 468 WriteReg(REG_COM14, COM14_VGA);
tomoya123 0:0a7fa0911e6c 469 WriteReg(REG_SCALING_XSC, SCALING_XSC_VGA);
tomoya123 0:0a7fa0911e6c 470 WriteReg(REG_SCALING_YSC, SCALING_YSC_VGA);
tomoya123 0:0a7fa0911e6c 471 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_VGA);
tomoya123 0:0a7fa0911e6c 472 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_VGA);
tomoya123 0:0a7fa0911e6c 473 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_VGA);
tomoya123 0:0a7fa0911e6c 474
tomoya123 0:0a7fa0911e6c 475 WriteReg(REG_HSTART, 0x17);
tomoya123 0:0a7fa0911e6c 476 WriteReg(REG_HSTOP, 0x5b);
tomoya123 0:0a7fa0911e6c 477 WriteReg(REG_VSTART, 0x12);
tomoya123 0:0a7fa0911e6c 478 WriteReg(REG_VSTOP, 0x6c);
tomoya123 0:0a7fa0911e6c 479 }
tomoya123 0:0a7fa0911e6c 480
tomoya123 0:0a7fa0911e6c 481 void HeptaCamera::InitVGA_3_4(void) {
tomoya123 0:0a7fa0911e6c 482 // VGA 3/4 -> 480x360
tomoya123 0:0a7fa0911e6c 483 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 484
tomoya123 0:0a7fa0911e6c 485 WriteReg(REG_COM7,reg_com7|COM7_VGA);
tomoya123 0:0a7fa0911e6c 486
tomoya123 0:0a7fa0911e6c 487 WriteReg(REG_HSTART,HSTART_VGA);
tomoya123 0:0a7fa0911e6c 488 WriteReg(REG_HSTOP,HSTOP_VGA);
tomoya123 0:0a7fa0911e6c 489 WriteReg(REG_HREF,HREF_VGA);
tomoya123 0:0a7fa0911e6c 490 WriteReg(REG_VSTART,VSTART_VGA);
tomoya123 0:0a7fa0911e6c 491 WriteReg(REG_VSTOP,VSTOP_VGA);
tomoya123 0:0a7fa0911e6c 492 WriteReg(REG_VREF,VREF_VGA);
tomoya123 0:0a7fa0911e6c 493 WriteReg(REG_COM3, COM3_VGA);
tomoya123 0:0a7fa0911e6c 494 WriteReg(REG_COM14, COM14_VGA);
tomoya123 0:0a7fa0911e6c 495 WriteReg(REG_SCALING_XSC, SCALING_XSC_VGA);
tomoya123 0:0a7fa0911e6c 496 WriteReg(REG_SCALING_YSC, SCALING_YSC_VGA);
tomoya123 0:0a7fa0911e6c 497 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_VGA);
tomoya123 0:0a7fa0911e6c 498 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_VGA);
tomoya123 0:0a7fa0911e6c 499 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_VGA);
tomoya123 0:0a7fa0911e6c 500
tomoya123 0:0a7fa0911e6c 501 WriteReg(REG_HSTART, 0x1b);
tomoya123 0:0a7fa0911e6c 502 WriteReg(REG_HSTOP, 0x57);
tomoya123 0:0a7fa0911e6c 503 WriteReg(REG_VSTART, 0x12);
tomoya123 0:0a7fa0911e6c 504 WriteReg(REG_VSTOP, 0x6c);
tomoya123 0:0a7fa0911e6c 505 }
tomoya123 0:0a7fa0911e6c 506
tomoya123 0:0a7fa0911e6c 507 void HeptaCamera::InitQVGA(void) {
tomoya123 0:0a7fa0911e6c 508 // QQVGA
tomoya123 0:0a7fa0911e6c 509 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 510
tomoya123 0:0a7fa0911e6c 511 WriteReg(REG_COM7,reg_com7|COM7_QVGA);
tomoya123 0:0a7fa0911e6c 512
tomoya123 0:0a7fa0911e6c 513 WriteReg(REG_HSTART,HSTART_QVGA);
tomoya123 0:0a7fa0911e6c 514 WriteReg(REG_HSTOP,HSTOP_QVGA);
tomoya123 0:0a7fa0911e6c 515 WriteReg(REG_HREF,HREF_QVGA);
tomoya123 0:0a7fa0911e6c 516 WriteReg(REG_VSTART,VSTART_QVGA);
tomoya123 0:0a7fa0911e6c 517 WriteReg(REG_VSTOP,VSTOP_QVGA);
tomoya123 0:0a7fa0911e6c 518 WriteReg(REG_VREF,VREF_QVGA);
tomoya123 0:0a7fa0911e6c 519 WriteReg(REG_COM3, COM3_QVGA);
tomoya123 0:0a7fa0911e6c 520 WriteReg(REG_COM14, COM14_QVGA);
tomoya123 0:0a7fa0911e6c 521 WriteReg(REG_SCALING_XSC, SCALING_XSC_QVGA);
tomoya123 0:0a7fa0911e6c 522 WriteReg(REG_SCALING_YSC, SCALING_YSC_QVGA);
tomoya123 0:0a7fa0911e6c 523 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_QVGA);
tomoya123 0:0a7fa0911e6c 524 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_QVGA);
tomoya123 0:0a7fa0911e6c 525 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_QVGA);
tomoya123 0:0a7fa0911e6c 526 }
tomoya123 0:0a7fa0911e6c 527
tomoya123 0:0a7fa0911e6c 528 void HeptaCamera::InitQQVGA(void) {
tomoya123 0:0a7fa0911e6c 529 // QQVGA
tomoya123 0:0a7fa0911e6c 530 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:0a7fa0911e6c 531
tomoya123 0:0a7fa0911e6c 532 WriteReg(REG_COM7,reg_com7|COM7_QQVGA);
tomoya123 0:0a7fa0911e6c 533
tomoya123 0:0a7fa0911e6c 534 WriteReg(REG_HSTART,HSTART_QQVGA);
tomoya123 0:0a7fa0911e6c 535 WriteReg(REG_HSTOP,HSTOP_QQVGA);
tomoya123 0:0a7fa0911e6c 536 WriteReg(REG_HREF,HREF_QQVGA);
tomoya123 0:0a7fa0911e6c 537 WriteReg(REG_VSTART,VSTART_QQVGA);
tomoya123 0:0a7fa0911e6c 538 WriteReg(REG_VSTOP,VSTOP_QQVGA);
tomoya123 0:0a7fa0911e6c 539 WriteReg(REG_VREF,VREF_QQVGA);
tomoya123 0:0a7fa0911e6c 540 WriteReg(REG_COM3, COM3_QQVGA);
tomoya123 0:0a7fa0911e6c 541 WriteReg(REG_COM14, COM14_QQVGA);
tomoya123 0:0a7fa0911e6c 542 WriteReg(REG_SCALING_XSC, SCALING_XSC_QQVGA);
tomoya123 0:0a7fa0911e6c 543 WriteReg(REG_SCALING_YSC, SCALING_YSC_QQVGA);
tomoya123 0:0a7fa0911e6c 544 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_QQVGA);
tomoya123 0:0a7fa0911e6c 545 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_QQVGA);
tomoya123 0:0a7fa0911e6c 546 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_QQVGA);
tomoya123 0:0a7fa0911e6c 547 }
tomoya123 0:0a7fa0911e6c 548
tomoya123 0:0a7fa0911e6c 549 // vsync handler
tomoya123 0:0a7fa0911e6c 550 void HeptaCamera::VsyncHandler(void)
tomoya123 0:0a7fa0911e6c 551 {
tomoya123 0:0a7fa0911e6c 552 // Capture Enable
tomoya123 0:0a7fa0911e6c 553 if (CaptureReq) {
tomoya123 0:0a7fa0911e6c 554 wen = 1;
tomoya123 0:0a7fa0911e6c 555 Done = false;
tomoya123 0:0a7fa0911e6c 556 CaptureReq = false;
tomoya123 0:0a7fa0911e6c 557 } else {
tomoya123 0:0a7fa0911e6c 558 wen = 0;
tomoya123 0:0a7fa0911e6c 559 if (Busy) {
tomoya123 0:0a7fa0911e6c 560 Busy = false;
tomoya123 0:0a7fa0911e6c 561 Done = true;
tomoya123 0:0a7fa0911e6c 562 }
tomoya123 0:0a7fa0911e6c 563 }
tomoya123 0:0a7fa0911e6c 564
tomoya123 0:0a7fa0911e6c 565 // Hline Counter
tomoya123 0:0a7fa0911e6c 566 LastLines = LineCounter;
tomoya123 0:0a7fa0911e6c 567 LineCounter = 0;
tomoya123 0:0a7fa0911e6c 568 }
tomoya123 0:0a7fa0911e6c 569
tomoya123 0:0a7fa0911e6c 570 // href handler
tomoya123 0:0a7fa0911e6c 571 void HeptaCamera::HrefHandler(void)
tomoya123 0:0a7fa0911e6c 572 {
tomoya123 0:0a7fa0911e6c 573 LineCounter++;
tomoya123 0:0a7fa0911e6c 574 }
tomoya123 0:0a7fa0911e6c 575
tomoya123 0:0a7fa0911e6c 576 // Data Read
tomoya123 0:0a7fa0911e6c 577 int HeptaCamera::ReadOneByte(void)
tomoya123 0:0a7fa0911e6c 578 {
tomoya123 0:0a7fa0911e6c 579 int result;
tomoya123 0:0a7fa0911e6c 580 rclk = 1;
tomoya123 0:0a7fa0911e6c 581 // wait_us(1);
tomoya123 0:0a7fa0911e6c 582 result = data;
tomoya123 0:0a7fa0911e6c 583 rclk = 0;
tomoya123 0:0a7fa0911e6c 584 return result;
tomoya123 0:0a7fa0911e6c 585 }
tomoya123 0:0a7fa0911e6c 586
tomoya123 0:0a7fa0911e6c 587 // Data Start
tomoya123 0:0a7fa0911e6c 588 void HeptaCamera::ReadStart(void)
tomoya123 0:0a7fa0911e6c 589 {
tomoya123 0:0a7fa0911e6c 590 rrst = 0;
tomoya123 0:0a7fa0911e6c 591 oe = 0;
tomoya123 0:0a7fa0911e6c 592 wait_us(1);
tomoya123 0:0a7fa0911e6c 593 rclk = 0;
tomoya123 0:0a7fa0911e6c 594 wait_us(1);
tomoya123 0:0a7fa0911e6c 595 rclk = 1;
tomoya123 0:0a7fa0911e6c 596 wait_us(1);
tomoya123 0:0a7fa0911e6c 597 rrst = 1;
tomoya123 0:0a7fa0911e6c 598 }
tomoya123 0:0a7fa0911e6c 599
tomoya123 0:0a7fa0911e6c 600 // Data Stop
tomoya123 0:0a7fa0911e6c 601 void HeptaCamera::ReadStop(void)
tomoya123 0:0a7fa0911e6c 602 {
tomoya123 0:0a7fa0911e6c 603 oe = 1;
tomoya123 0:0a7fa0911e6c 604 ReadOneByte();
tomoya123 0:0a7fa0911e6c 605 rclk = 1;
tomoya123 0:0a7fa0911e6c 606 }
tomoya123 0:0a7fa0911e6c 607
tomoya123 0:0a7fa0911e6c 608 void HeptaCamera::shoot()
tomoya123 0:0a7fa0911e6c 609 {
tomoya123 0:0a7fa0911e6c 610 //pc.baud(115200);
tomoya123 0:0a7fa0911e6c 611
tomoya123 0:0a7fa0911e6c 612 //pc.printf("Camera resetting..\r\n");
tomoya123 0:0a7fa0911e6c 613 HeptaCamera::Reset();
tomoya123 0:0a7fa0911e6c 614
tomoya123 0:0a7fa0911e6c 615 //pc.printf("Before Init...\r\n");
tomoya123 0:0a7fa0911e6c 616 HeptaCamera::PrintRegister();
tomoya123 0:0a7fa0911e6c 617 char color_format = '1';
tomoya123 0:0a7fa0911e6c 618 /*pc.printf("Select color format.\r\n") ;
tomoya123 0:0a7fa0911e6c 619 pc.printf("1: RGB444.\r\n");
tomoya123 0:0a7fa0911e6c 620 pc.printf("2: RGB555.\r\n");
tomoya123 0:0a7fa0911e6c 621 pc.printf("3: RGB565.\r\n");
tomoya123 0:0a7fa0911e6c 622 pc.printf("4: YUV(UYVY).\r\n");
tomoya123 0:0a7fa0911e6c 623 pc.printf("5: Bayer RGB(BGBG... GRGR...).\r\n");*/
tomoya123 0:0a7fa0911e6c 624
tomoya123 0:0a7fa0911e6c 625 /*while(!pc.readable());
tomoya123 0:0a7fa0911e6c 626 char color_format = pc.getc();
tomoya123 0:0a7fa0911e6c 627 switch (color_format) {
tomoya123 0:0a7fa0911e6c 628 case '1':
tomoya123 0:0a7fa0911e6c 629 camera.InitRGB444();
tomoya123 0:0a7fa0911e6c 630 break;
tomoya123 0:0a7fa0911e6c 631 case '2':
tomoya123 0:0a7fa0911e6c 632 camera.InitRGB555();
tomoya123 0:0a7fa0911e6c 633 break;
tomoya123 0:0a7fa0911e6c 634 case '3':
tomoya123 0:0a7fa0911e6c 635 camera.InitRGB565();
tomoya123 0:0a7fa0911e6c 636 break;
tomoya123 0:0a7fa0911e6c 637 case '4':
tomoya123 0:0a7fa0911e6c 638 camera.InitYUV();
tomoya123 0:0a7fa0911e6c 639 break;
tomoya123 0:0a7fa0911e6c 640 case '5':
tomoya123 0:0a7fa0911e6c 641 camera.InitBayerRGB();
tomoya123 0:0a7fa0911e6c 642 break;
tomoya123 0:0a7fa0911e6c 643 }
tomoya123 0:0a7fa0911e6c 644 pc.printf("select %c\r\n", color_format);
tomoya123 0:0a7fa0911e6c 645
tomoya123 0:0a7fa0911e6c 646 pc.printf("Select screen size.\r\n") ;
tomoya123 0:0a7fa0911e6c 647 switch (color_format) {
tomoya123 0:0a7fa0911e6c 648 case '5':
tomoya123 0:0a7fa0911e6c 649 pc.printf("1: VGA(640x480).\r\n");
tomoya123 0:0a7fa0911e6c 650 case '1':
tomoya123 0:0a7fa0911e6c 651 case '2':
tomoya123 0:0a7fa0911e6c 652 case '3':
tomoya123 0:0a7fa0911e6c 653 case '4':
tomoya123 0:0a7fa0911e6c 654 pc.printf("2: FIFO nealy limit(544x360).\r\n");
tomoya123 0:0a7fa0911e6c 655 pc.printf("3: VGA*3/4(480x360).\r\n");
tomoya123 0:0a7fa0911e6c 656 pc.printf("4: QVGA(320x240).\r\n");
tomoya123 0:0a7fa0911e6c 657 pc.printf("5: QQVGA(160x120).\r\n");
tomoya123 0:0a7fa0911e6c 658 break;
tomoya123 0:0a7fa0911e6c 659 }
tomoya123 0:0a7fa0911e6c 660 char screen_size = 4;
tomoya123 0:0a7fa0911e6c 661 while(!pc.readable());
tomoya123 0:0a7fa0911e6c 662 char screen_size = pc.getc() ;
tomoya123 0:0a7fa0911e6c 663 switch (screen_size) {
tomoya123 0:0a7fa0911e6c 664 case '1':
tomoya123 0:0a7fa0911e6c 665 sizex = 640;
tomoya123 0:0a7fa0911e6c 666 sizey = 480;
tomoya123 0:0a7fa0911e6c 667 camera.InitVGA();
tomoya123 0:0a7fa0911e6c 668 break;
tomoya123 0:0a7fa0911e6c 669 case '2':
tomoya123 0:0a7fa0911e6c 670 sizex = 544;
tomoya123 0:0a7fa0911e6c 671 sizey = 360;
tomoya123 0:0a7fa0911e6c 672 camera.InitFIFO_2bytes_color_nealy_limit_size();
tomoya123 0:0a7fa0911e6c 673 break;
tomoya123 0:0a7fa0911e6c 674 case '3':
tomoya123 0:0a7fa0911e6c 675 sizex = 480;
tomoya123 0:0a7fa0911e6c 676 sizey = 360;
tomoya123 0:0a7fa0911e6c 677 camera.InitVGA_3_4();
tomoya123 0:0a7fa0911e6c 678 break;
tomoya123 0:0a7fa0911e6c 679 case '4':
tomoya123 0:0a7fa0911e6c 680 sizex = 320;
tomoya123 0:0a7fa0911e6c 681 sizey = 240;
tomoya123 0:0a7fa0911e6c 682 camera.InitQVGA();
tomoya123 0:0a7fa0911e6c 683 break;
tomoya123 0:0a7fa0911e6c 684 case '5':
tomoya123 0:0a7fa0911e6c 685 sizex = 160;
tomoya123 0:0a7fa0911e6c 686 sizey = 120;
tomoya123 0:0a7fa0911e6c 687 camera.InitQQVGA();
tomoya123 0:0a7fa0911e6c 688 break;
tomoya123 0:0a7fa0911e6c 689 }
tomoya123 0:0a7fa0911e6c 690 pc.printf("select %c\r\n", screen_size);*/
tomoya123 0:0a7fa0911e6c 691 char screen_size = '4';
tomoya123 0:0a7fa0911e6c 692 HeptaCamera::InitRGB444();
tomoya123 0:0a7fa0911e6c 693 sizex = 320;
tomoya123 0:0a7fa0911e6c 694 sizey = 240;
tomoya123 0:0a7fa0911e6c 695 HeptaCamera::InitQVGA();
tomoya123 0:0a7fa0911e6c 696 HeptaCamera::InitForFIFOWriteReset();
tomoya123 0:0a7fa0911e6c 697 HeptaCamera::InitDefaultReg();
tomoya123 0:0a7fa0911e6c 698
tomoya123 0:0a7fa0911e6c 699 #ifdef COLORBAR
tomoya123 0:0a7fa0911e6c 700 HeptaCamera::InitSetColorbar();
tomoya123 0:0a7fa0911e6c 701 #endif
tomoya123 0:0a7fa0911e6c 702
tomoya123 0:0a7fa0911e6c 703 //pc.printf("After Init...\r\n");
tomoya123 0:0a7fa0911e6c 704 HeptaCamera::PrintRegister();
tomoya123 0:0a7fa0911e6c 705
tomoya123 0:0a7fa0911e6c 706 // CAPTURE and SEND LOOP
tomoya123 0:0a7fa0911e6c 707
tomoya123 0:0a7fa0911e6c 708 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 709 //pc.printf("Hit Any Key %dx%d Capture Data.\r\n", sizex, sizey) ;
tomoya123 0:0a7fa0911e6c 710 //while(!pc.readable());
tomoya123 0:0a7fa0911e6c 711 //pc.printf("*\r\n");
tomoya123 0:0a7fa0911e6c 712 //pc.getc();
tomoya123 0:0a7fa0911e6c 713
tomoya123 0:0a7fa0911e6c 714 int real_width = sizex*3 + sizey%4;
tomoya123 0:0a7fa0911e6c 715
tomoya123 0:0a7fa0911e6c 716 unsigned char *bmp_line_data; //画像1行分のRGB情報を格納する
tomoya123 0:0a7fa0911e6c 717 if((bmp_line_data = (unsigned char *)malloc(sizeof(unsigned char)*real_width)) == NULL){
tomoya123 0:0a7fa0911e6c 718 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:0a7fa0911e6c 719 //return 1;
tomoya123 0:0a7fa0911e6c 720 }
tomoya123 0:0a7fa0911e6c 721
tomoya123 0:0a7fa0911e6c 722 //RGB情報を4バイトの倍数に合わせている
tomoya123 0:0a7fa0911e6c 723 for(int i=sizex*3; i<real_width; i++){
tomoya123 0:0a7fa0911e6c 724 bmp_line_data[i] = 0;
tomoya123 0:0a7fa0911e6c 725 }
tomoya123 0:0a7fa0911e6c 726 #endif
tomoya123 0:0a7fa0911e6c 727 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:0a7fa0911e6c 728 FILE *fp;
tomoya123 0:0a7fa0911e6c 729 char *filename = "/local/test.bmp";
tomoya123 0:0a7fa0911e6c 730 if((fp = fopen(filename, "wb")) == NULL){
tomoya123 0:0a7fa0911e6c 731 //pc.printf("Error: %s could not open.", filename);
tomoya123 0:0a7fa0911e6c 732 //return 1;
tomoya123 0:0a7fa0911e6c 733 }
tomoya123 0:0a7fa0911e6c 734
tomoya123 0:0a7fa0911e6c 735 create_header(fp, sizex, sizey);
tomoya123 0:0a7fa0911e6c 736 #endif
tomoya123 0:0a7fa0911e6c 737 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 738 FILE *fp2;
tomoya123 0:0a7fa0911e6c 739 char *filename2 = "/local/test.txt";
tomoya123 0:0a7fa0911e6c 740 if((fp2 = fopen(filename2, "w")) == NULL){
tomoya123 0:0a7fa0911e6c 741 pc.printf("Error: %s could not open.", filename2);
tomoya123 0:0a7fa0911e6c 742 return 1;
tomoya123 0:0a7fa0911e6c 743 }
tomoya123 0:0a7fa0911e6c 744 #endif
tomoya123 0:0a7fa0911e6c 745
tomoya123 0:0a7fa0911e6c 746 HeptaCamera::CaptureNext();
tomoya123 0:0a7fa0911e6c 747 while(HeptaCamera::CaptureDone() == false);
tomoya123 0:0a7fa0911e6c 748 HeptaCamera::ReadStart();
tomoya123 0:0a7fa0911e6c 749
tomoya123 0:0a7fa0911e6c 750 int r=0, g=0, b=0, d1, d2;
tomoya123 0:0a7fa0911e6c 751
tomoya123 0:0a7fa0911e6c 752 switch (color_format) {
tomoya123 0:0a7fa0911e6c 753 case '1':
tomoya123 0:0a7fa0911e6c 754 case '2':
tomoya123 0:0a7fa0911e6c 755 case '3':
tomoya123 0:0a7fa0911e6c 756
tomoya123 0:0a7fa0911e6c 757 for (int y=0; y<sizey; y++) {
tomoya123 0:0a7fa0911e6c 758 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 759 d1 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 760 d2 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 761
tomoya123 0:0a7fa0911e6c 762 switch (color_format) {
tomoya123 0:0a7fa0911e6c 763 case '1':
tomoya123 0:0a7fa0911e6c 764 // RGB444 to RGB888
tomoya123 0:0a7fa0911e6c 765 b = (d1 & 0x0F) << 4;
tomoya123 0:0a7fa0911e6c 766 g = (d2 & 0xF0);
tomoya123 0:0a7fa0911e6c 767 r = (d2 & 0x0F) << 4;
tomoya123 0:0a7fa0911e6c 768 break;
tomoya123 0:0a7fa0911e6c 769 case '2':
tomoya123 0:0a7fa0911e6c 770 // RGB555 to RGB888
tomoya123 0:0a7fa0911e6c 771 b = (d1 & 0x1F) << 3;
tomoya123 0:0a7fa0911e6c 772 g = (((d1 & 0xE0) >> 2) | ((d2 & 0x03) << 6));
tomoya123 0:0a7fa0911e6c 773 r = (d2 & 0x7c) << 1;
tomoya123 0:0a7fa0911e6c 774 break;
tomoya123 0:0a7fa0911e6c 775 case '3':
tomoya123 0:0a7fa0911e6c 776 // RGB565 to RGB888
tomoya123 0:0a7fa0911e6c 777 b = (d1 & 0x1F) << 3;
tomoya123 0:0a7fa0911e6c 778 g = (((d1 & 0xE0) >> 3) | ((d2 & 0x07) << 5));
tomoya123 0:0a7fa0911e6c 779 r = (d2 & 0xF8);
tomoya123 0:0a7fa0911e6c 780 break;
tomoya123 0:0a7fa0911e6c 781 }
tomoya123 0:0a7fa0911e6c 782 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 783 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:0a7fa0911e6c 784 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:0a7fa0911e6c 785 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:0a7fa0911e6c 786 #endif
tomoya123 0:0a7fa0911e6c 787 /*
tomoya123 0:0a7fa0911e6c 788 // RGB
tomoya123 0:0a7fa0911e6c 789 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:0a7fa0911e6c 790 */
tomoya123 0:0a7fa0911e6c 791 }
tomoya123 0:0a7fa0911e6c 792 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 793 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 794 #endif
tomoya123 0:0a7fa0911e6c 795 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 796 for(int i=0; i<sizex*3; i++){
tomoya123 0:0a7fa0911e6c 797 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:0a7fa0911e6c 798 }
tomoya123 0:0a7fa0911e6c 799 #endif
tomoya123 0:0a7fa0911e6c 800 // pc.printf("\r\n") ;
tomoya123 0:0a7fa0911e6c 801 }
tomoya123 0:0a7fa0911e6c 802 break;
tomoya123 0:0a7fa0911e6c 803
tomoya123 0:0a7fa0911e6c 804 case '4':
tomoya123 0:0a7fa0911e6c 805 int index = 0;
tomoya123 0:0a7fa0911e6c 806 for (int y=0; y<sizey; y++) {
tomoya123 0:0a7fa0911e6c 807 int U0=0, Y0=0, V0=0, Y1=0;
tomoya123 0:0a7fa0911e6c 808 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 809 if(index%2 == 0) {
tomoya123 0:0a7fa0911e6c 810 U0 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 811 Y0 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 812 V0 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 813 Y1 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 814
tomoya123 0:0a7fa0911e6c 815 b = Y0 + 1.77200 * (U0 - 128);
tomoya123 0:0a7fa0911e6c 816 g = Y0 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 817 r = Y0 + 1.40200 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 818 } else {
tomoya123 0:0a7fa0911e6c 819 b = Y1 + 1.77200 * (U0 - 128);
tomoya123 0:0a7fa0911e6c 820 g = Y1 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 821 r = Y1 + 1.40200 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 822 }
tomoya123 0:0a7fa0911e6c 823
tomoya123 0:0a7fa0911e6c 824 b = min(max(b, 0), 255);
tomoya123 0:0a7fa0911e6c 825 g = min(max(g, 0), 255);
tomoya123 0:0a7fa0911e6c 826 r = min(max(r, 0), 255);
tomoya123 0:0a7fa0911e6c 827
tomoya123 0:0a7fa0911e6c 828 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 829 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:0a7fa0911e6c 830 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:0a7fa0911e6c 831 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:0a7fa0911e6c 832 #endif
tomoya123 0:0a7fa0911e6c 833 /*
tomoya123 0:0a7fa0911e6c 834 // RGB
tomoya123 0:0a7fa0911e6c 835 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:0a7fa0911e6c 836 */
tomoya123 0:0a7fa0911e6c 837 index++;
tomoya123 0:0a7fa0911e6c 838 }
tomoya123 0:0a7fa0911e6c 839 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 840 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 841 #endif
tomoya123 0:0a7fa0911e6c 842 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 843 for(int i=0; i<sizex*3; i++){
tomoya123 0:0a7fa0911e6c 844 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:0a7fa0911e6c 845 }
tomoya123 0:0a7fa0911e6c 846 #endif
tomoya123 0:0a7fa0911e6c 847 // pc.printf("\r\n") ;
tomoya123 0:0a7fa0911e6c 848 }
tomoya123 0:0a7fa0911e6c 849 break;
tomoya123 0:0a7fa0911e6c 850
tomoya123 0:0a7fa0911e6c 851 case '5':
tomoya123 0:0a7fa0911e6c 852 unsigned char *bayer_line[2];
tomoya123 0:0a7fa0911e6c 853 unsigned char *bayer_line_data[2]; //画像1行分のRGB情報を格納する2行分
tomoya123 0:0a7fa0911e6c 854 for(int i=0; i<2; i++) {
tomoya123 0:0a7fa0911e6c 855 if((bayer_line_data[i] = (unsigned char *)malloc(sizeof(unsigned char)*sizex)) == NULL){
tomoya123 0:0a7fa0911e6c 856 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:0a7fa0911e6c 857 //return 1;
tomoya123 0:0a7fa0911e6c 858 }
tomoya123 0:0a7fa0911e6c 859 }
tomoya123 0:0a7fa0911e6c 860
tomoya123 0:0a7fa0911e6c 861 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 862 // odd line BGBG... even line GRGR...
tomoya123 0:0a7fa0911e6c 863 bayer_line_data[0][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 864 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 865 bmp_line_data[x*3] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:0a7fa0911e6c 866 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:0a7fa0911e6c 867 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:0a7fa0911e6c 868 #endif
tomoya123 0:0a7fa0911e6c 869 }
tomoya123 0:0a7fa0911e6c 870 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 871 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 872 #endif
tomoya123 0:0a7fa0911e6c 873 bayer_line[1] = bayer_line_data[0];
tomoya123 0:0a7fa0911e6c 874
tomoya123 0:0a7fa0911e6c 875 for (int y=1; y<sizey; y++) {
tomoya123 0:0a7fa0911e6c 876 int line = y%2;
tomoya123 0:0a7fa0911e6c 877
tomoya123 0:0a7fa0911e6c 878 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 879 // odd line BGBG... even line GRGR...
tomoya123 0:0a7fa0911e6c 880 bayer_line_data[line][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 881 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 882 bmp_line_data[x*3] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:0a7fa0911e6c 883 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:0a7fa0911e6c 884 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:0a7fa0911e6c 885 #endif
tomoya123 0:0a7fa0911e6c 886 }
tomoya123 0:0a7fa0911e6c 887 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 888 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 889 #endif
tomoya123 0:0a7fa0911e6c 890 bayer_line[0] = bayer_line[1];
tomoya123 0:0a7fa0911e6c 891 bayer_line[1] = bayer_line_data[line];
tomoya123 0:0a7fa0911e6c 892
tomoya123 0:0a7fa0911e6c 893 for (int x=0; x<sizex - 1; x++) {
tomoya123 0:0a7fa0911e6c 894 if(y%2==1) {
tomoya123 0:0a7fa0911e6c 895 if(x%2==0) {
tomoya123 0:0a7fa0911e6c 896 // BG
tomoya123 0:0a7fa0911e6c 897 // GR
tomoya123 0:0a7fa0911e6c 898 b = bayer_line[0][x];
tomoya123 0:0a7fa0911e6c 899 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:0a7fa0911e6c 900 r = bayer_line[1][x+1];
tomoya123 0:0a7fa0911e6c 901 } else {
tomoya123 0:0a7fa0911e6c 902 // GB
tomoya123 0:0a7fa0911e6c 903 // RG
tomoya123 0:0a7fa0911e6c 904 b = bayer_line[0][x+1];
tomoya123 0:0a7fa0911e6c 905 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:0a7fa0911e6c 906 r = bayer_line[1][x];
tomoya123 0:0a7fa0911e6c 907 }
tomoya123 0:0a7fa0911e6c 908 } else {
tomoya123 0:0a7fa0911e6c 909 if(x%2==0) {
tomoya123 0:0a7fa0911e6c 910 // GR
tomoya123 0:0a7fa0911e6c 911 // BG
tomoya123 0:0a7fa0911e6c 912 b = bayer_line[1][x];
tomoya123 0:0a7fa0911e6c 913 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:0a7fa0911e6c 914 r = bayer_line[0][x+1];
tomoya123 0:0a7fa0911e6c 915 } else {
tomoya123 0:0a7fa0911e6c 916 // RG
tomoya123 0:0a7fa0911e6c 917 // GB
tomoya123 0:0a7fa0911e6c 918 b = bayer_line[1][x+1];
tomoya123 0:0a7fa0911e6c 919 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:0a7fa0911e6c 920 r = bayer_line[0][x];
tomoya123 0:0a7fa0911e6c 921 }
tomoya123 0:0a7fa0911e6c 922 }
tomoya123 0:0a7fa0911e6c 923 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 924 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:0a7fa0911e6c 925 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:0a7fa0911e6c 926 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:0a7fa0911e6c 927 #endif
tomoya123 0:0a7fa0911e6c 928 }
tomoya123 0:0a7fa0911e6c 929
tomoya123 0:0a7fa0911e6c 930 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 931 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 932 #endif
tomoya123 0:0a7fa0911e6c 933
tomoya123 0:0a7fa0911e6c 934 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 935 for(int i=0; i<sizex*3; i++){
tomoya123 0:0a7fa0911e6c 936 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:0a7fa0911e6c 937 }
tomoya123 0:0a7fa0911e6c 938 #endif
tomoya123 0:0a7fa0911e6c 939 }
tomoya123 0:0a7fa0911e6c 940
tomoya123 0:0a7fa0911e6c 941 for(int i=0; i<2; i++) {
tomoya123 0:0a7fa0911e6c 942 free(bayer_line_data[i]);
tomoya123 0:0a7fa0911e6c 943 }
tomoya123 0:0a7fa0911e6c 944 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 945 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 946 #endif
tomoya123 0:0a7fa0911e6c 947 break;
tomoya123 0:0a7fa0911e6c 948 }
tomoya123 0:0a7fa0911e6c 949 HeptaCamera::ReadStop();
tomoya123 0:0a7fa0911e6c 950
tomoya123 0:0a7fa0911e6c 951 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:0a7fa0911e6c 952 free(bmp_line_data);
tomoya123 0:0a7fa0911e6c 953 fclose(fp);
tomoya123 0:0a7fa0911e6c 954 #endif
tomoya123 0:0a7fa0911e6c 955 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 956 fclose(fp2);
tomoya123 0:0a7fa0911e6c 957 #endif
tomoya123 0:0a7fa0911e6c 958
tomoya123 0:0a7fa0911e6c 959 }
tomoya123 0:0a7fa0911e6c 960
tomoya123 0:0a7fa0911e6c 961 void HeptaCamera::shoot2()
tomoya123 0:0a7fa0911e6c 962 {
tomoya123 0:0a7fa0911e6c 963 //pc.baud(115200);
tomoya123 0:0a7fa0911e6c 964
tomoya123 0:0a7fa0911e6c 965 //pc.printf("Camera resetting..\r\n");
tomoya123 0:0a7fa0911e6c 966 HeptaCamera::Reset();
tomoya123 0:0a7fa0911e6c 967
tomoya123 0:0a7fa0911e6c 968 //pc.printf("Before Init...\r\n");
tomoya123 0:0a7fa0911e6c 969 HeptaCamera::PrintRegister();
tomoya123 0:0a7fa0911e6c 970 char color_format = '1';
tomoya123 0:0a7fa0911e6c 971 /*pc.printf("Select color format.\r\n") ;
tomoya123 0:0a7fa0911e6c 972 pc.printf("1: RGB444.\r\n");
tomoya123 0:0a7fa0911e6c 973 pc.printf("2: RGB555.\r\n");
tomoya123 0:0a7fa0911e6c 974 pc.printf("3: RGB565.\r\n");
tomoya123 0:0a7fa0911e6c 975 pc.printf("4: YUV(UYVY).\r\n");
tomoya123 0:0a7fa0911e6c 976 pc.printf("5: Bayer RGB(BGBG... GRGR...).\r\n");*/
tomoya123 0:0a7fa0911e6c 977
tomoya123 0:0a7fa0911e6c 978 /*while(!pc.readable());
tomoya123 0:0a7fa0911e6c 979 char color_format = pc.getc();
tomoya123 0:0a7fa0911e6c 980 switch (color_format) {
tomoya123 0:0a7fa0911e6c 981 case '1':
tomoya123 0:0a7fa0911e6c 982 camera.InitRGB444();
tomoya123 0:0a7fa0911e6c 983 break;
tomoya123 0:0a7fa0911e6c 984 case '2':
tomoya123 0:0a7fa0911e6c 985 camera.InitRGB555();
tomoya123 0:0a7fa0911e6c 986 break;
tomoya123 0:0a7fa0911e6c 987 case '3':
tomoya123 0:0a7fa0911e6c 988 camera.InitRGB565();
tomoya123 0:0a7fa0911e6c 989 break;
tomoya123 0:0a7fa0911e6c 990 case '4':
tomoya123 0:0a7fa0911e6c 991 camera.InitYUV();
tomoya123 0:0a7fa0911e6c 992 break;
tomoya123 0:0a7fa0911e6c 993 case '5':
tomoya123 0:0a7fa0911e6c 994 camera.InitBayerRGB();
tomoya123 0:0a7fa0911e6c 995 break;
tomoya123 0:0a7fa0911e6c 996 }
tomoya123 0:0a7fa0911e6c 997 pc.printf("select %c\r\n", color_format);
tomoya123 0:0a7fa0911e6c 998
tomoya123 0:0a7fa0911e6c 999 pc.printf("Select screen size.\r\n") ;
tomoya123 0:0a7fa0911e6c 1000 switch (color_format) {
tomoya123 0:0a7fa0911e6c 1001 case '5':
tomoya123 0:0a7fa0911e6c 1002 pc.printf("1: VGA(640x480).\r\n");
tomoya123 0:0a7fa0911e6c 1003 case '1':
tomoya123 0:0a7fa0911e6c 1004 case '2':
tomoya123 0:0a7fa0911e6c 1005 case '3':
tomoya123 0:0a7fa0911e6c 1006 case '4':
tomoya123 0:0a7fa0911e6c 1007 pc.printf("2: FIFO nealy limit(544x360).\r\n");
tomoya123 0:0a7fa0911e6c 1008 pc.printf("3: VGA*3/4(480x360).\r\n");
tomoya123 0:0a7fa0911e6c 1009 pc.printf("4: QVGA(320x240).\r\n");
tomoya123 0:0a7fa0911e6c 1010 pc.printf("5: QQVGA(160x120).\r\n");
tomoya123 0:0a7fa0911e6c 1011 break;
tomoya123 0:0a7fa0911e6c 1012 }
tomoya123 0:0a7fa0911e6c 1013 char screen_size = 4;
tomoya123 0:0a7fa0911e6c 1014 while(!pc.readable());
tomoya123 0:0a7fa0911e6c 1015 char screen_size = pc.getc() ;
tomoya123 0:0a7fa0911e6c 1016 switch (screen_size) {
tomoya123 0:0a7fa0911e6c 1017 case '1':
tomoya123 0:0a7fa0911e6c 1018 sizex = 640;
tomoya123 0:0a7fa0911e6c 1019 sizey = 480;
tomoya123 0:0a7fa0911e6c 1020 camera.InitVGA();
tomoya123 0:0a7fa0911e6c 1021 break;
tomoya123 0:0a7fa0911e6c 1022 case '2':
tomoya123 0:0a7fa0911e6c 1023 sizex = 544;
tomoya123 0:0a7fa0911e6c 1024 sizey = 360;
tomoya123 0:0a7fa0911e6c 1025 camera.InitFIFO_2bytes_color_nealy_limit_size();
tomoya123 0:0a7fa0911e6c 1026 break;
tomoya123 0:0a7fa0911e6c 1027 case '3':
tomoya123 0:0a7fa0911e6c 1028 sizex = 480;
tomoya123 0:0a7fa0911e6c 1029 sizey = 360;
tomoya123 0:0a7fa0911e6c 1030 camera.InitVGA_3_4();
tomoya123 0:0a7fa0911e6c 1031 break;
tomoya123 0:0a7fa0911e6c 1032 case '4':
tomoya123 0:0a7fa0911e6c 1033 sizex = 320;
tomoya123 0:0a7fa0911e6c 1034 sizey = 240;
tomoya123 0:0a7fa0911e6c 1035 camera.InitQVGA();
tomoya123 0:0a7fa0911e6c 1036 break;
tomoya123 0:0a7fa0911e6c 1037 case '5':
tomoya123 0:0a7fa0911e6c 1038 sizex = 160;
tomoya123 0:0a7fa0911e6c 1039 sizey = 120;
tomoya123 0:0a7fa0911e6c 1040 camera.InitQQVGA();
tomoya123 0:0a7fa0911e6c 1041 break;
tomoya123 0:0a7fa0911e6c 1042 }
tomoya123 0:0a7fa0911e6c 1043 pc.printf("select %c\r\n", screen_size);*/
tomoya123 0:0a7fa0911e6c 1044 char screen_size = '4';
tomoya123 0:0a7fa0911e6c 1045 HeptaCamera::InitRGB444();
tomoya123 0:0a7fa0911e6c 1046 sizex = 320;
tomoya123 0:0a7fa0911e6c 1047 sizey = 240;
tomoya123 0:0a7fa0911e6c 1048 HeptaCamera::InitQVGA();
tomoya123 0:0a7fa0911e6c 1049 HeptaCamera::InitForFIFOWriteReset();
tomoya123 0:0a7fa0911e6c 1050 HeptaCamera::InitDefaultReg();
tomoya123 0:0a7fa0911e6c 1051
tomoya123 0:0a7fa0911e6c 1052 #ifdef COLORBAR
tomoya123 0:0a7fa0911e6c 1053 HeptaCamera::InitSetColorbar();
tomoya123 0:0a7fa0911e6c 1054 #endif
tomoya123 0:0a7fa0911e6c 1055
tomoya123 0:0a7fa0911e6c 1056 //pc.printf("After Init...\r\n");
tomoya123 0:0a7fa0911e6c 1057 HeptaCamera::PrintRegister();
tomoya123 0:0a7fa0911e6c 1058
tomoya123 0:0a7fa0911e6c 1059 // CAPTURE and SEND LOOP
tomoya123 0:0a7fa0911e6c 1060
tomoya123 0:0a7fa0911e6c 1061 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 1062 //pc.printf("Hit Any Key %dx%d Capture Data.\r\n", sizex, sizey) ;
tomoya123 0:0a7fa0911e6c 1063 //while(!pc.readable());
tomoya123 0:0a7fa0911e6c 1064 //pc.printf("*\r\n");
tomoya123 0:0a7fa0911e6c 1065 //pc.getc();
tomoya123 0:0a7fa0911e6c 1066
tomoya123 0:0a7fa0911e6c 1067 int real_width = sizex*3 + sizey%4;
tomoya123 0:0a7fa0911e6c 1068
tomoya123 0:0a7fa0911e6c 1069 unsigned char *bmp_line_data; //画像1行分のRGB情報を格納する
tomoya123 0:0a7fa0911e6c 1070 if((bmp_line_data = (unsigned char *)malloc(sizeof(unsigned char)*real_width)) == NULL){
tomoya123 0:0a7fa0911e6c 1071 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:0a7fa0911e6c 1072 //return 1;
tomoya123 0:0a7fa0911e6c 1073 }
tomoya123 0:0a7fa0911e6c 1074
tomoya123 0:0a7fa0911e6c 1075 //RGB情報を4バイトの倍数に合わせている
tomoya123 0:0a7fa0911e6c 1076 for(int i=sizex*3; i<real_width; i++){
tomoya123 0:0a7fa0911e6c 1077 bmp_line_data[i] = 0;
tomoya123 0:0a7fa0911e6c 1078 }
tomoya123 0:0a7fa0911e6c 1079 #endif
tomoya123 0:0a7fa0911e6c 1080 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:0a7fa0911e6c 1081 mkdir("/sd/mydir", 0777);
tomoya123 0:0a7fa0911e6c 1082 FILE *fp = fopen("/sd/mydir/picture.bmp","w");
tomoya123 0:0a7fa0911e6c 1083 if(fp == NULL) {
tomoya123 0:0a7fa0911e6c 1084 error("Could not open file for write\r\n");
tomoya123 0:0a7fa0911e6c 1085 }
tomoya123 0:0a7fa0911e6c 1086
tomoya123 0:0a7fa0911e6c 1087 create_header(fp, sizex, sizey);
tomoya123 0:0a7fa0911e6c 1088 #endif
tomoya123 0:0a7fa0911e6c 1089 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 1090 FILE *fp2;
tomoya123 0:0a7fa0911e6c 1091 char *filename2 = "/local/test.txt";
tomoya123 0:0a7fa0911e6c 1092 if((fp2 = fopen(filename2, "w")) == NULL){
tomoya123 0:0a7fa0911e6c 1093 pc.printf("Error: %s could not open.", filename2);
tomoya123 0:0a7fa0911e6c 1094 return 1;
tomoya123 0:0a7fa0911e6c 1095 }
tomoya123 0:0a7fa0911e6c 1096 #endif
tomoya123 0:0a7fa0911e6c 1097
tomoya123 0:0a7fa0911e6c 1098 HeptaCamera::CaptureNext();
tomoya123 0:0a7fa0911e6c 1099 while(HeptaCamera::CaptureDone() == false);
tomoya123 0:0a7fa0911e6c 1100 HeptaCamera::ReadStart();
tomoya123 0:0a7fa0911e6c 1101
tomoya123 0:0a7fa0911e6c 1102 int r=0, g=0, b=0, d1, d2;
tomoya123 0:0a7fa0911e6c 1103
tomoya123 0:0a7fa0911e6c 1104 switch (color_format) {
tomoya123 0:0a7fa0911e6c 1105 case '1':
tomoya123 0:0a7fa0911e6c 1106 case '2':
tomoya123 0:0a7fa0911e6c 1107 case '3':
tomoya123 0:0a7fa0911e6c 1108
tomoya123 0:0a7fa0911e6c 1109 for (int y=0; y<sizey; y++) {
tomoya123 0:0a7fa0911e6c 1110 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 1111 d1 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1112 d2 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1113
tomoya123 0:0a7fa0911e6c 1114 switch (color_format) {
tomoya123 0:0a7fa0911e6c 1115 case '1':
tomoya123 0:0a7fa0911e6c 1116 // RGB444 to RGB888
tomoya123 0:0a7fa0911e6c 1117 b = (d1 & 0x0F) << 4;
tomoya123 0:0a7fa0911e6c 1118 g = (d2 & 0xF0);
tomoya123 0:0a7fa0911e6c 1119 r = (d2 & 0x0F) << 4;
tomoya123 0:0a7fa0911e6c 1120 break;
tomoya123 0:0a7fa0911e6c 1121 case '2':
tomoya123 0:0a7fa0911e6c 1122 // RGB555 to RGB888
tomoya123 0:0a7fa0911e6c 1123 b = (d1 & 0x1F) << 3;
tomoya123 0:0a7fa0911e6c 1124 g = (((d1 & 0xE0) >> 2) | ((d2 & 0x03) << 6));
tomoya123 0:0a7fa0911e6c 1125 r = (d2 & 0x7c) << 1;
tomoya123 0:0a7fa0911e6c 1126 break;
tomoya123 0:0a7fa0911e6c 1127 case '3':
tomoya123 0:0a7fa0911e6c 1128 // RGB565 to RGB888
tomoya123 0:0a7fa0911e6c 1129 b = (d1 & 0x1F) << 3;
tomoya123 0:0a7fa0911e6c 1130 g = (((d1 & 0xE0) >> 3) | ((d2 & 0x07) << 5));
tomoya123 0:0a7fa0911e6c 1131 r = (d2 & 0xF8);
tomoya123 0:0a7fa0911e6c 1132 break;
tomoya123 0:0a7fa0911e6c 1133 }
tomoya123 0:0a7fa0911e6c 1134 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 1135 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:0a7fa0911e6c 1136 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:0a7fa0911e6c 1137 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:0a7fa0911e6c 1138 #endif
tomoya123 0:0a7fa0911e6c 1139 /*
tomoya123 0:0a7fa0911e6c 1140 // RGB
tomoya123 0:0a7fa0911e6c 1141 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:0a7fa0911e6c 1142 */
tomoya123 0:0a7fa0911e6c 1143 }
tomoya123 0:0a7fa0911e6c 1144 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 1145 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 1146 #endif
tomoya123 0:0a7fa0911e6c 1147 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 1148 for(int i=0; i<sizex*3; i++){
tomoya123 0:0a7fa0911e6c 1149 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:0a7fa0911e6c 1150 }
tomoya123 0:0a7fa0911e6c 1151 #endif
tomoya123 0:0a7fa0911e6c 1152 // pc.printf("\r\n") ;
tomoya123 0:0a7fa0911e6c 1153 }
tomoya123 0:0a7fa0911e6c 1154 break;
tomoya123 0:0a7fa0911e6c 1155
tomoya123 0:0a7fa0911e6c 1156 case '4':
tomoya123 0:0a7fa0911e6c 1157 int index = 0;
tomoya123 0:0a7fa0911e6c 1158 for (int y=0; y<sizey; y++) {
tomoya123 0:0a7fa0911e6c 1159 int U0=0, Y0=0, V0=0, Y1=0;
tomoya123 0:0a7fa0911e6c 1160 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 1161 if(index%2 == 0) {
tomoya123 0:0a7fa0911e6c 1162 U0 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1163 Y0 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1164 V0 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1165 Y1 = HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1166
tomoya123 0:0a7fa0911e6c 1167 b = Y0 + 1.77200 * (U0 - 128);
tomoya123 0:0a7fa0911e6c 1168 g = Y0 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 1169 r = Y0 + 1.40200 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 1170 } else {
tomoya123 0:0a7fa0911e6c 1171 b = Y1 + 1.77200 * (U0 - 128);
tomoya123 0:0a7fa0911e6c 1172 g = Y1 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 1173 r = Y1 + 1.40200 * (V0 - 128);
tomoya123 0:0a7fa0911e6c 1174 }
tomoya123 0:0a7fa0911e6c 1175
tomoya123 0:0a7fa0911e6c 1176 b = min(max(b, 0), 255);
tomoya123 0:0a7fa0911e6c 1177 g = min(max(g, 0), 255);
tomoya123 0:0a7fa0911e6c 1178 r = min(max(r, 0), 255);
tomoya123 0:0a7fa0911e6c 1179
tomoya123 0:0a7fa0911e6c 1180 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 1181 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:0a7fa0911e6c 1182 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:0a7fa0911e6c 1183 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:0a7fa0911e6c 1184 #endif
tomoya123 0:0a7fa0911e6c 1185 /*
tomoya123 0:0a7fa0911e6c 1186 // RGB
tomoya123 0:0a7fa0911e6c 1187 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:0a7fa0911e6c 1188 */
tomoya123 0:0a7fa0911e6c 1189 index++;
tomoya123 0:0a7fa0911e6c 1190 }
tomoya123 0:0a7fa0911e6c 1191 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 1192 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 1193 #endif
tomoya123 0:0a7fa0911e6c 1194 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 1195 for(int i=0; i<sizex*3; i++){
tomoya123 0:0a7fa0911e6c 1196 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:0a7fa0911e6c 1197 }
tomoya123 0:0a7fa0911e6c 1198 #endif
tomoya123 0:0a7fa0911e6c 1199 // pc.printf("\r\n") ;
tomoya123 0:0a7fa0911e6c 1200 }
tomoya123 0:0a7fa0911e6c 1201 break;
tomoya123 0:0a7fa0911e6c 1202
tomoya123 0:0a7fa0911e6c 1203 case '5':
tomoya123 0:0a7fa0911e6c 1204 unsigned char *bayer_line[2];
tomoya123 0:0a7fa0911e6c 1205 unsigned char *bayer_line_data[2]; //画像1行分のRGB情報を格納する2行分
tomoya123 0:0a7fa0911e6c 1206 for(int i=0; i<2; i++) {
tomoya123 0:0a7fa0911e6c 1207 if((bayer_line_data[i] = (unsigned char *)malloc(sizeof(unsigned char)*sizex)) == NULL){
tomoya123 0:0a7fa0911e6c 1208 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:0a7fa0911e6c 1209 //return 1;
tomoya123 0:0a7fa0911e6c 1210 }
tomoya123 0:0a7fa0911e6c 1211 }
tomoya123 0:0a7fa0911e6c 1212
tomoya123 0:0a7fa0911e6c 1213 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 1214 // odd line BGBG... even line GRGR...
tomoya123 0:0a7fa0911e6c 1215 bayer_line_data[0][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1216 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 1217 bmp_line_data[x*3] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:0a7fa0911e6c 1218 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:0a7fa0911e6c 1219 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:0a7fa0911e6c 1220 #endif
tomoya123 0:0a7fa0911e6c 1221 }
tomoya123 0:0a7fa0911e6c 1222 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 1223 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 1224 #endif
tomoya123 0:0a7fa0911e6c 1225 bayer_line[1] = bayer_line_data[0];
tomoya123 0:0a7fa0911e6c 1226
tomoya123 0:0a7fa0911e6c 1227 for (int y=1; y<sizey; y++) {
tomoya123 0:0a7fa0911e6c 1228 int line = y%2;
tomoya123 0:0a7fa0911e6c 1229
tomoya123 0:0a7fa0911e6c 1230 for (int x=0; x<sizex; x++) {
tomoya123 0:0a7fa0911e6c 1231 // odd line BGBG... even line GRGR...
tomoya123 0:0a7fa0911e6c 1232 bayer_line_data[line][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:0a7fa0911e6c 1233 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 1234 bmp_line_data[x*3] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:0a7fa0911e6c 1235 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:0a7fa0911e6c 1236 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:0a7fa0911e6c 1237 #endif
tomoya123 0:0a7fa0911e6c 1238 }
tomoya123 0:0a7fa0911e6c 1239 #ifdef BAYERBITMAPFILE
tomoya123 0:0a7fa0911e6c 1240 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 1241 #endif
tomoya123 0:0a7fa0911e6c 1242 bayer_line[0] = bayer_line[1];
tomoya123 0:0a7fa0911e6c 1243 bayer_line[1] = bayer_line_data[line];
tomoya123 0:0a7fa0911e6c 1244
tomoya123 0:0a7fa0911e6c 1245 for (int x=0; x<sizex - 1; x++) {
tomoya123 0:0a7fa0911e6c 1246 if(y%2==1) {
tomoya123 0:0a7fa0911e6c 1247 if(x%2==0) {
tomoya123 0:0a7fa0911e6c 1248 // BG
tomoya123 0:0a7fa0911e6c 1249 // GR
tomoya123 0:0a7fa0911e6c 1250 b = bayer_line[0][x];
tomoya123 0:0a7fa0911e6c 1251 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:0a7fa0911e6c 1252 r = bayer_line[1][x+1];
tomoya123 0:0a7fa0911e6c 1253 } else {
tomoya123 0:0a7fa0911e6c 1254 // GB
tomoya123 0:0a7fa0911e6c 1255 // RG
tomoya123 0:0a7fa0911e6c 1256 b = bayer_line[0][x+1];
tomoya123 0:0a7fa0911e6c 1257 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:0a7fa0911e6c 1258 r = bayer_line[1][x];
tomoya123 0:0a7fa0911e6c 1259 }
tomoya123 0:0a7fa0911e6c 1260 } else {
tomoya123 0:0a7fa0911e6c 1261 if(x%2==0) {
tomoya123 0:0a7fa0911e6c 1262 // GR
tomoya123 0:0a7fa0911e6c 1263 // BG
tomoya123 0:0a7fa0911e6c 1264 b = bayer_line[1][x];
tomoya123 0:0a7fa0911e6c 1265 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:0a7fa0911e6c 1266 r = bayer_line[0][x+1];
tomoya123 0:0a7fa0911e6c 1267 } else {
tomoya123 0:0a7fa0911e6c 1268 // RG
tomoya123 0:0a7fa0911e6c 1269 // GB
tomoya123 0:0a7fa0911e6c 1270 b = bayer_line[1][x+1];
tomoya123 0:0a7fa0911e6c 1271 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:0a7fa0911e6c 1272 r = bayer_line[0][x];
tomoya123 0:0a7fa0911e6c 1273 }
tomoya123 0:0a7fa0911e6c 1274 }
tomoya123 0:0a7fa0911e6c 1275 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:0a7fa0911e6c 1276 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:0a7fa0911e6c 1277 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:0a7fa0911e6c 1278 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:0a7fa0911e6c 1279 #endif
tomoya123 0:0a7fa0911e6c 1280 }
tomoya123 0:0a7fa0911e6c 1281
tomoya123 0:0a7fa0911e6c 1282 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 1283 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 1284 #endif
tomoya123 0:0a7fa0911e6c 1285
tomoya123 0:0a7fa0911e6c 1286 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 1287 for(int i=0; i<sizex*3; i++){
tomoya123 0:0a7fa0911e6c 1288 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:0a7fa0911e6c 1289 }
tomoya123 0:0a7fa0911e6c 1290 #endif
tomoya123 0:0a7fa0911e6c 1291 }
tomoya123 0:0a7fa0911e6c 1292
tomoya123 0:0a7fa0911e6c 1293 for(int i=0; i<2; i++) {
tomoya123 0:0a7fa0911e6c 1294 free(bayer_line_data[i]);
tomoya123 0:0a7fa0911e6c 1295 }
tomoya123 0:0a7fa0911e6c 1296 #ifdef BITMAPFILE
tomoya123 0:0a7fa0911e6c 1297 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:0a7fa0911e6c 1298 #endif
tomoya123 0:0a7fa0911e6c 1299 break;
tomoya123 0:0a7fa0911e6c 1300 }
tomoya123 0:0a7fa0911e6c 1301 HeptaCamera::ReadStop();
tomoya123 0:0a7fa0911e6c 1302
tomoya123 0:0a7fa0911e6c 1303 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:0a7fa0911e6c 1304 free(bmp_line_data);
tomoya123 0:0a7fa0911e6c 1305 fclose(fp);
tomoya123 0:0a7fa0911e6c 1306 #endif
tomoya123 0:0a7fa0911e6c 1307 #ifdef HEXFILE
tomoya123 0:0a7fa0911e6c 1308 fclose(fp2);
tomoya123 0:0a7fa0911e6c 1309 #endif
tomoya123 0:0a7fa0911e6c 1310
tomoya123 0:0a7fa0911e6c 1311 }