Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

5/3 Wavelet Transform

somedays ago my code works well to perform 5/3 wavelet transform but today I cannot make it run.  Also, is there anyone can help to create the reverse part based on the forward part below?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SAVE_UNIT short
#define PROCESS_UNIT short


FILE *in_file, *out_file;
  PROCESS_UNIT **img, **tmp_img;
  int dl,N;

  void main (int argc, char *argv[])
  {
          int i,j;
            printf("Forward TT transform\n");
                  if(argc<5)
                  {
                        printf("Usage:\tt <in_file> <file size> <decomp layers> <out_file>\n");
                        exit(1);
                  }
                  N=atoi(argv[2]);
                  dl=atoi(argv[3]);
                  
                  matrix_allocate(img,N,N,PROCESS_UNIT);
                  matrix_allocate(tmp_img,N,N,PROCESS_UNIT);
       
                  if ((in_file=fopen(argv[1],"rb"))==NULL)
                  {
                        printf("Binary image doesn't exist\n");
                        exit(1);
                  }

                  for(i=0; i<N; i++)
                        for(j=0; j<N; j++)
                              img[i][j]=(PROCESS_UNIT) fgetc(in_file);
                        fclose(in_file);

                        /****TT transform****/

                        { int layer,layer_size,s_coeffs=2,p_coeffs=5,fi,index,index_plus_1;

                        PROCESS_UNIT p_coeff[5]={3,-22,0,22,-3};
                        printf("\n%d,%d,%d,%d,%d\n",p_coeff[0],p_coeff[1],p_coeff[2],p_coeff[3],p_coeff[4],p_coeff[5]);

                        layer_size=2*N;
                        for(layer=0; layer<dl-1; layer++){
                              layer_size=(layer_size>>1);
                              for(i=0;i<layer_size;i++){
                                    for(j=0;j<(layer_size>>1);j++){
                                          tmp_img[i][j]=0;
                                          for(fi=0; fi<s_coeffs; fi++){
                                                index=2*j+fi;
                                                if(index>layer_size-1)
                                                      index=layer_size-1;
                                                tmp_img[i][j]+=img[i][index];
                                          }

                                          tmp_img[i][j]=(PROCESS_UNIT)(tmp_img[i][j]>>1);
                                          tmp_img[i][j+(layer_size>>1)]=0;
                                          for(fi=0; fi<p_coeffs;fi++){
                                                index=2*j+2*fi-4;
                                                index_plus_1=index+1;
                                                if(index>layer_size-1){
                                                      index=layer_size-(index-(layer_size-1));
                                                      index_plus_1=index-1;
                                                }
                                                if(index<0){
                                                      index=-index;
                                                      index_plus_1=index+1;
                                                }

                                                tmp_img[i][j+(layer_size>>1)]+=(PROCESS_UNIT)(((img[i][index]+img[i][index_plus_1])>>1)*p_coeff[fi]);}
                                          tmp_img[i][j+(layer_size>>1)]+=32;

                                          tmp_img[i][j+(layer_size>>1)]=(PROCESS_UNIT)(tmp_img[i][j+(layer_size>>1)]>>6);
                                          tmp_img[i][j+(layer_size>>1)]+=(img[i][2*j]-img[i][2*j+1]);
                                    }
                              }

                              for(j=0; j<layer_size; j++){
                                    for(i=0; i<(layer_size>>1); i++){
                                          img[i][j]=0;
                                          for(fi=0;fi<s_coeffs; fi++){
                                                index=2*i+fi;

                                                if(index>layer_size-1)
                                                      index=layer_size-1;
                                                img[i][j]+=tmp_img[index][j];
                                          }
                                          img[i][j]=(PROCESS_UNIT)(img[i][j]>>1);

                                          img[i+(layer_size>>1)][j]=0;
                                          for(fi=0; fi<p_coeffs; fi++){
                                                index=2*i+2*fi-4;
                                                index_plus_1=index+1;
                                                if(index>layer_size-1){
                                                      index=layer_size-(index-(layer_size-1));
                                                      index_plus_1=index-1;
                                                }
                                                if(index<0){
                                                      index=-index;
                                                      index_plus_1=index+1;
                                                }
                  img[i+(layer_size>>1)][j]+=(PROCESS_UNIT)(((tmp_img[index][j]+tmp_img[index_plus_1][j])>>1)*p_coeff[fi]);
                                          }

                                          img[i+(layer_size>>1)][j]+=32;
                  img[i+(layer_size>>1)][j]=(PROCESS_UNIT)(img[i+(layer_size>>1)][j]>>6);
                  img[i+(layer_size>>1)][j]+=(tmp_img[2*i][j]-tmp_img[2*i+1][j]);
                                    }
                              }
                        }
                        }

                        if((out_file=fopen(argv[4],"wb"))==NULL)
                        {
                              printf("can't open out_put file %s\n",argv[4]);
                              exit(1);
                        }

                        {
                              SAVE_UNIT tmp;
                              for(i=0; i<N; i++){
                                    for(j=0; j<N; j++){
                                          tmp=(SAVE_UNIT)(img[i][j]);
                                          fwrite(&tmp,sizeof(SAVE_UNIT),1,out_file);
                                    }
                              }
                        }
                        fclose(out_file);
}




#define matrix_allocate(matrix, hor_size, ver_size, TYPE)
{
 
TYPE *imptr;
  int _i;
  matrix=(TYPE **)calloc((unsigned long)ver_size,sizeof(TYPE *));
  imptr=(TYPE*)calloc(((unsigned long)hor_size)*((unsigned long)ver_size),sizeof(TYPE));
  if (imptr==NULL){
         printf("\nNo Memory in matrix allocate");
         exit(-1);
                        }
  for (_i=0; _i<ver_size; ++_i,imptr+=hor_size)
        matrix[_i]=imptr;

}

thanks
0
gorexy
Asked:
gorexy
  • 10
  • 5
  • 4
  • +3
3 Solutions
 
Infinity08Commented:
First of all : what does "today I cannot make it run" mean ? What problem do you have, what are the errors you get, ... ?

Second : has the code been changed since the last time you were able to run it ?  If so, what has been changed ?

Third : what other circumstances are different now than the last time you ran it without problems ?
0
 
fridomCommented:
Replace the define with  a proper function.

Regards
Friedrich

0
 
Kent OlsenData Warehouse Architect / DBACommented:
Howdy....

Are you using the same compiler and flags?

You're creating stack variables from within the executable portions of the code.  This is a C++ extension that isn't universally accepted in C programming.


Kent
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
gorexyAuthor Commented:
Error message
I rearrange the code
//////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SAVE_UNIT short
#define PROCESS_UNIT short
#define matrix_allocate(matrix, hor_size, ver_size, TYPE)
{
 
TYPE *imptr;
  int _i;
  matrix=(TYPE **)calloc((unsigned long)ver_size,sizeof(TYPE *));
  imptr=(TYPE*)calloc(((unsigned long)hor_size)*((unsigned long)ver_size),sizeof(TYPE));
  if (imptr==NULL){
        printf("\nNo Memory in matrix allocate");
        exit(-1);
                    }
  for (_i=0; _i<ver_size; ++_i,imptr+=hor_size)
       matrix[_i]=imptr;

}

FILE *in_file, *out_file;
  PROCESS_UNIT **img, **tmp_img;
  int dl,N;

  void main (int argc, char *argv[])
  {
         int i,j;
          printf("Forward TT transform\n");
               if(argc<5)
               {
                    printf("Usage:\tt <in_file> <file size> <decomp layers> <out_file>\n");
                    exit(1);
               }
               N=atoi(argv[2]);
               dl=atoi(argv[3]);
               
               matrix_allocate(img,N,N,PROCESS_UNIT);
               matrix_allocate(tmp_img,N,N,PROCESS_UNIT);
       
               if ((in_file=fopen(argv[1],"rb"))==NULL)
               {
                    printf("Binary image doesn't exist\n");
                    exit(1);
               }

               for(i=0; i<N; i++)
                    for(j=0; j<N; j++)
                         img[i][j]=(PROCESS_UNIT) fgetc(in_file);
                    fclose(in_file);

                    /****TT transform****/

                    { int layer,layer_size,s_coeffs=2,p_coeffs=5,fi,index,index_plus_1;

                    PROCESS_UNIT p_coeff[5]={3,-22,0,22,-3};
                    printf("\n%d,%d,%d,%d,%d\n",p_coeff[0],p_coeff[1],p_coeff[2],p_coeff[3],p_coeff[4],p_coeff[5]);

                    layer_size=2*N;
                    for(layer=0; layer<dl-1; layer++){
                         layer_size=(layer_size>>1);
                         for(i=0;i<layer_size;i++){
                              for(j=0;j<(layer_size>>1);j++){
                                   tmp_img[i][j]=0;
                                   for(fi=0; fi<s_coeffs; fi++){
                                        index=2*j+fi;
                                        if(index>layer_size-1)
                                             index=layer_size-1;
                                        tmp_img[i][j]+=img[i][index];
                                   }

                                   tmp_img[i][j]=(PROCESS_UNIT)(tmp_img[i][j]>>1);
                                   tmp_img[i][j+(layer_size>>1)]=0;
                                   for(fi=0; fi<p_coeffs;fi++){
                                        index=2*j+2*fi-4;
                                        index_plus_1=index+1;
                                        if(index>layer_size-1){
                                             index=layer_size-(index-(layer_size-1));
                                             index_plus_1=index-1;
                                        }
                                        if(index<0){
                                             index=-index;
                                             index_plus_1=index+1;
                                        }

                                        tmp_img[i][j+(layer_size>>1)]+=(PROCESS_UNIT)(((img[i][index]+img[i][index_plus_1])>>1)*p_coeff[fi]);}
                                   tmp_img[i][j+(layer_size>>1)]+=32;

                                   tmp_img[i][j+(layer_size>>1)]=(PROCESS_UNIT)(tmp_img[i][j+(layer_size>>1)]>>6);
                                   tmp_img[i][j+(layer_size>>1)]+=(img[i][2*j]-img[i][2*j+1]);
                              }
                         }

                         for(j=0; j<layer_size; j++){
                              for(i=0; i<(layer_size>>1); i++){
                                   img[i][j]=0;
                                   for(fi=0;fi<s_coeffs; fi++){
                                        index=2*i+fi;

                                        if(index>layer_size-1)
                                             index=layer_size-1;
                                        img[i][j]+=tmp_img[index][j];
                                   }
                                   img[i][j]=(PROCESS_UNIT)(img[i][j]>>1);

                                   img[i+(layer_size>>1)][j]=0;
                                   for(fi=0; fi<p_coeffs; fi++){
                                        index=2*i+2*fi-4;
                                        index_plus_1=index+1;
                                        if(index>layer_size-1){
                                             index=layer_size-(index-(layer_size-1));
                                             index_plus_1=index-1;
                                        }
                                        if(index<0){
                                             index=-index;
                                             index_plus_1=index+1;
                                        }
               img[i+(layer_size>>1)][j]+=(PROCESS_UNIT)(((tmp_img[index][j]+tmp_img[index_plus_1][j])>>1)*p_coeff[fi]);
                                   }

                                   img[i+(layer_size>>1)][j]+=32;
               img[i+(layer_size>>1)][j]=(PROCESS_UNIT)(img[i+(layer_size>>1)][j]>>6);
               img[i+(layer_size>>1)][j]+=(tmp_img[2*i][j]-tmp_img[2*i+1][j]);
                              }
                         }
                    }
                    }

                    if((out_file=fopen(argv[4],"wb"))==NULL)
                    {
                         printf("can't open out_put file %s\n",argv[4]);
                         exit(1);
                    }

                    {
                         SAVE_UNIT tmp;
                         for(i=0; i<N; i++){
                              for(j=0; j<N; j++){
                                   tmp=(SAVE_UNIT)(img[i][j]);
                                   fwrite(&tmp,sizeof(SAVE_UNIT),1,out_file);
                              }
                         }
                    }
                    fclose(out_file);
}







error
1. line 7 F:\tt.cpp expected unqualified-id before '{' token
2. line7 F:\tt.cpp expected `,' or `;' before '{' token
3. line 27 F:\tt.cpp `main' must return `int'
0
 
Kent OlsenData Warehouse Architect / DBACommented:

That's a very strange way to define the matrix_allocate macro.  It appears that you really want to create a function and prototype.  If so, put a prototype in the code shortly after the #include statements and other macros.

matrix_allocate(matrix, hor_size, ver_size, TYPE) ;

Then define the function like any other:

#define matrix_allocate(matrix, hor_size, ver_size, TYPE)
{
...
}


Kent
0
 
gorexyAuthor Commented:
can u use my code and make the changes?
I cannot get exactly what you mean
0
 
Infinity08Commented:
And in case you do want a macro, don't forget to use \'s at each macro line break !! A multi-line macro has to be like this :

#define MULTI_LINE_MACRO  \
     line 1                               \
     line 2                               \
     line 3

And don't forget that the return type of main must be int, not void.
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Looking further, it appears that you're trying to define this as a macro to cause the code to be expanded within the outer function.  C doesn't let you do it this way, but it does support the functionality.

Create the prototype and define the function with the INLINE modifier:

inline matrix_allocate(matrix, hor_size, ver_size, TYPE) ;

Then define the function like any other:

inline matrix_allocate(matrix, hor_size, ver_size, TYPE)
{
...
}

Apologies, I should have dropped the keyword '#define' in my previous example.
Kent

0
 
gorexyAuthor Commented:
sorry i test but fail

do u mind to copy my code and try in your complier?
0
 
Infinity08Commented:
>> do u mind to copy my code and try in your complier?
who are you talking to ? Kdo, or me ?

If me : just add a \ at the end of each macro line, and change the main return type to int
But imo, changing the macro to an inline function (as Kdo suggested) is a lot better !



Just another side note : you're doing several memory allocations, but never a free !!
0
 
Kent OlsenData Warehouse Architect / DBACommented:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SAVE_UNIT short
#define PROCESS_UNIT short
matrix_allocate(matrix, hor_size, ver_size, TYPE) ;

matrix_allocate(matrix, hor_size, ver_size, TYPE)
{
 
TYPE *imptr;
  int _i;
  matrix=(TYPE **)calloc((unsigned long)ver_size,sizeof(TYPE *));
  imptr=(TYPE*)calloc(((unsigned long)hor_size)*((unsigned long)ver_size),sizeof(TYPE));
  if (imptr==NULL){
        printf("\nNo Memory in matrix allocate");
        exit(-1);
                    }
  for (_i=0; _i<ver_size; ++_i,imptr+=hor_size)
       matrix[_i]=imptr;

}

FILE *in_file, *out_file;
  PROCESS_UNIT **img, **tmp_img;
  int dl,N;

  main (int argc, char *argv[])
  {
.......  // remainder of code
0
 
gorexyAuthor Commented:
Infinity08/Kdo
I am using DevC++ to complie but seems doesn;t work

0
 
Kent OlsenData Warehouse Architect / DBACommented:

Whoops...

I'm trying to run too fast.   :~}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SAVE_UNIT short
#define PROCESS_UNIT short

matrix_allocate (TYPE**matrix, int hor_size, int ver_size) ;

matrix_allocate (TYPE **matrix, int hor_size, int ver_size)
{
 
TYPE *imptr;
  int _i;
  matrix=(TYPE **)calloc((unsigned long)ver_size,sizeof(TYPE *));
  imptr=(TYPE*)calloc(((unsigned long)hor_size)*((unsigned long)ver_size),sizeof(TYPE));
  if (imptr==NULL){
        printf("\nNo Memory in matrix allocate");
        exit(-1);
                    }
  for (_i=0; _i<ver_size; ++_i,imptr+=hor_size)
       matrix[_i]=imptr;

}

FILE *in_file, *out_file;
  PROCESS_UNIT **img, **tmp_img;
  int dl,N;

  main (int argc, char *argv[])
  {
.......  // remainder of code
0
 
gorexyAuthor Commented:
Kdo,
 I just copy and paste your code and compile I got errors

6 F:\tt.cpp expected constructor, destructor, or type conversion before '(' token
6 F:\tt.cpp expected `,' or `;' before '(' token
 F:\tt.cpp In function `int main(int, char**)':
41 F:\tt.cpp expected primary-expression before "short"
41 F:\tt.cpp `matrix_allocate' undeclared (first use this function)
  (Each undeclared identifier is reported only once for each function it appears in.)
42 F:\tt.cpp expected primary-expression before "short"
0
 
cwwkieCommented:
>> #define matrix_allocate(matrix, hor_size, ver_size, TYPE)

If you want to use your matrix_allocate function for different types, you have to use a #define, in the way Infinity08 has explained (http:#17043139)


If it is fine if it is just working for short, you can use the code from Kdo  (http:#17043317) with these modifications:

#define SAVE_UNIT short
#define PROCESS_UNIT short
#define TYPE short

void matrix_allocate (TYPE**matrix, int hor_size, int ver_size) ;

void matrix_allocate (TYPE **matrix, int hor_size, int ver_size)
{
    .......  // remainder of code
0
 
gorexyAuthor Commented:
now the code becomes:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SAVE_UNIT short
#define PROCESS_UNIT short
#define TYPE short
void matrix_allocate (TYPE**matrix, int hor_size, int ver_size, TYPE);
void matrix_allocate (TYPE**matrix, int hor_size, int ver_size, TYPE){
//void matrix_allocate(matrix, hor_size, ver_size, TYPE) {
  TYPE *imptr;
  int _i;
  matrix=(TYPE **)calloc((unsigned long)ver_size,sizeof(TYPE *));
  imptr=(TYPE*)calloc(((unsigned long)hor_size)*((unsigned long)ver_size),sizeof(TYPE));
  if (imptr==NULL){
         printf("\nNo Memory in matrix allocate");
         exit(-1);
                        }
  for (_i=0; _i<ver_size; ++_i,imptr+=hor_size)
          matrix[_i]=imptr;
  }


  FILE *in_file, *out_file;
  PROCESS_UNIT **img, **tmp_img;
  int dl,N;

int main (int argc, char *argv[])
  {
          int i,j;
            printf("Forward TT transform\n");
                  if(argc<5)
                  {
                        printf("Usage:\tt <in_file> <file size> <decomp layers> <out_file>\n");
                        exit(1);
                  }
                  N=atoi(argv[2]);
                  dl=atoi(argv[3]);
                  
                  matrix_allocate(img,N,N,PROCESS_UNIT);
                  matrix_allocate(tmp_img,N,N,PROCESS_UNIT);
       
                  if ((in_file=fopen(argv[1],"rb"))==NULL)
                  {
                        printf("Binary image doesn't exist\n");
                        exit(1);
                  }

                  for(i=0; i<N; i++)
                        for(j=0; j<N; j++)
                              img[i][j]=(PROCESS_UNIT) fgetc(in_file);
                        fclose(in_file);

                        /****TT transform****/

                        { int layer,layer_size,s_coeffs=2,p_coeffs=5,fi,index,index_plus_1;

                        PROCESS_UNIT p_coeff[5]={3,-22,0,22,-3};
                        printf("\n%d,%d,%d,%d,%d\n",p_coeff[0],p_coeff[1],p_coeff[2],p_coeff[3],p_coeff[4],p_coeff[5]);

                        layer_size=2*N;
                        for(layer=0; layer<dl-1; layer++){
                              layer_size=(layer_size>>1);
                              for(i=0;i<layer_size;i++){
                                    for(j=0;j<(layer_size>>1);j++){
                                          tmp_img[i][j]=0;
                                          for(fi=0; fi<s_coeffs; fi++){
                                                index=2*j+fi;
                                                if(index>layer_size-1)
                                                      index=layer_size-1;
                                                tmp_img[i][j]+=img[i][index];
                                          }

                                          tmp_img[i][j]=(PROCESS_UNIT)(tmp_img[i][j]>>1);
                                          tmp_img[i][j+(layer_size>>1)]=0;
                                          for(fi=0; fi<p_coeffs;fi++){
                                                index=2*j+2*fi-4;
                                                index_plus_1=index+1;
                                                if(index>layer_size-1){
                                                      index=layer_size-(index-(layer_size-1));
                                                      index_plus_1=index-1;
                                                }
                                                if(index<0){
                                                      index=-index;
                                                      index_plus_1=index+1;
                                                }

                                                tmp_img[i][j+(layer_size>>1)]+=(PROCESS_UNIT)(((img[i][index]+img[i][index_plus_1])>>1)*p_coeff[fi]);}
                                          tmp_img[i][j+(layer_size>>1)]+=32;

                                          tmp_img[i][j+(layer_size>>1)]=(PROCESS_UNIT)(tmp_img[i][j+(layer_size>>1)]>>6);
                                          tmp_img[i][j+(layer_size>>1)]+=(img[i][2*j]-img[i][2*j+1]);
                                    }
                              }

                              for(j=0; j<layer_size; j++){
                                    for(i=0; i<(layer_size>>1); i++){
                                          img[i][j]=0;
                                          for(fi=0;fi<s_coeffs; fi++){
                                                index=2*i+fi;

                                                if(index>layer_size-1)
                                                      index=layer_size-1;
                                                img[i][j]+=tmp_img[index][j];
                                          }
                                          img[i][j]=(PROCESS_UNIT)(img[i][j]>>1);

                                          img[i+(layer_size>>1)][j]=0;
                                          for(fi=0; fi<p_coeffs; fi++){
                                                index=2*i+2*fi-4;
                                                index_plus_1=index+1;
                                                if(index>layer_size-1){
                                                      index=layer_size-(index-(layer_size-1));
                                                      index_plus_1=index-1;
                                                }
                                                if(index<0){
                                                      index=-index;
                                                      index_plus_1=index+1;
                                                }
                  img[i+(layer_size>>1)][j]+=(PROCESS_UNIT)(((tmp_img[index][j]+tmp_img[index_plus_1][j])>>1)*p_coeff[fi]);
                                          }

                                          img[i+(layer_size>>1)][j]+=32;
                  img[i+(layer_size>>1)][j]=(PROCESS_UNIT)(img[i+(layer_size>>1)][j]>>6);
                  img[i+(layer_size>>1)][j]+=(tmp_img[2*i][j]-tmp_img[2*i+1][j]);
                                    }
                              }
                        }
                        }

                        if((out_file=fopen(argv[4],"wb"))==NULL)
                        {
                              printf("can't open out_put file %s\n",argv[4]);
                              exit(1);
                        }

                        {
                              SAVE_UNIT tmp;
                              for(i=0; i<N; i++){
                                    for(j=0; j<N; j++){
                                          tmp=(SAVE_UNIT)(img[i][j]);
                                          fwrite(&tmp,sizeof(SAVE_UNIT),1,out_file);
                                    }
                              }
                        }
                        fclose(out_file);
                        }


3 errors:

 D:\ctest\TT.cpp In function `int main(int, char**)':
39 D:\ctest\TT.cpp expected primary-expression before "short" (matrix_allocate(img,N,N,PROCESS_UNIT);)

40 D:\ctest\TT.cpp expected primary-expression before "short" (                  matrix_allocate(tmp_img,N,N,PROCESS_UNIT);)
0
 
NopiusCommented:
You can't pass type name 'short' as a parameter to the function.

Try to modify (remove last parameter at all):
void matrix_allocate (TYPE**matrix, int hor_size, int ver_size){

then change two calls:
matrix_allocate(img,N,N,PROCESS_UNIT);
matrix_allocate(tmp_img,N,N,PROCESS_UNIT);

to

matrix_allocate(img,N,N);
matrix_allocate(tmp_img,N,N);
0
 
gorexyAuthor Commented:
oh it works...
but when I run it, application errors.
0
 
NopiusCommented:
first, it may fail because size of 'short' is not that you expect
0
 
Infinity08Commented:
>> but when I run it, application errors.
Does it also fail when you try my earlier solution ? ie. Use this :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SAVE_UNIT short
#define PROCESS_UNIT short
#define matrix_allocate(matrix, hor_size, ver_size, TYPE)    \
{    \
     \
TYPE *imptr;    \
  int _i;    \
  matrix=(TYPE **)calloc((unsigned long)ver_size,sizeof(TYPE *));    \
  imptr=(TYPE*)calloc(((unsigned long)hor_size)*((unsigned long)ver_size),sizeof(TYPE));    \
  if (imptr==NULL){    \
        printf("\nNo Memory in matrix allocate");    \
        exit(-1);    \
                    }    \
  for (_i=0; _i<ver_size; ++_i,imptr+=hor_size)    \
       matrix[_i]=imptr;    \
    \
}

FILE *in_file, *out_file;
  PROCESS_UNIT **img, **tmp_img;

//rest of the code ...


If that also fails with application errors, then there's a problem with your code ... please post the exact errors.
0
 
gorexyAuthor Commented:
ok now..
but yes maybe the code get problem when I read an image, it promotes error
would you like to try?
0
 
NopiusCommented:
I guess it's better to run debug session to see what is wrong now with the data processing.
0
 
gorexyAuthor Commented:
I remove the core part and try to see what happen

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SAVE_UNIT short
#define PROCESS_UNIT short
#define matrix_allocate(matrix, hor_size, ver_size, TYPE)    \
{    \
     \
TYPE *imptr;    \
  int _i;    \
  matrix=(TYPE **)calloc((unsigned long)ver_size,sizeof(TYPE *));    \
  imptr=(TYPE*)calloc(((unsigned long)hor_size)*((unsigned long)ver_size),sizeof(TYPE));    \
  if (imptr==NULL){    \
        printf("\nNo Memory in matrix allocate");    \
        exit(-1);    \
                    }    \
  for (_i=0; _i<ver_size; ++_i,imptr+=hor_size)    \
       matrix[_i]=imptr;    \
    \
}




FILE *in_file, *out_file;
PROCESS_UNIT **img, **tmp_img;
int dl,N;



void main (int argc, char *argv[])
{
     
          int i,j;
            printf("Forward TT transform\n");
                  if(argc<5)
                  {
                        printf("Usage:\tt <in_file> <file size> <decomp layers> <out_file>\n");
                        exit(1);
                  }
                  N=atoi(argv[2]);
                  dl=atoi(argv[3]);
                  
                  matrix_allocate(img,N,N,PROCESS_UNIT);
                  matrix_allocate(tmp_img,N,N,PROCESS_UNIT);
       
                  if ((in_file=fopen(argv[1],"rb"))==NULL)
                  {
                        printf("Binary image doesn't exist\n");
                        exit(1);
                  }
//////////////////////////////////////////////////////////////////////////
                  //for(i=0; i<N; i++)
                  //      for(j=0; j<N; j++)
                  //            img[i][j]=(PROCESS_UNIT) fgetc(in_file);
                  //      fclose(in_file);
//
                        
//////////////////////////////////////////////////////////////////
                        if((out_file=fopen(argv[4],"wb"))==NULL)
                        {
                              printf("can't open out_put file %s\n",argv[4]);
                              exit(1);
                        }

                        {
                              SAVE_UNIT tmp;
                              for(i=0; i<N; i++){
                                    for(j=0; j<N; j++){
                                          tmp=(SAVE_UNIT)(img[i][j]);
                                          fwrite(&tmp,sizeof(SAVE_UNIT),1,out_file);
                                    }
                              }
                        }
                        fclose(out_file);
}




but still get errors during running
0
 
NopiusCommented:
> but still get errors during running

What errors?
0
 
gorexyAuthor Commented:
when run in DOS, it prompts application errors
now I found that

when I remark  tmp=(SAVE_UNIT)(img[i][j]);, it  can run
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 5
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now