just a little program using imlib2 and Pixmap and the other stuff ones needs to set an image on the back ground. I am trying to figure out why it is not working, I've narrowed it down to pixmap getting lost, but that does not mean it is just that, but it is deff one part of it. My code:
main:
Code:
/*
Sep 21, 2017
*/
#include <stdio.h>
#include <stdlib.h>
#include "image.h"
#include "rotate.h"
//globals
Display *dis;
Pixmap pixmap;
Imlib_Context context;
Imlib_Color_Modifier modifier;
Imlib_Image buff;
Imlib_Image img;
int sw = 0, sh = 0;
int main(int argc, char **argv)
{
int w,h;
dis = XOpenDisplay(NULL);
if(!dis)
return 1;
if(argc < 1)
return 1;
printf("argv[argc] %s\n", argv[1]);
if(pixmap)
printf("main init_imgs YES YES YES \n");
init_imgs(&w,&h, dis, pixmap, context, modifier, img, buff);
sw = w;
sh = h;
if(pixmap)
printf("main set_standard_image YES YES YES \n");
else
printf("main NO PIXMAP\n");
printf("MAIN\n");
set_standard_image(img,buff,sw,sh,argv[1],modifier,context,dis,pixmap);
return 0;
}
Image.c
Code:
/*
Sep 21, 2017
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include </usr/include/Imlib2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "image.h"
void init_imgs(int *sgw, int *sgh, Display *dis, Pixmap pixmap, Imlib_Context context, Imlib_Color_Modifier modifier, Imlib_Image img, Imlib_Image buff)
{
// dis = XOpenDisplay(NULL);
if(!dis)
return;
Visual *vis;
Colormap cm;
int w,h;
// Imlib_Color_Range range;
unsigned int depth;
// int alpha = 256;
//char *filename;
modifier = NULL;
context = imlib_context_new();
imlib_context_push(context);
imlib_context_set_display(dis);
vis = DefaultVisual(dis, 0);
cm = DefaultColormap(dis, 0);
w = DisplayWidth(dis, 0);
h = DisplayHeight(dis, 0);
*sgw = w;
*sgh = h;
// printf("init image:2: sw %d sh %d\n ",&sw,&sh);
depth = DefaultDepth(dis, 0);
pixmap = XCreatePixmap(dis, RootWindow(dis, 0), w, h, depth);
if(pixmap)
printf("YES YES YES \n");
imlib_context_set_display(dis);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(pixmap);
imlib_context_set_color_range(imlib_create_color_range());
buff = imlib_create_image(w, h);
imlib_context_set_image(buff);
// imlib_context_set_color(0, 0, 0, 255);
// imlib_image_fill_rectangle(0, 0,sw,sh);
imlib_context_set_dither(1);
imlib_context_set_blend(1);
modifier = imlib_create_color_modifier();
imlib_context_set_color_modifier(modifier);
if(pixmap)
printf("YES YES YES \n");
if(pixmap)
printf("YES YES YES \n");
if(pixmap)
printf("YES YES YES \n");
}
void load_image(Imlib_Image img, char *filename)
{
img = imlib_load_image(filename);
}
// Adapted from fluxbox' bsetroot
int setRootAtoms (Display *dis, Pixmap pixmap)
{
Atom atom_root, atom_eroot, type;
unsigned char *data_root, *data_eroot;
int format;
unsigned long length, after;
atom_root = XInternAtom (dis, "_XROOTMAP_ID", True);
atom_eroot = XInternAtom (dis, "ESETROOT_PMAP_ID", True);
// doing this to clean up after old background
if (atom_root != None && atom_eroot != None)
{
XGetWindowProperty (dis, RootWindow (dis, 0),
atom_root, 0L, 1L, False, AnyPropertyType,
&type, &format, &length, &after, &data_root);
if (type == XA_PIXMAP)
{
XGetWindowProperty (dis, RootWindow (dis, 0),
atom_eroot, 0L, 1L, False, AnyPropertyType,
&type, &format, &length, &after, &data_eroot);
if (data_root && data_eroot && type == XA_PIXMAP &&
*((Pixmap *) data_root) == *((Pixmap *) data_eroot))
{
XKillClient (dis, *((Pixmap *) data_root));
}
} // second if
} //first if
atom_root = XInternAtom (dis, "_XROOTPMAP_ID", False);
atom_eroot = XInternAtom (dis, "ESETROOT_PMAP_ID", False);
if (atom_root == None || atom_eroot == None)
return 0;
// setting new background atoms
XChangeProperty (dis, RootWindow (dis, 0),
atom_root, XA_PIXMAP, 32, PropModeReplace,
(unsigned char *) &pixmap, 1);
XChangeProperty (dis, RootWindow (dis, 0), atom_eroot,
XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pixmap,
1);
return 1;
}
void display_image(Imlib_Color_Modifier modifier, Imlib_Context context, Display *dis, Pixmap pixmap)
{
if (modifier != NULL) {
imlib_context_set_color_modifier(modifier);
imlib_apply_color_modifier();
imlib_free_color_modifier();
modifier = NULL;
}
printf("display image\n");
if(!dis)
printf("display_image no dis\n");
if(!pixmap)
printf("display_image no pixmap\n");
imlib_render_image_on_drawable(0, 0);
imlib_free_image();
imlib_free_color_range();
if (setRootAtoms (dis, pixmap) == 0)
fprintf (stderr, "Couldn't create atoms...\n");
XKillClient (dis, AllTemporary);
XSetCloseDownMode (dis, RetainTemporary);
XSetWindowBackgroundPixmap (dis, RootWindow (dis, 0),pixmap);
XClearWindow (dis, RootWindow (dis, 0));
XFlush (dis);
XSync (dis, False);
imlib_context_pop();
// imlib_context_free(context);
}
rotate.c . I haven't gotten that far yet, just trying to set this up to show/display an image on the background first.
Code:
/*
Sep 21, 2017
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include </usr/include/Imlib2.h>
#include <stdio.h>
#include <stdlib.h>
#include "image.h"
#include "rotate.h"
/*
imlib_context_set_image(img.image);
imlib_image_flip_horizontal();
imlib_context_set_blend(1);
imlib_context_set_image(buffer);
// imlib_blend_image_onto_image_at_angle (Imlib_Image source_image, char merge_alpha,
// int source_x, int source_y, int source_width, int source_height,
// int destination_x, int destination_y, int angle_x, int angle_y)
//right side left side image
imlib_blend_image_onto_image_at_angle(img.image, 0, 0,0,w,h,
R.destination_y, R.destination_x, R.angle_x , R.angle_y);
set_image();
free_image();
set_buffer();
display_image();
*/
void set_standard_image(Imlib_Image img, Imlib_Image buff,int sw, int sh, char *filename,
Imlib_Color_Modifier modifier, Imlib_Context context, Display *dis, Pixmap pixmap)
{
printf("In set _ image %s\n", filename);
int w = 0, h = 0;
if(!dis)
printf("no dis\n");
if(!pixmap)
printf("no pixmap\n");
if(!buff)
printf("no pixmap\n");
img = imlib_load_image(filename);
imlib_context_set_image(img);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(buff);
imlib_context_set_image(img);
imlib_blend_image_onto_image(img,0,0,0,w,h,0,0,sw,sh);
display_image(modifier, context, dis, pixmap);
}
output:
Code:
./rotate-me /home/userx/slackware0.jpg
argv[argc] /home/userx/slackware0.jpg
YES YES YES
YES YES YES
YES YES YES
YES YES YES
// (post comment ) after it leaves init_images pixmap gets lost
main NO PIXMAP
MAIN
In set _ image /home/userx/slackware0.jpg
no pixmap
no pixmap
display image
display_image no pixmap
userx@/media/data/C-Projects/experimental/rotate-me/bin/Debug <>
if I try declaring it a pointer in globals I get errors ( of course)
Code:
/media/data/C-Projects/experimental/rotate-me/image.c|57|warning: assignment makes pointer from integer without a cast [-Wint-conversion]|
/media/data/C-Projects/experimental/rotate-me/image.c|65|warning: passing argument 1 of 'imlib_context_set_drawable' makes integer from pointer without a cast [-Wint-conversion]|
/usr/include/Imlib2.h|134|note: expected 'Drawable {aka long unsigned int}' but argument is of type 'Pixmap * {aka long unsigned int *}'|
I know it is not getting out of that function only being passed into it to get
Code:
pixmap = XCreatePixmap(dis, RootWindow(dis, 0), w, h, depth);
but maing it global in main, isn't keeping it that way? google is not helping me so I am posting in here now.