SDFileSystem

Dependencies:   mbed PowerControl SDFileSystem

Fork of SDFilesystem by 智也 大野

Committer:
tomoya123
Date:
Fri Dec 09 05:02:42 2016 +0000
Revision:
0:8d235efb1150
SDcard

Who changed what in which revision?

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