1 /**
2  ** ialloc.c ---- Source Image Utility
3  **
4  ** by Michal Stencl Copyright (c) 1998
5  ** <e-mail>    - [stenclpmd@ba.telecom.sk]
6  **
7  ** This file is part of the GRX graphics library.
8  **
9  ** The GRX graphics library is free software; you can redistribute it
10  ** and/or modify it under some conditions; see the "copying.grx" file
11  ** for details.
12  **
13  ** This library is distributed in the hope that it will be useful,
14  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  **
17  ** modifications by Hartmut Schirmer Copyright (c) 1998
18  **
19  **/
20 
21 #include "libgrx.h"
22 #include "allocate.h"
23 #include "image/image.h"
24 
_GrImageTestSize(int wdt,int hgt)25 int _GrImageTestSize(int wdt,int hgt)
26 {
27   long total;
28   GRX_ENTER();
29   total = GrContextSize(wdt,hgt);
30 # ifdef _MAXMEMPLANESIZE
31   if ( total > _MAXMEMPLANESIZE ) total = 0L;
32 # endif
33   GRX_RETURN(total);
34 }
35 
_GrImageAllocate(GrContext * ctx,int nwidth,int nheight)36 GrImage *_GrImageAllocate(GrContext *ctx, int nwidth,int nheight)
37 {
38   GrImage   *img;
39 
40   GRX_ENTER();
41   img = NULL;
42   if ( _GrImageTestSize(nwidth, nheight) <= 0 ) goto done;
43   if (!GrCreateContext(nwidth, nheight, NULL, ctx)) goto done;
44   img = (GrImage *)malloc(sizeof(GrImage));
45   if ( !img ) {
46     GrDestroyContext(ctx);
47     goto done;
48   }
49   img->pxp_ispixmap = 1;
50   img->pxp_width  = nwidth;
51   img->pxp_height = nheight;
52   img->pxp_oper   = 0;
53   img->pxp_source = ctx->gc_frame;
54   img->pxp_source.gf_memflags =  3;/* MY_CONTEXT & MY_MEMORY */
55 done:
56   GRX_RETURN(img);
57 }
58