Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
glcompimage.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <cgraph/alloc.h>
12#include <glcomp/glcompimage.h>
13#include <glcomp/glcompfont.h>
14#include <glcomp/glcompset.h>
15#include <glcomp/glutils.h>
17#include <stdbool.h>
18
19glCompImage *glCompImageNew(glCompObj *par, float x, float y) {
20 glCompImage *p = gv_alloc(sizeof(glCompImage));
21 glCompInitCommon((glCompObj *) p, par, x, y);
23
25 p->stretch = 0;
26 p->texture = NULL;
28 return p;
29}
30
31/* glCompImageNewFile:
32 * Creates image from given input file.
33 * At present, we assume png input.
34 * Return 0 on failure.
35 */
36glCompImage *glCompImageNewFile(float x, float y, char *imgfile) {
37 int imageWidth, imageHeight;
38 unsigned char *data = glCompLoadPng (imgfile, &imageWidth, &imageHeight);
39 glCompImage *p;
40
41 if (!data) return NULL;
42 p = glCompImageNew(NULL, x, y);
43 if (!glCompImageLoad(p, data, imageWidth, imageHeight, 0)) {
45 return NULL;
46 }
47 return p;
48}
49
51{
53 if (p->texture)
55 free(p);
56}
57
58int glCompImageLoad(glCompImage *i, unsigned char *data, int width, int height,
59 bool is2D) {
60 if (data != NULL) { /*valid image data */
62 i->texture =
63 glCompSetAddNewTexImage(i->common.compset, width, height, data,
64 is2D);
65 if (i->texture) {
66 i->common.width = width;
67 i->common.height = height;
68 return 1;
69 }
70
71 }
72 return 0;
73}
74
75int glCompImageLoadPng(glCompImage *i, char *pngFile) {
76 int imageWidth, imageHeight;
77 unsigned char *data;
78 data = glCompLoadPng (pngFile, &imageWidth, &imageHeight);
79 return glCompImageLoad(i, data, imageWidth, imageHeight, 1);
80}
81
82void glCompImageDraw(void *obj)
83{
84 glCompImage *p = obj;
86 float w,h,d;
87
89 if (!p->common.visible)
90 return;
91 if (!p->texture)
92 return;
93
94 if(p->texture->id <=0)
95 {
96 glRasterPos2f(ref.pos.x, ref.pos.y);
97 glDrawPixels(p->texture->width, p->texture->height, GL_RGBA,GL_UNSIGNED_BYTE, p->texture->data);
98 }
99 else
100 {
101 w = p->width;
102 h = p->height;
103 d = (float)p->common.layer * GLCOMPSET_BEVEL_DIFF;
104 glDisable(GL_BLEND);
105 glEnable(GL_TEXTURE_2D);
106 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
107 glBindTexture(GL_TEXTURE_2D,p->texture->id);
108 glBegin(GL_QUADS);
109 glTexCoord2d(0.0f, 1.0f);glVertex3d(ref.pos.x,ref.pos.y,d);
110 glTexCoord2d(1.0f, 1.0f);glVertex3d(ref.pos.x+w,ref.pos.y,d);
111 glTexCoord2d(1.0f, 0.0f);glVertex3d(ref.pos.x+w,ref.pos.y+h,d);
112 glTexCoord2d(0.0f, 0.0f);glVertex3d(ref.pos.x,ref.pos.y+h,d);
113 glEnd();
114
115
116 glDisable(GL_TEXTURE_2D);
117 glEnable(GL_BLEND);
118 }
119
120}
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define GLCOMPSET_BEVEL_DIFF
Definition glcompdefs.h:76
@ glImageObj
Definition glcompdefs.h:94
void glCompImageDelete(glCompImage *p)
Definition glcompimage.c:50
glCompImage * glCompImageNewFile(float x, float y, char *imgfile)
Definition glcompimage.c:36
int glCompImageLoadPng(glCompImage *i, char *pngFile)
Definition glcompimage.c:75
int glCompImageLoad(glCompImage *i, unsigned char *data, int width, int height, bool is2D)
Definition glcompimage.c:58
glCompImage * glCompImageNew(glCompObj *par, float x, float y)
Definition glcompimage.c:19
void glCompImageDraw(void *obj)
Definition glcompimage.c:82
void glCompInitCommon(glCompObj *childObj, glCompObj *parentObj, float x, float y)
Definition glcompset.c:120
void glCompEmptyCommon(glCompCommon *c)
Definition glcompset.c:183
unsigned char * glCompLoadPng(char *filename, int *imageWidth, int *imageHeight)
glCompTex * glCompSetAddNewTexImage(glCompSet *s, int width, int height, unsigned char *data, bool is2D)
void glCompDeleteTexture(glCompTex *t)
void glCompCalcWidget(glCompCommon *parent, glCompCommon *child, glCompCommon *ref)
Definition glutils.c:195
void free(void *)
node NULL
Definition grammar.y:149
void ref(Site *v)
Definition site.c:59
Definition legal.c:50
glcompdrawfunc_t draw
Definition glcompdefs.h:190
glCompCallBacks functions
Definition glcompdefs.h:223
void * parent
Definition glcompdefs.h:216
void * compset
Definition glcompdefs.h:215
glObjType objType
Definition glcompdefs.h:229
glCompCommon common
Definition glcompdefs.h:230
glCompTex * texture
Definition glcompdefs.h:231
uint32_t id
Definition glcompdefs.h:162
unsigned char * data
Definition glcompdefs.h:170
float height
Definition glcompdefs.h:166
float width
Definition glcompdefs.h:165