Charge control

Dependencies:   mbed PowerControl SDFileSystem

Committer:
tomoya123
Date:
Tue Dec 13 07:44:05 2016 +0000
Revision:
1:cbbad81dc88d
Parent:
0:0842f00470eb
ChargeControl

Who changed what in which revision?

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