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
00029
00030
00031
00032
00033
00034
00035
00036
#include "idima.h"
00037
#include "idsig.h"
00038
#include "idprint.h"
00039
00040
00041
00042
00043 #define PCY 0.5
00044 #define MRG0 2
00045
00067
PPIMAGE_UCHAR
00068 IdImaSignalToImage(PSIGNAL sig,
int off,
int lh,
int Urg,
double maxi,
00069
double mini,
int dimx,
int dimy,
int bgnd,
int vpix)
00070 {
00071
int i, j, dx1, dy1, coo, end, ty, previousend=0, xfin;
00072
double kx,
val=0., step;
00073
PPIMAGE_UCHAR Im;
00074
double tmp;
00075
00076 Im = (
PPIMAGE_UCHAR)
IdImaAlloc(dimx, dimy,
IMA_UCHAR);
00077
if (!Im) {
00078
IdErrPrintf
00079 (
"erreur allocation image pour IdImaSignalToIma\n");
00080
return (0);
00081 }
00082
IdImaSetValue(Im, bgnd);
00083
00084
if (mini == -1.)
00085
if (maxi == -1.)
00086
IdSigMinMaxInterv(sig, off, off + lh, &mini,
00087 &maxi);
00088
else
00089
IdSigMinMaxInterv(sig, off, off + lh, &mini, &tmp);
00090
else if (maxi == -1)
00091
IdSigMinMaxInterv(sig, off, off + lh, &tmp, &maxi);
00092
00093 dx1 =
IdImaDimX(Im) - 1;
00094 dy1 =
IdImaDimY(Im) - 1;
00095 ty =
IdSigType(sig);
00096
00097
00098
00099
00100
00101
for (j = 0; j < (dx1 + 1); j++) {
00102 Im[0][j] = vpix;
00103 Im[dy1][j] = vpix;
00104 }
00105
for (i = 0; i < (dy1 + 1); i++) {
00106 Im[i][0] = vpix;
00107 Im[i][dx1] = vpix;
00108 }
00109
00110
if (lh >= dimx)
00111 {
00112
00113
00114
00115 kx = (
double) (lh) / dx1;
00116
for (j = 1; j < dx1; j++) {
00117 coo = (
int) (j * kx + off - 1 + .5);
00118
switch (ty) {
00119
case SIG_UCHAR:
00120
val = ((
PSIGNAL_UCHAR) sig)[coo];
00121
break;
00122
case SIG_CHAR:
00123
val = ((
PSIGNAL_CHAR) sig)[coo];
00124
break;
00125
case SIG_USHORT:
00126
val = ((
PSIGNAL_USHORT) sig)[coo];
00127
break;
00128
case SIG_SHORT:
00129
val = ((
PSIGNAL_SHORT) sig)[coo];
00130
break;
00131
case SIG_LONG:
00132
val = ((
PSIGNAL_LONG) sig)[coo];
00133
break;
00134
case SIG_ULONG:
00135
val = ((
PSIGNAL_ULONG) sig)[coo];
00136
break;
00137
case SIG_FLOAT:
00138
val = ((
PSIGNAL_FLOAT) sig)[coo];
00139
break;
00140
case SIG_DOUBLE:
00141
val = ((
PSIGNAL_DOUBLE) sig)[coo];
00142
break;
00143 }
00144 end = (
int) (((maxi -
val) / (maxi - mini)) * dy1);
00145
00146
if (end < 0)
00147 end = 0;
00148
if (j == 1) {
00149 previousend = end;
00150 }
00151
else {
00152 Im =
00153
IdImaDrawLine(Im, vpix, 0, j - 1,
00154 previousend, j, end);
00155 previousend = end;
00156 }
00157
00158 }
00159 }
00160
00161
00162
00163
00164
else {
00165
00166
00167
00168 step = (
double) dimx / (
double) (lh - 1);
00169
00170
for (j = 0; j < lh; j++) {
00171
00172
00173 coo = j + off;
00174
switch (ty) {
00175
case SIG_UCHAR:
00176
val = ((
PSIGNAL_UCHAR) sig)[coo];
00177
break;
00178
case SIG_CHAR:
00179
val = ((
PSIGNAL_CHAR) sig)[coo];
00180
break;
00181
case SIG_USHORT:
00182
val = ((
PSIGNAL_USHORT) sig)[coo];
00183
break;
00184
case SIG_SHORT:
00185
val = ((
PSIGNAL_SHORT) sig)[coo];
00186
break;
00187
case SIG_LONG:
00188
val = ((
PSIGNAL_LONG) sig)[coo];
00189
break;
00190
case SIG_ULONG:
00191
val = ((
PSIGNAL_ULONG) sig)[coo];
00192
break;
00193
case SIG_FLOAT:
00194
val = ((
PSIGNAL_FLOAT) sig)[coo];
00195
break;
00196
case SIG_DOUBLE:
00197
val = ((
PSIGNAL_DOUBLE) sig)[coo];
00198
break;
00199 }
00200
00201 end = (
int) (((maxi -
val) / (maxi - mini)) * dy1);
00202
if (end < 0)
00203 end = 0;
00204
00205
if (j == 0) {
00206 previousend = end;
00207 }
00208
00209
else {
00210
if ((xfin = (
int) (j * step)) == dimx)
00211 xfin--;
00212 Im =
00213
IdImaDrawLine(Im, vpix, 0,
00214 (
int) ((j - 1) * step),
00215 previousend, xfin, end);
00216 previousend = end;
00217 }
00218 }
00219
00220 }
00221
return (Im);
00222 }