00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <math.h>
00039
00040 #include "omega_trim.h"
00041 #include "omega_fits.h"
00042 #include "omega_pfits.h"
00043 #include "omega_stats.h"
00044 #include "omega_utils.h"
00045
00087 cpl_image * TrimOscanCorrect(const cpl_frame *frame, int oscan, int extn)
00088 {
00089
00090 int x0 = 1;
00091 int x1 = 1;
00092 int ry0 = 1;
00093 int ry1 = 1;
00094
00095 const char *_id = "TrimOscanCorrect";
00096
00097 cpl_image *image;
00098 cpl_image *trim_image;
00099 cpl_image *tmp_img;
00100 cpl_vector *region;
00101 cpl_stats *px = NULL;
00102 cpl_stats *py = NULL;
00103 cpl_stats *ox = NULL;
00104 cpl_stats *oy = NULL;
00105
00106 if(frame == NULL) {
00107 cpl_msg_error(_id,"NULL input frame. %s",cpl_error_get_message());
00108 return NULL;
00109 }
00110
00111 image = cpl_image_load(cpl_frame_get_filename(frame), CPL_TYPE_FLOAT, 0, extn);
00112 if(image == NULL) {
00113 cpl_msg_error(_id,"Cannot load input image. %s",cpl_error_get_message());
00114 return NULL;
00115 }
00116
00117 if(oscan == 0){
00118 tmp_img = cpl_image_duplicate(image);
00119 }
00120
00121
00122 if (oscan > 0 && oscan < 5){
00123
00124
00125
00126
00127
00128 DoStatistics(frame, image, extn, &px,&py,&ox,&oy);
00129
00130 switch(oscan){
00131 case 1:
00132 if(px != NULL){
00133 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(px));
00134 }
00135 else{
00136 tmp_img = cpl_image_duplicate(image);
00137 cpl_msg_warning(_id,"The overscan method %d may not suit these data",oscan);
00138 }
00139 break;
00140
00141 case 2:
00142 if(ox != NULL){
00143 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(ox));
00144 }
00145 else{
00146 tmp_img = cpl_image_duplicate(image);
00147 cpl_msg_warning(_id,"The overscan method %d may not suit these data",oscan);
00148 }
00149 break;
00150
00151 case 3:
00152 if(py != NULL){
00153 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(py));
00154 }
00155 else{
00156 tmp_img = cpl_image_duplicate(image);
00157 cpl_msg_warning(_id,"The overscan method %d may not suit these data",oscan);
00158 }
00159 break;
00160
00161 case 4:
00162 if(oy != NULL){
00163 tmp_img = cpl_image_subtract_scalar_create(image,cpl_stats_get_median(oy));
00164 }
00165 else{
00166 tmp_img = cpl_image_duplicate(image);
00167 cpl_msg_warning(_id,"The overscan method %d may not suit these data",oscan);
00168 }
00169 break;
00170 }
00171
00172 }
00173 else {
00174 cpl_propertylist *plist = cpl_propertylist_load(cpl_frame_get_filename(frame), extn);
00175 if(oscan == 5){
00176 region = omega_get_scan_coord(plist, 0);
00177 tmp_img = oscan_row(image, (int)cpl_vector_get(region,0),(int)cpl_vector_get(region,2));
00178 }
00179 if(oscan == 6){
00180 region = omega_get_scan_coord(plist, 2);
00181 tmp_img = oscan_row(image, (int)cpl_vector_get(region,0),(int)cpl_vector_get(region,2));
00182 }
00183 freeplist(plist);
00184 }
00185
00186 region = get_trim_region(frame, extn);
00187 x0 = (int)cpl_vector_get(region,0);
00188 ry0 = (int)cpl_vector_get(region,1);
00189 x1 = (int)cpl_vector_get(region,2);
00190 ry1 = (int)cpl_vector_get(region,3);
00191
00192 trim_image = cpl_image_extract(tmp_img, x0, ry0, x1, ry1);
00193 if (trim_image == NULL) {
00194 cpl_msg_error (_id,"Cannot extract trimmed image <%s>", cpl_error_get_message());
00195 freeimage(image);
00196 freeimage(tmp_img);
00197 freevector(region);
00198 freestats(px);
00199 freestats(py);
00200 freestats(ox);
00201 freestats(oy);
00202 return NULL;
00203 }
00204
00205 freeimage(image);
00206 freeimage(tmp_img);
00207 freevector(region);
00208 freestats(px);
00209 freestats(py);
00210 freestats(ox);
00211 freestats(oy);
00212
00213 return trim_image;
00214 }
00215
00246 cpl_image *omega_trim_oscan_correct(omega_fits *ofits, int oscan)
00247 {
00248
00249 int x0 = 1;
00250 int x1 = 1;
00251 int ry0 = 1;
00252 int ry1 = 1;
00253
00254 cpl_image *trim_image;
00255 cpl_image *tmp_img;
00256 cpl_vector *region;
00257 cpl_propertylist *xlist;
00258 cpl_stats *px = NULL;
00259 cpl_stats *py = NULL;
00260 cpl_stats *ox = NULL;
00261 cpl_stats *oy = NULL;
00262
00263 if(ofits == NULL) {
00264 cpl_msg_error(cpl_func,"NULL input file. %s",cpl_error_get_message());
00265 return NULL;
00266 }
00267
00268 if(oscan == 0){
00269 tmp_img = cpl_image_duplicate(omega_fits_get_image(ofits));
00270 }
00271
00272
00273 if (oscan > 0 && oscan < 5){
00274
00275 omega_scan_stats(ofits,&px ,&py, &ox, &oy);
00276
00277 switch(oscan){
00278 case 1:
00279 if(px != NULL){
00280 tmp_img = cpl_image_subtract_scalar_create(omega_fits_get_image(ofits),cpl_stats_get_median(px));
00281 }
00282 else{
00283 tmp_img = cpl_image_duplicate(omega_fits_get_image(ofits));
00284 cpl_msg_warning(cpl_func,"The overscan method %d may not suit these data",oscan);
00285 }
00286 break;
00287
00288 case 2:
00289 if(ox != NULL){
00290 tmp_img = cpl_image_subtract_scalar_create(omega_fits_get_image(ofits),cpl_stats_get_median(ox));
00291 }
00292 else{
00293 tmp_img = cpl_image_duplicate(omega_fits_get_image(ofits));
00294 cpl_msg_warning(cpl_func,"The overscan method %d may not suit these data",oscan);
00295 }
00296 break;
00297
00298 case 3:
00299 if(py != NULL){
00300 tmp_img = cpl_image_subtract_scalar_create(omega_fits_get_image(ofits),cpl_stats_get_median(py));
00301 }
00302 else{
00303 tmp_img = cpl_image_duplicate(omega_fits_get_image(ofits));
00304 cpl_msg_warning(cpl_func,"The overscan method %d may not suit these data",oscan);
00305 }
00306 break;
00307
00308 case 4:
00309 if(oy != NULL){
00310 tmp_img = cpl_image_subtract_scalar_create(omega_fits_get_image(ofits),cpl_stats_get_median(oy));
00311 }
00312 else{
00313 tmp_img = cpl_image_duplicate(omega_fits_get_image(ofits));
00314 cpl_msg_warning(cpl_func,"The overscan method %d may not suit these data",oscan);
00315 }
00316 break;
00317 }
00318
00319 }
00320 else {
00321 xlist = omega_fits_get_ehu(ofits);
00322 if(oscan == 5){
00323 region = omega_get_scan_coord(xlist, 0);
00324 tmp_img = oscan_row(omega_fits_get_image(ofits), (int)cpl_vector_get(region,0),
00325 (int)cpl_vector_get(region,2));
00326 }
00327 if(oscan == 6){
00328 region = omega_get_scan_coord(xlist, 2);
00329 tmp_img = oscan_row(omega_fits_get_image(ofits), (int)cpl_vector_get(region,0),
00330 (int)cpl_vector_get(region,2));
00331 }
00332 xlist = NULL;
00333 }
00334
00335 region = omega_get_trim_region(ofits);
00336 x0 = (int)cpl_vector_get(region,0);
00337 ry0 = (int)cpl_vector_get(region,1);
00338 x1 = (int)cpl_vector_get(region,2);
00339 ry1 = (int)cpl_vector_get(region,3);
00340
00341 trim_image = cpl_image_extract(tmp_img, x0, ry0, x1, ry1);
00342 if (trim_image == NULL) {
00343 cpl_msg_error (cpl_func,"Cannot extract trimmed image <%s>", cpl_error_get_message());
00344 freeimage(tmp_img);
00345 freevector(region);
00346 freestats(px);
00347 freestats(py);
00348 freestats(ox);
00349 freestats(oy);
00350 return NULL;
00351 }
00352
00353 freeimage(tmp_img);
00354 freevector(region);
00355 freestats(px);
00356 freestats(py);
00357 freestats(ox);
00358 freestats(oy);
00359
00360 return trim_image;
00361 }
00362
00363
00364
00373
00374 cpl_image *oscan_row (cpl_image *img, int x1, int x2)
00375 {
00376
00377 int i = 0;
00378 int j = 0;
00379 int lx = 256;
00380 int ly = 256;
00381 int offset = 0;
00382 int oscanoffset = 0;
00383 int oscansize = 0;
00384 float med = 0.0f;
00385
00386 float * pindata;
00387 float * poutdata;
00388
00389 cpl_image *image_out;
00390
00391
00392 lx = cpl_image_get_size_x (img);
00393 ly = cpl_image_get_size_y (img);
00394
00395 image_out = cpl_image_new (lx, ly, CPL_TYPE_FLOAT);
00396
00397 oscansize = x2-x1+1;
00398
00399
00400 pindata = (float *)cpl_image_get_data (img);
00401 poutdata = (float *)cpl_image_get_data (image_out);
00402
00403 for (i=0; i<ly; i++)
00404 {
00405 offset = i * lx;
00406 oscanoffset = offset+x1-1;
00407 med = 0.0;
00408
00409 for (j=0; j<oscansize; j++)
00410 {
00411 med += pindata[oscanoffset+j];
00412 }
00413
00414
00415 med /= oscansize;
00416
00417 for (j=0; j<lx; j++){
00418 poutdata[offset+j] = pindata[offset+j]-med;
00419 }
00420 }
00421
00422
00423
00424 return image_out;
00425 }
00426
00427
00441 cpl_vector * get_trim_region(const cpl_frame *frame, int extnum)
00442 {
00443
00444 int orient = 0;
00445 int naxis1 = 0;
00446 int naxis2 = 0;
00447 int ovscx = 0;
00448 int ovscy = 0;
00449 int prscx = 0;
00450 int prscy = 0;
00451 int x0 = 1;
00452 int x1 = 1;
00453 int ry0 = 1;
00454 int ry1 = 1;
00455
00456 const char *filename = NULL;
00457
00458 cpl_propertylist *xplist;
00459 cpl_vector *region;
00460 cpl_vector *sregion;
00461
00462
00463 if(frame == NULL){
00464 cpl_msg_error(cpl_func,"Input frame is NULL");
00465 return NULL;
00466 }
00467
00468 filename = cpl_frame_get_filename(frame);
00469
00470
00471 xplist = cpl_propertylist_load(filename, extnum);
00472 if(xplist == NULL) {
00473 cpl_msg_error(cpl_func,"Cannot load header");
00474 return NULL;
00475 }
00476
00477 naxis1 = cpl_propertylist_get_int(xplist, "NAXIS1");
00478 naxis2 = cpl_propertylist_get_int(xplist, "NAXIS2");
00479 if (naxis1 == 0 || naxis2 == 0){
00480 cpl_msg_error(cpl_func,"NAXIS1 or NAXIS2 is 0");
00481 freeplist(xplist);
00482 return NULL;
00483 }
00484
00485
00486 sregion = omega_pfits_get_preovscan(xplist);
00487 if(sregion == NULL){
00488 cpl_msg_warning(cpl_func,"Cannot get pre and overscan regions");
00489 freeplist(xplist);
00490 return NULL;
00491 }
00492
00493 prscx = cpl_vector_get(sregion,0);
00494 prscy = cpl_vector_get(sregion,1);
00495 ovscx = cpl_vector_get(sregion,2);
00496 ovscy = cpl_vector_get(sregion,3);
00497
00498 freeplist(xplist);
00499
00500
00501
00502 orient = omega_get_chip_orientation(extnum);
00503
00504 switch(orient){
00505 case 1:
00506 x0 = prscx + 1;
00507 ry0 = prscy + 1;
00508 x1 = naxis1 - ovscx;
00509 ry1 = naxis2 - ovscy;
00510 break;
00511 case 2:
00512 x0 = ovscx + 1;
00513 ry0 = ovscy + 1;
00514 x1 = naxis1 - prscx;
00515 ry1 = naxis2 - prscy;
00516 break;
00517 default:
00518 x0 = prscx + 1;
00519 ry0 = prscy + 1;
00520 x1 = naxis1 - ovscx;
00521 ry1 = naxis2 - ovscy;
00522 cpl_msg_warning(cpl_func,"Using default chip layout");
00523 break;
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565 region = cpl_vector_new(4);
00566 cpl_vector_set(region, 0, x0);
00567 cpl_vector_set(region, 1, ry0);
00568 cpl_vector_set(region, 2, x1);
00569 cpl_vector_set(region, 3, ry1);
00570
00571 freevector(sregion);
00572
00573 return region;
00574
00575 }
00576
00591 cpl_vector * omega_get_trim_region(omega_fits *ofits)
00592 {
00593
00594 int orient = 0;
00595 int naxis1 = 0;
00596 int naxis2 = 0;
00597 int ovscx = 0;
00598 int ovscy = 0;
00599 int prscx = 0;
00600 int prscy = 0;
00601 int x0 = 1;
00602 int x1 = 1;
00603 int ry0 = 1;
00604 int ry1 = 1;
00605
00606 cpl_vector *region;
00607 cpl_vector *sregion;
00608 cpl_propertylist *xlist;
00609
00610
00611 if(ofits == NULL){
00612 cpl_msg_error(cpl_func,"Input frame is NULL");
00613 return NULL;
00614 }
00615
00616 xlist = omega_fits_get_ehu(ofits);
00617 naxis1 = cpl_propertylist_get_int(xlist, "NAXIS1");
00618 naxis2 = cpl_propertylist_get_int(xlist, "NAXIS2");
00619 if (naxis1 == 0 || naxis2 == 0){
00620 cpl_msg_error(cpl_func,"NAXIS1 or NAXIS2 is 0");
00621 xlist = NULL;
00622 return NULL;
00623 }
00624
00625
00626 sregion = omega_pfits_get_preovscan(xlist);
00627 if(sregion == NULL){
00628 cpl_msg_warning(cpl_func,"Cannot get pre and overscan regions");
00629 return NULL;
00630 }
00631
00632 prscx = cpl_vector_get(sregion,0);
00633 prscy = cpl_vector_get(sregion,1);
00634 ovscx = cpl_vector_get(sregion,2);
00635 ovscy = cpl_vector_get(sregion,3);
00636
00637
00638
00639 orient = omega_get_chip_orientation(omega_fits_get_extnum(ofits));
00640 switch(orient){
00641 case 1:
00642 x0 = prscx + 1;
00643 ry0 = prscy + 1;
00644 x1 = naxis1 - ovscx;
00645 ry1 = naxis2 - ovscy;
00646 break;
00647 case 2:
00648 x0 = ovscx + 1;
00649 ry0 = ovscy + 1;
00650 x1 = naxis1 - prscx;
00651 ry1 = naxis2 - prscy;
00652 break;
00653 default:
00654 x0 = prscx + 1;
00655 ry0 = prscy + 1;
00656 x1 = naxis1 - ovscx;
00657 ry1 = naxis2 - ovscy;
00658 cpl_msg_warning(cpl_func,"Using default chip layout");
00659 break;
00660 }
00661
00662 region = cpl_vector_new(4);
00663 cpl_vector_set(region, 0, x0);
00664 cpl_vector_set(region, 1, ry0);
00665 cpl_vector_set(region, 2, x1);
00666 cpl_vector_set(region, 3, ry1);
00667
00668 freevector(sregion);
00669 xlist = NULL;
00670
00671 return region;
00672
00673 }
00674
00690 void DoStatistics (const cpl_frame *frame, cpl_image *image, int extnum,
00691 cpl_stats **px,cpl_stats **py,cpl_stats **ox,cpl_stats **oy)
00692 {
00693 int x0 = 0;
00694 int ry0 = 0;
00695 int x1 = 0;
00696 int ry1 = 0;
00697 int iscan = 0;
00698 double threshold = 1.0;
00699 int iter = 5;
00700 cpl_vector *region;
00701 cpl_propertylist *plist;
00702
00703
00704 if((plist = cpl_propertylist_load(cpl_frame_get_filename(frame), extnum)) == NULL)
00705 return;
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 iscan = 0;
00719 region = omega_get_scan_coord(plist, iscan);
00720 x0 = (int)cpl_vector_get(region,0);
00721 ry0 = (int)cpl_vector_get(region,1);
00722 x1 = (int)cpl_vector_get(region,2);
00723 ry1 = (int)cpl_vector_get(region,3);
00724
00725
00726
00727
00728
00729
00730
00731 if (x1 - x0 +1 > 0){
00732 *px = omega_iter_stat_opts(image,region, threshold, iter);
00733 }
00734 freevector(region);
00735
00736 iscan = 1;
00737 region = omega_get_scan_coord(plist, iscan);
00738 x0 = (int)cpl_vector_get(region,0);
00739 ry0 = (int)cpl_vector_get(region,1);
00740 x1 = (int)cpl_vector_get(region,2);
00741 ry1 = (int)cpl_vector_get(region,3);
00742
00743
00744
00745
00746
00747
00748
00749 if (ry1 - ry0 +1 > 0){
00750 *py = omega_iter_stat_opts(image,region,threshold, iter);
00751 }
00752 freevector(region);
00753
00754 iscan = 2;
00755 region = omega_get_scan_coord(plist, iscan);
00756 x0 = (int)cpl_vector_get(region,0);
00757 ry0 = (int)cpl_vector_get(region,1);
00758 x1 = (int)cpl_vector_get(region,2);
00759 ry1 = (int)cpl_vector_get(region,3);
00760
00761
00762
00763
00764
00765
00766
00767 if (x1 - x0 +1 > 0){
00768 *ox = omega_iter_stat_opts(image,region,threshold, iter);
00769 }
00770 freevector(region);
00771
00772 iscan = 3;
00773 region = omega_get_scan_coord(plist, iscan);
00774 x0 = (int)cpl_vector_get(region,0);
00775 ry0 = (int)cpl_vector_get(region,1);
00776 x1 = (int)cpl_vector_get(region,2);
00777 ry1 = (int)cpl_vector_get(region,3);
00778
00779
00780
00781
00782
00783
00784
00785 if (ry1 - ry0 +1 > 0){
00786 *oy = omega_iter_stat_opts(image,region,threshold, iter);
00787 }
00788
00789 freevector(region);
00790 freeplist(plist);
00791
00792 return;
00793
00794 }
00795
00809 void omega_scan_stats (omega_fits *ofits,cpl_stats **px,cpl_stats **py,
00810 cpl_stats **ox,cpl_stats **oy)
00811 {
00812 int x0 = 0;
00813 int ry0 = 0;
00814 int x1 = 0;
00815 int ry1 = 0;
00816 int iscan = 0;
00817 double threshold = 1.0;
00818 int iter = 5;
00819 cpl_vector *region;
00820 cpl_propertylist *xlist;
00821
00822 if(ofits == NULL)
00823 return;
00824
00825 xlist = omega_fits_get_ehu(ofits);
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838 iscan = 0;
00839 region = omega_get_scan_coord(xlist, iscan);
00840 x0 = (int)cpl_vector_get(region,0);
00841 ry0 = (int)cpl_vector_get(region,1);
00842 x1 = (int)cpl_vector_get(region,2);
00843 ry1 = (int)cpl_vector_get(region,3);
00844
00845
00846 if (x1 - x0 +1 > 0){
00847 *px = omega_iter_stat_opts(omega_fits_get_image(ofits),region, threshold, iter);
00848 }
00849 freevector(region);
00850
00851 iscan = 1;
00852 region = omega_get_scan_coord(xlist, iscan);
00853 x0 = (int)cpl_vector_get(region,0);
00854 ry0 = (int)cpl_vector_get(region,1);
00855 x1 = (int)cpl_vector_get(region,2);
00856 ry1 = (int)cpl_vector_get(region,3);
00857
00858 if (ry1 - ry0 +1 > 0){
00859 *py = omega_iter_stat_opts(omega_fits_get_image(ofits),region,threshold, iter);
00860 }
00861 freevector(region);
00862
00863 iscan = 2;
00864 region = omega_get_scan_coord(xlist, iscan);
00865 x0 = (int)cpl_vector_get(region,0);
00866 ry0 = (int)cpl_vector_get(region,1);
00867 x1 = (int)cpl_vector_get(region,2);
00868 ry1 = (int)cpl_vector_get(region,3);
00869
00870 if (x1 - x0 +1 > 0){
00871 *ox = omega_iter_stat_opts(omega_fits_get_image(ofits),region,threshold, iter);
00872 }
00873 freevector(region);
00874
00875 iscan = 3;
00876 region = omega_get_scan_coord(xlist, iscan);
00877 x0 = (int)cpl_vector_get(region,0);
00878 ry0 = (int)cpl_vector_get(region,1);
00879 x1 = (int)cpl_vector_get(region,2);
00880 ry1 = (int)cpl_vector_get(region,3);
00881
00882 if (ry1 - ry0 +1 > 0){
00883 *oy = omega_iter_stat_opts(omega_fits_get_image(ofits),region,threshold, iter);
00884 }
00885
00886 freevector(region);
00887 xlist = NULL;
00888
00889 return;
00890
00891 }
00892
00917 cpl_vector * omega_get_scan_coord(const cpl_propertylist *plist, int iscan)
00918 {
00919
00920 int naxis1 = 0;
00921 int naxis2 = 0;
00922 int ovscx = 0;
00923 int ovscy = 0;
00924 int prscx = 0;
00925 int prscy = 0;
00926 int x0 = 0;
00927 int x1 = 0;
00928 int ry0 = 0;
00929 int ry1 = 0;
00930 const char * chipid;
00931 int chipornt=0;
00932
00933 cpl_vector *region;
00934 cpl_vector *sregion;
00935
00936
00937 if(plist == NULL)
00938 return NULL;
00939
00940 naxis1 = cpl_propertylist_get_int(plist, "NAXIS1");
00941 naxis2 = cpl_propertylist_get_int(plist, "NAXIS2");
00942 if (naxis1 == 0 || naxis2 == 0){
00943 cpl_msg_error(cpl_func,"NAXIS1 or NAXIS2 is 0");
00944 return NULL;
00945 }
00946
00947 chipid = omega_pfits_get_chipid(plist);
00948 chipornt = omega_pfits_get_orientation(chipid);
00949
00950 if(chipornt == 0) chipornt = 1;
00951
00952
00953 sregion = omega_pfits_get_preovscan(plist);
00954
00955 prscx = (int)cpl_vector_get(sregion,0);
00956 prscy = (int)cpl_vector_get(sregion,1);
00957 ovscx = (int)cpl_vector_get(sregion,2);
00958 ovscy = (int)cpl_vector_get(sregion,3);
00959
00960
00961
00962 if(chipornt==1)
00963 {
00964 switch(iscan){
00965 case 0:
00966
00967 x0 = 1;
00968 ry0 = prscy+1;
00969 x1 = prscx;
00970 ry1 = naxis2 - ovscy;
00971 cpl_msg_debug(cpl_func,"px: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
00972 break;
00973 case 1:
00974
00975 x0 = prscx+1;
00976 ry0 = 1;
00977 x1 = naxis1-ovscx;
00978 ry1 = prscy;
00979 cpl_msg_debug(cpl_func,"py: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
00980 break;
00981 case 2:
00982
00983 x0 = naxis1-ovscx+1;
00984 ry0 = prscy+1;
00985 x1 = naxis1;
00986 ry1 = naxis2 - ovscy;
00987 cpl_msg_debug(cpl_func,"ox: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
00988 break;
00989 case 3:
00990
00991 x0 = prscx+1;
00992 ry0 = naxis2-ovscy+1;
00993 x1 = naxis1-ovscx;
00994 ry1 = naxis2;
00995 cpl_msg_debug(cpl_func,"oy: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
00996 break;
00997 default:
00998 cpl_msg_error(cpl_func,"Unable to get pre/overscan coordinates");
00999 freevector(sregion);
01000 return NULL;
01001
01002 }
01003 }
01004 if(chipornt==2)
01005 {
01006 switch(iscan){
01007 case 0:
01008
01009 x0 = naxis1 - prscx + 1;
01010 ry0 = ovscy+1;
01011 x1 = naxis1;
01012 ry1 = naxis2-prscy;
01013 cpl_msg_debug(cpl_func,"px: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
01014 break;
01015 case 1:
01016
01017 x0 = ovscx+1;
01018 ry0 = naxis2-prscy;
01019 x1 = naxis1-prscx;
01020 ry1 = naxis2;
01021 cpl_msg_debug(cpl_func,"py: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
01022 break;
01023 case 2:
01024
01025 x0 = 1;
01026 ry0 = ovscy+1;
01027 x1 = ovscx;
01028 ry1 = naxis2 - prscy;
01029 cpl_msg_debug(cpl_func,"ox: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
01030 break;
01031 case 3:
01032
01033 x0 = ovscx+1;
01034 ry0 = 1;
01035 x1 = naxis1-prscx;
01036 ry1 = ovscy;
01037 cpl_msg_debug(cpl_func,"oy: x0:%5d ry0:%5d x1:%5d ry1:%5d", x0,ry0,x1,ry1 );
01038 break;
01039 default:
01040 cpl_msg_error(cpl_func,"Unable to get pre/overscan coordinates");
01041 freevector(sregion);
01042 return NULL;
01043
01044 }
01045 }
01046
01047 region = cpl_vector_new(4);
01048 cpl_vector_set(region, 0, x0);
01049 cpl_vector_set(region, 1, ry0);
01050 cpl_vector_set(region, 2, x1);
01051 cpl_vector_set(region, 3, ry1);
01052
01053
01054 freevector(sregion);
01055
01056 return region;
01057
01058 }
01059