Ejemplo n.º 1
0
JNIEXPORT jintArray JNICALL Java_nl_kb_jp2_JP2Reader_getTile
  (JNIEnv *env, jclass cls, jstring fname, jint tile_index, jint reduction_factor, jobjectArray pixels) {
    const char *filename = (*env)->GetStringUTFChars(env, fname, 0);
    jclass intArrayClass = (*env)->FindClass(env, "[I");
    jintArray ary = (*env)->NewIntArray(env, 3);

    int data[3];
    int i = 0;
    for(i = 0; i < 3; ++i) { data[i] = 0; }
    data[0] = READ_FAILURE;

    FILE *fptr = fopen(filename, "rb");
    if(fptr != NULL && is_jp2(fptr)) {
        opj_dparameters_t parameters;
        opj_set_default_decoder_parameters(&parameters);
        parameters.cp_reduce = reduction_factor;
        struct opj_res resources = opj_init(filename, &parameters);
        if(resources.status == 0 && opj_get_decoded_tile(resources.l_codec, resources.l_stream, resources.image, tile_index)) {
            int numpix = resources.image->comps[0].w * resources.image->comps[0].h;
            int comp;
            for(comp = 0; comp < resources.image->numcomps; ++comp) {
                jintArray data = (*env)->NewIntArray(env, numpix);
                (*env)->SetIntArrayRegion(env, data, (jsize) 0, (jsize) numpix, (jint*) resources.image->comps[comp].data);
                (*env)->SetObjectArrayElement(env, pixels, (jsize) comp, data);
            }
            data[0] = READ_SUCCESS;
            data[1] = resources.image->comps[0].w;
            data[2] = resources.image->comps[0].h;
        }
        opj_cleanup(&resources);
    }

    (*env)->SetIntArrayRegion(env, ary, 0, 3, data);
    return ary;
}
Ejemplo n.º 2
0
JNIEXPORT jintArray JNICALL Java_nl_kb_jp2_JP2Reader_getJp2Specs
  (JNIEnv *env, jclass cls, jstring fname) {

    const char *filename = (*env)->GetStringUTFChars(env, fname, 0);
    jintArray ary = (*env)->NewIntArray(env, FIELD_LEN);

    int data[FIELD_LEN];
    int i = 0;
    for(i = 0; i < FIELD_LEN; ++i) { data[i] = 0; }
    data[0] = READ_FAILURE;

    FILE *fptr = fopen(filename, "rb");
    if(fptr != NULL && is_jp2(fptr)) {
        opj_dparameters_t parameters;
        opj_set_default_decoder_parameters(&parameters);
        struct opj_res resources = opj_init(filename, &parameters);

        opj_codestream_info_v2_t* info = get_info(&resources);
        if(resources.status == 0) {
            data[0] = READ_SUCCESS;
            data[1] = resources.image->x1;
            data[2] = resources.image->y1;
            data[3] = info->tw;
            data[4] = info->th;
            data[5] = info->tdx;
            data[6] = info->tdy;
            data[7] = info->m_default_tile_info.tccp_info[0].numresolutions;
            data[8] = resources.image->numcomps;
        }
        opj_cleanup(&resources);
    } else {
        error_callback("Cannot read file:", NULL);
        error_callback(filename, NULL);
    }
    (*env)->SetIntArrayRegion(env, ary, 0, FIELD_LEN, data);
    return ary;
}
Ejemplo n.º 3
0
int image_type(int *img_type, unsigned char *idata, const int ilen)
{
   int ret;
   unsigned short marker;
   unsigned char *cbufptr, *ebufptr;
   char ihdr_size[SHORT_CHARS];
   unsigned char header[8];

   cbufptr = idata;
   ebufptr = idata + ilen;

   if((ret = getc_ushort(&marker, &cbufptr, ebufptr)))
      return(ret);
   if(marker == SOI_WSQ){
      *img_type = WSQ_IMG;
      return(0);
   } else  if(marker == SOI){
      if((ret = jpeg_type(img_type, idata, ilen)))
         return(ret);
      return(0);
   }

   sprintf(ihdr_size, "%d", IHDR_SIZE);
   if(strncmp((char *)idata, ihdr_size, strlen(ihdr_size)) == 0){
      *img_type = IHEAD_IMG;
      return(0);
   }

#ifdef __NBIS_PNG__
   memcpy(header, idata, 8);
   if (!(png_sig_cmp(header, 0, 8))){
      *img_type = PNG_IMG;
      return(0);
   }
#endif

#ifdef __NBIS_JASPER__
   if (is_jp2(idata, ilen) > 0){
      *img_type = JP2_IMG;
      return(0);
   }
#endif

#ifdef __NBIS_OPENJPEG__
   if (is_jp2(idata, ilen) > 0){
      *img_type = JP2_IMG;
      return(0);
   }
#endif


   ret = is_ANSI_NIST(idata, ilen);
   /* if system error */
   if(ret < 0)
      return(ret);
   if((ret == TRUE)){
      *img_type = ANSI_NIST_IMG;
      return(0);
   }

   /* Otherwise, image type is UNKNOWN ... */
   *img_type = UNKNOWN_IMG;

   return(0);
}