NCBI C Toolkit Cross Reference

C/gif/pictogif.c


  1 /*   pictogif.c
  2 * ===========================================================================
  3 *
  4 *                            PUBLIC DOMAIN NOTICE
  5 *            National Center for Biotechnology Information (NCBI)
  6 *
  7 *  This software/database is a "United States Government Work" under the
  8 *  terms of the United States Copyright Act.  It was written as part of
  9 *  the author's official duties as a United States Government employee and
 10 *  thus cannot be copyrighted.  This software/database is freely available
 11 *  to the public for use. The National Library of Medicine and the U.S.
 12 *  Government do not place any restriction on its use or reproduction.
 13 *  We would, however, appreciate having the NCBI and the author cited in
 14 *  any work or product based on this material
 15 *
 16 *  Although all reasonable efforts have been taken to ensure the accuracy
 17 *  and reliability of the software and data, the NLM and the U.S.
 18 *  Government do not and cannot warrant the performance or results that
 19 *  may be obtained by using this software or data. The NLM and the U.S.
 20 *  Government disclaim all warranties, express or implied, including
 21 *  warranties of performance, merchantability or fitness for any particular
 22 *  purpose.
 23 *
 24 * ===========================================================================
 25 *
 26 * File Name:  pictogif
 27 *
 28 * Author:  Alex Smirnov
 29 *
 30 * Version Creation Date:   11/23/95
 31 *
 32 * $Revision: 6.2 $
 33 *
 34 * File Description: 
 35 *
 36 * Modifications:  
 37 * --------------------------------------------------------------------------
 38 * $Log: pictogif.c,v $
 39 * Revision 6.2  1999/10/20 23:14:00  vakatov
 40 * + Nlm_Picture2gdImage() -- to draw in gdImage.
 41 * Nlm_PictureToGIF() -- restore current GIF image (if any) when the
 42 * dump is complete.
 43 *
 44 * Revision 6.1  1998/07/02 18:19:29  vakatov
 45 * Cleaned the code & made it pass through the C++ compilation
 46 *
 47 * ==========================================================================
 48 */
 49 
 50 #include <vibrant.h>
 51 #include <picturep.h>
 52 #include <mappingp.h>
 53 #include <drawingp.h>
 54 #include <ncbigif.h>
 55 #include <gifgen.h>
 56 
 57 
 58 /****************************************************************************/
 59 /* DEFINES */
 60 /****************************************************************************/
 61 #define PROXIMITY    2
 62 
 63 
 64 /****************************************************************************/
 65 /* STATIC FUNCTIONS */
 66 /****************************************************************************/
 67 
 68 static Boolean Nlm_MakeScaleGIF ( SegmenT picture, Int2 gifWidth, 
 69                                  Int2 gifHeight, Int4 pntX, Int4 pntY,
 70                                  Int2 align, Int4 scaleX, Int4 scaleY,
 71                                  ScalePtr scale )
 72 {
 73   Int2 pGifX, pGifY;
 74 
 75   if ( scaleX < 0 ) scaleX = -scaleX;
 76   if ( scaleY < 0 ) scaleY = -scaleY;
 77   SelectFont (systemFont);
 78   RecalculateSegment (picture, scaleX, scaleY);
 79   switch (align) {
 80     case MIDDLE_CENTER :
 81       pGifX = gifWidth / 2;
 82       pGifY = gifHeight / 2;
 83       break;
 84     case UPPER_LEFT :
 85       pGifX = 0;
 86       pGifY = 0;
 87       break;
 88     case LOWER_LEFT :
 89       pGifX = 0;
 90       pGifY = gifHeight-1;
 91       break;
 92     case UPPER_RIGHT :
 93       pGifX = gifWidth-1;
 94       pGifY = 0;
 95       break;
 96     case LOWER_RIGHT :
 97       pGifX = gifWidth-1;
 98       pGifY = gifHeight-1;
 99       break;
100     case UPPER_CENTER :
101       pGifX = gifWidth / 2;
102       pGifY = 0;
103       break;
104     case LOWER_CENTER :
105       pGifX = gifWidth / 2;
106       pGifY = gifHeight-1;
107       break;
108     case MIDDLE_LEFT :
109       pGifX = 0;
110       pGifY = gifHeight / 2;
111       break;
112     case MIDDLE_RIGHT :
113       pGifX = gifWidth-1;
114       pGifY = gifHeight / 2;
115       break;
116     default :
117       return FALSE;
118   }
119   scale->scaleX = scaleX;
120   scale->scaleY = scaleY;
121   scale->offsetX = (Int4)pGifX * scaleX - pntX;
122   scale->offsetY = (Int4)pGifY * scaleY + pntY ;
123   scale->worldWindow.left = - scale->offsetX;
124   scale->worldWindow.right = (Int4)gifWidth * scaleX - scale->offsetX;
125   scale->worldWindow.top = scale->offsetY;
126   scale->worldWindow.bottom = - (Int4)gifHeight * scaleY + scale->offsetY;
127   scale->worldWindow16.left = -1000 * scaleX - scale->offsetX;
128   scale->worldWindow16.right =  4000 * scaleX - scale->offsetX;
129   scale->worldWindow16.top = 1000 * scaleY + scale->offsetY;
130   scale->worldWindow16.bottom = -4000 * scaleY + scale->offsetY;
131   return TRUE;
132 }
133 
134 /****************************************************************************/
135 /* GLOBAL FUNCTIONS */
136 /****************************************************************************/
137 
138 NLM_EXTERN Boolean Nlm_PictureToGIF
139 (FILE* out, Int2 gifWidth, Int2 gifHeight,
140  SegmenT picture, Int4 pntX, Int4 pntY,
141  Int2 align, Int4 scaleX, Int4 scaleY,
142  Boolean transparent)
143 {
144   Nlm_DrawInfo dInfo;
145 
146   if (!out  ||  !picture  ||  !scaleX  ||  !scaleY  ||
147       gifWidth <= 0  ||  gifHeight <= 0  ||
148       ((PicPPtr) picture)->base.code != PICTURE)
149     return FALSE;
150 
151   if ( !Nlm_MakeScaleGIF(picture, gifWidth, gifHeight, pntX, pntY,
152                          align, scaleX, scaleY, &dInfo.scale) )
153     return FALSE;
154   
155   {{ /* Draw */
156     gdImage* im_prev = Nlm_SetCurrentGIF(0);
157     if ( !Nlm_CreateGIF(gifWidth, gifHeight, transparent) ) {
158       Nlm_SetCurrentGIF(im_prev);
159       return FALSE;
160     }
161     dInfo.checked  = FALSE;
162     dInfo.curattrib = blackAttPData;
163     dInfo.highlight = 0;
164     Nlm_DrawSegment((SegPPtr)picture, &dInfo);
165     Nlm_SaveGIF(out);
166     Nlm_DestroyGIF();
167     Nlm_SetCurrentGIF(im_prev);
168   }}
169 
170   return TRUE;
171 }
172 
173 
174 NLM_EXTERN Boolean Nlm_Picture2gdImage
175 (struct gdImageStruct* im, SegmenT picture,
176  Int4 pntX, Int4 pntY, Int2 align, Int4 scaleX, Int4 scaleY)
177 {
178   Nlm_DrawInfo dInfo;
179 
180   if (!im  ||  !picture  ||  !scaleX  ||  !scaleY  ||
181       ((PicPPtr) picture)->base.code != PICTURE)
182     return FALSE;
183 
184   {{ /* Scale and position of the picture in the GD image */
185     int width, height;
186     gdImageGetDimensions(im, &width, &height);
187     if ( !Nlm_MakeScaleGIF(picture, (Int2)width, (Int2)height, pntX, pntY,
188                            align, scaleX, scaleY, &dInfo.scale) )
189       return FALSE;
190   }}
191 
192   dInfo.checked   = FALSE;
193   dInfo.curattrib = blackAttPData;
194   dInfo.highlight = 0;
195 
196   {{ /* Draw */
197     gdImage* im_prev = Nlm_SetCurrentGIF(im);
198     Nlm_DrawSegment((SegPPtr) picture, &dInfo);
199     Nlm_SetCurrentGIF(im_prev);
200   }}
201   return TRUE;
202 }
203 
204 
205 NLM_EXTERN SegmenT Nlm_FindPrimGIF
206 (SegmenT picture, PoinT pt,
207  Int2 gifWidth, Int2 gifHeight,
208  Int4 pntX, Int4 pntY,
209  Int2 align, Int4 scaleX, Int4 scaleY,
210  Uint2Ptr segIDPtr, 
211  Uint2Ptr primIDPtr, PrimitivE PNTR primPtr)
212 {
213   SegmenT      found = NULL;
214   PrimitivE    prim  = NULL;
215   PicPPtr      pic;
216   ScaleInfo    scale;
217   RecT         r;
218   Uint2        segID = 0;
219   Uint2        primID = 0;
220 
221   if ( picture != NULL && gifWidth > 0 && gifHeight > 0 
222        && scaleX != 0 && scaleY != 0 ) {
223     pic = (PicPPtr) picture;
224     if (pic->base.code == PICTURE) {
225       if ( !Nlm_MakeScaleGIF ( picture, gifWidth, gifHeight, pntX, pntY,
226            align, scaleX, scaleY, &scale )) return NULL;
227       LoadRect(&r,
228                (Int2)(pt.x - PROXIMITY), (Int2)(pt.y - PROXIMITY), 
229                (Int2)(pt.x + PROXIMITY), (Int2)(pt.y + PROXIMITY));
230       MapRectToWorldBox ( &(scale.worldWindow), &r, &scale );
231       found = SearchSegment (picture, &scale, &prim );
232       if (found != NULL) {
233         segID = SegmentID (found);
234         primID = ((GenPPtr)prim)->primID;
235       }
236       if (segIDPtr != NULL) *segIDPtr = segID;
237       if (primIDPtr != NULL) *primIDPtr = primID;
238       if ( primPtr != NULL) *primPtr = prim;
239       return found;
240     }
241   }
242   return NULL;
243 }
244 
245 
246 NLM_EXTERN SegmenT Nlm_FindSegGIF
247 (SegmenT picture, PoinT pt,
248  Int2 gifWidth, Int2 gifHeight,
249  Int4 pntX, Int4 pntY,
250  Int2 align, Int4 scaleX, Int4 scaleY,
251  Uint2Ptr segIDPtr, 
252  Uint2Ptr primIDPtr, Uint2Ptr primCtPtr)
253 {
254   SegmenT   found;
255   PrimitivE prim;
256   BasePPtr  item;
257   SegPPtr   seg;
258   Uint2     primCt = 0;
259 
260   found = FindPrimGIF ( picture, pt, gifWidth, gifHeight,
261                         pntX, pntY, align, scaleX, scaleY,
262                         segIDPtr, primIDPtr, &prim );
263   if ( found != NULL ) {
264     seg = (SegPPtr) found;
265     item = seg->seg.head;
266     while (item != (BasePPtr)prim ) {
267       item = item->next;
268       primCt++;
269     }
270   }
271   if ( primCtPtr != NULL ){
272     *primCtPtr = primCt + 1;
273   }
274   return found;
275 }
276 
277 /*EOF*/
278 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.