libxputty 0.1
Loading...
Searching...
No Matches
Functions
xpngloader.c File Reference

Go to the source code of this file.

Functions

cairo_status_t png_stream_reader (void *_stream, unsigned char *data, unsigned int length)
 
cairo_surface_t * cairo_image_surface_create_from_stream (const unsigned char *name)
 cairo_image_surface_create_from_stream - read binary data into cairo surface from stream
 
void _copy_surface_to_widget (Widget_t *w, cairo_surface_t *getpng)
 
void _copy_scaled_surface_to_widget (Widget_t *w, cairo_surface_t *getpng)
 
void widget_get_png (Widget_t *w, const unsigned char *name)
 widget_get_png - read png into Widget_t xlib surface
 
void widget_get_scaled_png (Widget_t *w, const unsigned char *name)
 widget_get_scaled_png - read scaled png into Widget_t xlib surface
 
void widget_get_png_from_file (Widget_t *w, const char *filename)
 widget_get_png_from_file - read png from file into Widget_t xlib surface
 
void widget_get_scaled_png_from_file (Widget_t *w, const char *filename)
 widget_get_scaled_png_from_file - read scaled png into Widget_t xlib surface
 
void widget_get_surface_ptr (Widget_t *w, Widget_t *wid)
 widget_get_surface_ptr - set pointer to a 2. Widget_t xlib surface
 
cairo_surface_t * surface_get_png (Widget_t *w, cairo_surface_t *sf, const unsigned char *name)
 surface_get_png - read png into Widget_t xlib surface
 
void widget_set_icon_from_surface (Widget_t *w, cairo_surface_t *image)
 widget_set_icon_from_surface - set icon image from cairo surface for Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)
 
void widget_set_icon_from_png (Widget_t *w, const unsigned char *name)
 widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)
 

Function Documentation

◆ _copy_scaled_surface_to_widget()

void _copy_scaled_surface_to_widget ( Widget_t w,
cairo_surface_t *  getpng 
)

Definition at line 56 of file xpngloader.c.

56 {
57 int width = cairo_image_surface_get_width(getpng);
58 int height = cairo_image_surface_get_height(getpng);
59 int width_t = w->scale.init_width;
60 int height_t = w->scale.init_height;
61 double x = (double)width_t/(double)width;
62 double y = (double)height_t/(double)height;
63 cairo_surface_destroy(w->image);
64 w->image = NULL;
65
66 w->image = cairo_surface_create_similar (w->surface,
67 CAIRO_CONTENT_COLOR_ALPHA, width_t, height_t);
68 cairo_t *cri = cairo_create (w->image);
69 cairo_scale(cri, x,y);
70 cairo_set_source_surface (cri, getpng,0,0);
71 cairo_paint (cri);
72 cairo_destroy(cri);
73}
int init_height
Definition xwidget.h:355
int init_width
Definition xwidget.h:353
Resize_t scale
Definition xwidget.h:525
cairo_surface_t * image
Definition xwidget.h:491
cairo_surface_t * surface
Definition xwidget.h:483

References Widget_t::image, Resize_t::init_height, Resize_t::init_width, Widget_t::scale, and Widget_t::surface.

Referenced by widget_get_scaled_png(), and widget_get_scaled_png_from_file().

◆ _copy_surface_to_widget()

void _copy_surface_to_widget ( Widget_t w,
cairo_surface_t *  getpng 
)

Definition at line 42 of file xpngloader.c.

42 {
43 int width = cairo_image_surface_get_width(getpng);
44 int height = cairo_image_surface_get_height(getpng);
45 cairo_surface_destroy(w->image);
46 w->image = NULL;
47
48 w->image = cairo_surface_create_similar (w->surface,
49 CAIRO_CONTENT_COLOR_ALPHA, width, height);
50 cairo_t *cri = cairo_create (w->image);
51 cairo_set_source_surface (cri, getpng,0,0);
52 cairo_paint (cri);
53 cairo_destroy(cri);
54}

References Widget_t::image, and Widget_t::surface.

Referenced by widget_get_png(), and widget_get_png_from_file().

◆ cairo_image_surface_create_from_stream()

cairo_surface_t * cairo_image_surface_create_from_stream ( const unsigned char *  name)

cairo_image_surface_create_from_stream - read binary data into cairo surface from stream

Parameters
*name- pointer to the binary image data LDVAR(name)
Returns
cairo_surface_t - the cairo_image_surface

Definition at line 35 of file xpngloader.c.

35 {
36 binary_stream png_stream;
37 png_stream.data = name;
38 png_stream.position = 0;
39 return cairo_image_surface_create_from_png_stream(&png_stream_reader, (void *)&png_stream);
40}
binary_stream - struct definition to read binary data into cairo surface
Definition xpngloader.h:104
long int position
Definition xpngloader.h:106
const unsigned char * data
Definition xpngloader.h:105
cairo_status_t png_stream_reader(void *_stream, unsigned char *data, unsigned int length)
Definition xpngloader.c:28

References binary_stream::data, png_stream_reader(), and binary_stream::position.

Referenced by surface_get_png(), widget_get_png(), widget_get_scaled_png(), and widget_set_icon_from_png().

◆ png_stream_reader()

cairo_status_t png_stream_reader ( void *  _stream,
unsigned char *  data,
unsigned int  length 
)

Definition at line 28 of file xpngloader.c.

28 {
29 binary_stream * stream = (binary_stream *) _stream;
30 memcpy(data, &stream->data[stream->position],length);
31 stream->position += length;
32 return CAIRO_STATUS_SUCCESS;
33}

References binary_stream::data, and binary_stream::position.

Referenced by cairo_image_surface_create_from_stream().

◆ surface_get_png()

cairo_surface_t * surface_get_png ( Widget_t w,
cairo_surface_t *  sf,
const unsigned char *  name 
)

surface_get_png - read png into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*sf- pointer to the cairo_surface_t which should hold the png
*name- pointer to the binary image data LDVAR(name)
Returns
cairo_surface_t - the cairo_xlib_surface, you need to free it by yourself

Definition at line 104 of file xpngloader.c.

104 {
105 cairo_surface_t *getpng = cairo_image_surface_create_from_stream (name);
106 int width = cairo_image_surface_get_width(getpng);
107 int height = cairo_image_surface_get_height(getpng);
108
109 sf = cairo_surface_create_similar (w->surface,
110 CAIRO_CONTENT_COLOR_ALPHA, width, height);
111 cairo_t *cri = cairo_create (sf);
112 cairo_set_source_surface (cri, getpng,0,0);
113 cairo_paint (cri);
114 cairo_surface_destroy(getpng);
115 cairo_destroy(cri);
116 return sf;
117}
cairo_surface_t * cairo_image_surface_create_from_stream(const unsigned char *name)
cairo_image_surface_create_from_stream - read binary data into cairo surface from stream
Definition xpngloader.c:35

References cairo_image_surface_create_from_stream(), and Widget_t::surface.

Referenced by add_listview(), and add_multi_listview().

◆ widget_get_png()

void widget_get_png ( Widget_t w,
const unsigned char *  name 
)

widget_get_png - read png into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*name- pointer to the binary image data LDVAR(name)

Definition at line 75 of file xpngloader.c.

75 {
76 cairo_surface_t *getpng = cairo_image_surface_create_from_stream (name);
77 _copy_surface_to_widget(w, getpng);
78 cairo_surface_destroy(getpng);
79}
void _copy_surface_to_widget(Widget_t *w, cairo_surface_t *getpng)
Definition xpngloader.c:42

References _copy_surface_to_widget(), and cairo_image_surface_create_from_stream().

Referenced by add_directory_button(), add_file_button(), add_save_file_button(), and open_message_dialog().

◆ widget_get_png_from_file()

void widget_get_png_from_file ( Widget_t w,
const char *  filename 
)

widget_get_png_from_file - read png from file into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*filename- pointer to the image path/file

Definition at line 87 of file xpngloader.c.

87 {
88 cairo_surface_t *getpng = cairo_image_surface_create_from_png (filename);
89 _copy_surface_to_widget(w, getpng);
90 cairo_surface_destroy(getpng);
91}

References _copy_surface_to_widget().

◆ widget_get_scaled_png()

void widget_get_scaled_png ( Widget_t w,
const unsigned char *  name 
)

widget_get_scaled_png - read scaled png into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*name- pointer to the binary image data LDVAR(name)

Definition at line 81 of file xpngloader.c.

81 {
82 cairo_surface_t *getpng = cairo_image_surface_create_from_stream (name);
84 cairo_surface_destroy(getpng);
85}
void _copy_scaled_surface_to_widget(Widget_t *w, cairo_surface_t *getpng)
Definition xpngloader.c:56

References _copy_scaled_surface_to_widget(), and cairo_image_surface_create_from_stream().

◆ widget_get_scaled_png_from_file()

void widget_get_scaled_png_from_file ( Widget_t w,
const char *  filename 
)

widget_get_scaled_png_from_file - read scaled png into Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the png
*filename- pointer to the image path/file

Definition at line 93 of file xpngloader.c.

93 {
94 cairo_surface_t *getpng = cairo_image_surface_create_from_png (filename);
96 cairo_surface_destroy(getpng);
97}

References _copy_scaled_surface_to_widget().

◆ widget_get_surface_ptr()

void widget_get_surface_ptr ( Widget_t w,
Widget_t wid 
)

widget_get_surface_ptr - set pointer to a 2. Widget_t xlib surface

Parameters
*w- pointer to the Widget_t which should use the surface
*wid- pointer to the Widget_t which hold the surface

Definition at line 99 of file xpngloader.c.

99 {
100 w->image = wid->image;
101 w->flags |= REUSE_IMAGE;
102}
long long flags
Definition xwidget.h:461
@ REUSE_IMAGE
Definition xwidget.h:414

References Widget_t::flags, Widget_t::image, and REUSE_IMAGE.

◆ widget_set_icon_from_png()

void widget_set_icon_from_png ( Widget_t w,
const unsigned char *  name 
)

widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)

Parameters
*w- pointer to the Widget_t which should use the icon
*name- pointer to the binary image data LDVAR(name)

Definition at line 159 of file xpngloader.c.

159 {
160#ifdef _WIN32 //PixmapIcon
161 return; // TODO
162#else
163 cairo_surface_t *image = cairo_image_surface_create_from_stream (name);
164 int width_t = cairo_image_surface_get_width(image);
165 int height_t = cairo_image_surface_get_height(image);
166 int stride = cairo_image_surface_get_stride (image);
167 unsigned long* icon_data = malloc(16+width_t*height_t * sizeof(unsigned long));
168 memset(icon_data, 0, 16+width_t*height_t * sizeof(unsigned long));
169 const unsigned char *data = cairo_image_surface_get_data(image);
170 icon_data[0] = width_t;
171 icon_data[1] = height_t;
172 int x = 0;
173 int y = 0;
174 unsigned long* output_pixel = icon_data;
175 output_pixel += 2;
176 for (y = 0; y < height_t; y++) {
177 uint32_t *row = (uint32_t*) (data + y * stride);
178 for (x = 0; x < width_t; x++) {
179 output_pixel[0] |= row[x];
180 output_pixel ++;
181 }
182 }
183
184 Atom net_wm_icon = XInternAtom(w->app->dpy, "_NET_WM_ICON", False);
185 Atom cardinal = XInternAtom(w->app->dpy, "CARDINAL", False);
186 XChangeProperty(w->app->dpy, w->widget, net_wm_icon, cardinal, 32, PropModeReplace,
187 (const unsigned char*) icon_data, 2+width_t*height_t);
188
189 cairo_surface_destroy(image);
190 free(icon_data);
191#endif
192}
Window widget
Definition xwidget.h:469
Xputty * app
Definition xwidget.h:465
Display * dpy
Definition xputty.h:232
unsigned long int Atom

References Widget_t::app, cairo_image_surface_create_from_stream(), Xputty::dpy, and Widget_t::widget.

Referenced by mk_open_midi_keyboard(), open_directory_dialog(), open_file_dialog(), and save_file_dialog().

◆ widget_set_icon_from_surface()

void widget_set_icon_from_surface ( Widget_t w,
cairo_surface_t *  image 
)

widget_set_icon_from_surface - set icon image from cairo surface for Widget_t those icon will be used in the Window decoration and the toolbar (depending on the Widnow manager)

Parameters
*w- pointer to the Widget_t which should use the icon
*image- pointer to the cairo_surface_t to use for the icon

Definition at line 119 of file xpngloader.c.

119 {
120#ifdef _WIN32 //PixmapIcon
121 return; // TODO
122#else
123 int width_t = cairo_xlib_surface_get_width(image);
124 int height_t = cairo_xlib_surface_get_height(image);
125 cairo_surface_t *icon = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width_t, height_t);
126 cairo_t *cri = cairo_create (icon);
127 cairo_set_source_surface (cri, image,0,0);
128 cairo_paint (cri);
129
130 int stride = cairo_image_surface_get_stride (icon);
131 unsigned long* icon_data = malloc(2+width_t*height_t * sizeof(unsigned long));
132 memset(icon_data, 0, 2+width_t*height_t * sizeof(unsigned long));
133 const unsigned char *data = cairo_image_surface_get_data(icon);
134 icon_data[0] = width_t;
135 icon_data[1] = height_t;
136 int x = 0;
137 int y = 0;
138 unsigned long* output_pixel = icon_data;
139 output_pixel += 2;
140 for (y = 0; y < height_t; y++) {
141 uint32_t *row = (uint32_t*) (data + y * stride);
142 for (x = 0; x < width_t; x++) {
143 output_pixel[0] |= row[x];
144 output_pixel ++;
145 }
146 }
147
148 Atom net_wm_icon = XInternAtom(w->app->dpy, "_NET_WM_ICON", False);
149 Atom cardinal = XInternAtom(w->app->dpy, "CARDINAL", False);
150 XChangeProperty(w->app->dpy, w->widget, net_wm_icon, cardinal, 32, PropModeReplace,
151 (const unsigned char*) icon_data, 2+width_t*height_t);
152
153 cairo_surface_destroy(icon);
154 cairo_destroy(cri);
155 free(icon_data);
156#endif
157}

References Widget_t::app, Xputty::dpy, and Widget_t::widget.

Referenced by open_message_dialog().