This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

sarju savani

Greenhorn
+ Follow
since Sep 06, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sarju savani

Hello...

I have just entered in JNI world and facing some problem to working on it. I have read online tutorial from Sun Java website to understand JNI clearly. But getting poblem while writing implementation of C source code of my following code. I am giving whole detail whatever i have done so you could give me better answer of my question. I am very hopeful on you as i am not going ahead due to my poor knowladge to JNI and also in Java .

__________________________________________________________

1) First i made //Wsq.java //

___________________________________________________________

public class Wsq

{
// Native Method Declaration
public native int wsq_decode_mem(ImageParam param); // encoder.c


public native int wsq_encode_mem(ImageParam param); //decoder.c




//Load the library
static
{
System.loadLibrary("Wsq");
}



public static void main(String args[])
{
/* image characteristic parameters */
int width=336;
int height=512;
int depth=8;
int ppi=500;
byte[] odata = new byte [128];
byte[] idata = new byte [128];

/* Encode/compress the image pixmap. */
ImageParam param = new ImageParam(width, height, depth, ppi, idata, odata);

Wsq wsq = new Wsq ();
int ret = wsq.wsq_encode_mem(param);
}
}
_____________________________________________________

2) Then ,I have created Object class // ImageParam.java//
______________________________________________________


import java.lang.System;



public class ImageParam

{
privateint m_width = 336;
private int m_height = 512;
private int m_depth = 8;
private int m_ppi = 500;
private byte [] m_idata = null; /* image rawdata */
private byte [] m_odata = null; /* image wsqdata */



// Constructor

public ImageParam(int width, int height, int depth, int ppi, byte[] idata, byte[] odata)
{
m_width = width;
m_height = height;
m_depth = depth;
m_ppi = ppi;
m_idata = idata;
m_odata = odata;
}


// All Accessor methods

public final int getImageWidth()
{
return m_width;
}



public final int getImageHeight()
{
return m_height;
}



public final int getImageDepth()
{
return m_depth;
}


public final int getImagePpi()
{
return m_ppi;
}



public final byte [] getIdataContent()
{
return m_idata;
}


public final byte [] getOdataContent()
{
return m_odata;
}



// All Mutator Methods

public void setImageWidth(int width)
{
m_width=width;
}

public void setImageHeight(int height)
{
m_height=height;
}

public void setImageDepth(int depth)
{
m_depth=depth;
}

public void setImagePpi(int ppi)
{
m_ppi=ppi;
}


public void setIdataContent(byte[] idata) //idata
{
if (idata.length > 0)
{
m_idata = new byte [idata.length];
System.arraycopy (idata, 0, m_idata, 0, idata.length);
}
}


public void setWsqOdataContent(byte[] odata) //odata
{
if (odata.length > 0)
{
m_odata = new byte [odata.length];
System.arraycopy (odata, 0, m_odata, 0, odata.length);
}
}

}

_________________________________________________________

3) Then , I compiled Wsq.java and it has been compiled without any error . So i am having wsq.class and ImageParam.Class file

Afterthat, I have created headerfile using javah -jni Wsq command. And it has been also generated . So i am also having wsq.h file .

________________________________________________________

Machine generated headerfile // Wsq.h //

_________________________________________________________

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>

/* Header for class com_axa_wsq_Wsq */

#ifndef _Included_com_axa_wsq_Wsq
#define _Included_com_axa_wsq_Wsq

#ifdef __cplusplus
extern "C" {
#endif

/*

* Class: com_axa_wsq_Wsq

* Method: wsq_decode_mem

* Signature: (Lcom/axa/wsq/ImageParam I

*/

JNIEXPORT jint JNICALL Java_com_axa_wsq_Wsq_wsq_1decode_1mem

(JNIEnv *, jobject, jobject);


/*

* Class: Wsq

* Method: wsq_encode_mem

* Signature: (Lcom/axa/wsq/ImageParam I

*/


JNIEXPORT jint JNICALL Java_com_axa_wsq_Wsq_wsq_1encode_1mem

(JNIEnv *, jobject, jobject);


#ifdef __cplusplus
}
#endif

#endif


__________________________________________________________

5) Then , I am writing Implementaion of Wsq.c file And here i am facing the problem like ???..... First i would like to show you my Wsq.c file implementation whatever i have cwritten , it is still incompleted as dont know what to do ?



// Wsq.c //

__________________________________________________________

#include <jni.h>
#include "com_axa_wsq_Wsq.h"
#include <stdio.h>
JNIEXPORT jint JNICALL Java_com_axa_wsq_Wsq_wsq_1decode_1mem(JNIEnv *env, jobject obj, jobject param)
{

jclass cls;
jmethodID mid;
jbyteArray byteArray;


/*********************************************/
/* Get a class reference to ImageParam Class */
/*********************************************/

cls = (*env)->GetObjectClass(env, param);
if(cls == NULL)
{
printf("Class Not Found [com_axa_wsq_ImageParam]\n");
return;
}
else
printf(" - Class Loaded\n");


/**************************************/
/* Invoke method getImageWidth */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "getImageWidth", "()I");
if (mid == 0)
{
printf("Method [getImageWidth(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallIntMethod(env, obj, mid);
printf(" - Method [setImageWidth] Invoked\n");



/**************************************/
/* Invoke method getImageHeight */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "getImageHeight", "()I");
if (mid == 0)
{
printf("Method [getImageHeight(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallIntMethod(env, obj, mid);
printf(" - Method [getImageHeight] Invoked\n");


/**************************************/
/* Invoke method getImageDepth */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "getImageDepth", "()I");
if (mid == 0)
{
printf("Method [getImageDepth(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallIntMethod(env, obj, mid);
printf(" - Method [getImageDepth] Invoked\n");


/**************************************/
/* Invoke method getImagePpi */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "getImagePpi", "()V");
if (mid == 0)
{
printf("Method [getImagePpi(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallIntMethod(env, obj, mid);
printf(" - Method [getImagePpi] Invoked\n");

/**************************************/
/* Invoke method getIdataContent */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "getIdataContent", "()[B");
if (mid == 0)
{
printf("Method [getIdataContent(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallByteMethod(env, obj, mid);
printf(" - Method [getIdataContent] Invoked\n");



byteArray = (*env)->CallIntMethod(env, obj, mid);




/**************************************/
/* Invoke method getOdataContent */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "getOdataContent", "()[B");
if (mid == 0)
{
printf("Method [getOdataContent(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallByteMethod(env, obj, mid);
printf(" - Method [getOdataContent] Invoked\n");


/**************************************/
/* Invoke method setImageWidth */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "setImageWidth", "(I)V");
if (mid == 0)
{
printf("Method [setImageWidth(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallVoidMethod(env, obj, mid, width);
printf(" - Method [setImageWidth] Invoked\n");



/**************************************/
/* Invoke method setImageHidth */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "setImageHeight", "(I)V");
if (mid == 0)
{
printf("Method [setImageHeight(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallVoidMethod(env, obj, mid, height);
printf(" - Method [setImageHeight] Invoked\n");


/**************************************/
/* Invoke method setImageDepth */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "setImageDepth", "(I)V");
if (mid == 0)
{
printf("Method [setImageDepth(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallVoidMethod(env, obj, mid, depth);
printf(" - Method [setImageDepth] Invoked\n");


/**************************************/
/* Invoke method setImagePpi OK */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "setImagePpi", "(I)V");
if (mid == 0)
{
printf("Method [setImagePpi(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallVoidMethod(env, obj, mid, ppi);
printf(" - Method [setImagePpi] Invoked\n");




/**************************************/
/* Invoke method setIdataContent OK */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "setIdataContent", "(B)V");
if (mid == 0)
{
printf("Method [setIdataContent(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallVoidMethod(env, obj, mid, odata);
printf(" - Method [setIdataContent] Invoked\n");



/**************************************/
/* Invoke method setOdataContent OK */
/**************************************/

mid = (*env)->GetMethodID(env, cls, "setOdataContent", "(B)V");
if (mid == 0)
{
printf("Method [setIdataContent(int)] Not Found into [com_axa_wsq_ImageParam]] Class\n");
return;
}

(*env)->CallVoidMethod(env, obj, mid, null );
printf(" - Method [setOdataContent] Invoked\n");




}






JNIEXPORT jint JNICALL Java_com_axalto_wsq_Wsq_wsq_1encode_1mem((JNIEnv env*, jobject obj, jobject param)


??? // I will write afterwards but before i would like to ask several question .....


_________________________________________________________

So Now my question is you think that i am going on write direction . Should i need to call all get and set method which i declareed in my ImageParam.java class (Means its compulsary to call all those methods or its depends on my requirement). I also want to know that i need to pass GetByteArrayElements() JNI function in my WSQ.c code but dont know how ? Could you help me means what i need to declare in Wsq.c class. I am very very hopeful on you . Pleas give me an answer of my questions.

Thanx in advance

Nishu,



_____________________________________________________


SOme more files i am attaching here , may be it will help you to understand more about my code .
________________________________________________________


_______________________

encoder.c

_______________________


/*****************/
/* Include files */
/*****************/

#include <stdio.h>
#include <wsq.h>
#include <img_io.h>



int debug = 1;

int main(int argc, char *argv[])
{
unsigned char *odata; /* Output data */
int olen; /* Number of bytes in output data. */
float r_bitrate=.75; /* target bit compression rate */
unsigned char *idata; /* Input data */
int width=336;
int height=512; /* image characteristic parameters */
int depth=8;
int ppi=500;
int ret;

int rawflag=1; /* input image flag: 1 == Raw, 0 == IHead */

char *ifile="test.raw";
char *ofile="test.wsq"; /* Input/Output filenames */
IHEAD *ihead; /* Ihead pointer */

/* Read the image into memory (IHead or raw pixmap). */
if(ret = read_raw_or_ihead_wsq(!rawflag, ifile,
&ihead, &idata, &width, &height, &depth))
exit(ret);

if(debug > 0)
fprintf(stdout, "File %s read\n", ifile);


/* Encode/compress the image pixmap. */
if(ret = wsq_encode_mem(&odata, &olen, r_bitrate,
idata, width, height, depth, ppi, (char*)NULL)){
free(idata);
exit(ret);
}

free(idata);

if(debug > 0)
fprintf(stdout, "Image data encoded, compressed byte length = %d\n",
olen);

if(ret = write_raw_from_memsize(ofile, odata, olen)){
free(odata);
exit(ret);
}

free(odata);

/* Exit normally. */
exit(0);
}


____________________

Decoder.c

____________________


#include <stdio.h>
#include <wsq.h>
#include <img_io.h>

int debug = 1;

main(argc,argv)
int argc;
char **argv;
{
int ret;
IHEAD *ihead; /* Ihead pointer */
int rawflag=1; /* raw input data or Ihead image */
char *outext; /* ouput file extension */
char *ifile="test.wsq";
char *ofile="test.raw"; /* file names */
int ilen;
int width;
int height; /* image parameters */
int depth;
int ppi;
unsigned char *idata, *odata; /* image pointers */
int lossyflag; /* data loss flag */
NISTCOM *nistcom; /* NIST Comment */
char *ppi_str;


if(ret = read_raw_from_filesize(ifile, &idata, &ilen))
exit(ret);

if(ret = wsq_decode_mem(&odata, &width, &height, &depth, &ppi,
&lossyflag, idata, ilen)){
free(idata);
exit(ret);
}

if(debug > 1)
fprintf(stderr, "Image pixmap constructed\n");


if(ret = getc_nistcom_wsq(&nistcom, idata, ilen)){
free(idata);
exit(ret);
}
free(idata);

if(ret = write_raw_or_ihead(!rawflag, ofile,
odata, width, height, depth, ppi)){
free(odata);
exit(ret);
}
free(odata);

if(debug > 1)
fprintf(stdout, "Image pixmap written to %s\n", ofile);

exit(0);
}
15 years ago
Hello friends,

I m working on JNI and i have never worked before on java technolgy. So i dont have so much more experience to java programming. So could please help me in this regard.

I have application and libraries written in C programming language and i wish to make it accessible with java code. I have already read tutorial in JNI from sunjava website but still some facing some problem as i am not comfortable with java Programming. I am explaing my problem here:

I have two source file : encoder.c and decoder.c and i want to convert only below two methods to JNI.

encoder.c
-----------

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <wsq.h>
#include <dataio.h>


int wsq_encode_mem(unsigned char **odata, int *olen, const float r_bitrate,
unsigned char *idata, const int w, const int h,
const int d, const int ppi, char *comment_text)
{
int ret, num_pix;
float *fdata; /* floating point pixel image */
float m_shift, r_scale; /* shift/scale parameters */
short *qdata; /* quantized image pointer */
int qsize, qsize1, qsize2, qsize3; /* quantized block sizes */
unsigned char *huffbits, *huffvalues; /* huffman code parameters */
HUFFCODE *hufftable; /* huffcode table */
unsigned char *huff_buf; /* huffman encoded buffer */
int hsize, hsize1, hsize2, hsize3; /* Huffman coded blocks sizes */
unsigned char *wsq_data; /* compressed data buffer */
int wsq_alloc, wsq_len; /* number of bytes in buffer */
int block_sizes[2];

/* Compute the total number of pixels in image. */
num_pix = w * h;

/* Allocate floating point pixmap. */
if((fdata = (float *) malloc(num_pix*sizeof(float))) == NULL) {
fprintf(stderr,"ERROR : wsq_encode_1 : malloc : fdata\n");
return(-10);
}

/* Convert image pixels to floating point. */
conv_img_2_flt(fdata, &m_shift, &r_scale, idata, num_pix);

if(debug > 0)
fprintf(stderr, "Input image pixels converted to floating point\n\n");

/* Build WSQ decomposition trees */
build_wsq_trees(w_tree, W_TREELEN, q_tree, Q_TREELEN, w, h);

if(debug > 0)
fprintf(stderr, "Tables for wavelet decomposition finished\n\n");

/* WSQ decompose the image */
if(ret = wsq_decompose(fdata, w, h, w_tree, W_TREELEN,
hifilt, MAX_HIFILT, lofilt, MAX_LOFILT)){
free(fdata);
return(ret);
}

if(debug > 0)
fprintf(stderr, "WSQ decomposition of image finished\n\n");

/* Set compression ratio and 'q' to zero. */
quant_vals.cr = 0;
quant_vals.q = 0.0;
/* Assign specified r-bitrate into quantization structure. */
quant_vals.r = r_bitrate;
/* Compute subband variances. */
variance(&quant_vals, q_tree, Q_TREELEN, fdata, w, h);

if(debug > 0)
fprintf(stderr, "Subband variances computed\n\n");

/* Quantize the floating point pixmap. */
if(ret = quantize(&qdata, &qsize, &quant_vals, q_tree, Q_TREELEN,
fdata, w, h)){
free(fdata);
return(ret);
}

/* Done with floating point wsq subband data. */
free(fdata);

if(debug > 0)
fprintf(stderr, "WSQ subband decomposition data quantized\n\n");

/* Compute quantized WSQ subband block sizes */
quant_block_sizes(&qsize1, &qsize2, &qsize3, &quant_vals,
w_tree, W_TREELEN, q_tree, Q_TREELEN);

if(qsize != qsize1+qsize2+qsize3){
fprintf(stderr,
"ERROR : wsq_encode_1 : problem w/quantization block sizes\n");
return(-11);
}

/* Allocate a WSQ-encoded output buffer. Allocate this buffer */
/* to be the size of the original pixmap. If the encoded data */
/* exceeds this buffer size, then throw an error because we do */
/* not want our compressed data to be larger than the original */
/* image data. */
wsq_data = (unsigned char *)malloc(num_pix);
if(wsq_data == (unsigned char *)NULL){
free(qdata);
fprintf(stderr, "ERROR : wsq_encode_1 : malloc : wsq_data\n");
return(-12);
}
wsq_alloc = num_pix;
wsq_len = 0;

/* Add a Start Of Image (SOI) marker to the WSQ buffer. */
if(ret = putc_ushort(SOI_WSQ, wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
return(ret);
}

if(ret = putc_nistcom_wsq(comment_text, w, h, d, ppi, 1 /* lossy */,
r_bitrate, wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
return(ret);
}

/* Store the Wavelet filter taps to the WSQ buffer. */
if(ret = putc_transform_table(lofilt, MAX_LOFILT,
hifilt, MAX_HIFILT,
wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
return(ret);
}

/* Store the quantization parameters to the WSQ buffer. */
if(ret = putc_quantization_table(&quant_vals,
wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
return(ret);
}

/* Store a frame header to the WSQ buffer. */
if(ret = putc_frame_header_wsq(w, h, m_shift, r_scale,
wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
return(ret);
}

if(debug > 0)
fprintf(stderr, "SOI, tables, and frame header written\n\n");

/* Allocate a temporary buffer for holding compressed block data. */
/* This buffer is allocated to the size of the original input image, */
/* and it is "assumed" that the compressed blocks will not exceed */
/* this buffer size. */
huff_buf = (unsigned char *)malloc(num_pix);
if(huff_buf == (unsigned char *)NULL) {
free(qdata);
free(wsq_data);
fprintf(stderr, "ERROR : wsq_encode_1 : malloc : huff_buf\n");
return(-13);
}

/******************/
/* ENCODE Block 1 */
/******************/
/* Compute Huffman table for Block 1. */
if(ret = gen_hufftable_wsq(&hufftable, &huffbits, &huffvalues,
qdata, &qsize1, 1)){
free(qdata);
free(wsq_data);
free(huff_buf);
return(ret);
}

/* Store Huffman table for Block 1 to WSQ buffer. */
if(ret = putc_huffman_table(DHT_WSQ, 0, huffbits, huffvalues,
wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
free(huff_buf);
free(huffbits);
free(huffvalues);
free(hufftable);
return(ret);
}
free(huffbits);
free(huffvalues);

if(debug > 0)
fprintf(stderr, "Huffman code Table 1 generated and written\n\n");

/* Compress Block 1 data. */
if(ret = compress_block(huff_buf, &hsize1, qdata, qsize1,
MAX_HUFFCOEFF, MAX_HUFFZRUN, hufftable)){
free(qdata);
free(wsq_data);
free(huff_buf);
free(hufftable);
return(ret);
}
/* Done with current Huffman table. */
free(hufftable);

/* Accumulate number of bytes compressed. */
hsize = hsize1;

/* Store Block 1's header to WSQ buffer. */
if(ret = putc_block_header(0, wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
free(huff_buf);
return(ret);
}

/* Store Block 1's compressed data to WSQ buffer. */
if(ret = putc_bytes(huff_buf, hsize1, wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
free(huff_buf);
return(ret);
}

if(debug > 0)
fprintf(stderr, "Block 1 compressed and written\n\n");

/******************/
/* ENCODE Block 2 */
/******************/
/* Compute Huffman table for Blocks 2 & 3. */
block_sizes[0] = qsize2;
block_sizes[1] = qsize3;
if(ret = gen_hufftable_wsq(&hufftable, &huffbits, &huffvalues,
qdata+qsize1, block_sizes, 2)){
free(qdata);
free(wsq_data);
free(huff_buf);
return(ret);
}

/* Store Huffman table for Blocks 2 & 3 to WSQ buffer. */
if(ret = putc_huffman_table(DHT_WSQ, 1, huffbits, huffvalues,
wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
free(huff_buf);
free(huffbits);
free(huffvalues);
free(hufftable);
return(ret);
}
free(huffbits);
free(huffvalues);

if(debug > 0)
fprintf(stderr, "Huffman code Table 2 generated and written\n\n");

/* Compress Block 2 data. */
if(ret = compress_block(huff_buf, &hsize2, qdata+qsize1, qsize2,
MAX_HUFFCOEFF, MAX_HUFFZRUN, hufftable)){
free(qdata);
free(wsq_data);
free(huff_buf);
free(hufftable);
return(ret);
}

/* Accumulate number of bytes compressed. */
hsize += hsize2;

/* Store Block 2's header to WSQ buffer. */
if(ret = putc_block_header(1, wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
free(huff_buf);
free(hufftable);
return(ret);
}

/* Store Block 2's compressed data to WSQ buffer. */
if(ret = putc_bytes(huff_buf, hsize2, wsq_data, wsq_alloc, &wsq_len)){
free(qdata);
free(wsq_data);
free(huff_buf);
free(hufftable);
return(ret);
}

if(debug > 0)
fprintf(stderr, "Block 2 compressed and written\n\n");

/******************/
/* ENCODE Block 3 */
/******************/
/* Compress Block 3 data. */
if(ret = compress_block(huff_buf, &hsize3, qdata+qsize1+qsize2, qsize3,
MAX_HUFFCOEFF, MAX_HUFFZRUN, hufftable)){
free(qdata);
free(wsq_data);
free(huff_buf);
free(hufftable);
return(ret);
}
/* Done with current Huffman table. */
free(hufftable);

/* Done with quantized image buffer. */
free(qdata);

/* Accumulate number of bytes compressed. */
hsize += hsize3;

/* Store Block 3's header to WSQ buffer. */
if(ret = putc_block_header(1, wsq_data, wsq_alloc, &wsq_len)){
free(wsq_data);
free(huff_buf);
return(ret);
}

/* Store Block 3's compressed data to WSQ buffer. */
if(ret = putc_bytes(huff_buf, hsize3, wsq_data, wsq_alloc, &wsq_len)){
free(wsq_data);
free(huff_buf);
return(ret);
}

if(debug > 0)
fprintf(stderr, "Block 3 compressed and written\n\n");

/* Done with huffman compressing blocks, so done with buffer. */
free(huff_buf);

/* Add a End Of Image (EOI) marker to the WSQ buffer. */
if(ret = putc_ushort(EOI_WSQ, wsq_data, wsq_alloc, &wsq_len)){
free(wsq_data);
return(ret);
}

if(debug >= 1) {
fprintf(stderr,
"hsize1 = %d :: hsize2 = %d :: hsize3 = %d\n", hsize1, hsize2, hsize3);
fprintf(stderr,"@ r = %.3f :: complen = %d :: ratio = %.1f\n",
r_bitrate, hsize, (float)(num_pix)/(float)hsize);
}

*odata = wsq_data;
*olen = wsq_len;

/* Return normally. */
return(0);
}

Decoder.c
----------

int wsq_decode_mem(unsigned char **odata, int *ow, int *oh, int *od, int *oppi,
int *lossyflag, unsigned char *idata, const int ilen)
{
int ret, i;
unsigned short marker; /* WSQ marker */
int num_pix; /* image size and counter */
int width, height, ppi; /* image parameters */
unsigned char *cdata; /* image pointer */
float *fdata; /* image pointers */
short *qdata; /* image pointers */
unsigned char *cbufptr; /* points to current byte in buffer */
unsigned char *ebufptr; /* points to end of buffer */


/* Set memory buffer pointers. */
cbufptr = idata;
ebufptr = idata + ilen;

/* Init DHT Tables to 0. */
for(i = 0; i < MAX_DHT_TABLES; i++)
(dht_table + i)->tabdef = 0;

/* Read the SOI marker. */
if(ret = getc_marker_wsq(&marker, SOI_WSQ, &cbufptr, ebufptr)){
return(ret);
}

/* Read in supporting tables up to the SOF marker. */
if(ret = getc_marker_wsq(&marker, TBLS_N_SOF, &cbufptr, ebufptr)){
return(ret);
}
while(marker != SOF_WSQ) {
if(ret = getc_table_wsq(marker, &dtt_table, &dqt_table, dht_table,
&cbufptr, ebufptr)){
return(ret);
}
if(ret = getc_marker_wsq(&marker, TBLS_N_SOF, &cbufptr, ebufptr)){
return(ret);
}
}

/* Read in the Frame Header. */
if(ret = getc_frame_header_wsq(&frm_header_wsq, &cbufptr, ebufptr)){
return(ret);
}
width = frm_header_wsq.width;
height = frm_header_wsq.height;
num_pix = width * height;

if(ret = getc_ppi_wsq(&ppi, idata, ilen))
return(ret);

if(debug > 0)
fprintf(stderr, "SOI, tables, and frame header read\n\n");

/* Build WSQ decomposition trees. */
build_wsq_trees(w_tree, W_TREELEN, q_tree, Q_TREELEN, width, height);

if(debug > 0)
fprintf(stderr, "Tables for wavelet decomposition finished\n\n");

/* Allocate working memory. */
qdata = (short *) malloc(num_pix * sizeof(short));
if(qdata == (short *)NULL) {
fprintf(stderr,"ERROR: wsq_decode_mem : malloc : qdata1\n");
return(-20);
}
/* Decode the Huffman encoded data blocks. */
if(ret = huffman_decode_data_mem(qdata, &dtt_table, &dqt_table, dht_table,
&cbufptr, ebufptr)){
free(qdata);
return(ret);
}

if(debug > 0)
fprintf(stderr,
"Quantized WSQ subband data blocks read and Huffman decoded\n\n");

/* Decode the quantize wavelet subband data. */
if(ret = unquantize(&fdata, &dqt_table, q_tree, Q_TREELEN,
qdata, width, height)){
free(qdata);
return(ret);
}

if(debug > 0)
fprintf(stderr, "WSQ subband data blocks unquantized\n\n");

/* Done with quantized wavelet subband data. */
free(qdata);

if(ret = wsq_reconstruct(fdata, width, height, w_tree, W_TREELEN,
&dtt_table)){
free(fdata);
return(ret);
}

if(debug > 0)
fprintf(stderr, "WSQ reconstruction of image finished\n\n");

cdata = (unsigned char *)malloc(num_pix * sizeof(unsigned char));
if(cdata == (unsigned char *)NULL) {
free(fdata);
fprintf(stderr,"ERROR: wsq_decode_mem : malloc : cdata\n");
return(-21);
}

/* Convert floating point pixels to unsigned char pixels. */
conv_img_2_uchar(cdata, fdata, width, height,
frm_header_wsq.m_shift, frm_header_wsq.r_scale);

/* Done with floating point pixels. */
free(fdata);

if(debug > 0)
fprintf(stderr, "Doubleing point pixels converted to unsigned char\n\n");


/* Assign reconstructed pixmap and attributes to output pointers. */
*odata = cdata;
*ow = width;
*oh = height;
*od = 8;
*oppi = ppi;
*lossyflag = 1;

/* Return normally. */
return(0);
}

-----------------------------------------------------------------------
And for this i have made one java file wsq.java and following things i have included to java file :

wsq.java

package com.axalto.wsq;

publi class Wsq
{

public native int wsq_decode_mem(Imageparam Param ); // decoder.c



public native int wsq_encode_mem(ImageParam param ); //encoder.c



static
{
System.loadLibrary("wsq");
}

}


ImageParam.java
---------------
public class ImageParam

{
private int width =336;
private int height =512;
private int depth; =8;
private int ppi; =500;
private byte outputdata[];
private byte inputdata[];
private int bufferlen;


But now i dont understand that how should i declared get/set method for this class . As i have never done programming in java before . So could you help me to make this class . Means what are the remaining things i should declared ??...

Plz help me ...
Thanx
15 years ago