static void adjust() { if (gs.vp.width < jas_image_width(gs.image) / gs.sx) { float mnx; float mxx; mnx = jas_image_tlx(gs.image) + 0.5 * gs.vp.width * gs.sx; mxx = jas_image_brx(gs.image) - 0.5 * gs.vp.width * gs.sx; if (gs.vcx < mnx) { gs.vcx = mnx; } else if (gs.vcx > mxx) { gs.vcx = mxx; } } else { gs.vcx = (jas_image_tlx(gs.image) + jas_image_brx(gs.image)) / 2.0; } if (gs.vp.height < jas_image_height(gs.image) / gs.sy) { float mny; float mxy; mny = jas_image_tly(gs.image) + 0.5 * gs.vp.height * gs.sy; mxy = jas_image_bry(gs.image) - 0.5 * gs.vp.height * gs.sy; if (gs.vcy < mny) { gs.vcy = mny; } else if (gs.vcy > mxy) { gs.vcy = mxy; } } else { gs.vcy = (jas_image_tly(gs.image) + jas_image_bry(gs.image)) / 2.0; } }
static void reshape(int w, int h) { if (cmdopts.verbose) { jas_eprintf("reshape(%d, %d)\n", w, h); dumpstate(); } if (pixmap_resize(&gs.vp, w, h)) { cleanupandexit(EXIT_FAILURE); } pixmap_clear(&gs.vp); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0, w, 0, h, 0.f, 1.f ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, 0); glRasterPos2i(0, 0); if (gs.vp.width > jas_image_width(gs.image) / gs.sx) { gs.vcx = (jas_image_tlx(gs.image) + jas_image_brx(gs.image)) / 2.0; } if (gs.vp.height > jas_image_height(gs.image) / gs.sy) { gs.vcy = (jas_image_tly(gs.image) + jas_image_bry(gs.image)) / 2.0; } gs.dirty = 1; }
int img_dat_generate(IMG_DAT **oimg_dat, jas_image_t *image) { IMG_DAT *img_dat; int i; int cmptscnt; int rwcnt; int max_hor, max_vrt; /* Allocate memory for image data structure. */ img_dat = (IMG_DAT *)calloc(1, sizeof(IMG_DAT)); if(img_dat == NULL){ fprintf(stderr, "ERROR : img_dat_generate : " "calloc : img_dat (%lu bytes)\n", (unsigned long)sizeof(IMG_DAT)); return(-2); } /* Get component count. */ cmptscnt = jas_image_numcmpts(image); /* Initialize img_dat info */ img_dat->max_width = jas_image_brx(image); img_dat->max_height = jas_image_bry(image); img_dat->ppi = -1; img_dat->intrlv = 0; img_dat->n_cmpnts = cmptscnt; img_dat->cmpnt_depth = jas_image_cmptprec(image, 0); max_hor = -1; max_vrt = -1; img_dat->pix_depth = 0; for(i = 0; i < cmptscnt; i++){ int cdepth; img_dat->hor_sampfctr[i] = 1; img_dat->vrt_sampfctr[i] = 1; cdepth = jas_image_cmptprec(image, i); img_dat->pix_depth += cdepth; if (cdepth != img_dat->cmpnt_depth) { fprintf(stderr, "WARNING : img_dat_generate: " "unequal component depths, 0: %d and %d: %d\n", i, cdepth, jas_image_cmptprec(image, i)); } if(max_hor < img_dat->hor_sampfctr[i]) max_hor = img_dat->hor_sampfctr[i]; if(max_vrt < img_dat->vrt_sampfctr[i]) max_vrt = img_dat->vrt_sampfctr[i]; } for(i = 0; i < img_dat->n_cmpnts; i++){ img_dat->samp_width[i] = (int)ceil(img_dat->max_width * (img_dat->hor_sampfctr[i]/(double)max_hor)); img_dat->samp_height[i] = (int)ceil(img_dat->max_height * (img_dat->vrt_sampfctr[i]/(double)max_vrt)); } /* Put the image raw pixels to image data sturcture component plains. */ cmptscnt = jas_image_numcmpts(image); for (i = 0; i < cmptscnt; i++){ jas_stream_rewind(image->cmpts_[i]->stream_); rwcnt = jas_stream_getrwcount(image->cmpts_[i]->stream_) - 1; img_dat->image[i] = (unsigned char *)malloc(rwcnt * sizeof(unsigned char)); if(img_dat->image[i] == NULL){ fprintf(stderr, "ERROR : get_raw_image: " "calloc : img_dat->image[%d] (%lu bytes)\n", i, (unsigned long)(rwcnt * sizeof(unsigned char))); return(-3); } jas_stream_read(image->cmpts_[i]->stream_, img_dat->image[i], rwcnt); } *oimg_dat = img_dat; return(0); }
static int loadimage() { int reshapeflag; jas_stream_t *in; int scrnwidth; int scrnheight; int vh; int vw; char *pathname; jas_cmprof_t *outprof; assert(!gs.image); assert(!gs.altimage); gs.image = 0; gs.altimage = 0; pathname = cmdopts.filenames[gs.filenum]; if (pathname && pathname[0] != '\0') { #if 1 jas_eprintf("opening %s\n", pathname); #endif /* The input image is to be read from a file. */ if (!(in = jas_stream_fopen(pathname, "rb"))) { jas_eprintf("error: cannot open file %s\n", pathname); goto error; } } else { /* The input image is to be read from standard input. */ in = streamin; } /* Get the input image data. */ if (!(gs.image = jas_image_decode(in, -1, 0))) { jas_eprintf("error: cannot load image data\n"); goto error; } /* Close the input stream. */ if (in != streamin) { jas_stream_close(in); } if (!(outprof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB))) goto error; if (!(gs.altimage = jas_image_chclrspc(gs.image, outprof, JAS_CMXFORM_INTENT_PER))) goto error; if ((scrnwidth = glutGet(GLUT_SCREEN_WIDTH)) < 0) { scrnwidth = 256; } if ((scrnheight = glutGet(GLUT_SCREEN_HEIGHT)) < 0) { scrnheight = 256; } vw = min(jas_image_width(gs.image), 0.95 * scrnwidth); vh = min(jas_image_height(gs.image), 0.95 * scrnheight); gs.vcx = (jas_image_tlx(gs.image) + jas_image_brx(gs.image)) / 2.0; gs.vcy = (jas_image_tly(gs.image) + jas_image_bry(gs.image)) / 2.0; gs.sx = 1.0; gs.sy = 1.0; if (gs.altimage) { gs.monomode = 0; } else { gs.monomode = 1; gs.cmptno = 0; } #if 1 jas_eprintf("num of components %d\n", jas_image_numcmpts(gs.image)); #endif if (vw < jas_image_width(gs.image)) { gs.sx = jas_image_width(gs.image) / ((float) vw); } if (vh < jas_image_height(gs.image)) { gs.sy = jas_image_height(gs.image) / ((float) vh); } if (gs.sx > gs.sy) { gs.sy = gs.sx; } else if (gs.sx < gs.sy) { gs.sx = gs.sy; } vw = jas_image_width(gs.image) / gs.sx; vh = jas_image_height(gs.image) / gs.sy; gs.dirty = 1; reshapeflag = 0; if (vw != glutGet(GLUT_WINDOW_WIDTH) || vh != glutGet(GLUT_WINDOW_HEIGHT)) { glutReshapeWindow(vw, vh); reshapeflag = 1; } if (cmdopts.title) { glutSetWindowTitle(cmdopts.title); } else { glutSetWindowTitle((pathname && pathname[0] != '\0') ? pathname : "stdin"); } /* If we reshaped the window, GLUT will automatically invoke both the reshape and display callback (in this order). Therefore, we only need to explicitly force the display callback to be invoked if the window was not reshaped. */ if (!reshapeflag) { glutPostRedisplay(); } if (cmdopts.tmout != 0) { glutTimerFunc(cmdopts.tmout, timer, gs.nexttmid); gs.activetmid = gs.nexttmid; ++gs.nexttmid; } return 0; error: unloadimage(); return -1; }
static void special(int key, int x, int y) { if (cmdopts.verbose) { jas_eprintf("special(%d, %d, %d)\n", key, x, y); } switch (key) { case GLUT_KEY_UP: { float oldvcy; float vh; float pan; if (gs.vp.height < jas_image_height(gs.image) / gs.sy) { pan = (glutGetModifiers() & GLUT_ACTIVE_SHIFT) ? BIGPAN : SMALLPAN; oldvcy = gs.vcy; vh = gs.sy * gs.vp.height; gs.vcy = max(gs.vcy - pan * vh, jas_image_tly(gs.image) + 0.5 * vh); if (gs.vcy != oldvcy) { gs.dirty = 1; glutPostRedisplay(); } } } break; case GLUT_KEY_DOWN: { float oldvcy; float vh; float pan; if (gs.vp.height < jas_image_height(gs.image) / gs.sy) { pan = (glutGetModifiers() & GLUT_ACTIVE_SHIFT) ? BIGPAN : SMALLPAN; oldvcy = gs.vcy; vh = gs.sy * gs.vp.height; gs.vcy = min(gs.vcy + pan * vh, jas_image_bry(gs.image) - 0.5 * vh); if (gs.vcy != oldvcy) { gs.dirty = 1; glutPostRedisplay(); } } } break; case GLUT_KEY_LEFT: { float oldvcx; float vw; float pan; if (gs.vp.width < jas_image_width(gs.image) / gs.sx) { pan = (glutGetModifiers() & GLUT_ACTIVE_SHIFT) ? BIGPAN : SMALLPAN; oldvcx = gs.vcx; vw = gs.sx * gs.vp.width; gs.vcx = max(gs.vcx - pan * vw, jas_image_tlx(gs.image) + 0.5 * vw); if (gs.vcx != oldvcx) { gs.dirty = 1; glutPostRedisplay(); } } } break; case GLUT_KEY_RIGHT: { float oldvcx; float vw; float pan; if (gs.vp.width < jas_image_width(gs.image) / gs.sx) { pan = (glutGetModifiers() & GLUT_ACTIVE_SHIFT) ? BIGPAN : SMALLPAN; oldvcx = gs.vcx; vw = gs.sx * gs.vp.width; gs.vcx = min(gs.vcx + pan * vw, jas_image_brx(gs.image) - 0.5 * vw); if (gs.vcx != oldvcx) { gs.dirty = 1; glutPostRedisplay(); } } } break; default: break; } }