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
|
fb_gdkpixbuf.c 0.2 Copyright (C) 2002, hito
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -6,124 +6,132 @@
|
|||||||
#include "fb.h"
|
#include "fb.h"
|
||||||
#include "fb_img.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;
|
GdkPixbuf *pixbuf;
|
||||||
IMAGE *img;
|
IMAGE *img;
|
||||||
|
|
||||||
if(filename == NULL)
|
if (filename == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
img = malloc(sizeof(*img));
|
img = malloc(sizeof(*img));
|
||||||
if(img == NULL)
|
if (img == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pixbuf = gdk_pixbuf_new_from_file(filename);
|
|
||||||
if(pixbuf == NULL){
|
|
||||||
free(img);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
img->pixbuf = pixbuf;
|
pixbuf = gdk_pixbuf_new_from_file(filename);
|
||||||
set_prm(img);
|
if (pixbuf == NULL) {
|
||||||
|
free(img);
|
||||||
fb_resize_image(img, w, h);
|
return NULL;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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;
|
int i, j, r, g, b, offset, bpp;
|
||||||
if(width < 1 || height < 1 || img == NULL)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
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;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pixbuf = gdk_pixbuf_scale_simple(img->pixbuf, width, height, GDK_INTERP_HYPER);
|
int
|
||||||
if(pixbuf == NULL)
|
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;
|
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)
|
GdkPixbuf *pixbuf;
|
||||||
return;
|
|
||||||
|
|
||||||
gdk_pixbuf_finalize(img->pixbuf);
|
if (img == NULL)
|
||||||
free(img);
|
return;
|
||||||
}
|
pixbuf = img->pixbuf;
|
||||||
|
|
||||||
IMAGE *fb_dup_image(IMAGE *img)
|
img->pixels = gdk_pixbuf_get_pixels(pixbuf);
|
||||||
{
|
img->width = gdk_pixbuf_get_width(pixbuf);
|
||||||
GdkPixbuf *pixbuf;
|
img->height = gdk_pixbuf_get_height(pixbuf);
|
||||||
IMAGE *new_img;
|
img->alpha = gdk_pixbuf_get_has_alpha(pixbuf);
|
||||||
|
img->rowstride = gdk_pixbuf_get_rowstride(pixbuf);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -10,21 +10,23 @@
|
|||||||
static int bg_r = 0, bg_g = 0, bg_b = 0;
|
static int bg_r = 0, bg_g = 0, bg_b = 0;
|
||||||
|
|
||||||
#if defined(USE_IMLIB2)
|
#if defined(USE_IMLIB2)
|
||||||
#include "w3mimg/fb/fb_imlib2.c"
|
#include "w3mimg/fb/fb_imlib2.c"
|
||||||
#elif defined(USE_GDKPIXBUF)
|
#elif defined(USE_GDKPIXBUF)
|
||||||
#include "w3mimg/fb/fb_gdkpixbuf.c"
|
#include "w3mimg/fb/fb_gdkpixbuf.c"
|
||||||
#else
|
#else
|
||||||
#error no Imlib2 and GdkPixbuf support
|
#error no Imlib2 and GdkPixbuf support
|
||||||
#endif
|
#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_r = r;
|
||||||
bg_g = g;
|
bg_g = g;
|
||||||
bg_b = b;
|
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
|
fb_imlib2.c 0.2 Copyright (C) 2002, hito
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -6,146 +6,157 @@
|
|||||||
#include "fb.h"
|
#include "fb.h"
|
||||||
#include "fb_img.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;
|
Imlib_Image image;
|
||||||
IMAGE *img;
|
IMAGE *img;
|
||||||
|
|
||||||
if(filename == NULL)
|
if (filename == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
img = malloc(sizeof(*img));
|
img = malloc(sizeof(*img));
|
||||||
if(img == NULL)
|
if (img == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
image = imlib_load_image(filename);
|
image = imlib_load_image(filename);
|
||||||
if(image == NULL){
|
if (image == NULL) {
|
||||||
free(img);
|
free(img);
|
||||||
return NULL;
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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)
|
if (img == NULL)
|
||||||
return 1;
|
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;
|
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)
|
Imlib_Image image;
|
||||||
return;
|
|
||||||
|
|
||||||
imlib_context_set_image(img->image);
|
if (width < 1 || height < 1 || img == NULL)
|
||||||
imlib_free_image();
|
return 1;
|
||||||
free(img);
|
|
||||||
|
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;
|
if (img == NULL)
|
||||||
IMAGE *new_img;
|
return;
|
||||||
|
|
||||||
if(img == NULL)
|
imlib_context_set_image(img->image);
|
||||||
return NULL;
|
imlib_free_image();
|
||||||
|
free(img);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
if (img == NULL)
|
||||||
return 1;
|
return NULL;
|
||||||
|
|
||||||
imlib_context_set_image(img->image);
|
new_img = malloc(sizeof(*img));
|
||||||
|
if (new_img == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if(angle == 90){
|
imlib_context_set_image(img->image);
|
||||||
orientation = 1;
|
image = imlib_clone_image();
|
||||||
}else if(angle == -90){
|
|
||||||
orientation = 3;
|
|
||||||
}else{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
imlib_image_orientate(orientation);
|
if (image == NULL) {
|
||||||
set_prm(img);
|
free(new_img);
|
||||||
return 0;
|
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)
|
int orientation;
|
||||||
return;
|
|
||||||
|
|
||||||
imlib_context_set_image(img->image);
|
if (img == NULL)
|
||||||
img->data = imlib_image_get_data_for_reading_only();
|
return 1;
|
||||||
img->width = imlib_image_get_width();
|
|
||||||
img->height = imlib_image_get_height();
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
/* $Id: w3mimg.c,v 1.1 2002/07/18 06:07:39 ukai Exp $ */
|
/* $Id: w3mimg.c,v 1.2 2002/07/18 15:14:36 ukai Exp $ */
|
||||||
|
|
||||||
#include "w3mimg/w3mimg.h"
|
#include "w3mimg/w3mimg.h"
|
||||||
|
|
||||||
w3mimg_op *w3mimg_open() {
|
w3mimg_op *
|
||||||
|
w3mimg_open()
|
||||||
|
{
|
||||||
w3mimg_op *w_op = NULL;
|
w3mimg_op *w_op = NULL;
|
||||||
#ifdef USE_W3MIMG_X11
|
#ifdef USE_W3MIMG_X11
|
||||||
if (w_op == NULL)
|
if (w_op == NULL)
|
||||||
@@ -14,4 +16,3 @@ w3mimg_op *w3mimg_open() {
|
|||||||
#endif
|
#endif
|
||||||
return w_op;
|
return w_op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: w3mimg.h,v 1.2 2002/07/18 06:07:25 ukai Exp $ */
|
/* $Id: w3mimg.h,v 1.3 2002/07/18 15:14:51 ukai Exp $ */
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef USE_W3MIMG_FB
|
#ifdef USE_W3MIMG_FB
|
||||||
@@ -7,28 +7,28 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *pixmap; /* driver specific */
|
void *pixmap; /* driver specific */
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
} W3MImage;
|
} W3MImage;
|
||||||
|
|
||||||
typedef struct _w3mimg_op {
|
typedef struct _w3mimg_op {
|
||||||
void *priv; /* driver specific data */
|
void *priv; /* driver specific data */
|
||||||
int width, height; /* window width, height */
|
int width, height; /* window width, height */
|
||||||
int offset_x, offset_y; /* offset */
|
int offset_x, offset_y; /* offset */
|
||||||
|
|
||||||
int (*init)(struct _w3mimg_op *self);
|
int (*init) (struct _w3mimg_op * self);
|
||||||
int (*finish)(struct _w3mimg_op *self);
|
int (*finish) (struct _w3mimg_op * self);
|
||||||
int (*active)(struct _w3mimg_op *self);
|
int (*active) (struct _w3mimg_op * self);
|
||||||
void (*set_background)(struct _w3mimg_op *self, char *background);
|
void (*set_background) (struct _w3mimg_op * self, char *background);
|
||||||
void (*sync)(struct _w3mimg_op *self);
|
void (*sync) (struct _w3mimg_op * self);
|
||||||
void (*close)(struct _w3mimg_op *self);
|
void (*close) (struct _w3mimg_op * self);
|
||||||
|
|
||||||
int (*load_image)(struct _w3mimg_op *self, W3MImage *img, char *fname,
|
int (*load_image) (struct _w3mimg_op * self, W3MImage * img, char *fname,
|
||||||
int w, int h);
|
int w, int h);
|
||||||
int (*show_image)(struct _w3mimg_op *self, W3MImage *img,
|
int (*show_image) (struct _w3mimg_op * self, W3MImage * img,
|
||||||
int sx, int sy, int sw, int sh, int x, int y);
|
int sx, int sy, int sw, int sh, int x, int y);
|
||||||
void (*free_image)(struct _w3mimg_op *self, W3MImage *img);
|
void (*free_image) (struct _w3mimg_op * self, W3MImage * img);
|
||||||
} w3mimg_op;
|
} w3mimg_op;
|
||||||
|
|
||||||
#ifdef USE_W3MIMG_X11
|
#ifdef USE_W3MIMG_X11
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: x11_w3mimg.c,v 1.3 2002/07/18 14:32:12 ukai Exp $ */
|
/* $Id: x11_w3mimg.c,v 1.4 2002/07/18 15:15:32 ukai Exp $ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -19,7 +19,7 @@ struct x11_info {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x11_init(w3mimg_op *self)
|
x11_init(w3mimg_op * self)
|
||||||
{
|
{
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
@@ -27,21 +27,21 @@ x11_init(w3mimg_op *self)
|
|||||||
xi = (struct x11_info *)self->priv;
|
xi = (struct x11_info *)self->priv;
|
||||||
if (xi == NULL)
|
if (xi == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (! xi->id) {
|
if (!xi->id) {
|
||||||
xi->id = Imlib_init(xi->display);
|
xi->id = Imlib_init(xi->display);
|
||||||
if (! xi->id)
|
if (!xi->id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (! xi->imageGC) {
|
if (!xi->imageGC) {
|
||||||
xi->imageGC = XCreateGC(xi->display, xi->parent, 0, NULL);
|
xi->imageGC = XCreateGC(xi->display, xi->parent, 0, NULL);
|
||||||
if (! xi->imageGC)
|
if (!xi->imageGC)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x11_finish(w3mimg_op *self)
|
x11_finish(w3mimg_op * self)
|
||||||
{
|
{
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
@@ -57,7 +57,7 @@ x11_finish(w3mimg_op *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x11_active(w3mimg_op *self)
|
x11_active(w3mimg_op * self)
|
||||||
{
|
{
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
@@ -65,13 +65,13 @@ x11_active(w3mimg_op *self)
|
|||||||
xi = (struct x11_info *)self->priv;
|
xi = (struct x11_info *)self->priv;
|
||||||
if (xi == NULL)
|
if (xi == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (! xi->imageGC)
|
if (!xi->imageGC)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
x11_set_background(w3mimg_op *self, char *background)
|
x11_set_background(w3mimg_op * self, char *background)
|
||||||
{
|
{
|
||||||
XColor screen_def, exact_def;
|
XColor screen_def, exact_def;
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
@@ -81,7 +81,7 @@ x11_set_background(w3mimg_op *self, char *background)
|
|||||||
if (xi == NULL)
|
if (xi == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (background &&
|
if (background &&
|
||||||
XAllocNamedColor(xi->display, DefaultColormap(xi->display, 0),
|
XAllocNamedColor(xi->display, DefaultColormap(xi->display, 0),
|
||||||
background, &screen_def, &exact_def))
|
background, &screen_def, &exact_def))
|
||||||
xi->background_pixel = screen_def.pixel;
|
xi->background_pixel = screen_def.pixel;
|
||||||
@@ -90,11 +90,11 @@ x11_set_background(w3mimg_op *self, char *background)
|
|||||||
GC gc;
|
GC gc;
|
||||||
XImage *i;
|
XImage *i;
|
||||||
|
|
||||||
p = XCreatePixmap(xi->display, xi->window, 1, 1,
|
p = XCreatePixmap(xi->display, xi->window, 1, 1,
|
||||||
DefaultDepth(xi->display, 0));
|
DefaultDepth(xi->display, 0));
|
||||||
gc = XCreateGC(xi->display, xi->window, 0, NULL);
|
gc = XCreateGC(xi->display, xi->window, 0, NULL);
|
||||||
if (!p || !gc)
|
if (!p || !gc)
|
||||||
exit(1); /* XXX */
|
exit(1); /* XXX */
|
||||||
XCopyArea(xi->display, xi->window, p, gc,
|
XCopyArea(xi->display, xi->window, p, gc,
|
||||||
(self->offset_x >= 1) ? (self->offset_x - 1) : 0,
|
(self->offset_x >= 1) ? (self->offset_x - 1) : 0,
|
||||||
(self->offset_y >= 1) ? (self->offset_y - 1) : 0,
|
(self->offset_y >= 1) ? (self->offset_y - 1) : 0,
|
||||||
@@ -110,7 +110,7 @@ x11_set_background(w3mimg_op *self, char *background)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
x11_sync(w3mimg_op *self)
|
x11_sync(w3mimg_op * self)
|
||||||
{
|
{
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
@@ -122,13 +122,13 @@ x11_sync(w3mimg_op *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
x11_close(w3mimg_op *self)
|
x11_close(w3mimg_op * self)
|
||||||
{
|
{
|
||||||
/* XCloseDisplay(xi->display); */
|
/* XCloseDisplay(xi->display); */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x11_load_image(w3mimg_op *self, W3MImage *img, char *fname, int w, int h)
|
x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
|
||||||
{
|
{
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
ImlibImage *im;
|
ImlibImage *im;
|
||||||
@@ -148,11 +148,11 @@ x11_load_image(w3mimg_op *self, W3MImage *img, char *fname, int w, int h)
|
|||||||
h = im->rgb_height;
|
h = im->rgb_height;
|
||||||
img->pixmap = (void *)XCreatePixmap(xi->display, xi->parent, w, h,
|
img->pixmap = (void *)XCreatePixmap(xi->display, xi->parent, w, h,
|
||||||
DefaultDepth(xi->display, 0));
|
DefaultDepth(xi->display, 0));
|
||||||
if (! img->pixmap)
|
if (!img->pixmap)
|
||||||
return 0;
|
return 0;
|
||||||
XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
|
XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
|
||||||
XFillRectangle(xi->display, (Pixmap)img->pixmap, xi->imageGC, 0, 0, w, h);
|
XFillRectangle(xi->display, (Pixmap) img->pixmap, xi->imageGC, 0, 0, w, h);
|
||||||
Imlib_paste_image(xi->id, im, (Pixmap)img->pixmap, 0, 0, w, h);
|
Imlib_paste_image(xi->id, im, (Pixmap) img->pixmap, 0, 0, w, h);
|
||||||
Imlib_kill_image(xi->id, im);
|
Imlib_kill_image(xi->id, im);
|
||||||
img->width = w;
|
img->width = w;
|
||||||
img->height = h;
|
img->height = h;
|
||||||
@@ -160,8 +160,8 @@ x11_load_image(w3mimg_op *self, W3MImage *img, char *fname, int w, int h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x11_show_image(w3mimg_op *self, W3MImage *img, int sx, int sy, int sw, int sh,
|
x11_show_image(w3mimg_op * self, W3MImage * img, int sx, int sy, int sw,
|
||||||
int x, int y)
|
int sh, int x, int y)
|
||||||
{
|
{
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
@@ -170,16 +170,15 @@ x11_show_image(w3mimg_op *self, W3MImage *img, int sx, int sy, int sw, int sh,
|
|||||||
if (xi == NULL)
|
if (xi == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
XCopyArea(xi->display, (Pixmap)img->pixmap, xi->window, xi->imageGC,
|
XCopyArea(xi->display, (Pixmap) img->pixmap, xi->window, xi->imageGC,
|
||||||
sx, sy,
|
sx, sy,
|
||||||
(sw ? sw : img->width),
|
(sw ? sw : img->width),
|
||||||
(sh ? sh : img->height),
|
(sh ? sh : img->height), x + self->offset_x, y + self->offset_y);
|
||||||
x + self->offset_x, y + self->offset_y);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
x11_free_image(w3mimg_op *self, W3MImage *img)
|
x11_free_image(w3mimg_op * self, W3MImage * img)
|
||||||
{
|
{
|
||||||
struct x11_info *xi;
|
struct x11_info *xi;
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
@@ -188,7 +187,7 @@ x11_free_image(w3mimg_op *self, W3MImage *img)
|
|||||||
if (xi == NULL)
|
if (xi == NULL)
|
||||||
return;
|
return;
|
||||||
if (img && img->pixmap) {
|
if (img && img->pixmap) {
|
||||||
XFreePixmap(xi->display, (Pixmap)img->pixmap);
|
XFreePixmap(xi->display, (Pixmap) img->pixmap);
|
||||||
img->pixmap = NULL;
|
img->pixmap = NULL;
|
||||||
img->width = 0;
|
img->width = 0;
|
||||||
img->height = 0;
|
img->height = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user