Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Functions
float_to_exp.c File Reference
#include <stdio.h>
#include "rle.h"
#include <math.h>
Include dependency graph for float_to_exp.c:

Go to the source code of this file.

Functions

void float_to_exp (int count, float *floats, rle_pixel *pixels)
 

Function Documentation

void float_to_exp ( int  count,
float *  floats,
rle_pixel pixels 
)

Definition at line 42 of file float_to_exp.c.

46 {
47  register int i;
48  int expon, max_exp = -2000;
49  float * fptr = floats;
50  double f_exp;
51 
52  /* Find largest exponent */
53  /* Use "Block normalization":
54  * ExpScan[x] is largest exponent of the three
55  * color components. Red/Grn/BluScan[1..3] are the
56  * normalized color components.
57  */
58 
59  for (i = 0; i < count; i++)
60  {
61  frexp( *fptr++, &expon );
62  max_exp = (expon > max_exp) ? expon : max_exp;
63  }
64 
65  /* Don't over/underflow */
66  if (max_exp > 128) max_exp = 128;
67  else
68  if (max_exp < -127) max_exp = -127;
69 
70  f_exp = ldexp( 256.0, -max_exp );
71 
72  fptr = floats;
73  for( i = 0; i < count; i++ ) /* Extra casts for broken HP compiler */
74  *pixels++ = (rle_pixel) ((int)(*fptr++ * f_exp));
75 
76  /* Excess 127 exponent */
77  *pixels = (rle_pixel) (max_exp + 127);
78 }
int
Definition: getami.c:848
unsigned char rle_pixel
Definition: rle.h:56
int i
Definition: rletorla.c:82