#include "mdp.h" #if defined(__STDC__) || defined (__stdc__) void scale_pict(Pict,double,double); #else void scale_pict(); #endif double sx,sy; int fixedw = 0, fixedh = 0; void redraw(Widget w,XtPointer c,XtPointer a) { XPutImage(theDisp,pixmap,theGC,image,0,0,0,0, pict_width(pict),pict_height(pict)); } Pixmap load_pixmap(char *file_name,Widget parent) { Arg al[20]; Pict auxpict; int ac,i; Widget da,label; Pixmap pm; pict = pict_read_pict(file_name); if (fixedw>0) sx = fixedw/(double)pict_width(pict); if (fixedh>0) sy = fixedh/(double)pict_height(pict); scale_pict(pict,sx,sy); auxpict = pict_24_to_8(pict,mode,4,256-usedcolors); pict_free(pict); pict = auxpict; wide = pict_width(pict); high = pict_height(pict); ac = 0; /* XtSetArg(al[ac], XmNheight, wide); ac++;*/ /* XtSetArg(al[ac], XmNwidth, high); ac++;*/ da = XmCreateDrawingArea(parent,"d_area",al,ac); XtAddCallback(da,XmNexposeCallback,redraw,NULL); XtManageChild(da); for (i=0 ; ipixels[i] += usedcolors; pm = XCreatePixmap(theDisp,XtWindow(da),wide,high,theDepth); image = XCreateImage(theDisp,theVisual,8,ZPixmap,0, (char *)pict->pixels, wide,high,8,wide); ac = 0; XtSetArg(al[ac], XmNx, 0); ac++; XtSetArg(al[ac], XmNy, 0); ac++; /* XtSetArg(al[ac], XmNheight, high); ac++;*/ /* XtSetArg(al[ac], XmNwidth, wide); ac++;*/ XtSetArg(al[ac], XmNlabelType,XmPIXMAP); ac++; XtSetArg(al[ac], XmNlabelPixmap,pm); ac++; XtSetArg(al[ac], XmNlabelInsensitivePixmap,pm); ac++; label = XmCreateLabel(da,"label",al,ac); XtManageChild(label); XPutImage(theDisp,pm,theGC,image,0,0,0,0,wide,high); return pm; } #if defined(__STDC__) || defined (__stdc__) void scale_pict(Pict p,double sx,double sy) #else void scale_pict(p,sx,sy) Pict p; double sx; double sy; #endif { int nw,nh; U_char r00,g00,b00,a00; U_char r01,g01,b01,a01; U_char r10,g10,b10,a10; U_char r11,g11,b11,a11; U_char *buff,*pix; double ki,kj; double ri,rj,ri1,rj1; int oi,oj,di,dj; nw = (int)(sx*p->image_W); nh = (int)(sy*p->image_H); buff = (U_char *)malloc(4*(size_t)nw*nh+10); ki = (double)(p->image_W-1.0)/(double)(nw-1.0); kj = (double)(p->image_H-1.0)/(double)(nh-1.0); pix = buff; for (dj=0; djclr_mode != M_MONO) { *pix++ = ri1*rj1*r00+ri*rj1*r01+ri1*rj*r10+ri*rj*r11; *pix++ = ri1*rj1*g00+ri*rj1*g01+ri1*rj*g10+ri*rj*g11; *pix++ = ri1*rj1*b00+ri*rj1*b01+ri1*rj*b10+ri*rj*b11; *pix++ = ri1*rj1*a00+ri*rj1*a01+ri1*rj*a10+ri*rj*a11; } else { *pix++ = 255 - (ri1*rj1*r00+ri*rj1*r01+ri1*rj*r10+ri*rj*r11); } } } free(p->pixels); p->pixels = buff; p->image_W = nw; p->image_H = nh; if (p->clr_mode != M_MONO) { p->clr_mode = M_RGBA32; p->row_bytes = 4*nw; p->ctr_size = (p->row_bytes <= 250 ? BYTE : WORD); p->n_comp = 4; } }