~ubuntu-branches/ubuntu/gutsy/xmedcon/gutsy

« back to all changes in this revision

Viewing changes to source/xutils.c

  • Committer: Bazaar Package Importer
  • Author(s): Roland Marcus Rutschmann
  • Date: 2004-11-11 15:53:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041111155337-tgza2ptocg0g3wsj
Tags: 0.9.8.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 *                XMdcHandlerToHide()         - Hide widget (no delete)    *
24
24
 *                XMdcFreeRGB()               - Free RGB image             *
25
25
 *                XMdcToggleVisibility()      - Toggle widget visibility   *
 
26
 *                XMdcSetImageScales()        - Set width & height scale   *
 
27
 *                XMdcScaleW()                - Scale image width          *
 
28
 *                XMdcScaleH()                - Scale image height         *
26
29
 *                                                                         *
27
30
 * Note         : Algoritme for gamma/brightness/contrast correction in    *
28
31
 *                function XMdcSetGbcCorrection() copied from library      *
29
32
 *                Imlib by Rasterman                                       *
30
33
 *                                                                         *
31
34
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
32
 
/* $Id: xutils.c,v 1.19 2004/01/04 22:36:17 enlf Exp $
 
35
/* $Id: xutils.c,v 1.22 2004/10/21 23:48:39 enlf Exp $
33
36
 */
34
37
 
35
38
/*
274
277
  return(imgRGB);
275
278
}
276
279
 
277
 
GdkPixbuf *XMdcBuildGdkPixbuf(Uint8 *img8, Uint32 w, Uint32 h, Int16 type, Uint8 *vgbc, int RESIZE)
 
280
GdkPixbuf *XMdcBuildGdkPixbuf(Uint8 *img8, Uint32 w, Uint32 h, Int16 type, Uint8 *vgbc)
278
281
{
279
282
  GdkPixbuf *imtmp, *im;
280
283
  Uint8 *imgRGB;
290
293
                                         ,(int)(3*w),XMdcFreeRGB,NULL);
291
294
  if (imtmp == NULL) { MdcFree(imgRGB); return(NULL); }
292
295
 
293
 
  if (RESIZE && sResizeSelection.CurType != XMDC_RESIZE_ORIGINAL) {
294
 
    rw = (gint)XMdcResize(w); rh = (gint)XMdcResize(h);
 
296
  rw = (gint)XMdcScaleW(w); rh = (gint)XMdcScaleH(h);
 
297
 
 
298
  if ((rw != w) || (rh != h)) {
295
299
    im = gdk_pixbuf_scale_simple(imtmp,rw,rh,sRenderSelection.Interp);
296
300
    gdk_pixbuf_unref(imtmp);
297
301
  }else{
301
305
  return(im);
302
306
}
303
307
 
304
 
GdkPixbuf *XMdcBuildGdkPixbufFI(FILEINFO *fi,Uint32 i,Uint8 *vgbc,int RESIZE)
 
308
GdkPixbuf *XMdcBuildGdkPixbufFI(FILEINFO *fi,Uint32 i,Uint8 *vgbc)
305
309
{
306
310
   GdkPixbuf *im;
307
311
   Uint8 *img8;
316
320
   if (img8 == NULL)
317
321
     XMdcDisplayFatalErr(MDC_BAD_ALLOC,"Couldn't create byte image");
318
322
 
319
 
   im = XMdcBuildGdkPixbuf(img8, w, h, t, vgbc, RESIZE); 
 
323
   im = XMdcBuildGdkPixbuf(img8, w, h, t, vgbc);
320
324
 
321
325
   MdcFree(img8);
322
326
 
352
356
    gtk_widget_show(widget);
353
357
  }
354
358
}
 
359
 
 
360
void XMdcSetImageScales(void)
 
361
{
 
362
  my.scale_width = 1.; my.scale_height = 1.;
 
363
 
 
364
  if (my.fi->pixdim[1] > my.fi->pixdim[2]) {
 
365
 
 
366
    /* width > height -> height is unit */
 
367
    my.scale_width  = my.fi->pixdim[1] / my.fi->pixdim[2];
 
368
 
 
369
  }else if (my.fi->pixdim[2] > my.fi->pixdim[1]) {
 
370
 
 
371
    /* height > width -> width  is unit */
 
372
    my.scale_height = my.fi->pixdim[2] / my.fi->pixdim[1];
 
373
 
 
374
  }
 
375
 
 
376
}
 
377
 
 
378
Uint32 XMdcScaleW(Uint32 width)
 
379
{
 
380
  Uint32 new_width = width;
 
381
 
 
382
  if (my.scale_width != 1.) {
 
383
 
 
384
    new_width = (Uint32)((float)width * my.scale_width);
 
385
 
 
386
  }
 
387
  
 
388
  return(XMdcResize(new_width));
 
389
}
 
390
 
 
391
Uint32 XMdcScaleH(Uint32 height)
 
392
{
 
393
  Uint32 new_height = height;
 
394
 
 
395
  if (my.scale_height != 1.) {
 
396
 
 
397
    new_height = (Uint32)((float)height * my.scale_height);
 
398
 
 
399
  }
 
400
  
 
401
  return(XMdcResize(new_height));
 
402
}