~ubuntu-branches/ubuntu/gutsy/xmedcon/gutsy

« back to all changes in this revision

Viewing changes to source/m-algori.c

  • Committer: Bazaar Package Importer
  • Author(s): Roland Marcus Rutschmann
  • Date: 2005-12-19 21:02:43 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20051219210243-kbjmoaczrwybusxv
Tags: 0.9.9.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 *                MdcUnpackBIT12()        - Unpack 12 bit into Uint16      *
40
40
 *                                                                         *
41
41
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
42
 
/* $Id: m-algori.c,v 1.70 2005/05/16 07:35:00 enlf Exp $ 
 
42
/* $Id: m-algori.c,v 1.77 2005/12/16 23:34:46 enlf Exp $ 
43
43
 */
44
44
 
45
45
/*
65
65
 
66
66
#include "m-depend.h"
67
67
#include <stdio.h>
 
68
#define __USE_ISOC99 1
68
69
#include <math.h>
69
70
#ifdef HAVE_STDLIB_H
70
71
#include <stdlib.h>
250
251
 
251
252
  memcpy((void *)f,(void *)&number.n4,4);
252
253
 
253
 
 
254
}
 
255
 
 
256
int MdcFixFloat(float *ref)
 
257
{
 
258
  float value = *ref;
 
259
  int fixed = 0;
 
260
 
 
261
#ifdef HAVE_ISNAN
 
262
  if (isnan(value)) { value = 0.; fixed = 1; }
 
263
#endif
 
264
#ifdef HAVE_ISINF
 
265
  if (isinf(value)) { value = 0.; fixed = 1; }
 
266
#endif
 
267
 
 
268
  *ref = value;
 
269
 
 
270
  return(fixed);
 
271
}
 
272
 
 
273
int MdcFixDouble(double *ref)
 
274
{
 
275
  double value = *ref;
 
276
  int fixed = 0;
 
277
 
 
278
#ifdef HAVE_ISNAN
 
279
  if (isnan(value)) { value = 0.; fixed = 1; }
 
280
#endif
 
281
#ifdef HAVE_ISINF
 
282
  if (isinf(value)) { value = 0.; fixed = 1; }
 
283
#endif
 
284
 
 
285
  *ref = value;
 
286
 
 
287
  return(fixed);
 
288
}
254
289
 
255
290
int MdcType2Bytes(int type)
256
291
{
382
417
  float start, duration;
383
418
  double fmin=0., fmax=0., qfmin=0., qfmax=0.; 
384
419
  char *msg;
 
420
  int FixWarn=0;
385
421
 
386
422
  /* initial checks for FILEINFO integrity */
387
423
  if (fi->number == 0) return("Internal Error ## Improper fi->number value");
563
599
     n = id->width * id->height;
564
600
     sd = id->sdata;
565
601
 
 
602
     if (MDC_FORCE_RESCALE) {
 
603
       id->quant_scale = mdc_si_slope;
 
604
       id->calibr_fctr = 1.;
 
605
       id->intercept   = mdc_si_intercept; 
 
606
     }
 
607
 
566
608
     if (MDC_QUANTIFY) {
567
609
       id->rescale_slope = id->quant_scale;
568
610
       id->rescale_intercept = id->intercept;
574
616
       id->rescale_intercept = 0.;
575
617
     }
576
618
 
 
619
     if (fi->contrast_remapped == MDC_YES) {
 
620
       /* any rescale already done */
 
621
       id->quant_scale = 1.;
 
622
       id->calibr_fctr = 1.;
 
623
       id->intercept   = 0.;
 
624
       id->rescale_slope = 1.;
 
625
       id->rescale_intercept = 0.;
 
626
     }
 
627
 
577
628
     switch (id->type) {
578
629
 
579
630
      case BIT8_U:
806
857
         /* init first pixel */
807
858
         memcpy((void *)&pix0,(void *)pix,4);
808
859
         MdcSwapBytes((Uint8 *)&pix0, 4);
 
860
         FixWarn |= MdcFixFloat(&pix0);
809
861
         if (!MDC_NEGATIVE && (pix0 < 0.)) pix0 = 0.;
810
862
 
811
863
         /* init max,min values */
818
870
 
819
871
         for (i=0; i<n; i++, pix++) {
820
872
            MdcSwapBytes((Uint8 *)pix, 4);
 
873
            FixWarn |= MdcFixFloat(pix);
821
874
            if (!MDC_NEGATIVE && (*pix < 0.)) *pix = 0.;
822
875
            maxmin(*pix, max, min);
823
876
            if (sd != NULL) sd->total_counts += (float)*pix;
835
888
         /* init first pixel */
836
889
         memcpy((void *)&pix0,(void *)pix,8);
837
890
         MdcSwapBytes((Uint8 *)&pix0, 8);
 
891
         FixWarn |= MdcFixDouble(&pix0);
838
892
         if (!MDC_NEGATIVE && (pix0 < 0.)) pix0 = 0.;
839
893
 
840
894
         /* init max,min values */
841
895
         min = pix0;
842
896
         max = pix0;
843
 
         if (j == 0 ) {
 
897
         if (j == 0) {
844
898
           fi->glmin = pix0;
845
899
           fi->glmax = pix0;
846
900
         }
848
902
         /* go through all pixels */
849
903
         for (i=0; i<n; i++, pix++) {
850
904
            MdcSwapBytes((Uint8 *)pix, 8);
 
905
            FixWarn |= MdcFixDouble(pix);
851
906
            if (!MDC_NEGATIVE && (*pix < 0.)) *pix = 0.;
852
907
            maxmin(*pix, max, min);
853
908
            if (sd != NULL) sd->total_counts += (float)*pix; /* overflow */
858
913
       break;
859
914
     }
860
915
 
 
916
     /* no negatives -> min = 0 */
 
917
     if (!MDC_NEGATIVE && (id->min < 0.)) id->min = 0.;
 
918
 
 
919
     /* handle global max,min values */
861
920
     if (j == 0) {
862
921
       fi->glmin = id->min;  fi->glmax = id->max;
863
922
     }else{
865
924
       if ( id->min < fi->glmin ) fi->glmin = id->min;
866
925
     }
867
926
 
868
 
     /* do it even if not MDC_QUANTIFY or not MDC_CALIBRATE */
869
 
     /* handle global min values */
870
 
     if (!MDC_NEGATIVE) { fi->qglmin =  fi->glmin = id->min = 0.; }
871
 
     else { 
872
 
        id->qmin = (double)((float)id->min * id->rescale_slope);
873
 
        id->qmin += (double)id->rescale_intercept;
874
 
        if (j == 0) {
875
 
          fi->qglmin = id->qmin;
876
 
        }else{
877
 
          if ( id->qmin < fi->qglmin) fi->qglmin = id->qmin;
878
 
        }
879
 
     }
880
 
     /* handle global max values */ 
 
927
     /* get quantified max,min */
 
928
     id->qmin = (double)((float)id->min * id->rescale_slope);
 
929
     id->qmin += (double)id->rescale_intercept;
 
930
 
881
931
     id->qmax = (double)((float)id->max * id->rescale_slope);
882
932
     id->qmax += (double)id->rescale_intercept;
883
933
 
 
934
     /* negative slope -> reverse qmax,qmin */
 
935
     if (id->rescale_slope < 0.) {
 
936
       double x;
 
937
       x = id->qmin; id->qmin = id->qmax; id->qmax = x;
 
938
     }
 
939
 
 
940
     /* handle quantified global min values */
 
941
     if (j == 0) {
 
942
       fi->qglmin = id->qmin;
 
943
     }else{
 
944
       if ( id->qmin < fi->qglmin) fi->qglmin = id->qmin;
 
945
     }
 
946
     /* handle quantified global max values */ 
884
947
     if (j == 0) { 
885
948
       fi->qglmax = id->qmax;
886
949
     }else{
918
981
 
919
982
  }
920
983
 
 
984
  /* warn about fixed values */
 
985
  if (FixWarn) MdcPrntWarn("Fixed image(s) with bad floats (= set to zero)");
 
986
 
921
987
  /* don't forget to fill in the min/max values for the last frame group */
922
988
  for (t=j - fi->dim[3]; t<j ; t++) {        
923
989
     idprev = &fi->image[t];