Browse Source

pre 2.0 monster commit :

new dsp code
ngvi test
tags/v1.8.0
Thierry Leconte 19 years ago
parent
commit
c7e205473c
12 changed files with 309 additions and 143 deletions
  1. +3
    -4
      Makefile
  2. +14
    -11
      dsp.c
  3. +30
    -1
      fcolor.c
  4. +3
    -5
      filter.c
  5. +1
    -1
      filter.h
  6. +106
    -55
      filtercoeff.h
  7. +11
    -22
      image.c
  8. +84
    -43
      main.c
  9. +8
    -0
      offsets.h
  10. +10
    -0
      satcal.h
  11. +38
    -0
      temppalette.h
  12. +1
    -1
      version.h

+ 3
- 4
Makefile View File

@@ -8,12 +8,11 @@ OBJS= main.o image.o dsp.o filter.o reg.o fcolor.o
atpdec: $(OBJS)
$(CC) -o $@ $(OBJS) -lm -lsndfile -lpng

main.o: main.c version.h
main.o: main.c version.h temppalette.h offsets.h
dsp.o: dsp.c filtercoeff.h filter.h
filter.o: filter.c filter.h
image.o: image.c satcal.h
fcolor.o : fcolor.c
dres.o : dres.c
image.o: image.c satcal.h offsets.h
fcolor.o : fcolor.c offsets.h

clean:
rm -f *.o atpdec

+ 14
- 11
dsp.c View File

@@ -19,6 +19,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
#ifndef M_PI
@@ -88,7 +89,7 @@ static inline double Phase(double I,double Q)
return(-angle);
}

static float pll(double I, double Q)
static double pll(double I, double Q)
{

/* pll coeff */
@@ -106,7 +107,6 @@ static float pll(double I, double Q)
Qp = Q*Io-I*Qo;
DPhi = Phase(Ip,Qp);


/* loop filter */

PhaseOsc += 2.0 * M_PI * (K1 * DPhi + FreqOsc);
@@ -121,10 +121,10 @@ static float pll(double I, double Q)
if (FreqOsc < ((Fc - DFc) / Fe))
FreqOsc = (Fc - DFc) / Fe;

return ((float)Ip);
return (Ip);
}

static int getamp(float *ambuff, int nb)
static int getamp(double *ambuff, int nb)
{

#define BLKIN 1024
@@ -137,18 +137,19 @@ static int getamp(float *ambuff, int nb)
for (n = 0; n < nb; n++) {
double I,Q;

if (nin < IQFilterLen*2) {
if (nin < IQFilterLen*2+2) {
int res;
memmove(inbuff, &(inbuff[idxin]), nin * sizeof(float));
idxin = 0;
res = getsample(&(inbuff[nin]), BLKIN - nin);
nin += res;
if (nin < IQFilterLen*2)
if (nin < IQFilterLen*2+2)
return (n);
}

iqfir(&inbuff[idxin],iqfilter,IQFilterLen,&I,&Q);
ambuff[n] = pll(I,Q);

idxin += 1;
nin -= 1;
}
@@ -159,14 +160,14 @@ int getpixelv(float *pvbuff, int nb)
{

#define BLKAMP 1024
static float ambuff[BLKAMP];
static double ambuff[BLKAMP];
static int nam = 0;
static int idxam = 0;

int n,m;
double mult;

mult = (double) Fi / Fe *FreqLine;
mult = (double) Fi/Fe*FreqLine;

m=RSFilterLen/mult+1;

@@ -175,7 +176,7 @@ int getpixelv(float *pvbuff, int nb)

if (nam < m) {
int res;
memmove(ambuff, &(ambuff[idxam]), nam * sizeof(float));
memmove(ambuff, &(ambuff[idxam]), nam * sizeof(double));
idxam = 0;
res = getamp(&(ambuff[nam]), BLKAMP - nam);
nam += res;
@@ -185,6 +186,8 @@ int getpixelv(float *pvbuff, int nb)

pvbuff[n] = rsfir(&(ambuff[idxam]), rsfilter, RSFilterLen, offset, mult) * mult * 256.0;

//printf("%g\n",pvbuff[n]);

shift = ((int) floor((RSMULT - offset) / mult))+1;
offset = shift*mult+offset-RSMULT ;

@@ -214,10 +217,10 @@ int getpixelrow(float *pixelv)
}

/* test sync */
corr = fir(&(pixelv[1]), Sync, SyncFilterLen);
ecorr = fir(pixelv, Sync, SyncFilterLen);
corr = fir(&(pixelv[1]), Sync, SyncFilterLen);
lcorr = fir(&(pixelv[2]), Sync, SyncFilterLen);
FreqLine = 1.0+((ecorr - lcorr) / corr / PixelLine / 4.0);
FreqLine = 1.0+((ecorr-lcorr) / corr / PixelLine / 4.0);
if (corr < 0.75 * max) {
synced = 0;
FreqLine = 1.0;


+ 30
- 1
fcolor.c View File

@@ -1,6 +1,6 @@
#include <stdio.h>
#include <math.h>
#include "offsets.h"

typedef struct {
float h, s, v;
@@ -139,3 +139,32 @@ void falsecolor(double v, double t, float *r, float *g, float *b)

HSVtoRGB(r, g, b, c);
};

void Ngiv(float **prow, int nrow)
{
int n;

printf("Vegetation ... ");
fflush(stdout);

for (n = 0; n < nrow; n++) {
float *pixelv;
int i;

pixelv = prow[n];
for (i = 0; i < CH_WIDTH; i++) {
float pv;

pv = (pixelv[i + CHA_OFFSET]-pixelv[i + CHB_OFFSET])/(pixelv[i + CHA_OFFSET]+pixelv[i + CHB_OFFSET])*128.0+128.0;

if (pv > 255.0)
pv = 255.0;
if (pv < 0.0)
pv = 0.0;

pixelv[i + CHB_OFFSET] = pv;
}
}
printf("Done\n");
};


+ 3
- 5
filter.c View File

@@ -40,17 +40,15 @@ void iqfir(float *buff, const float *coeff, const int len,double *I,double *Q)
double i,q;

i=q=0.0;
for (k = 0; k < len-1; k++) {
for (k = 0; k < len; k++) {
q += buff[2*k] * coeff[k];
i += buff[2*k+1] ;
i += buff[2*k] ;
}
q += buff[2*k] * coeff[k];
i= buff[len-1]-i/len;
*I=i,*Q=q;
}

float
rsfir(float *buff, const float *coeff, const int len, const double offset,
float rsfir(double *buff, const float *coeff, const int len, const double offset,
const double delta)
{
int i;


+ 1
- 1
filter.h View File

@@ -23,5 +23,5 @@
float fir(float *buff,const float *coeff,const int len);
void iqfir(float *buff,const float *coeff,const int len,double *I,double *Q);
float rsfir(float *buff,const float *coeff,const int len ,const double offset ,const double delta);
float rsfir(double *buff,const float *coeff,const int len ,const double offset ,const double delta);

+ 106
- 55
filtercoeff.h View File

@@ -1,55 +1,106 @@
/*
* Atpdec
* Copyright (c) 2003 by Thierry Leconte (F4DWV)
*
* $Id$
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#define IQFilterLen 32
const float iqfilter[IQFilterLen] = {
0.0205361, 0.0219524, 0.0235785, 0.0254648,
0.0276791, 0.0303152, 0.0335063, 0.0374482,
0.0424413, 0.0489708, 0.0578745, 0.0707355,
0.0909457, 0.127324, 0.212207, 0.63662,
-0.63662, -0.212207,-0.127324,-0.0909457,
-0.0707355,-0.0578745,-0.0489708,-0.0424413,
-0.0374482,-0.0335063,-0.0303152,-0.0276791,
-0.0254648,-0.0235785,-0.0219524,-0.0205361
};
#define SyncFilterLen 32
const float Sync[SyncFilterLen]={
-14,-14,-14,
18,18,-14,-14,18,18,-14,-14,18,18,-14,-14,
18,18,-14,-14,18,18,-14,-14,18,18,-14,-14,
18,18,-14,-14,-14
};
#define RSFilterLen 75
const float rsfilter[RSFilterLen] = {
0.000684467, 0.000686301, 0.000680827, 0.000657135, 0.000598639, 0.000484572, 0.000292259, -4.07622e-19,
-0.000409636, -0.000946387, -0.00160904, -0.00238265, -0.00323652, -0.00412324, -0.00497894, -0.00572484,
-0.00627025, -0.00651673, -0.00636341, -0.00571307, -0.00447871, -0.00259011, 1.72476e-18, 0.00331064,
0.00732849, 0.0120054, 0.017258, 0.0229688, 0.0289897, 0.0351475, 0.0412507, 0.0470982,
0.052488, 0.0572273, 0.0611415, 0.0640834, 0.0659403, 0.0666398, 0.0661536, 0.0644993,
0.061739, 0.0579765, 0.0533519, 0.0480347, 0.0422149, 0.0360944, 0.0298768, 0.023758,
0.0179179, 0.0125126, 0.00766851, 0.00347853, 1.81998e-18, -0.00274526, -0.00476897, -0.00611273,
-0.00684295, -0.00704483, -0.00681579, -0.00625878, -0.00547594, -0.00456294, -0.00360441, -0.00267047,
-0.00181474, -0.00107366, -0.000467084, -4.66468e-19, 0.000334865, 0.000553877, 0.000679047, 0.000734606,
0.000743914, 0.000726905, 0.00069827 };
/*
* Atpdec
* Copyright (c) 2003 by Thierry Leconte (F4DWV)
*
* $Id$
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#define IQFilterLen 32
const float iqfilter[IQFilterLen] =
{ 0.0205361, 0.0219524, 0.0235785, 0.0254648, 0.0276791, 0.0303152,
0.0335063, 0.0374482, 0.0424413, 0.0489708, 0.0578745, 0.0707355, 0.0909457, 0.127324, 0.212207, 0.63662,
-0.63662, -0.212207, -0.127324, -0.0909457, -0.0707355, -0.0578745, -0.0489708, -0.0424413, -0.0374482,
-0.0335063, -0.0303152, -0.0276791, -0.0254648, -0.0235785, -0.0219524, -0.0205361
};


#define SyncFilterLen 32
const float Sync[SyncFilterLen] =
{ -14, -14, -14, 18, 18, -14, -14, 18, 18, -14, -14, 18, 18, -14, -14,
18, 18, -14, -14, 18, 18, -14, -14, 18, 18, -14, -14, 18, 18, -14, -14, -14
};


#define RSFilterLen 437
const float rsfilter[RSFilterLen] =
{ -3.37279e-04, -8.80292e-06, -3.96418e-04, -1.78544e-04, -5.27511e-04,
-3.75376e-04, -6.95337e-04, -5.93148e-04, -8.79730e-04, -8.15327e-04, -1.05669e-03, -1.01377e-03,
-1.19836e-03, -1.15443e-03, -1.26937e-03, -1.20955e-03, -1.23904e-03, -1.15302e-03, -1.08660e-03,
-9.64235e-04, -8.02450e-04, -6.46202e-04, -3.95376e-04, -2.18096e-04, 1.11906e-04, 2.89567e-04,
6.67167e-04, 8.19039e-04, 1.21725e-03, 1.30556e-03, 1.69365e-03, 1.68588e-03, 2.03277e-03, 1.90159e-03,
2.18455e-03, 1.90833e-03, 2.12100e-03, 1.69052e-03, 1.77484e-03, 1.42542e-03, 1.18292e-03, 8.66979e-04,
5.54161e-04, 2.15793e-04, -1.11623e-04, -4.35173e-04, -7.27194e-04, -9.91551e-04, -1.20407e-03,
-1.37032e-03, -1.46991e-03, -1.51120e-03, -1.48008e-03, -1.39047e-03, -1.23115e-03, -1.02128e-03,
-7.60099e-04, -4.68008e-04, -1.46339e-04, 1.80867e-04, 5.11244e-04, 8.19243e-04, 1.09739e-03, 1.32668e-03,
1.50632e-03, 1.61522e-03, 1.66246e-03, 1.62390e-03, 1.52430e-03, 1.34273e-03, 1.10736e-03, 8.10335e-04,
4.76814e-04, 1.13622e-04, -2.64150e-04, -6.26595e-04, -9.95436e-04, -1.27846e-03, -1.54080e-03,
-1.74292e-03, -1.86141e-03, -1.89318e-03, -1.83969e-03, -1.69770e-03, -1.47938e-03, -1.18696e-03,
-8.37003e-04, -4.39507e-04, -1.56907e-05, 4.19904e-04, 8.43172e-04, 1.23827e-03, 1.58411e-03,
1.86382e-03, 2.06312e-03, 2.17177e-03, 2.18121e-03, 2.08906e-03, 1.89772e-03, 1.61153e-03,
1.24507e-03, 8.13976e-04, 3.29944e-04, -1.74591e-04, -6.83619e-04, -1.17826e-03, -1.61659e-03,
-2.00403e-03, -2.29070e-03, -2.49179e-03, -2.56546e-03, -2.53448e-03, -2.37032e-03, -2.10060e-03,
-1.72140e-03, -1.24542e-03, -7.15425e-04, -1.24964e-04, 4.83736e-04, 1.08328e-03, 1.64530e-03,
2.14503e-03, 2.55400e-03, 2.85589e-03, 3.02785e-03, 3.06271e-03, 2.95067e-03, 2.69770e-03,
2.30599e-03, 1.79763e-03, 1.18587e-03, 5.04003e-04, -2.23591e-04, -9.57591e-04, -1.66939e-03,
-2.31717e-03, -2.87636e-03, -3.31209e-03, -3.60506e-03, -3.73609e-03, -3.69208e-03, -3.44913e-03,
-3.06572e-03, -2.50229e-03, -1.80630e-03, -1.00532e-03, -1.22305e-04, 7.83910e-04, 1.69402e-03,
2.53826e-03, 3.30312e-03, 3.91841e-03, 4.38017e-03, 4.63546e-03, 4.68091e-03, 4.50037e-03,
4.09614e-03, 3.47811e-03, 2.67306e-03, 1.70418e-03, 6.20542e-04, -5.36994e-04, -1.70981e-03,
-2.84712e-03, -3.88827e-03, -4.78659e-03, -5.48593e-03, -5.95049e-03, -6.14483e-03, -6.05118e-03,
-5.65829e-03, -4.97525e-03, -4.01796e-03, -2.82224e-03, -1.43003e-03, 1.00410e-04, 1.71169e-03,
3.31983e-03, 4.87796e-03, 6.23237e-03, 7.31013e-03, 8.20642e-03, 8.67374e-03, 8.77681e-03,
8.43444e-03, 7.66794e-03, 6.46827e-03, 4.87294e-03, 2.92923e-03, 6.98913e-04, -1.72126e-03,
-4.24785e-03, -6.75380e-03, -9.13309e-03, -1.12532e-02, -1.30038e-02, -1.42633e-02, -1.49338e-02,
-1.49145e-02, -1.41484e-02, -1.25761e-02, -1.01870e-02, -6.97432e-03, -2.97910e-03, 1.75386e-03,
7.11899e-03, 1.30225e-02, 1.93173e-02, 2.58685e-02, 3.24965e-02, 3.90469e-02, 4.53316e-02,
5.11931e-02, 5.64604e-02, 6.09924e-02, 6.46584e-02, 6.73547e-02, 6.90049e-02, 6.97096e-02,
6.90049e-02, 6.73547e-02, 6.46584e-02, 6.09924e-02, 5.64604e-02, 5.11931e-02, 4.53316e-02,
3.90469e-02, 3.24965e-02, 2.58685e-02, 1.93173e-02, 1.30225e-02, 7.11899e-03, 1.75386e-03,
-2.97910e-03, -6.97432e-03, -1.01870e-02, -1.25761e-02, -1.41484e-02, -1.49145e-02, -1.49338e-02,
-1.42633e-02, -1.30038e-02, -1.12532e-02, -9.13309e-03, -6.75380e-03, -4.24785e-03, -1.72126e-03,
6.98913e-04, 2.92923e-03, 4.87294e-03, 6.46827e-03, 7.66794e-03, 8.43444e-03, 8.77681e-03,
8.67374e-03, 8.20642e-03, 7.31013e-03, 6.23237e-03, 4.87796e-03, 3.31983e-03, 1.71169e-03,
1.00410e-04, -1.43003e-03, -2.82224e-03, -4.01796e-03, -4.97525e-03, -5.65829e-03, -6.05118e-03,
-6.14483e-03, -5.95049e-03, -5.48593e-03, -4.78659e-03, -3.88827e-03, -2.84712e-03, -1.70981e-03,
-5.36994e-04, 6.20542e-04, 1.70418e-03, 2.67306e-03, 3.47811e-03, 4.09614e-03, 4.50037e-03,
4.68091e-03, 4.63546e-03, 4.38017e-03, 3.91841e-03, 3.30312e-03, 2.53826e-03, 1.69402e-03,
7.83910e-04, -1.22305e-04, -1.00532e-03, -1.80630e-03, -2.50229e-03, -3.06572e-03, -3.44913e-03,
-3.69208e-03, -3.73609e-03, -3.60506e-03, -3.31209e-03, -2.87636e-03, -2.31717e-03, -1.66939e-03,
-9.57591e-04, -2.23591e-04, 5.04003e-04, 1.18587e-03, 1.79763e-03, 2.30599e-03, 2.69770e-03,
2.95067e-03, 3.06271e-03, 3.02785e-03, 2.85589e-03, 2.55400e-03, 2.14503e-03, 1.64530e-03,
1.08328e-03, 4.83736e-04, -1.24964e-04, -7.15425e-04, -1.24542e-03, -1.72140e-03, -2.10060e-03,
-2.37032e-03, -2.53448e-03, -2.56546e-03, -2.49179e-03, -2.29070e-03, -2.00403e-03, -1.61659e-03,
-1.17826e-03, -6.83619e-04, -1.74591e-04, 3.29944e-04, 8.13976e-04, 1.24507e-03, 1.61153e-03,
1.89772e-03, 2.08906e-03, 2.18121e-03, 2.17177e-03, 2.06312e-03, 1.86382e-03, 1.58411e-03,
1.23827e-03, 8.43172e-04, 4.19904e-04, -1.56907e-05, -4.39507e-04, -8.37003e-04, -1.18696e-03,
-1.47938e-03, -1.69770e-03, -1.83969e-03, -1.89318e-03, -1.86141e-03, -1.74292e-03, -1.54080e-03,
-1.27846e-03, -9.95436e-04, -6.26595e-04, -2.64150e-04, 1.13622e-04, 4.76814e-04, 8.10335e-04,
1.10736e-03, 1.34273e-03, 1.52430e-03, 1.62390e-03, 1.66246e-03, 1.61522e-03, 1.50632e-03,
1.32668e-03, 1.09739e-03, 8.19243e-04, 5.11244e-04, 1.80867e-04, -1.46339e-04, -4.68008e-04,
-7.60099e-04, -1.02128e-03, -1.23115e-03, -1.39047e-03, -1.48008e-03, -1.51120e-03, -1.46991e-03,
-1.37032e-03, -1.20407e-03, -9.91551e-04, -7.27194e-04, -4.35173e-04, -1.11623e-04, 2.15793e-04,
5.54161e-04, 8.66979e-04, 1.18292e-03, 1.42542e-03, 1.77484e-03, 1.69052e-03, 2.12100e-03,
1.90833e-03, 2.18455e-03, 1.90159e-03, 2.03277e-03, 1.68588e-03, 1.69365e-03, 1.30556e-03,
1.21725e-03, 8.19039e-04, 6.67167e-04, 2.89567e-04, 1.11906e-04, -2.18096e-04, -3.95376e-04,
-6.46202e-04, -8.02450e-04, -9.64235e-04, -1.08660e-03, -1.15302e-03, -1.23904e-03, -1.20955e-03,
-1.26937e-03, -1.15443e-03, -1.19836e-03, -1.01377e-03, -1.05669e-03, -8.15327e-04, -8.79730e-04,
-5.93148e-04, -6.95337e-04, -3.75376e-04, -5.27511e-04, -1.78544e-04, -3.96418e-04, -8.80292e-06,
-3.37279e-04
};



+ 11
- 22
image.c View File

@@ -25,6 +25,8 @@
#include <sndfile.h>
#include <math.h>

#include "offsets.h"

#define REGORDER 3
typedef struct {
double cf[REGORDER + 1];
@@ -79,7 +81,7 @@ int Calibrate(float **prow, int nrow, int offset)

teleline[n] = 0.0;
for (i = 3; i < 43; i++) {
teleline[n] += prow[n][i + offset + 956];
teleline[n] += prow[n][i + offset + CH_WIDTH];
}
teleline[n] /= 40.0;
}
@@ -136,7 +138,6 @@ int Calibrate(float **prow, int nrow, int offset)
}



/* channel ID */
for (j = 0, max = 10000.0, channel = -1; j < 6; j++) {
float df;
@@ -154,7 +155,7 @@ int Calibrate(float **prow, int nrow, int offset)
double csline;

for (csline = 0.0, l = 3; l < 43; l++)
csline += prow[n][l + offset];
csline += prow[n][l + offset -SPC_WIDTH];
csline /= 40.0;
if (csline > 50.0) {
Cs += csline;
@@ -173,7 +174,7 @@ int Calibrate(float **prow, int nrow, int offset)
int i;

pixelv = prow[n];
for (i = 0; i < 1001; i++) {
for (i = 0; i < CH_WIDTH; i++) {
float pv;
int k, kof;

@@ -207,21 +208,11 @@ int Calibrate(float **prow, int nrow, int offset)
}
}
printf("Done\n");
return (channel);
return (channel+1);
}

/* ------------------------------temperature calibration -----------------------*/
extern int satnum;
const struct {
float d[4][3];
struct {
float vc, A, B;
} rad[3];
struct {
float Ns;
float b[3];
} cor[3];
} satcal[4] =
#include "satcal.h"

typedef struct {
@@ -238,7 +229,7 @@ static void tempcomp(double t[16], int ch, tempparam * tpr)
double C;
int n;

tpr->ch = ch - 3;
tpr->ch = ch - 4;

/* compute equivalent T black body */
for (n = 0; n < 4; n++) {
@@ -282,11 +273,10 @@ static double tempcal(float Ce, tempparam * rgpr)

vc = satcal[satnum].rad[rgpr->ch].vc;
T = c2 * vc / log(c1 * vc * vc * vc / Ne + 1.0);
T = (T -
satcal[satnum].rad[rgpr->ch].A) / satcal[satnum].rad[rgpr->ch].B;
T = (T - satcal[satnum].rad[rgpr->ch].A) / satcal[satnum].rad[rgpr->ch].B;

/* rescale to range 0-255 for +40-60 °C */
T = (-T + 273.15 + 40) / 100.0 * 255.0;
/* rescale to range 0-255 for -60 +40 °C */
T = (T - 273.15 + 60.0) / 100.0 * 256.0;

return (T);
}
@@ -301,13 +291,12 @@ void Temperature(float **prow, int nrow, int channel, int offset)

tempcomp(tele, channel, &temp);


for (n = 0; n < nrow; n++) {
float *pixelv;
int i;

pixelv = prow[n];
for (i = 0; i < 1001; i++) {
for (i = 0; i < CH_WIDTH; i++) {
float pv;

pv = tempcal(pixelv[i + offset], &temp);


+ 84
- 43
main.c View File

@@ -32,17 +32,12 @@
#include <png.h>

#include "version.h"
#include "temppalette.h"
#include "offsets.h"

extern int getpixelrow(float *pixelv);
extern int init_dsp(double F);;

#define SYNC_WIDTH 39
#define SPC_WIDTH 47
#define TELE_WIDTH 45
#define CH_WIDTH 909
#define CH_OFFSET (SYNC_WIDTH+SPC_WIDTH+CH_WIDTH+TELE_WIDTH)
#define IMG_WIDTH 2080

static SNDFILE *inwav;

static int initsnd(char *filename)
@@ -93,7 +88,7 @@ static png_text text_ptr[] = {

static int
ImageOut(char *filename, char *chid, float **prow, int nrow,
int width, int offset)
int width, int offset, png_color *palette)
{
FILE *pngfile;
png_infop info_ptr;
@@ -115,9 +110,18 @@ ImageOut(char *filename, char *chid, float **prow, int nrow,
return (1);
}

png_set_IHDR(png_ptr, info_ptr, width, nrow,
if(palette==NULL) {
/* grey image */
png_set_IHDR(png_ptr, info_ptr, width, nrow,
8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
} else {
/* palette color mage */
png_set_IHDR(png_ptr, info_ptr, width, nrow,
8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_PLTE(png_ptr, info_ptr, palette, 256);
}

text_ptr[1].text = chid;
text_ptr[1].text_length = strlen(chid);
@@ -152,13 +156,12 @@ ImageOut(char *filename, char *chid, float **prow, int nrow,
return (0);
}

int ImageColorOut(char *filename, float **prow, int nrow)
static int ImageRGBOut(char *filename, float **prow, int nrow)
{
FILE *pngfile;
png_infop info_ptr;
png_structp png_ptr;
int n;
float *pixelc, *pixelp;

extern void falsecolor(double v, double t, float *r, float *g,
float *b);
@@ -198,20 +201,19 @@ int ImageColorOut(char *filename, float **prow, int nrow)
png_init_io(png_ptr, pngfile);
png_write_info(png_ptr, info_ptr);

pixelc=prow[0];
for (n = 0; n < nrow ; n++) {
png_color pix[CH_WIDTH];
float *pixelc;
int i;

pixelp=pixelc;
pixelc = prow[n];

for (i = 0; i < CH_WIDTH - 1; i++) {
float v, t;
float r, g, b;

v = pixelc[i+SYNC_WIDTH + SPC_WIDTH];
t = (2.0*pixelc[i+SYNC_WIDTH + SPC_WIDTH + CH_OFFSET]+pixelp[i+SYNC_WIDTH + SPC_WIDTH + CH_OFFSET])/3.0;
v = pixelc[i+CHA_OFFSET];
t = pixelc[i+CHB_OFFSET];

falsecolor(v, t, &r, &g, &b);

@@ -228,8 +230,48 @@ int ImageColorOut(char *filename, float **prow, int nrow)
return (0);
}


static void Distrib(char *filename,float **prow,int nrow)
{
unsigned int distrib[256][256];
int n;
int x,y;
int max=0;
FILE *df;

for(y=0;y<256;y++)
for(x=0;x<256;x++)
distrib[y][x]=0;

for(n=0;n<nrow;n++) {
float *pixelv;
int i;

pixelv=prow[n];
for(i=0;i<CH_WIDTH;i++) {

y=(int)(pixelv[i+CHA_OFFSET]);
x=(int)(pixelv[i+CHB_OFFSET]);
distrib[y][x]+=1;
if(distrib[y][x]> max) max=distrib[y][x];
}
}
df=fopen(filename,"w");

printf("Writing %s\n",filename);

fprintf(df,"P2\n#max %d\n",max);
fprintf(df,"256 256\n255\n");
for(y=0;y<256;y++)
for(x=0;x<256;x++)
fprintf(df,"%d\n",(int)((255.0*(double)(distrib[y][x]))/(double)max));
fclose(df);
}


extern int Calibrate(float **prow, int nrow, int offset);
extern void Temperature(float **prow, int nrow, int ch, int offset);
extern int Ngiv(float **prow, int nrow);
extern void readfconf(char *file);
extern int optind, opterr;
extern char *optarg;
@@ -250,9 +292,9 @@ int main(int argc, char **argv)
char pngdirname[1024] = "";
char imgopt[20] = "ac";
float *prow[3000];
char *chid[6] = { "1", "2", "3A", "4", "5", "3B" };
char *chid[] = { "?", "1", "2", "3A", "4", "5", "3B" };
int nrow;
int ch;
int chA,chB;
int c;

printf("%s\n", version);
@@ -285,7 +327,8 @@ int main(int argc, char **argv)
prow[nrow] = NULL;

for (; optind < argc; optind++) {
int a = 0, b = 0;

chA=chB=0;

strcpy(pngfilename, argv[optind]);
strcpy(name, basename(pngfilename));
@@ -312,28 +355,24 @@ int main(int argc, char **argv)
printf("\nDone\n");
sf_close(inwav);


/* raw image */
if (strchr(imgopt, (int) 'r') != NULL) {
sprintf(pngfilename, "%s/%s-r.png", pngdirname, name);
ImageOut(pngfilename, "raw", prow, nrow, IMG_WIDTH, 0);
ImageOut(pngfilename, "raw", prow, nrow, IMG_WIDTH, 0,NULL);
}

/* Channel A */
if (((strchr(imgopt, (int) 'a') != NULL)
|| (strchr(imgopt, (int) 'c') != NULL)
|| (strchr(imgopt, (int) 'd') != NULL))) {
ch = Calibrate(prow, nrow, SYNC_WIDTH);
if (ch >= 0) {
chA = Calibrate(prow, nrow, CHA_OFFSET);
if (chA >= 0) {
if (strchr(imgopt, (int) 'a') != NULL) {
sprintf(pngfilename, "%s/%s-%s.png", pngdirname, name,
chid[ch]);
ImageOut(pngfilename, chid[ch], prow, nrow,
SPC_WIDTH + CH_WIDTH + TELE_WIDTH,
SYNC_WIDTH);
sprintf(pngfilename, "%s/%s-%s.png", pngdirname, name, chid[chA]);
ImageOut(pngfilename, chid[chA], prow, nrow, CH_WIDTH , CHA_OFFSET,NULL);
}
}
if (ch < 2)
a = 1;
}

/* Channel B */
@@ -341,38 +380,40 @@ int main(int argc, char **argv)
|| (strchr(imgopt, (int) 'c') != NULL)
|| (strchr(imgopt, (int) 't') != NULL)
|| (strchr(imgopt, (int) 'd') != NULL)) {
ch = Calibrate(prow, nrow, CH_OFFSET + SYNC_WIDTH);
if (ch >= 0) {
chB = Calibrate(prow, nrow, CHB_OFFSET);
if (chB >= 0) {
if (strchr(imgopt, (int) 'b') != NULL) {
sprintf(pngfilename, "%s/%s-%s.png", pngdirname, name,
chid[ch]);
ImageOut(pngfilename, chid[ch], prow, nrow,
SPC_WIDTH + CH_WIDTH + TELE_WIDTH,
CH_OFFSET + SYNC_WIDTH);
sprintf(pngfilename, "%s/%s-%s.png", pngdirname, name, chid[chB]);
ImageOut(pngfilename, chid[chB], prow, nrow, CH_WIDTH , CHB_OFFSET ,NULL);
}
}
if (ch > 2) {
b = 1;
Temperature(prow, nrow, ch, CH_OFFSET + SYNC_WIDTH);
if (chB > 3) {
Temperature(prow, nrow, chB, CHB_OFFSET);
if (strchr(imgopt, (int) 't') != NULL) {
sprintf(pngfilename, "%s/%s-t.png", pngdirname, name);
ImageOut(pngfilename, "Temperature", prow, nrow,
CH_WIDTH, CH_OFFSET + SYNC_WIDTH + SPC_WIDTH);
ImageOut(pngfilename, "Temperature", prow, nrow, CH_WIDTH, CHB_OFFSET, (png_color*)TempPalette);
}
}
}

/* distribution */
if (a && b && strchr(imgopt, (int) 'd') != NULL) {
if (chA && chB && strchr(imgopt, (int) 'd') != NULL) {
sprintf(pngfilename, "%s/%s-d.pnm", pngdirname, name);
Distrib(pngfilename, prow, nrow);
}

/* color image */
if (a && b && strchr(imgopt, (int) 'c') != NULL) {
if (chA==2 && chB==4 && strchr(imgopt, (int) 'c') != NULL) {
sprintf(pngfilename, "%s/%s-c.png", pngdirname, name);
ImageColorOut(pngfilename, prow, nrow);
ImageRGBOut(pngfilename, prow, nrow);
}

/* vegetation image */
if (chA==1 && chB==2 && strchr(imgopt, (int) 'c') != NULL) {
Ngiv(prow, nrow);
sprintf(pngfilename, "%s/%s-c.png", pngdirname, name);
ImageOut(pngfilename, "Vegetation", prow, nrow, CH_WIDTH, CHB_OFFSET, (png_color*)TempPalette);
}
}
exit(0);
}

+ 8
- 0
offsets.h View File

@@ -0,0 +1,8 @@
#define SYNC_WIDTH 39
#define SPC_WIDTH 47
#define TELE_WIDTH 45
#define CH_WIDTH 909
#define CH_OFFSET (SYNC_WIDTH+SPC_WIDTH+CH_WIDTH+TELE_WIDTH)
#define IMG_WIDTH 2080
#define CHA_OFFSET (SYNC_WIDTH+SPC_WIDTH)
#define CHB_OFFSET (SYNC_WIDTH+SPC_WIDTH+CH_WIDTH+TELE_WIDTH+SYNC_WIDTH+SPC_WIDTH)

+ 10
- 0
satcal.h View File

@@ -1,3 +1,13 @@
const struct {
float d[4][3];
struct {
float vc, A, B;
} rad[3];
struct {
float Ns;
float b[3];
} cor[3];
} satcal[4] =
{/* calibration coeff from NOAA KLM POES satellite user guide */
{/* NOAA-15 */
{ /* PRT coeff d0,d1,d2 */


+ 38
- 0
temppalette.h View File

@@ -0,0 +1,38 @@
unsigned char TempPalette[256*3]= {
"ff\362gg\362hh\362ih\362ii\362kj\363ll\363mm\362mn\362oo\363oo\362qq\363"
"rr\362ss\363ts\363uu\364vu\363vv\363xx\364yy\364zz\364{{\363{{\364}}\363"
"~~\364~~\364\200\200\364\200\200\364\201\201\364\202\201\364\202\203\364"
"\204\203\365\205\205\365\206\206\365\207\207\364\210\210\364\210\211\364"
"\212\212\365\212\213\364\214\213\365\214\215\365\215\216\365\217\217\366"
"\220\217\365\221\221\365\222\222\365\222\222\366\224\224\366\225\225\366"
"\226\225\366\227\227\365\230\230\366\230\230\366\231\232\366\232\233\366"
"\233\233\367\235\234\367\235\235\367\237\237\367\240\240\367\241\241\366"
"\241\242\367\243\243\367\243\243\367\244\245\367\246\245\367\246\247\367"
"\250\250\367\251\250\367\252\251\370\253\253\370\254\253\370\255\254\367"
"\256\256\370\257\256\367\260\257\370\260\261\370\261\262\370\262\262\370"
"\263\264\371\265\265\370\266\266\370\267\267\370\270\270\371\270\271\371"
"\271\272\371\272\273\371\274\274\371\274\274\370\275\276\371\276\277\371"
"\277\300\372\300\301\371\302\302\372\303\303\371\303\304\371\305\305\372"
"\306\305\371\307\307\371\307\307\372\310\311\371\312\312\372\313\313\372"
"\314\314\373\314\314\372\316\316\372\317\316\372\320\317\372\321\321\372"
"\322\322\372\323\323\372\324\324\372\324\325\373\325\325\373\327\327\373"
"\330\330\373\331\331\373\332\332\373\332\332\373\334\334\373\335\334\374"
"\336\335\373\337\336\373\340\340\374\340\341\374\342\342\373\343\343\374"
"\343\343\374\345\345\374\346\346\374\346\347\375\350\347\374\350\350\375"
"\351\351\374\353\353\375\354\354\374\354\355\374\355\355\374\356\357\375"
"\357\357\375\361\360\375\362\361\375\363\363\375\364\364\375\365\365\376"
"\366\366\376\366\366\375\370\370\375\370\370\376\372\372\376\372\372\375"
"\374\373\376\375\374\375\376\376\376^~Y]\177W\\\201UZ\204SY\206RX\211PW\214"
"OV\216LU\221JS\223IR\226GQ\231EP\234CO\236BN\240@M\243>K\246<J\251:I\253"
"9H\2557G\2605F\2633D\2652D\2700B\273.A\275,@\300+?\302)=\305'=\310&;\312"
"$:\315!9\317\40""8\322\36""7\325\35""5\327\32""4\332\31""3\335\27""2\337"
"\25""1\341\23""0\344\22.\347\20-\352\16,\354\14+\356\12*\361\11(\363\7(\367"
"\5'\370\4%\374\2&\373\2'\370\4*\370\3/\370\4""4\371\4""9\370\4=\370\4C\371"
"\3G\371\4L\371\3R\371\4V\372\3[\371\3`\371\3e\372\3j\372\3p\372\3u\371\2"
"y\372\3~\372\3\203\372\2\207\373\2\215\372\3\221\373\2\226\372\2\234\373"
"\2\241\373\2\245\373\2\252\373\1\257\373\2\265\373\1\272\374\1\277\373\2"
"\304\373\1\311\374\1\316\374\2\324\374\1\330\374\1\336\374\1\343\375\1\350"
"\375\1\356\375\1\363\375\1\370\375\1\375\375\1\375\371\0\376\364\1\376\357"
"\0\376\351\0\376\344\0\376\337\1\376\333\0",
};


+ 1
- 1
version.h View File

@@ -1,2 +1,2 @@
const char version[]="Atpdec CVS version (c) 2004-2005 Thierry Leconte F4DWV";
char version[]="Atpdec CVS version (c) 2004-2005 Thierry Leconte F4DWV";


Loading…
Cancel
Save