⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.cpp

📁 Jpeg2000在vxworks下的实现
💻 CPP
字号:
#include "vxworks.h"
#include "stdio.h"
#include <string.h>
#include <stdlib.h>
#include <iolib.h>



#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 <vxworks.h>
#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<para.height; y++)
{
  for( x=0; x<para.width; x++)
    {
       *pr=*ps;  ps++; pr++;
       *pg=*ps;  ps++; pg++;
       *pr=*ps;  ps++; pr++;
    }
}



    len=j2kEncode(&para,buf);
    printf("\n J2k Encode Ok!!\n");

    fj2k=open("test.j2k",O_RDWR|O_CREAT,0x777);	
    i= write(fj2k,(char*)buf,len);
    close(fj2k);

para.size=len;



printf("\n\n Decoding...............\n");

j2kDecode(&para,buf);



f=open("test11.raw",O_CREAT|O_RDWR,0x777);

pr=para.R;
pg=para.G;
pb=para.B;
for (y=0; y<para.height; y++)
{
  for( x=0; x<para.width; x++)
    {
         write(f,(char*)pb,1); pb++;
         write(f,(char*)pg,1); pg++;
         write(f,(char*)pr,1); pr++;
    }
}

close(f);


printf("\n Decode finished\n");
return ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -