indent
This commit is contained in:
		
							
								
								
									
										1100
									
								
								w3mimg/fb/fb.c
									
									
									
									
									
								
							
							
						
						
									
										1100
									
								
								w3mimg/fb/fb.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: fb_gdkpixbuf.c,v 1.4 2002/07/18 15:01:31 ukai Exp $ */
 | 
			
		||||
/* $Id: fb_gdkpixbuf.c,v 1.5 2002/07/18 15:12:06 ukai Exp $ */
 | 
			
		||||
/**************************************************************************
 | 
			
		||||
                fb_gdkpixbuf.c 0.2 Copyright (C) 2002, hito
 | 
			
		||||
 **************************************************************************/
 | 
			
		||||
@@ -6,124 +6,132 @@
 | 
			
		||||
#include "fb.h"
 | 
			
		||||
#include "fb_img.h"
 | 
			
		||||
 | 
			
		||||
static void set_prm(IMAGE *img);
 | 
			
		||||
static void set_prm(IMAGE * img);
 | 
			
		||||
 | 
			
		||||
IMAGE *fb_load_image(char *filename, int w, int h)
 | 
			
		||||
IMAGE *
 | 
			
		||||
fb_load_image(char *filename, int w, int h)
 | 
			
		||||
{
 | 
			
		||||
  GdkPixbuf *pixbuf;
 | 
			
		||||
  IMAGE *img;
 | 
			
		||||
    GdkPixbuf *pixbuf;
 | 
			
		||||
    IMAGE *img;
 | 
			
		||||
 | 
			
		||||
  if(filename == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
    if (filename == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
  img = malloc(sizeof(*img));
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
  
 | 
			
		||||
  pixbuf = gdk_pixbuf_new_from_file(filename);
 | 
			
		||||
  if(pixbuf == NULL){
 | 
			
		||||
    free(img);
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
    img = malloc(sizeof(*img));
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
  img->pixbuf = pixbuf;
 | 
			
		||||
  set_prm(img);
 | 
			
		||||
 | 
			
		||||
  fb_resize_image(img, w, h);
 | 
			
		||||
 | 
			
		||||
  return img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int fb_draw_image(IMAGE *img, int x, int y, int sx, int sy, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
  int i, j, r, g, b, offset, bpp;
 | 
			
		||||
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return 1;
 | 
			
		||||
 | 
			
		||||
  bpp = img->rowstride / img->width;
 | 
			
		||||
  for(j = sy; j < sy + height && j < img->height; j++){
 | 
			
		||||
    offset = j * img->rowstride + bpp * sx;
 | 
			
		||||
    for(i = sx; i < sx + width && i < img->width; i++, offset += bpp){
 | 
			
		||||
      r = img->pixels[offset];
 | 
			
		||||
      g = img->pixels[offset + 1];
 | 
			
		||||
      b = img->pixels[offset + 2];
 | 
			
		||||
      if(img->alpha && img->pixels[offset + 3] == 0)
 | 
			
		||||
	fb_pset(i + x - sx, j + y - sy, bg_r, bg_g, bg_b);
 | 
			
		||||
      else
 | 
			
		||||
	fb_pset(i + x - sx, j + y - sy, r, g, b);
 | 
			
		||||
    pixbuf = gdk_pixbuf_new_from_file(filename);
 | 
			
		||||
    if (pixbuf == NULL) {
 | 
			
		||||
	free(img);
 | 
			
		||||
	return NULL;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
 | 
			
		||||
    img->pixbuf = pixbuf;
 | 
			
		||||
    set_prm(img);
 | 
			
		||||
 | 
			
		||||
    fb_resize_image(img, w, h);
 | 
			
		||||
 | 
			
		||||
    return img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int fb_resize_image(IMAGE *img, int width, int height)
 | 
			
		||||
int
 | 
			
		||||
fb_draw_image(IMAGE * img, int x, int y, int sx, int sy, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
  GdkPixbuf *pixbuf;
 | 
			
		||||
  if(width < 1 || height < 1 || img == NULL)
 | 
			
		||||
    return 1;
 | 
			
		||||
    int i, j, r, g, b, offset, bpp;
 | 
			
		||||
 | 
			
		||||
  if(width == img->width && height == img->height)
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
    bpp = img->rowstride / img->width;
 | 
			
		||||
    for (j = sy; j < sy + height && j < img->height; j++) {
 | 
			
		||||
	offset = j * img->rowstride + bpp * sx;
 | 
			
		||||
	for (i = sx; i < sx + width && i < img->width; i++, offset += bpp) {
 | 
			
		||||
	    r = img->pixels[offset];
 | 
			
		||||
	    g = img->pixels[offset + 1];
 | 
			
		||||
	    b = img->pixels[offset + 2];
 | 
			
		||||
	    if (img->alpha && img->pixels[offset + 3] == 0)
 | 
			
		||||
		fb_pset(i + x - sx, j + y - sy, bg_r, bg_g, bg_b);
 | 
			
		||||
	    else
 | 
			
		||||
		fb_pset(i + x - sx, j + y - sy, r, g, b);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
  pixbuf = gdk_pixbuf_scale_simple(img->pixbuf, width, height, GDK_INTERP_HYPER);
 | 
			
		||||
  if(pixbuf == NULL)
 | 
			
		||||
int
 | 
			
		||||
fb_resize_image(IMAGE * img, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
    GdkPixbuf *pixbuf;
 | 
			
		||||
    if (width < 1 || height < 1 || img == NULL)
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
    if (width == img->width && height == img->height)
 | 
			
		||||
	return 0;
 | 
			
		||||
 | 
			
		||||
    pixbuf =
 | 
			
		||||
	gdk_pixbuf_scale_simple(img->pixbuf, width, height, GDK_INTERP_HYPER);
 | 
			
		||||
    if (pixbuf == NULL)
 | 
			
		||||
	return 1;
 | 
			
		||||
    gdk_pixbuf_finalize(img->pixbuf);
 | 
			
		||||
 | 
			
		||||
    img->pixbuf = pixbuf;
 | 
			
		||||
    set_prm(img);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fb_free_image(IMAGE * img)
 | 
			
		||||
{
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return;
 | 
			
		||||
 | 
			
		||||
    gdk_pixbuf_finalize(img->pixbuf);
 | 
			
		||||
    free(img);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IMAGE *
 | 
			
		||||
fb_dup_image(IMAGE * img)
 | 
			
		||||
{
 | 
			
		||||
    GdkPixbuf *pixbuf;
 | 
			
		||||
    IMAGE *new_img;
 | 
			
		||||
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
    new_img = malloc(sizeof(*img));
 | 
			
		||||
    if (new_img == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
    pixbuf = gdk_pixbuf_copy(img->pixbuf);
 | 
			
		||||
    if (pixbuf == NULL) {
 | 
			
		||||
	free(new_img);
 | 
			
		||||
	return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    new_img->pixbuf = pixbuf;
 | 
			
		||||
    set_prm(new_img);
 | 
			
		||||
    return new_img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
fb_rotate_image(IMAGE * img, int angle)
 | 
			
		||||
{
 | 
			
		||||
    return 1;
 | 
			
		||||
  gdk_pixbuf_finalize(img->pixbuf);
 | 
			
		||||
 | 
			
		||||
  img->pixbuf = pixbuf;
 | 
			
		||||
  set_prm(img);
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void fb_free_image(IMAGE *img)
 | 
			
		||||
static void
 | 
			
		||||
set_prm(IMAGE * img)
 | 
			
		||||
{
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return;
 | 
			
		||||
    GdkPixbuf *pixbuf;
 | 
			
		||||
 | 
			
		||||
  gdk_pixbuf_finalize(img->pixbuf);
 | 
			
		||||
  free(img);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IMAGE *fb_dup_image(IMAGE *img)
 | 
			
		||||
{
 | 
			
		||||
  GdkPixbuf *pixbuf;
 | 
			
		||||
  IMAGE *new_img;
 | 
			
		||||
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
 | 
			
		||||
  new_img = malloc(sizeof(*img));
 | 
			
		||||
  if(new_img == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
 | 
			
		||||
  pixbuf = gdk_pixbuf_copy(img->pixbuf);
 | 
			
		||||
  if(pixbuf == NULL){
 | 
			
		||||
    free(new_img);
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  new_img->pixbuf = pixbuf;
 | 
			
		||||
  set_prm(new_img);
 | 
			
		||||
  return new_img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int fb_rotate_image(IMAGE *img, int angle)
 | 
			
		||||
{
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void set_prm(IMAGE *img)
 | 
			
		||||
{
 | 
			
		||||
  GdkPixbuf *pixbuf;
 | 
			
		||||
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return;
 | 
			
		||||
  pixbuf = img->pixbuf;
 | 
			
		||||
 | 
			
		||||
  img->pixels = gdk_pixbuf_get_pixels(pixbuf);
 | 
			
		||||
  img->width  = gdk_pixbuf_get_width(pixbuf);
 | 
			
		||||
  img->height = gdk_pixbuf_get_height(pixbuf);
 | 
			
		||||
  img->alpha  = gdk_pixbuf_get_has_alpha(pixbuf);
 | 
			
		||||
  img->rowstride = gdk_pixbuf_get_rowstride(pixbuf);
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return;
 | 
			
		||||
    pixbuf = img->pixbuf;
 | 
			
		||||
 | 
			
		||||
    img->pixels = gdk_pixbuf_get_pixels(pixbuf);
 | 
			
		||||
    img->width = gdk_pixbuf_get_width(pixbuf);
 | 
			
		||||
    img->height = gdk_pixbuf_get_height(pixbuf);
 | 
			
		||||
    img->alpha = gdk_pixbuf_get_has_alpha(pixbuf);
 | 
			
		||||
    img->rowstride = gdk_pixbuf_get_rowstride(pixbuf);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: fb_img.c,v 1.2 2002/07/18 15:01:31 ukai Exp $ */
 | 
			
		||||
/* $Id: fb_img.c,v 1.3 2002/07/18 15:13:13 ukai Exp $ */
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
@@ -10,21 +10,23 @@
 | 
			
		||||
static int bg_r = 0, bg_g = 0, bg_b = 0;
 | 
			
		||||
 | 
			
		||||
#if defined(USE_IMLIB2)
 | 
			
		||||
 #include "w3mimg/fb/fb_imlib2.c"
 | 
			
		||||
#include "w3mimg/fb/fb_imlib2.c"
 | 
			
		||||
#elif defined(USE_GDKPIXBUF)
 | 
			
		||||
 #include "w3mimg/fb/fb_gdkpixbuf.c"
 | 
			
		||||
#include "w3mimg/fb/fb_gdkpixbuf.c"
 | 
			
		||||
#else
 | 
			
		||||
#error no Imlib2 and GdkPixbuf support
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int fb_draw_image_simple(IMAGE *img, int x, int y)
 | 
			
		||||
int
 | 
			
		||||
fb_draw_image_simple(IMAGE * img, int x, int y)
 | 
			
		||||
{
 | 
			
		||||
  return fb_draw_image(img, x, y, 0, 0, img->width, img->height);
 | 
			
		||||
    return fb_draw_image(img, x, y, 0, 0, img->width, img->height);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void fb_set_bg(int r, int g, int b)
 | 
			
		||||
void
 | 
			
		||||
fb_set_bg(int r, int g, int b)
 | 
			
		||||
{
 | 
			
		||||
  bg_r = r;
 | 
			
		||||
  bg_g = g;
 | 
			
		||||
  bg_b = b;
 | 
			
		||||
    bg_r = r;
 | 
			
		||||
    bg_g = g;
 | 
			
		||||
    bg_b = b;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: fb_imlib2.c,v 1.4 2002/07/18 15:01:31 ukai Exp $ */
 | 
			
		||||
/* $Id: fb_imlib2.c,v 1.5 2002/07/18 15:14:21 ukai Exp $ */
 | 
			
		||||
/**************************************************************************
 | 
			
		||||
                fb_imlib2.c 0.2 Copyright (C) 2002, hito
 | 
			
		||||
 **************************************************************************/
 | 
			
		||||
@@ -6,146 +6,157 @@
 | 
			
		||||
#include "fb.h"
 | 
			
		||||
#include "fb_img.h"
 | 
			
		||||
 | 
			
		||||
static void set_prm(IMAGE *img);
 | 
			
		||||
static void set_prm(IMAGE * img);
 | 
			
		||||
 | 
			
		||||
IMAGE *fb_load_image(char *filename, int w, int h)
 | 
			
		||||
IMAGE *
 | 
			
		||||
fb_load_image(char *filename, int w, int h)
 | 
			
		||||
{
 | 
			
		||||
  Imlib_Image image;
 | 
			
		||||
  IMAGE *img;
 | 
			
		||||
    Imlib_Image image;
 | 
			
		||||
    IMAGE *img;
 | 
			
		||||
 | 
			
		||||
  if(filename == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
    if (filename == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
  img = malloc(sizeof(*img));
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
    img = malloc(sizeof(*img));
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
  image = imlib_load_image(filename);
 | 
			
		||||
  if(image == NULL){
 | 
			
		||||
    free(img);
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  imlib_context_set_image(image);
 | 
			
		||||
 | 
			
		||||
  img->image = image;
 | 
			
		||||
  set_prm(img);
 | 
			
		||||
 | 
			
		||||
  fb_resize_image(img, w, h);
 | 
			
		||||
 | 
			
		||||
  return img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int fb_draw_image(IMAGE *img, int x, int y, int sx, int sy, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
  int i, j, r, g, b, a = 0, offset;
 | 
			
		||||
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return 1;
 | 
			
		||||
 | 
			
		||||
  for(j = sy; j < sy + height && j < img->height; j++){
 | 
			
		||||
    offset = j * img->width;
 | 
			
		||||
    for(i = sx; i < sx + width && i < img->width; i++){
 | 
			
		||||
      a = (img->data[offset + i] >> 24) & 0x000000ff;
 | 
			
		||||
      r = (img->data[offset + i] >> 16) & 0x000000ff;
 | 
			
		||||
      g = (img->data[offset + i] >>  8) & 0x000000ff;
 | 
			
		||||
      b = (img->data[offset + i]      ) & 0x000000ff;
 | 
			
		||||
 | 
			
		||||
      if(a == 0)
 | 
			
		||||
	fb_pset(i + x - sx, j + y - sy, bg_r, bg_g, bg_b);
 | 
			
		||||
      else
 | 
			
		||||
	fb_pset(i + x - sx, j + y - sy, r, g, b);
 | 
			
		||||
    image = imlib_load_image(filename);
 | 
			
		||||
    if (image == NULL) {
 | 
			
		||||
	free(img);
 | 
			
		||||
	return NULL;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
 | 
			
		||||
    imlib_context_set_image(image);
 | 
			
		||||
 | 
			
		||||
    img->image = image;
 | 
			
		||||
    set_prm(img);
 | 
			
		||||
 | 
			
		||||
    fb_resize_image(img, w, h);
 | 
			
		||||
 | 
			
		||||
    return img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int fb_resize_image(IMAGE *img, int width, int height)
 | 
			
		||||
int
 | 
			
		||||
fb_draw_image(IMAGE * img, int x, int y, int sx, int sy, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
  Imlib_Image image;
 | 
			
		||||
    int i, j, r, g, b, a = 0, offset;
 | 
			
		||||
 | 
			
		||||
  if(width < 1 || height < 1 || img == NULL)
 | 
			
		||||
    return 1;
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
  if(width == img->width && height == img->height)
 | 
			
		||||
    for (j = sy; j < sy + height && j < img->height; j++) {
 | 
			
		||||
	offset = j * img->width;
 | 
			
		||||
	for (i = sx; i < sx + width && i < img->width; i++) {
 | 
			
		||||
	    a = (img->data[offset + i] >> 24) & 0x000000ff;
 | 
			
		||||
	    r = (img->data[offset + i] >> 16) & 0x000000ff;
 | 
			
		||||
	    g = (img->data[offset + i] >> 8) & 0x000000ff;
 | 
			
		||||
	    b = (img->data[offset + i]) & 0x000000ff;
 | 
			
		||||
 | 
			
		||||
	    if (a == 0)
 | 
			
		||||
		fb_pset(i + x - sx, j + y - sy, bg_r, bg_g, bg_b);
 | 
			
		||||
	    else
 | 
			
		||||
		fb_pset(i + x - sx, j + y - sy, r, g, b);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
  image = imlib_create_cropped_scaled_image(0, 0, img->width, img->height, width, height);
 | 
			
		||||
  if(image == NULL)
 | 
			
		||||
    return 1;
 | 
			
		||||
 | 
			
		||||
  imlib_context_set_image(img->image);
 | 
			
		||||
  imlib_free_image();
 | 
			
		||||
 | 
			
		||||
  img->image = image;
 | 
			
		||||
  set_prm(img);
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void fb_free_image(IMAGE *img)
 | 
			
		||||
int
 | 
			
		||||
fb_resize_image(IMAGE * img, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return;
 | 
			
		||||
    Imlib_Image image;
 | 
			
		||||
 | 
			
		||||
  imlib_context_set_image(img->image);
 | 
			
		||||
  imlib_free_image();
 | 
			
		||||
  free(img);
 | 
			
		||||
    if (width < 1 || height < 1 || img == NULL)
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
    if (width == img->width && height == img->height)
 | 
			
		||||
	return 0;
 | 
			
		||||
 | 
			
		||||
    image =
 | 
			
		||||
	imlib_create_cropped_scaled_image(0, 0, img->width, img->height, width,
 | 
			
		||||
					  height);
 | 
			
		||||
    if (image == NULL)
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
    imlib_context_set_image(img->image);
 | 
			
		||||
    imlib_free_image();
 | 
			
		||||
 | 
			
		||||
    img->image = image;
 | 
			
		||||
    set_prm(img);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IMAGE *fb_dup_image(IMAGE *img)
 | 
			
		||||
void
 | 
			
		||||
fb_free_image(IMAGE * img)
 | 
			
		||||
{
 | 
			
		||||
  Imlib_Image image;
 | 
			
		||||
  IMAGE *new_img;
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return;
 | 
			
		||||
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
 | 
			
		||||
  new_img = malloc(sizeof(*img));
 | 
			
		||||
  if(new_img == NULL)
 | 
			
		||||
    return NULL;
 | 
			
		||||
 | 
			
		||||
  imlib_context_set_image(img->image);
 | 
			
		||||
  image = imlib_clone_image();
 | 
			
		||||
 | 
			
		||||
  if(image == NULL){
 | 
			
		||||
    free(new_img);
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  new_img->image = image;
 | 
			
		||||
  set_prm(new_img);
 | 
			
		||||
  return new_img;
 | 
			
		||||
    imlib_context_set_image(img->image);
 | 
			
		||||
    imlib_free_image();
 | 
			
		||||
    free(img);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int fb_rotate_image(IMAGE *img, int angle)
 | 
			
		||||
IMAGE *
 | 
			
		||||
fb_dup_image(IMAGE * img)
 | 
			
		||||
{
 | 
			
		||||
  int orientation;
 | 
			
		||||
    Imlib_Image image;
 | 
			
		||||
    IMAGE *new_img;
 | 
			
		||||
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return 1;
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
  imlib_context_set_image(img->image);
 | 
			
		||||
    new_img = malloc(sizeof(*img));
 | 
			
		||||
    if (new_img == NULL)
 | 
			
		||||
	return NULL;
 | 
			
		||||
 | 
			
		||||
  if(angle == 90){
 | 
			
		||||
    orientation = 1;
 | 
			
		||||
  }else if(angle == -90){
 | 
			
		||||
    orientation = 3;
 | 
			
		||||
  }else{
 | 
			
		||||
    return 1;
 | 
			
		||||
  }
 | 
			
		||||
    imlib_context_set_image(img->image);
 | 
			
		||||
    image = imlib_clone_image();
 | 
			
		||||
 | 
			
		||||
  imlib_image_orientate(orientation);
 | 
			
		||||
  set_prm(img);
 | 
			
		||||
  return 0;
 | 
			
		||||
    if (image == NULL) {
 | 
			
		||||
	free(new_img);
 | 
			
		||||
	return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    new_img->image = image;
 | 
			
		||||
    set_prm(new_img);
 | 
			
		||||
    return new_img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void set_prm(IMAGE *img)
 | 
			
		||||
int
 | 
			
		||||
fb_rotate_image(IMAGE * img, int angle)
 | 
			
		||||
{
 | 
			
		||||
  if(img == NULL)
 | 
			
		||||
    return;
 | 
			
		||||
    int orientation;
 | 
			
		||||
 | 
			
		||||
  imlib_context_set_image(img->image);
 | 
			
		||||
  img->data   = imlib_image_get_data_for_reading_only();
 | 
			
		||||
  img->width  = imlib_image_get_width();
 | 
			
		||||
  img->height = imlib_image_get_height();
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return 1;
 | 
			
		||||
 | 
			
		||||
    imlib_context_set_image(img->image);
 | 
			
		||||
 | 
			
		||||
    if (angle == 90) {
 | 
			
		||||
	orientation = 1;
 | 
			
		||||
    }
 | 
			
		||||
    else if (angle == -90) {
 | 
			
		||||
	orientation = 3;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
	return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    imlib_image_orientate(orientation);
 | 
			
		||||
    set_prm(img);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
set_prm(IMAGE * img)
 | 
			
		||||
{
 | 
			
		||||
    if (img == NULL)
 | 
			
		||||
	return;
 | 
			
		||||
 | 
			
		||||
    imlib_context_set_image(img->image);
 | 
			
		||||
    img->data = imlib_image_get_data_for_reading_only();
 | 
			
		||||
    img->width = imlib_image_get_width();
 | 
			
		||||
    img->height = imlib_image_get_height();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user