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