Octopus
gdlib_f.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2006 the octopus team
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18
19*/
20
21#include <config.h>
22
23#ifdef HAVE_GDLIB
24
25#include <assert.h>
26#include <ctype.h>
27#include <gd.h>
28#include <string.h>
29
30/* ---------------------- Interface to GD functions ------------------------ */
31gdImagePtr gdlib_image_create_from(char *name) {
32 char *ext;
33 FILE *in;
34 gdImagePtr im;
35
36 if ((in = fopen(name, "rb")) == NULL) {
37 return NULL; /* could not open file */
38 }
39
40 /* get extension of filename */
41 for (ext = name + strlen(name); *ext != '.' && ext >= name; ext--) {
42 *ext = tolower(*ext);
43 }
44 if (ext < name || ext == name + strlen(name)) {
45 fclose(in);
46 return NULL; /* could not find file type */
47 }
49 /* get rid of . in extension */
50 ext++;
51
52 /* load image file */
53 im = NULL;
54#ifdef HAVE_GD_JPEG
55 if ((strcmp(ext, "jpg") == 0) || (strcmp(ext, "JPG") == 0) ||
56 (strcmp(ext, "jpeg") == 0) || (strcmp(ext, "JPEG") == 0))
57 im = gdImageCreateFromJpeg(in);
58#endif
59
60#ifdef HAVE_GD_PNG
61 if ((strcmp(ext, "png") == 0) || (strcmp(ext, "PNG") == 0))
62 im = gdImageCreateFromPng(in);
63#endif
64
65#ifdef HAVE_GD_GIF
66 if ((strcmp(ext, "gif") == 0) || (strcmp(ext, "GIF") == 0))
67 im = gdImageCreateFromGif(in);
68#endif
69
70 fclose(in);
71
72 return im;
73}
74
75int gdlib_image_sx(const gdImagePtr *im) {
76 assert(*im != NULL);
77
78 return gdImageSX(*im);
81int gdlib_image_sy(const gdImagePtr *im) {
82 assert(*im != NULL);
83
84 return gdImageSY(*im);
87void gdlib_image_get_pixel_rgb(const gdImagePtr *im, const int *x, const int *y,
88 int *r, int *g, int *b) {
89 int color;
91 assert(*im != NULL);
93 if (gdImageBoundsSafe(*im, *x, *y)) {
94 color = gdImageGetPixel(*im, *x, *y);
95 *r = gdImageRed(*im, color);
96 *g = gdImageGreen(*im, color);
97 *b = gdImageBlue(*im, color);
98 } else {
99 /* this will happen for boundary points */
100 // fprintf(stderr, "Illegal pixel coordinate %d %d\n", *x, *y);
101 *r = 0;
102 *g = 0;
103 *b = 0;
107#else
108/* this is to avoid an empty source file (not allowed by ANSI C)*/
109void useless() {}
110#endif
111/* defined HAVEGDLIB */
int fclose(FILE *__stream)
type(c_ptr) function, public gdlib_image_create_from(filename)
Definition: gdlib.F90:161
integer, parameter in
Definition: pes_mask.F90:258