Example #1
0
ExcCode screen_shot(int x, int y, int width, int height,
		Imlib_Image *res) {
	int x1 = x + width;
	int y1 = y + height;
	x = MAX(x, 0);
	y = MAX(y, 0);
	x1 = MIN(x1, screen->width_in_pixels);
	y1 = MIN(y1, screen->height_in_pixels);
	width = x1 - x;
	height = y1 - y;
	
	*res = NULL;
	if (shm_available) {
		xcb_shm_get_image_cookie_t cookie =
				xcb_shm_get_image(display,
				root, x, y, width, height,
				XCB_ALL_PLANES, XCB_IMAGE_FORMAT_Z_PIXMAP,
				shmseg, 0);
		xcb_shm_get_image_reply_t *reply =
				xcb_shm_get_image_reply(display, cookie, NULL);
		if (reply != NULL) {
			*res = imlib_create_image_using_copied_data(width, height,
					(unsigned *) shmaddr);
			free(reply);
		}
	}
	if (*res == NULL) {
		// If shm can't be used due to lack of the libraries or
		// because we connect to X11 on another machine (e.g. via SSH),
		// try to get an image via sockets.

		xcb_get_image_cookie_t cookie = xcb_get_image(display,
				XCB_IMAGE_FORMAT_Z_PIXMAP, root, x, y, width, height,
				XCB_ALL_PLANES);
		xcb_get_image_reply_t *reply =
				xcb_get_image_reply(display, cookie, NULL);
		if (reply == NULL)
			PANIC(ERR_X_REQUEST, "screen_shot (xcb_get_image_reply)");
		*res = imlib_create_image_using_copied_data(width, height,
				(unsigned *) xcb_get_image_data(reply));
		free(reply);
	}
	if (*res == NULL)
		PANIC(ERR_IMAGE);
		
	if (cursor_capturing_enabled && cursor_available)
		screen_cursor_blend(x, y, *res);
	return 0;
}
Example #2
0
Imlib_Image Convert_OpenCV_to_Imlib(PointGrey_t2* PG)
{
  cv::Mat tempMat;
  cvtColor(PG->uncompressedImage, tempMat, CV_BGR2BGRA);
  return imlib_create_image_using_copied_data(PG->uncompressedImage.cols,
					      PG->uncompressedImage.rows,
					      (unsigned int*) tempMat.data);}
Example #3
0
int main(int argc, char** argv) {
    struct stat sb;
    if (!(stat(OUTPUT_DIR, &sb) == 0 && S_ISDIR(sb.st_mode)))
    {
        if (mkdir(OUTPUT_DIR, S_IRWXU | S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH) != 0)
        {
            printf("Error creating directory %s\n",OUTPUT_DIR);
            return -1;
        }
    }
    char tempFileName[512];
    sprintf(tempFileName, "%stest.txt",OUTPUT_DIR);
    FILE* tempFile = fopen(tempFileName, "w+");
    if (tempFile == NULL)
    {
        printf("Failed to create file in current folder.  Please check permissions.\n");
        return -1;
    }
    fclose(tempFile);
    remove(tempFileName);
    //if we get here, we know the directory exists and we can write to it
    //now set up, start, and grab image from camera
    fc2Context context;
    fc2PGRGuid guid;
    fc2Image raw_image, converted_image;
    Imlib_Image temp_image;
    check_point_grey(fc2CreateContext(&context));
    check_point_grey(fc2GetCameraFromIndex(context,0,&guid));
    check_point_grey(fc2Connect(context,&guid));
    check_point_grey(fc2SetDefaultColorProcessing(FC2_IPP));
    check_point_grey(fc2SetVideoModeAndFrameRate(context,
                     FC2_VIDEOMODE_1280x960Y8,
                     FC2_FRAMERATE_15));
    PrintCameraInfo(context);
    check_point_grey(fc2CreateImage(&raw_image));
    check_point_grey(fc2CreateImage(&converted_image));
    check_point_grey(fc2StartCapture(context));
    check_point_grey(fc2RetrieveBuffer(context,&raw_image));
    check_point_grey(fc2ConvertImageTo(FC2_PIXEL_FORMAT_BGRU,&raw_image,&converted_image));
    temp_image = imlib_create_image_using_copied_data(converted_image.cols,
                 converted_image.rows,
                 (unsigned int *)
                 converted_image.pData);
    imlib_context_set_image(temp_image);
    char filename[512];
    sprintf(filename,"%stest.ppm",OUTPUT_DIR);
    imlib_save_image(filename);
    printf("Saved %s\n",filename);
    //image saved, now clean up
    imlib_free_image_and_decache();
    check_point_grey(fc2StopCapture(context));
    check_point_grey(fc2DestroyContext(context));
    check_point_grey(fc2DestroyImage(&raw_image));
    check_point_grey(fc2DestroyImage(&converted_image));
    printf("finished cleanup\n");
    return 0;
}
Example #4
0
ExcCode screen_shot(int x, int y, int width, int height,
		Imlib_Image *res) {
	int x1 = x + width;
	int y1 = y + height;
	x = MAX(x, 0);
	y = MAX(y, 0);
	x1 = MIN(x1, screen->width_in_pixels);
	y1 = MIN(y1, screen->height_in_pixels);
	width = x1 - x;
	height = y1 - y;
	
	if (shm_available) {
		xcb_shm_get_image_cookie_t cookie =
				xcb_shm_get_image(display,
				root, x, y, width, height,
				XCB_ALL_PLANES, XCB_IMAGE_FORMAT_Z_PIXMAP,
				shmseg, 0);
		xcb_shm_get_image_reply_t *reply =
				xcb_shm_get_image_reply(display, cookie, NULL);
		if (reply == NULL)
			PANIC(ERR_X_REQUEST, "screen_shot (xcb_shm_get_image_reply)");
		*res = imlib_create_image_using_copied_data(width, height,
				(unsigned *) shmaddr);
		free(reply);
	} else {
		xcb_get_image_cookie_t cookie = xcb_get_image(display,
				XCB_IMAGE_FORMAT_Z_PIXMAP, root, x, y, width, height,
				XCB_ALL_PLANES);
		xcb_get_image_reply_t *reply =
				xcb_get_image_reply(display, cookie, NULL);
		if (reply == NULL)
			PANIC(ERR_X_REQUEST, "screen_shot (xcb_get_image_reply)");
		*res = imlib_create_image_using_copied_data(width, height,
				(unsigned *) xcb_get_image_data(reply));
		free(reply);
	}
	if (*res == NULL)
		PANIC(ERR_IMAGE);
		
	if (cursor_capturing_enabled && cursor_available)
		screen_cursor_blend(x, y, *res);
	return 0;
}
Example #5
0
File: image.c Project: JulioJu/sxiv
bool img_load_gif(img_t *img, const fileinfo_t *file)
{
	GifFileType *gif;
	GifRowType *rows = NULL;
	GifRecordType rec;
	ColorMapObject *cmap;
	DATA32 bgpixel, *data, *ptr;
	DATA32 *prev_frame = NULL;
	Imlib_Image im;
	int i, j, bg, r, g, b;
	int x, y, w, h, sw, sh;
	int px, py, pw, ph;
	int intoffset[] = { 0, 4, 2, 1 };
	int intjump[] = { 8, 8, 4, 2 };
	int transp = -1;
	unsigned int disposal = 0, prev_disposal = 0;
	unsigned int delay = 0;
	bool err = false;

	if (img->multi.cap == 0) {
		img->multi.cap = 8;
		img->multi.frames = (img_frame_t*)
		                    s_malloc(sizeof(img_frame_t) * img->multi.cap);
	}
	img->multi.cnt = img->multi.sel = 0;
	img->multi.length = 0;

#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
	gif = DGifOpenFileName(file->path, NULL);
#else
	gif = DGifOpenFileName(file->path);
#endif
	if (gif == NULL) {
		warn("could not open gif file: %s", file->name);
		return false;
	}
	bg = gif->SBackGroundColor;
	sw = gif->SWidth;
	sh = gif->SHeight;
	px = py = pw = ph = 0;

	do {
		if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
			err = true;
			break;
		}
		if (rec == EXTENSION_RECORD_TYPE) {
			int ext_code;
			GifByteType *ext = NULL;

			DGifGetExtension(gif, &ext_code, &ext);
			while (ext) {
				if (ext_code == GRAPHICS_EXT_FUNC_CODE) {
					if (ext[1] & 1)
						transp = (int) ext[4];
					else
						transp = -1;

					delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
					disposal = (unsigned int) ext[1] >> 2 & 0x7;
				}
				ext = NULL;
				DGifGetExtensionNext(gif, &ext);
			}
		} else if (rec == IMAGE_DESC_RECORD_TYPE) {
			if (DGifGetImageDesc(gif) == GIF_ERROR) {
				err = true;
				break;
			}
			x = gif->Image.Left;
			y = gif->Image.Top;
			w = gif->Image.Width;
			h = gif->Image.Height;

			rows = (GifRowType*) s_malloc(h * sizeof(GifRowType));
			for (i = 0; i < h; i++)
				rows[i] = (GifRowType) s_malloc(w * sizeof(GifPixelType));
			if (gif->Image.Interlace) {
				for (i = 0; i < 4; i++) {
					for (j = intoffset[i]; j < h; j += intjump[i])
						DGifGetLine(gif, rows[j], w);
				}
			} else {
				for (i = 0; i < h; i++)
					DGifGetLine(gif, rows[i], w);
			}

			ptr = data = (DATA32*) s_malloc(sizeof(DATA32) * sw * sh);
			cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap;
			r = cmap->Colors[bg].Red;
			g = cmap->Colors[bg].Green;
			b = cmap->Colors[bg].Blue;
			bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);

			for (i = 0; i < sh; i++) {
				for (j = 0; j < sw; j++) {
					if (i < y || i >= y + h || j < x || j >= x + w ||
					    rows[i-y][j-x] == transp)
					{
						if (prev_frame != NULL && (prev_disposal != 2 ||
						    i < py || i >= py + ph || j < px || j >= px + pw))
						{
							*ptr = prev_frame[i * sw + j];
						} else {
							*ptr = bgpixel;
						}
					} else {
						r = cmap->Colors[rows[i-y][j-x]].Red;
						g = cmap->Colors[rows[i-y][j-x]].Green;
						b = cmap->Colors[rows[i-y][j-x]].Blue;
						*ptr = 0xff << 24 | r << 16 | g << 8 | b;
					}
					ptr++;
				}
			}

			im = imlib_create_image_using_copied_data(sw, sh, data);

			for (i = 0; i < h; i++)
				free(rows[i]);
			free(rows);
			free(data);

			if (im == NULL) {
				err = true;
				break;
			}

			imlib_context_set_image(im);
			imlib_image_set_format("gif");
			if (transp >= 0)
				imlib_image_set_has_alpha(1);

			if (disposal != 3)
				prev_frame = imlib_image_get_data_for_reading_only();
			prev_disposal = disposal;
			px = x, py = y, pw = w, ph = h;

			if (img->multi.cnt == img->multi.cap) {
				img->multi.cap *= 2;
				img->multi.frames = (img_frame_t*)
				                    s_realloc(img->multi.frames,
				                              img->multi.cap * sizeof(img_frame_t));
			}
			img->multi.frames[img->multi.cnt].im = im;
			img->multi.frames[img->multi.cnt].delay = delay > 0 ? delay : DEF_GIF_DELAY;
			img->multi.length += img->multi.frames[img->multi.cnt].delay;
			img->multi.cnt++;
		}
	} while (rec != TERMINATE_RECORD_TYPE);
Example #6
0
/* Originally based on, but in its current form merely inspired by Imlib2's
 * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
 */
bool img_load_gif(img_t *img, const fileinfo_t *file) {
	GifFileType *gif;
	GifRowType *rows = NULL;
	GifRecordType rec;
	ColorMapObject *cmap;
	DATA32 bgpixel, *data, *ptr;
	DATA32 *prev_frame = NULL;
	Imlib_Image *im;
	int i, j, bg, r, g, b;
	int x, y, w, h, sw, sh;
	int intoffset[] = { 0, 4, 2, 1 };
	int intjump[] = { 8, 8, 4, 2 };
	int transp = -1;
	unsigned int delay = 0;
	bool err = false;

	if (img->multi.cap == 0) {
		img->multi.cap = 8;
		img->multi.frames = (img_frame_t*)
		                    s_malloc(sizeof(img_frame_t) * img->multi.cap);
	}
	img->multi.cnt = 0;
	img->multi.sel = 0;

	gif = DGifOpenFileName(file->path);
	if (gif == NULL) {
		warn("could not open gif file: %s", file->name);
		return false;
	}
	bg = gif->SBackGroundColor;
	sw = gif->SWidth;
	sh = gif->SHeight;

	do {
		if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
			err = true;
			break;
		}
		if (rec == EXTENSION_RECORD_TYPE) {
			int ext_code;
			GifByteType *ext = NULL;

			DGifGetExtension(gif, &ext_code, &ext);
			while (ext) {
				if (ext_code == 0xf9) {
					if (ext[1] & 1)
						transp = (int) ext[4];
					else
						transp = -1;

					delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
					if (delay)
						delay = MAX(delay, MIN_GIF_DELAY);

					/* TODO: handle disposal method, section 23.c.iv of
					         http://www.w3.org/Graphics/GIF/spec-gif89a.txt */
				}
				ext = NULL;
				DGifGetExtensionNext(gif, &ext);
			}
		} else if (rec == IMAGE_DESC_RECORD_TYPE) {
			if (DGifGetImageDesc(gif) == GIF_ERROR) {
				err = true;
				break;
			}
			x = gif->Image.Left;
			y = gif->Image.Top;
			w = gif->Image.Width;
			h = gif->Image.Height;

			rows = (GifRowType*) s_malloc(h * sizeof(GifRowType));
			for (i = 0; i < h; i++)
				rows[i] = (GifRowType) s_malloc(w * sizeof(GifPixelType));
			if (gif->Image.Interlace) {
				for (i = 0; i < 4; i++) {
					for (j = intoffset[i]; j < h; j += intjump[i])
						DGifGetLine(gif, rows[j], w);
				}
			} else {
				for (i = 0; i < h; i++)
					DGifGetLine(gif, rows[i], w);
			}

			ptr = data = (DATA32*) s_malloc(sizeof(DATA32) * sw * sh);
			cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap;
			r = cmap->Colors[bg].Red;
			g = cmap->Colors[bg].Green;
			b = cmap->Colors[bg].Blue;
			bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);

			for (i = 0; i < sh; i++) {
				for (j = 0; j < sw; j++) {
					if (i < y || i >= y + h || j < x || j >= x + w ||
					    rows[i-y][j-x] == transp)
					{
						if (prev_frame != NULL)
							*ptr = prev_frame[i * sw + j];
						else
							*ptr = bgpixel;
					} else {
						r = cmap->Colors[rows[i-y][j-x]].Red;
						g = cmap->Colors[rows[i-y][j-x]].Green;
						b = cmap->Colors[rows[i-y][j-x]].Blue;
						*ptr = 0xff << 24 | r << 16 | g << 8 | b;
					}
					ptr++;
				}
			}

			im = imlib_create_image_using_copied_data(sw, sh, data);

			for (i = 0; i < h; i++)
				free(rows[i]);
			free(rows);
			free(data);

			if (im == NULL) {
				err = true;
				break;
			}

			imlib_context_set_image(im);
			prev_frame = imlib_image_get_data_for_reading_only();

			imlib_image_set_format("gif");
			if (transp >= 0)
				imlib_image_set_has_alpha(1);

			if (img->multi.cnt == img->multi.cap) {
				img->multi.cap *= 2;
				img->multi.frames = (img_frame_t*)
				                    s_realloc(img->multi.frames,
				                              img->multi.cap * sizeof(img_frame_t));
			}
			img->multi.frames[img->multi.cnt].im = im;
			img->multi.frames[img->multi.cnt].delay = delay ? delay : GIF_DELAY;
			img->multi.cnt++;
		}
	} while (rec != TERMINATE_RECORD_TYPE);

	DGifCloseFile(gif);

	if (err && !file->loaded)
		warn("corrupted gif file: %s", file->name);

	if (img->multi.cnt > 1) {
		imlib_context_set_image(img->im);
		imlib_free_image();
		img->im = img->multi.frames[0].im;
		img->multi.animate = GIF_AUTOPLAY;
	} else if (img->multi.cnt == 1) {
		imlib_context_set_image(img->multi.frames[0].im);
		imlib_free_image();
		img->multi.cnt = 0;
		img->multi.animate = false;
	}

	imlib_context_set_image(img->im);

	return !err;
}
Example #7
0
int main(int argc, char** argv){
  int numPics = 100;
  fc2VideoMode mode1 = FC2_VIDEOMODE_640x480Y8;
  char *mode1_str = "FC2_VIDEOMODE_640x480Y8";
  //fc2FrameRate rate1 = FC2_FRAMERATE_30;
  //char *rate1_str = "FC2_FRAMERATE_30";
  fc2VideoMode mode2 = FC2_VIDEOMODE_1280x960Y8;
  char *mode2_str = "FC2_VIDEOMODE_1280x960Y8"; 
  fc2FrameRate rate = FC2_FRAMERATE_15;
  char *rate_str = "FC2_FRAMERATE_15";
  fc2VideoMode mode;
  char *mode_str;
  //fc2FrameRate rate;
  //char *rate_str;

  //int prog_mode;
  int camOffset = 0;

  PrintBuildInfo();
  /* if (argc != 2)  */
  /* { */
  /*   printf("Error: Must chose mode\n"); */
  /*   printf("Usage: %s {1, 2, 3, 4, 5, 6} \n",argv[0]); */
  /*   printf("Modes: 1 = first camera at 1280x960Y8\n" */
  /* 	   "       2 = second camera at 1280x960Y8\n" */
  /* 	   "       3 = both cameras at 1280x960Y8\n" */
  /* 	   "       4 = first camera at 640x480Y8\n" */
  /* 	   "       5 = second camera at 640x480Y8\n" */
  /* 	   "       6 = both cameras at 640x480Y8\n"); */
  /*   return -1; */
  /* } */

  /* prog_mode = atoi(argv[1]);   */
  /* if ((prog_mode > 6) || (prog_mode < 1)) */
  /* { */
  /*   printf("Must chose valid mode, 1 through 6\n"); */
  /* } */
  if (CheckSaving(OUTPUT_DIR) != 0)
  {
    printf("Cannot save to %s, please check permissions\n",OUTPUT_DIR);
    return -1;
  }
  //have correct number of arguments and can save
  
  fc2Context tempContext;
  check_point_grey(fc2CreateContext(&tempContext));
  unsigned int numCams;
  check_point_grey(fc2GetNumOfCameras(tempContext, &numCams));
  check_point_grey(fc2DestroyContext(tempContext));
  if (numCams == 0)
  { //no cameras
    printf("No cameras found, exiting.\n");
    return -1;
  } 
  //if we get here, we know we have at least 1 camera connected

  /* if (prog_mode < 4) */
  /* { */
  /*   mode = FC2_VIDEOMODE_1280x960Y8; */
  /*   mode_str = "FC2_VIDEOMODE_1280x960Y8"; */
  /*   rate = FC2_FRAMERATE_15; */
  /*   rate_str = "FC2_FRAMERATE_15"; */
  /* } */
  //  printf("Using resolution %s and frame rate %s\n",mode_str,rate_str);

  /* if ((prog_mode == 1) || (prog_mode == 4)) */
  /* { // run only the first camera */
  /*   numCams = 1; */
  /* } */
  /* if ((prog_mode == 2) || (prog_mode == 5)) */
  /* { // run only the second camera */
  /*   camOffset = 1; */
  /* } */

  printf("Taking %i pictures per camera with %i camera(s).\n",numPics, (numCams - camOffset)); 
  

  struct point_grey *pg_ptr[numCams - camOffset];
  for (int i = 0; i < (numCams - camOffset); i++) //initialization loop
  {
    if (i == 0)
    {
      mode = mode2;
      mode_str = mode2_str;
      //rate = rate2;
      //rate_str = rate2_str;
    }
    else
    {
      mode = mode1;
      mode_str = mode1_str;
      //rate = rate1;
      //rate_str = rate1_str;
    }

    pg_ptr[i] =
      (struct point_grey *)point_grey_malloc(sizeof(struct point_grey));
    check_point_grey(fc2CreateContext(&pg_ptr[i]->context));
    check_point_grey(fc2GetCameraFromIndex(pg_ptr[i]->context,
					   (i + camOffset),
					   &pg_ptr[i]->guid));
    check_point_grey(fc2Connect(pg_ptr[i]->context,
				&pg_ptr[i]->guid));
    check_point_grey(fc2SetDefaultColorProcessing(FC2_NEAREST_NEIGHBOR_FAST));
    check_point_grey(fc2SetVideoModeAndFrameRate(pg_ptr[i]->context,
						 mode,
						 rate));
    AssignName(pg_ptr[i]->context, pg_ptr[i]->name);
    check_point_grey(fc2CreateImage(&pg_ptr[i]->raw_image));
    check_point_grey(fc2CreateImage(&pg_ptr[i]->converted_image));
    PrintCameraInfo(pg_ptr[i]->context);
    printf("Using resolution %s and frame rate %s\n",mode_str,rate_str);
    //**CALLING THIS HERE WILL WORK WITH 2 CAMERAS AT 640X480 BUT NOT AT
    //1280X960**
    check_point_grey(fc2StartCapture(pg_ptr[i]->context))
    printf("completed initialization loop iteration %d, %s\n",i,pg_ptr[i]->name);
  } // initialization loop

  Imlib_Image temp_image;
  double start = current_time();

  for (int j = 0; j < numPics; j++) //loop through numPics
  {
    for (int i = 0; i < (numCams - camOffset); i++) //picture taking loop
    {
      check_point_grey(fc2RetrieveBuffer(pg_ptr[i]->context,
					 &pg_ptr[i]->raw_image));
      check_point_grey(fc2ConvertImageTo(FC2_PIXEL_FORMAT_BGRU,
					 &pg_ptr[i]->raw_image,
					 &pg_ptr[i]->converted_image));
      temp_image = imlib_create_image_using_copied_data(pg_ptr[i]->converted_image.cols,
							pg_ptr[i]->converted_image.rows,
						  (unsigned int *)
						  pg_ptr[i]->converted_image.pData);


      printf("%simage_%d\n",pg_ptr[i]->name,j);
      if (j == (numPics - 1))
      {//save the final image from each camera
	SaveImlibImage(temp_image, pg_ptr[i]->name, mode_str);
      }
      else
      {
	imlib_context_set_image(temp_image);
	//this is where we would do something else with the image
	imlib_free_image_and_decache();
      }
    } //picture taking loop
  } //numPics loop

  double stop = current_time();
  //check elapsed time
  double elapsed = stop - start;
  double images_per_sec = (double)numPics / elapsed;
  printf("%d images per camera taken in %f seconds (%f images/sec/cam)\n",
	 numPics, elapsed, images_per_sec);

  for (int i = 0; i < (numCams - camOffset); i++) //cleanup loop
  {
    //**CALLING THIS HERE WILL WORK WITH 2 CAMERAS AT 640X480 BUT NOT AT
    //1280X960**
    check_point_grey(fc2StopCapture(pg_ptr[i]->context));

    check_point_grey(fc2DestroyContext(pg_ptr[i]->context));
    check_point_grey(fc2DestroyImage(&pg_ptr[i]->raw_image));
    check_point_grey(fc2DestroyImage(&pg_ptr[i]->converted_image));
    free(pg_ptr[i]);

    printf("completed cleanup loop iteration %d\n",i);
  } //cleanup loop  
  printf("Program complete!\n");
  return 0; 
}
Example #8
0
void get_icon (Task *tsk)
{
	Panel *panel = tsk->area.panel;
	if (!panel->g_task.icon) return;
	size_t i;
	Imlib_Image img = NULL;
	XWMHints *hints = 0;
	gulong *data = 0;

	int k;
	for (k=0; k<TASK_STATE_COUNT; ++k) {
		if (tsk->icon[k]) {
			imlib_context_set_image(tsk->icon[k]);
			imlib_free_image();
			tsk->icon[k] = 0;
		}
	}

	data = server_get_property (tsk->win, server.atom._NET_WM_ICON, XA_CARDINAL, (int*)&i);
	if (data) {
		// get ARGB icon
		int w, h;
		gulong *tmp_data;

		tmp_data = get_best_icon (data, get_icon_count (data, i), i, &w, &h, panel->g_task.icon_size1);
#ifdef __x86_64__
		DATA32 icon_data[w * h];
		size_t length = w * h;
		for (i = 0; i < length; ++i)
			icon_data[i] =  tmp_data[i];
		img = imlib_create_image_using_copied_data (w, h, icon_data);
#else
		img = imlib_create_image_using_data (w, h, (DATA32*)tmp_data);
#endif
	}
	else {
		// get Pixmap icon
		hints = XGetWMHints(server.dsp, tsk->win);
		if (hints) {
			if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
				// get width, height and depth for the pixmap
				Window root;
				int  icon_x, icon_y;
				uint32_t border_width, bpp;
				uint32_t w, h;

				//printf("  get pixmap\n");
				XGetGeometry(server.dsp, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp);
				imlib_context_set_drawable(hints->icon_pixmap);
				img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0);
			}
		}
	}
	if (img == NULL) {
		imlib_context_set_image(default_icon);
		img = imlib_clone_image();
	}

	// transform icons
	imlib_context_set_image(img);
	imlib_image_set_has_alpha(1);
	int w, h;
	w = imlib_image_get_width();
	h = imlib_image_get_height();
	Imlib_Image orig_image = imlib_create_cropped_scaled_image(0, 0, w, h, panel->g_task.icon_size1, panel->g_task.icon_size1);
	imlib_free_image();

	imlib_context_set_image(orig_image);
	tsk->icon_width = imlib_image_get_width();
	tsk->icon_height = imlib_image_get_height();
	for (k=0; k<TASK_STATE_COUNT; ++k) {
		imlib_context_set_image(orig_image);
		tsk->icon[k] = imlib_clone_image();
		imlib_context_set_image(tsk->icon[k]);
		DATA32 *data32;
		if (panel->g_task.alpha[k] != 100 || panel->g_task.saturation[k] != 0 || panel->g_task.brightness[k] != 0) {
			data32 = imlib_image_get_data();
			adjust_asb(data32, tsk->icon_width, tsk->icon_height, panel->g_task.alpha[k], (float)panel->g_task.saturation[k]/100, (float)panel->g_task.brightness[k]/100);
			imlib_image_put_back_data(data32);
		}
	}
	imlib_context_set_image(orig_image);
	imlib_free_image();

	if (hints)
		XFree(hints);
	if (data)
		XFree (data);

	GPtrArray* task_group = task_get_tasks(tsk->win);
	if (task_group) {
		for (i=0; i<task_group->len; ++i) {
			Task* tsk2 = g_ptr_array_index(task_group, i);
			tsk2->icon_width = tsk->icon_width;
			tsk2->icon_height = tsk->icon_height;
			int k;
			for (k=0; k<TASK_STATE_COUNT; ++k)
				tsk2->icon[k] = tsk->icon[k];
			set_task_redraw(tsk2);
		}
	}
}