- Timestamp:
- 01/22/11 01:15:10 (2 years ago)
- File:
-
- 1 edited
-
trunk/core/raw.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/raw.c
r1049 r1053 31 31 static char dir[32]; 32 32 static int develop_raw=0; 33 //------------------------------------------------------------------- 34 void raw_prepare_develop(const char* filename){ 35 if (filename) {36 develop_raw=1;37 strcpy(fn,filename);38 }39 else {40 develop_raw=0;41 }33 34 //------------------------------------------------------------------- 35 void raw_prepare_develop(const char* filename) { 36 if (filename) { 37 develop_raw=1; 38 strcpy(fn,filename); 39 } else { 40 develop_raw=0; 41 } 42 42 } 43 43 … … 46 46 //------------------------------------------------------------------- 47 47 48 char* get_raw_image_addr(void) {49 if (!conf.raw_cache) return hook_raw_image_addr();50 else return (char*) ((int)hook_raw_image_addr()&~CAM_UNCACHED_BIT);51 } 52 53 char* get_alt_raw_image_addr(void) { // return inactive buffer for cameras with multiple RAW buffers (otherwise return active buffer)54 if (!conf.raw_cache) return hook_alt_raw_image_addr();55 else return (char*) ((int)hook_alt_raw_image_addr()&~CAM_UNCACHED_BIT);48 char* get_raw_image_addr(void) { 49 if (!conf.raw_cache) return hook_raw_image_addr(); 50 else return (char*) ((int)hook_raw_image_addr()&~CAM_UNCACHED_BIT); 51 } 52 53 char* get_alt_raw_image_addr(void) { // return inactive buffer for cameras with multiple RAW buffers (otherwise return active buffer) 54 if (!conf.raw_cache) return hook_alt_raw_image_addr(); 55 else return (char*) ((int)hook_alt_raw_image_addr()&~CAM_UNCACHED_BIT); 56 56 } 57 57 … … 63 63 64 64 int init_badpixel_bin_flag; // contants above to count/create file, > 0 num bad pixel 65 int raw_init_badpixel_bin() {66 int count;67 unsigned short c[2];68 FILE*f;69 if(init_badpixel_bin_flag == INIT_BADPIXEL_FILE) {70 f=fopen(PATH_BAD_TMP_BIN,"w+b");71 } else if (init_badpixel_bin_flag == INIT_BADPIXEL_COUNT){72 f=NULL;73 } else {74 return 0;75 }76 count = 0;77 for (c[1]=CAM_ACTIVE_AREA_Y1; c[1]<CAM_ACTIVE_AREA_Y2; c[1]++) {78 for (c[0]=CAM_ACTIVE_AREA_X1; c[0]<CAM_ACTIVE_AREA_X2; c[0]++) {79 if (get_raw_pixel(c[0],c[1])==0) {80 if(f) {81 fwrite(c, 1, 4, f);82 }83 count++;84 }85 }86 }87 if(f) {88 fclose(f);89 }90 init_badpixel_bin_flag = count;91 state_shooting_progress = SHOOTING_PROGRESS_PROCESSING;92 return 1;65 int raw_init_badpixel_bin() { 66 int count; 67 unsigned short c[2]; 68 FILE*f; 69 if(init_badpixel_bin_flag == INIT_BADPIXEL_FILE) { 70 f=fopen(PATH_BAD_TMP_BIN,"w+b"); 71 } else if (init_badpixel_bin_flag == INIT_BADPIXEL_COUNT) { 72 f=NULL; 73 } else { 74 return 0; 75 } 76 count = 0; 77 for (c[1]=CAM_ACTIVE_AREA_Y1; c[1]<CAM_ACTIVE_AREA_Y2; c[1]++) { 78 for (c[0]=CAM_ACTIVE_AREA_X1; c[0]<CAM_ACTIVE_AREA_X2; c[0]++) { 79 if (get_raw_pixel(c[0],c[1])==0) { 80 if(f) { 81 fwrite(c, 1, 4, f); 82 } 83 count++; 84 } 85 } 86 } 87 if(f) { 88 fclose(f); 89 } 90 init_badpixel_bin_flag = count; 91 state_shooting_progress = SHOOTING_PROGRESS_PROCESSING; 92 return 1; 93 93 } 94 94 … … 97 97 static unsigned char gamma[256]; 98 98 99 void fill_gamma_buf(void) {100 int i;101 if (gamma[255]) return;99 void fill_gamma_buf(void) { 100 int i; 101 if (gamma[255]) return; 102 102 #if defined(CAMERA_sx30) || defined(CAMERA_g12) 103 for (i=0; i<12; i++) gamma[i]=255*pow(i/255.0, 0.5);104 for (i=12; i<64; i++) gamma[i]=255*pow(i/255.0, 0.4);105 for (i=64; i<=255; i++) gamma[i]=255*pow(i/255.0, 0.25);103 for (i=0; i<12; i++) gamma[i]=255*pow(i/255.0, 0.5); 104 for (i=12; i<64; i++) gamma[i]=255*pow(i/255.0, 0.4); 105 for (i=64; i<=255; i++) gamma[i]=255*pow(i/255.0, 0.25); 106 106 #else 107 for (i=0; i<=255; i++) gamma[i]=255*pow(i/255.0, 0.5); 108 #endif 109 } 110 111 112 void create_thumbnail(char* buf){ 113 unsigned int i, j, x, y; 114 unsigned char r, g, b; 115 for (i=0; i<DNG_TH_HEIGHT; i++) 116 for (j=0; j<DNG_TH_WIDTH; j++) { 117 x=CAM_ACTIVE_AREA_X1+((CAM_ACTIVE_AREA_X2-CAM_ACTIVE_AREA_X1)*j)/DNG_TH_WIDTH; 118 y=CAM_ACTIVE_AREA_Y1+((CAM_ACTIVE_AREA_Y2-CAM_ACTIVE_AREA_Y1)*i)/DNG_TH_HEIGHT; 107 for (i=0; i<=255; i++) gamma[i]=255*pow(i/255.0, 0.5); 108 #endif 109 } 110 111 void create_thumbnail(char* buf) { 112 unsigned int i, j, x, y; 113 unsigned char r, g, b; 114 for (i=0; i<DNG_TH_HEIGHT; i++) 115 for (j=0; j<DNG_TH_WIDTH; j++) { 116 x=CAM_ACTIVE_AREA_X1+((CAM_ACTIVE_AREA_X2-CAM_ACTIVE_AREA_X1)*j)/DNG_TH_WIDTH; 117 y=CAM_ACTIVE_AREA_Y1+((CAM_ACTIVE_AREA_Y2-CAM_ACTIVE_AREA_Y1)*i)/DNG_TH_HEIGHT; 119 118 #if cam_CFAPattern==0x02010100 // Red Green Green Blue 120 r=gamma[get_raw_pixel((x/2)*2,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; // red pixel121 g=gamma[6*(get_raw_pixel((x/2)*2+1,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8))/10]; // green pixel122 b=gamma[get_raw_pixel((x/2)*2+1,(y/2)*2+1)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; //blue pixel119 r=gamma[get_raw_pixel((x/2)*2,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; // red pixel 120 g=gamma[6*(get_raw_pixel((x/2)*2+1,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8))/10]; // green pixel 121 b=gamma[get_raw_pixel((x/2)*2+1,(y/2)*2+1)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; //blue pixel 123 122 #elif cam_CFAPattern==0x01000201 // Green Blue Red Green 124 r=gamma[get_raw_pixel((x/2)*2,(y/2)*2+1)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; // red pixel125 g=gamma[6*(get_raw_pixel((x/2)*2,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8))/10]; // green pixel126 b=gamma[get_raw_pixel((x/2)*2+1,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; //blue pixel123 r=gamma[get_raw_pixel((x/2)*2,(y/2)*2+1)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; // red pixel 124 g=gamma[6*(get_raw_pixel((x/2)*2,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8))/10]; // green pixel 125 b=gamma[get_raw_pixel((x/2)*2+1,(y/2)*2)>>(CAM_SENSOR_BITS_PER_PIXEL-8)]; //blue pixel 127 126 #else 128 #error please define new pattern here129 #endif 130 *buf++=r; *buf++=g; *buf++=b;131 }127 #error please define new pattern here 128 #endif 129 *buf++=r; *buf++=g; *buf++=b; 130 } 132 131 } 133 132 #else // no DNG_SUPPORT 134 static inline int __attribute__((always_inline)) raw_init_badpixel_bin(void) {return 0;}133 static inline int __attribute__((always_inline)) raw_init_badpixel_bin(void) {return 0;} 135 134 #endif 136 135 //------------------------------------------------------------------- 137 136 138 137 int raw_savefile() { 139 int ret = 0; 138 int ret = 0; 140 139 int fd, m=(mode_get()&MODE_SHOOTING_MASK); 141 140 static struct utimbuf t; 142 141 static int br_counter; 143 142 #if DNG_SUPPORT 144 struct t_data_for_exif* exif_data = NULL;145 char *thumbnail_buf = NULL;146 if (conf.dng_raw) exif_data=capture_data_for_exif();143 struct t_data_for_exif* exif_data = NULL; 144 char *thumbnail_buf = NULL; 145 if (conf.dng_raw) exif_data=capture_data_for_exif(); 147 146 #endif 148 147 if (state_kbd_script_run && shot_histogram_isenabled()) build_shot_histogram(); … … 154 153 // count/save badpixels if requested 155 154 if(raw_init_badpixel_bin()) { 156 return 0;155 return 0; 157 156 } 158 157 159 158 if (develop_raw) { 160 started();161 fd = open(fn, O_RDONLY, 0777);162 if (fd>=0) {163 read(fd, get_raw_image_addr(), hook_raw_size());164 close(fd);165 }159 started(); 160 fd = open(fn, O_RDONLY, 0777); 161 if (fd>=0) { 162 read(fd, get_raw_image_addr(), hook_raw_size()); 163 close(fd); 164 } 166 165 #ifdef OPT_CURVES 167 if (conf.curve_enable) curve_apply();168 #endif 169 finished();170 develop_raw=0;171 return 0;166 if (conf.curve_enable) curve_apply(); 167 #endif 168 finished(); 169 develop_raw=0; 170 return 0; 172 171 } 173 172 … … 185 184 br_counter=0; 186 185 187 188 186 // got here second time in a row. Skip second RAW saving. 189 187 if (conf.raw_save_first_only && state_shooting_progress == SHOOTING_PROGRESS_PROCESSING) { 190 188 return 0; 191 189 } 192 190 193 191 state_shooting_progress = SHOOTING_PROGRESS_PROCESSING; 194 192 … … 233 231 img_prefixes[conf.raw_prefix], 234 232 get_target_file_num(), 235 conf.dng_raw&&conf.raw_dng_ext ? ".DNG" : img_exts[conf.raw_ext]); 233 conf.dng_raw&&conf.raw_dng_ext ? ".DNG" : img_exts[conf.raw_ext]); 236 234 } 237 235 fd = open(fn, O_WRONLY|O_CREAT, 0777); … … 240 238 #if DNG_SUPPORT 241 239 if (conf.dng_raw) { 242 fill_gamma_buf();243 create_dng_header(exif_data);244 thumbnail_buf = malloc(DNG_TH_WIDTH*DNG_TH_HEIGHT*3);245 if (get_dng_header() && thumbnail_buf) {246 patch_bad_pixels_b();247 create_thumbnail(thumbnail_buf);248 write(fd, get_dng_header(), get_dng_header_size());249 write(fd, thumbnail_buf, DNG_TH_WIDTH*DNG_TH_HEIGHT*3);250 reverse_bytes_order2(rawadr, altrawadr, hook_raw_size());251 }240 fill_gamma_buf(); 241 create_dng_header(exif_data); 242 thumbnail_buf = malloc(DNG_TH_WIDTH*DNG_TH_HEIGHT*3); 243 if (get_dng_header() && thumbnail_buf) { 244 patch_bad_pixels_b(); 245 create_thumbnail(thumbnail_buf); 246 write(fd, get_dng_header(), get_dng_header_size()); 247 write(fd, thumbnail_buf, DNG_TH_WIDTH*DNG_TH_HEIGHT*3); 248 reverse_bytes_order2(rawadr, altrawadr, hook_raw_size()); 249 } 252 250 } 253 251 #endif … … 255 253 // Write alternate (inactive) buffer that we reversed the bytes into above (if only one buffer then it will be the active buffer instead) 256 254 write(fd, (char*)(((unsigned long)altrawadr)|CAM_UNCACHED_BIT), hook_raw_size()); 257 } 258 else 259 { 255 } else { 260 256 // Write active RAW buffer 261 257 write(fd, (char*)(((unsigned long)rawadr)|CAM_UNCACHED_BIT), hook_raw_size()); … … 265 261 #if DNG_SUPPORT 266 262 if (conf.dng_raw) { 267 if (get_dng_header() && thumbnail_buf) {268 if (rawadr == altrawadr) // If only one RAW buffer then we have to swap the bytes back269 reverse_bytes_order2(rawadr, altrawadr, hook_raw_size());270 //unpatch_bad_pixels_b();271 }272 if (get_dng_header()) free_dng_header();273 if (thumbnail_buf) free(thumbnail_buf);263 if (get_dng_header() && thumbnail_buf) { 264 if (rawadr == altrawadr) // If only one RAW buffer then we have to swap the bytes back 265 reverse_bytes_order2(rawadr, altrawadr, hook_raw_size()); 266 //unpatch_bad_pixels_b(); 267 } 268 if (get_dng_header()) free_dng_header(); 269 if (thumbnail_buf) free(thumbnail_buf); 274 270 } 275 271 #endif … … 298 294 //------------------------------------------------------------------- 299 295 300 void set_raw_pixel(unsigned int x, unsigned int y, unsigned short value) {296 void set_raw_pixel(unsigned int x, unsigned int y, unsigned short value) { 301 297 #if CAM_SENSOR_BITS_PER_PIXEL==10 302 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/8)*CAM_SENSOR_BITS_PER_PIXEL;303 switch (x%8) {304 case 0: addr[0]=(addr[0]&0x3F)|(value<<6); addr[1]=value>>2; break;305 case 1: addr[0]=(addr[0]&0xC0)|(value>>4); addr[3]=(addr[3]&0x0F)|(value<<4); break;306 case 2: addr[2]=(addr[2]&0x03)|(value<<2); addr[3]=(addr[3]&0xF0)|(value>>6); break;307 case 3: addr[2]=(addr[2]&0xFC)|(value>>8); addr[5]=value; break;308 case 4: addr[4]=value>>2; addr[7]=(addr[7]&0x3F)|(value<<6); break;309 case 5: addr[6]=(addr[6]&0x0F)|(value<<4); addr[7]=(addr[7]&0xC0)|(value>>4); break;310 case 6: addr[6]=(addr[6]&0xF0)|(value>>6); addr[9]=(addr[9]&0x03)|(value<<2); break;311 case 7: addr[8]=value; addr[9]=(addr[9]&0xFC)|(value>>8); break;312 }298 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/8)*CAM_SENSOR_BITS_PER_PIXEL; 299 switch (x%8) { 300 case 0: addr[0]=(addr[0]&0x3F)|(value<<6); addr[1]=value>>2; break; 301 case 1: addr[0]=(addr[0]&0xC0)|(value>>4); addr[3]=(addr[3]&0x0F)|(value<<4); break; 302 case 2: addr[2]=(addr[2]&0x03)|(value<<2); addr[3]=(addr[3]&0xF0)|(value>>6); break; 303 case 3: addr[2]=(addr[2]&0xFC)|(value>>8); addr[5]=value; break; 304 case 4: addr[4]=value>>2; addr[7]=(addr[7]&0x3F)|(value<<6); break; 305 case 5: addr[6]=(addr[6]&0x0F)|(value<<4); addr[7]=(addr[7]&0xC0)|(value>>4); break; 306 case 6: addr[6]=(addr[6]&0xF0)|(value>>6); addr[9]=(addr[9]&0x03)|(value<<2); break; 307 case 7: addr[8]=value; addr[9]=(addr[9]&0xFC)|(value>>8); break; 308 } 313 309 #elif CAM_SENSOR_BITS_PER_PIXEL==12 314 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/4)*6;315 switch (x%4) {316 case 0: addr[0] = (addr[0]&0x0F) | (unsigned char)(value << 4); addr[1] = (unsigned char)(value >> 4); break;317 case 1: addr[0] = (addr[0]&0xF0) | (unsigned char)(value >> 8); addr[3] = (unsigned char)value; break;318 case 2: addr[2] = (unsigned char)(value >> 4); addr[5] = (addr[5]&0x0F) | (unsigned char)(value << 4); break;319 case 3: addr[4] = (unsigned char)value; addr[5] = (addr[5]&0xF0) | (unsigned char)(value >> 8); break;320 }310 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/4)*6; 311 switch (x%4) { 312 case 0: addr[0] = (addr[0]&0x0F) | (unsigned char)(value << 4); addr[1] = (unsigned char)(value >> 4); break; 313 case 1: addr[0] = (addr[0]&0xF0) | (unsigned char)(value >> 8); addr[3] = (unsigned char)value; break; 314 case 2: addr[2] = (unsigned char)(value >> 4); addr[5] = (addr[5]&0x0F) | (unsigned char)(value << 4); break; 315 case 3: addr[4] = (unsigned char)value; addr[5] = (addr[5]&0xF0) | (unsigned char)(value >> 8); break; 316 } 321 317 #else 322 #error define set_raw_pixel for sensor bit depth323 #endif 324 } 325 326 //------------------------------------------------------------------- 327 unsigned short get_raw_pixel(unsigned int x,unsigned int y) {318 #error define set_raw_pixel for sensor bit depth 319 #endif 320 } 321 322 //------------------------------------------------------------------- 323 unsigned short get_raw_pixel(unsigned int x,unsigned int y) { 328 324 #if CAM_SENSOR_BITS_PER_PIXEL==10 329 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/8)*CAM_SENSOR_BITS_PER_PIXEL;330 switch (x%8) {331 case 0: return ((0x3fc&(((unsigned short)addr[1])<<2)) | (addr[0] >> 6));332 case 1: return ((0x3f0&(((unsigned short)addr[0])<<4)) | (addr[3] >> 4));333 case 2: return ((0x3c0&(((unsigned short)addr[3])<<6)) | (addr[2] >> 2));334 case 3: return ((0x300&(((unsigned short)addr[2])<<8)) | (addr[5]));335 case 4: return ((0x3fc&(((unsigned short)addr[4])<<2)) | (addr[7] >> 6));336 case 5: return ((0x3f0&(((unsigned short)addr[7])<<4)) | (addr[6] >> 4));337 case 6: return ((0x3c0&(((unsigned short)addr[6])<<6)) | (addr[9] >> 2));338 case 7: return ((0x300&(((unsigned short)addr[9])<<8)) | (addr[8]));339 }325 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/8)*CAM_SENSOR_BITS_PER_PIXEL; 326 switch (x%8) { 327 case 0: return ((0x3fc&(((unsigned short)addr[1])<<2)) | (addr[0] >> 6)); 328 case 1: return ((0x3f0&(((unsigned short)addr[0])<<4)) | (addr[3] >> 4)); 329 case 2: return ((0x3c0&(((unsigned short)addr[3])<<6)) | (addr[2] >> 2)); 330 case 3: return ((0x300&(((unsigned short)addr[2])<<8)) | (addr[5])); 331 case 4: return ((0x3fc&(((unsigned short)addr[4])<<2)) | (addr[7] >> 6)); 332 case 5: return ((0x3f0&(((unsigned short)addr[7])<<4)) | (addr[6] >> 4)); 333 case 6: return ((0x3c0&(((unsigned short)addr[6])<<6)) | (addr[9] >> 2)); 334 case 7: return ((0x300&(((unsigned short)addr[9])<<8)) | (addr[8])); 335 } 340 336 #elif CAM_SENSOR_BITS_PER_PIXEL==12 341 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/4)*6;342 switch (x%4) {343 case 0: return ((unsigned short)(addr[1]) << 4) | (addr[0] >> 4);344 case 1: return ((unsigned short)(addr[0] & 0x0F) << 8) | (addr[3]);345 case 2: return ((unsigned short)(addr[2]) << 4) | (addr[5] >> 4);346 case 3: return ((unsigned short)(addr[5] & 0x0F) << 8) | (addr[4]);347 }337 unsigned char* addr=(unsigned char*)get_raw_image_addr()+y*RAW_ROWLEN+(x/4)*6; 338 switch (x%4) { 339 case 0: return ((unsigned short)(addr[1]) << 4) | (addr[0] >> 4); 340 case 1: return ((unsigned short)(addr[0] & 0x0F) << 8) | (addr[3]); 341 case 2: return ((unsigned short)(addr[2]) << 4) | (addr[5] >> 4); 342 case 3: return ((unsigned short)(addr[5] & 0x0F) << 8) | (addr[4]); 343 } 348 344 #else 349 #error define get_raw_pixel for sensor bit depth 350 #endif 351 return 0; 352 } 353 354 //------------------------------------------------------------------- 355 void patch_bad_pixel(unsigned int x,unsigned int y){ 356 int sum=0; 357 int nzero=0; 358 int i,j; 359 int val; 360 if ((x>=2) && (x<CAM_RAW_ROWPIX-2) && (y>=2) && (y<CAM_RAW_ROWS-2)) { 361 if ((conf.bad_pixel_removal==1) || conf.dng_raw) { // interpolation or DNG saving 362 for (i=-2; i<=2; i+=2) 363 for (j=-2; j<=2; j+=2) 364 if ((i!=0) && (j!=0)) { 365 val=get_raw_pixel(x+i, y+j); 366 if (val) {sum+=val; nzero++;} 367 } 368 if (nzero) set_raw_pixel(x,y,sum/nzero); 369 } 370 else if (conf.bad_pixel_removal==2) // or this makes RAW converter (internal/external) 371 set_raw_pixel(x,y,0); 372 } 345 #error define get_raw_pixel for sensor bit depth 346 #endif 347 return 0; 348 } 349 350 //------------------------------------------------------------------- 351 void patch_bad_pixel(unsigned int x,unsigned int y) { 352 int sum=0; 353 int nzero=0; 354 int i,j; 355 int val; 356 if ((x>=2) && (x<CAM_RAW_ROWPIX-2) && (y>=2) && (y<CAM_RAW_ROWS-2)) { 357 if ((conf.bad_pixel_removal==1) || conf.dng_raw) { // interpolation or DNG saving 358 for (i=-2; i<=2; i+=2) 359 for (j=-2; j<=2; j+=2) 360 if ((i!=0) && (j!=0)) { 361 val=get_raw_pixel(x+i, y+j); 362 if (val) {sum+=val; nzero++;} 363 } 364 if (nzero) set_raw_pixel(x,y,sum/nzero); 365 } else if (conf.bad_pixel_removal==2) // or this makes RAW converter (internal/external) 366 set_raw_pixel(x,y,0); 367 } 373 368 } 374 369 375 370 struct point{ 376 int x;377 int y;378 struct point *next;371 int x; 372 int y; 373 struct point *next; 379 374 } *pixel_list=NULL; 380 375 381 void patch_bad_pixels(void) {382 struct point *pixel=pixel_list;383 while (pixel){384 patch_bad_pixel((*pixel).x,(*pixel).y);385 pixel=(*pixel).next;386 }387 } 388 389 void make_pixel_list(char * ptr) {390 int x,y;391 struct point *pixel;392 char *endptr;393 while(*ptr){394 while (*ptr==' ' || *ptr=='\t') ++ptr;// whitespaces395 x=strtol(ptr, &endptr, 0);396 if (endptr != ptr) {397 ptr = endptr;398 if (*ptr++==',') {399 while (*ptr==' ' || *ptr=='\t') ++ptr;// whitespaces400 if (*ptr!='\n' && *ptr!='\r'){401 y=strtol(ptr, &endptr, 0);402 if (endptr != ptr) {403 ptr = endptr;404 pixel=malloc(sizeof(struct point));405 if (pixel) {406 (*pixel).x=x;407 (*pixel).y=y;408 (*pixel).next=pixel_list;409 pixel_list=pixel;410 }411 }412 }413 }414 }415 while (*ptr && *ptr!='\n') ++ptr;// unless end of line416 if (*ptr) ++ptr;417 }376 void patch_bad_pixels(void) { 377 struct point *pixel=pixel_list; 378 while (pixel) { 379 patch_bad_pixel((*pixel).x,(*pixel).y); 380 pixel=(*pixel).next; 381 } 382 } 383 384 void make_pixel_list(char * ptr) { 385 int x,y; 386 struct point *pixel; 387 char *endptr; 388 while(*ptr) { 389 while (*ptr==' ' || *ptr=='\t') ++ptr; // whitespaces 390 x=strtol(ptr, &endptr, 0); 391 if (endptr != ptr) { 392 ptr = endptr; 393 if (*ptr++==',') { 394 while (*ptr==' ' || *ptr=='\t') ++ptr; // whitespaces 395 if (*ptr!='\n' && *ptr!='\r') { 396 y=strtol(ptr, &endptr, 0); 397 if (endptr != ptr) { 398 ptr = endptr; 399 pixel=malloc(sizeof(struct point)); 400 if (pixel) { 401 (*pixel).x=x; 402 (*pixel).y=y; 403 (*pixel).next=pixel_list; 404 pixel_list=pixel; 405 } 406 } 407 } 408 } 409 } 410 while (*ptr && *ptr!='\n') ++ptr; // unless end of line 411 if (*ptr) ++ptr; 412 } 418 413 } 419 414 420 415 #define PIXELS_BUF_SIZE 8192 421 void load_bad_pixels_list(const char* filename) {416 void load_bad_pixels_list(const char* filename) { 422 417 char *buf; 423 418 int fd; … … 448 443 int binary_count=0; 449 444 450 void load_bad_pixels_list_b(char* filename) {451 struct stat st;452 long filesize;453 void* ptr;454 FILE *fd;455 binary_count=0;456 if (stat(filename,&st)!=0) return;457 filesize=st.st_size;458 if ((filesize==0) || (filesize%(2*sizeof(short))!=0)) return;459 ptr=malloc(filesize);460 if (!ptr) return;461 fd=fopen(filename, "rb");462 if (fd) {463 fread(ptr,1, filesize,fd);464 fclose(fd);465 binary_list=ptr;466 binary_count=filesize/(2*sizeof(short));467 }468 else free(ptr);469 } 470 471 void unload_bad_pixels_list_b(void) {472 if (binary_list) free(binary_list);473 binary_list=NULL;474 binary_count=0;475 } 476 477 void patch_bad_pixels_b(void) {478 int i;479 short* ptr=binary_list;480 for (i=0; i<binary_count; i++, ptr+=2) if (get_raw_pixel(ptr[0], ptr[1])==0) patch_bad_pixel(ptr[0], ptr[1]);445 void load_bad_pixels_list_b(char* filename) { 446 struct stat st; 447 long filesize; 448 void* ptr; 449 FILE *fd; 450 binary_count=0; 451 if (stat(filename,&st)!=0) return; 452 filesize=st.st_size; 453 if ((filesize==0) || (filesize%(2*sizeof(short))!=0)) return; 454 ptr=malloc(filesize); 455 if (!ptr) return; 456 fd=fopen(filename, "rb"); 457 if (fd) { 458 fread(ptr,1, filesize,fd); 459 fclose(fd); 460 binary_list=ptr; 461 binary_count=filesize/(2*sizeof(short)); 462 } 463 else free(ptr); 464 } 465 466 void unload_bad_pixels_list_b(void) { 467 if (binary_list) free(binary_list); 468 binary_list=NULL; 469 binary_count=0; 470 } 471 472 void patch_bad_pixels_b(void) { 473 int i; 474 short* ptr=binary_list; 475 for (i=0; i<binary_count; i++, ptr+=2) if (get_raw_pixel(ptr[0], ptr[1])==0) patch_bad_pixel(ptr[0], ptr[1]); 481 476 } 482 477 /* 483 void unpatch_bad_pixels_b(void) {484 int i;485 short* ptr=binary_list;486 for (i=0; i<binary_count; i++, ptr+=2) set_raw_pixel(ptr[0], ptr[1], 0);478 void unpatch_bad_pixels_b(void) { 479 int i; 480 short* ptr=binary_list; 481 for (i=0; i<binary_count; i++, ptr+=2) set_raw_pixel(ptr[0], ptr[1], 0); 487 482 } 488 483 */ 489 int badpixel_list_loaded_b(void) {490 return binary_count;484 int badpixel_list_loaded_b(void) { 485 return binary_count; 491 486 } 492 487 493 488 // ----------------------------------------------- 494 489 495 enum BadpixelFSM 496 { 490 enum BadpixelFSM { 497 491 BADPIX_START, 498 492 BADPIX_S1, … … 500 494 }; 501 495 502 int badpixel_task_stack(long p) 503 { 496 int badpixel_task_stack(long p) { 504 497 static unsigned int badpix_cnt1; 505 498 506 switch(p) 507 { 508 509 case BADPIX_START: 510 action_pop(); 511 512 console_clear(); 513 console_add_line("Wait please... "); 514 console_add_line("This takes a few seconds,"); 515 console_add_line("don't panic!"); 516 517 init_badpixel_bin_flag = INIT_BADPIXEL_COUNT; 518 519 shooting_set_tv96_direct(96, SET_LATER); 520 action_push(BADPIX_S1); 521 action_push(AS_SHOOT); 522 action_push_delay(3000); 523 break; 524 case BADPIX_S1: 525 action_pop(); 526 527 badpix_cnt1 = init_badpixel_bin_flag; 528 init_badpixel_bin_flag = INIT_BADPIXEL_FILE; 529 shooting_set_tv96_direct(96, SET_LATER); 530 531 action_push(BADPIX_S2); 532 action_push(AS_SHOOT); 533 break; 534 case BADPIX_S2: 535 action_pop(); 536 537 console_clear(); 538 if (badpix_cnt1 == init_badpixel_bin_flag) 539 { 540 // TODO script asked confirmation first 541 // should sanity check bad pixel count at least, 542 /// wrong buffer address could make badpixel bigger than available mem 543 char msg[32]; 544 console_add_line("badpixel.bin created."); 545 sprintf(msg, "Bad pixel count: %d", badpix_cnt1); 546 console_add_line(msg); 547 DeleteFile_Fut(PATH_BADPIXEL_BIN); 548 RenameFile_Fut(PATH_BAD_TMP_BIN,PATH_BADPIXEL_BIN); 549 } 550 else 551 { 552 console_add_line("badpixel.bin failed."); 553 console_add_line("Please try again."); 554 } 555 init_badpixel_bin_flag = 0; 556 DeleteFile_Fut(PATH_BAD_TMP_BIN); 557 558 action_push_delay(3000); 559 break; 560 default: 561 action_stack_standard(p); 562 break; 499 switch(p) { 500 case BADPIX_START: 501 action_pop(); 502 503 console_clear(); 504 console_add_line("Wait please... "); 505 console_add_line("This takes a few seconds,"); 506 console_add_line("don't panic!"); 507 508 init_badpixel_bin_flag = INIT_BADPIXEL_COUNT; 509 510 shooting_set_tv96_direct(96, SET_LATER); 511 action_push(BADPIX_S1); 512 action_push(AS_SHOOT); 513 action_push_delay(3000); 514 break; 515 case BADPIX_S1: 516 action_pop(); 517 518 badpix_cnt1 = init_badpixel_bin_flag; 519 init_badpixel_bin_flag = INIT_BADPIXEL_FILE; 520 shooting_set_tv96_direct(96, SET_LATER); 521 522 action_push(BADPIX_S2); 523 action_push(AS_SHOOT); 524 break; 525 case BADPIX_S2: 526 action_pop(); 527 528 console_clear(); 529 if (badpix_cnt1 == init_badpixel_bin_flag) { 530 // TODO script asked confirmation first 531 // should sanity check bad pixel count at least, 532 // wrong buffer address could make badpixel bigger than available mem 533 char msg[32]; 534 console_add_line("badpixel.bin created."); 535 sprintf(msg, "Bad pixel count: %d", badpix_cnt1); 536 console_add_line(msg); 537 DeleteFile_Fut(PATH_BADPIXEL_BIN); 538 RenameFile_Fut(PATH_BAD_TMP_BIN,PATH_BADPIXEL_BIN); 539 } else { 540 console_add_line("badpixel.bin failed."); 541 console_add_line("Please try again."); 542 } 543 init_badpixel_bin_flag = 0; 544 DeleteFile_Fut(PATH_BAD_TMP_BIN); 545 546 action_push_delay(3000); 547 break; 548 default: 549 action_stack_standard(p); 550 break; 563 551 } 564 552 … … 567 555 568 556 569 void create_badpixel_bin() 570 { 571 if (!(mode_get() & MODE_REC)) 572 { 557 void create_badpixel_bin() { 558 if (!(mode_get() & MODE_REC)) { 573 559 gui_mbox_init(LANG_ERROR, LANG_MSG_RECMODE_REQUIRED, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL); 574 560 return; 575 561 } 576 562 577 563 gui_set_mode(GUI_MODE_ALT); 578 564 action_stack_create(&badpixel_task_stack, BADPIX_START);
Note: See TracChangeset
for help on using the changeset viewer.