www.pudn.com > ±à½âÂëv1_01.rar > test.cpp


#include "vxworks.h" 
#include "stdio.h" 
#include  
#include  
#include  
 
 
 
#define  X  512 
#define  Y  512 
#define  RATE  10000 
 
#define  BYTE  unsigned char  
#define  LONG  long 
#define  DWORD unsigned long 
#define  WORD  unsigned short 
 
 
 
/* 
 
JPEG 2000 
Encode() 
para: describe the parameter , must be set correctly 
      image: RRRRRGGGGGGBBBBBB 
jBuf: buffer for coded Jpeg2000 bit streame. user should  initialize it 
 
return:if correctly encoded,     return length of bit streame. 
       if not correctly encoded, return a negative value 
attention: 
       it is users liability to allocate and release the jBuf and para memory 
        
*/ 
 
 
/* 
JPEG 2000 
Decode() 
Important:  The usr must fill in the para.size field!! 
 
para: describe the parameter , must be set correctly 
      image: RRRRRGGGGGGBBBBBB 
jBuf: buffer for coded Jpeg2000 bit streame. user should  initialize it 
 
return:if correctly encoded,     return length of bit streame. 
       if not correctly encoded, return a negative value 
       para->R/G/B: store the recoverd image data , unsigned char type, RRRRRGGGGGBBBBB format 
       if it's a gray level image, it was stored in the para->R field. 
 
attention:   it is user's task to release the image memory in the *para. 
             The image mem was allocated by Decoder,  
             User neednt to allocate or initialize the mem. 
*/ 
 
#include  
#include "j2k.hpp" 
 
 
 
 
void j() 
{ 
int fj2k; 
int fbmp; 
J2K_COMPRESS_PARA  para; 
unsigned char *buf; 
unsigned char *ps; 
unsigned char *pb,*pg,*pr; 
int x,y; 
int i,frag; 
int len; 
int f; 
  
buf=(unsigned char*)malloc(sizeof(char )*467*700*3); 
if (buf==NULL)   
  { 
    printf("\n alloc error!"); 
    return; 
  }; 
 
    fbmp=open("test.bmp",O_RDWR|O_CREAT,0x777);	 
    i= read(fbmp,(char*)buf,54); 
    i= read(fbmp,(char*)buf,para.width*para.height*3); 
    close(fbmp); 
 
para.width=640; 
para.height=480; 
para.format=0; 
para.depth=24;// for RGB bitmap, this is 24bits; for B/W bitmap, this is 8 bits 
para.headlen=54; 
para.size=15000;  
para.R=(unsigned char*)malloc(sizeof(char )*para.width*para.height); 
para.G=(unsigned char*)malloc(sizeof(char )*para.width*para.height); 
para.B=(unsigned char*)malloc(sizeof(char )*para.width*para.height); 
ps=buf; 
pb=para.B; 
pg=para.G; 
pr=para.R; 
 
for (y=0; y