forked from vitrine/wmaker
Compare commits
5 Commits
migrate-to
...
trial-rust
| Author | SHA1 | Date | |
|---|---|---|---|
| 8814830f89 | |||
| 3256959257 | |||
| 639a401f7f | |||
| 0aecec095f | |||
| 66e2ade2dc |
@@ -444,7 +444,7 @@ static Bool loadPixmaps(WMScreen * scr)
|
||||
if (!image)
|
||||
image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
|
||||
if (!image) {
|
||||
wwarning(_("WINGs: could not load widget images file: %s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("WINGs: could not load widget images file: %s"), wraster_current_error_message());
|
||||
return False;
|
||||
}
|
||||
/* home icon */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
# http_archive(
|
||||
# name = "bazel_pkg_config",
|
||||
@@ -6,6 +6,26 @@
|
||||
# urls = ["https://github.com/cherrry/bazel_pkg_config/archive/master.zip"],
|
||||
# )
|
||||
|
||||
# To find additional information on this release or newer ones visit:
|
||||
# https://github.com/bazelbuild/rules_rust/releases
|
||||
http_archive(
|
||||
name = "rules_rust",
|
||||
integrity = "sha256-Weev1uz2QztBlDA88JX6A1N72SucD1V8lBsaliM0TTg=",
|
||||
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.48.0/rules_rust-v0.48.0.tar.gz"],
|
||||
)
|
||||
|
||||
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
|
||||
|
||||
rules_rust_dependencies()
|
||||
rust_register_toolchains()
|
||||
|
||||
rust_register_toolchains(
|
||||
edition = "2021",
|
||||
versions = [
|
||||
"1.79.0"
|
||||
],
|
||||
)
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
|
||||
local_repository(
|
||||
name = "bazel_pkg_config",
|
||||
|
||||
@@ -657,7 +657,7 @@ renderTexture(WScreen * scr, WTexture * texture, int width, int height,
|
||||
|
||||
img = wTextureRenderImage(texture, width, height, WREL_FLAT);
|
||||
if (!img) {
|
||||
wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("could not render texture: %s"), wraster_current_error_message());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -680,7 +680,7 @@ renderTexture(WScreen * scr, WTexture * texture, int width, int height,
|
||||
if (limg) {
|
||||
RBevelImage(limg, RBEV_RAISED2);
|
||||
if (!RConvertImage(scr->rcontext, limg, lbutton))
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
|
||||
x += limg->width;
|
||||
w -= limg->width;
|
||||
@@ -690,7 +690,7 @@ renderTexture(WScreen * scr, WTexture * texture, int width, int height,
|
||||
if (timg) {
|
||||
RBevelImage(timg, RBEV_RAISED2);
|
||||
if (!RConvertImage(scr->rcontext, timg, languagebutton))
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
|
||||
x += timg->width;
|
||||
w -= timg->width;
|
||||
@@ -706,7 +706,7 @@ renderTexture(WScreen * scr, WTexture * texture, int width, int height,
|
||||
if (rimg) {
|
||||
RBevelImage(rimg, RBEV_RAISED2);
|
||||
if (!RConvertImage(scr->rcontext, rimg, rbutton))
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
|
||||
w -= rimg->width;
|
||||
RReleaseImage(rimg);
|
||||
@@ -717,20 +717,20 @@ renderTexture(WScreen * scr, WTexture * texture, int width, int height,
|
||||
RBevelImage(mimg, RBEV_RAISED2);
|
||||
|
||||
if (!RConvertImage(scr->rcontext, mimg, title))
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
|
||||
RReleaseImage(mimg);
|
||||
} else {
|
||||
RBevelImage(img, RBEV_RAISED2);
|
||||
|
||||
if (!RConvertImage(scr->rcontext, img, title))
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
}
|
||||
} else {
|
||||
RBevelImage(img, RBEV_RAISED2);
|
||||
|
||||
if (!RConvertImage(scr->rcontext, img, title))
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
}
|
||||
|
||||
RReleaseImage(img);
|
||||
@@ -747,7 +747,7 @@ renderResizebarTexture(WScreen * scr, WTexture * texture, int width, int height,
|
||||
|
||||
img = wTextureRenderImage(texture, width, height, WREL_FLAT);
|
||||
if (!img) {
|
||||
wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("could not render texture: %s"), wraster_current_error_message());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -775,7 +775,7 @@ renderResizebarTexture(WScreen * scr, WTexture * texture, int width, int height,
|
||||
#endif /* SHADOW_RESIZEBAR */
|
||||
|
||||
if (!RConvertImage(scr->rcontext, img, pmap))
|
||||
wwarning(_("error rendering image: %s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image: %s"), wraster_current_error_message());
|
||||
|
||||
RReleaseImage(img);
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ static void icon_update_pixmap(WIcon *icon, RImage *image)
|
||||
}
|
||||
|
||||
if (!RConvertImage(scr->rcontext, tile, &pixmap))
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
|
||||
RReleaseImage(tile);
|
||||
|
||||
|
||||
@@ -402,7 +402,7 @@ static Pixmap renderTexture(WMenu * menu)
|
||||
img = wTextureRenderImage(texture, menu->menu->width, menu->menu->height + 1, WREL_MENUENTRY);
|
||||
}
|
||||
if (!img) {
|
||||
wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("could not render texture: %s"), wraster_current_error_message());
|
||||
|
||||
return None;
|
||||
}
|
||||
@@ -429,7 +429,7 @@ static Pixmap renderTexture(WMenu * menu)
|
||||
}
|
||||
}
|
||||
if (!RConvertImage(scr->rcontext, img, &pix)) {
|
||||
wwarning(_("error rendering image:%s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("error rendering image:%s"), wraster_current_error_message());
|
||||
}
|
||||
RReleaseImage(img);
|
||||
|
||||
|
||||
@@ -526,7 +526,7 @@ void create_logo_image(WScreen *scr)
|
||||
RImage *image = get_icon_image(scr, "Logo", "WMPanel", 128);
|
||||
|
||||
if (!image) {
|
||||
wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("could not load logo image for panels: %s"), wraster_current_error_message());
|
||||
} else {
|
||||
WMSetApplicationIconImage(scr->wmscreen, image);
|
||||
RReleaseImage(image);
|
||||
@@ -702,8 +702,8 @@ WScreen *wScreenInit(int screen_number)
|
||||
|
||||
scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
|
||||
|
||||
if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
|
||||
wwarning("%s", RMessageForError(RErrorCode));
|
||||
if (!scr->rcontext && wraster_current_error_code() == RERR_STDCMAPFAIL) {
|
||||
wwarning("%s", wraster_current_error_message());
|
||||
|
||||
rattr.flags &= ~RC_StandardColormap;
|
||||
rattr.standard_colormap_mode = RUseStdColormap;
|
||||
@@ -712,7 +712,7 @@ WScreen *wScreenInit(int screen_number)
|
||||
}
|
||||
if (scr->rcontext == NULL) {
|
||||
wfatal(_("can't create Context on screen %d, %s"),
|
||||
screen_number, RMessageForError(RErrorCode));
|
||||
screen_number, wraster_current_error_message());
|
||||
goto abort_no_context;
|
||||
}
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ static RImage * get_texture_image(WScreen *scr, const char *pixmap_file)
|
||||
}
|
||||
image = RLoadImage(scr->rcontext, file, 0);
|
||||
if (!image) {
|
||||
wwarning(_("could not load texture pixmap \"%s\":%s"), file, RMessageForError(RErrorCode));
|
||||
wwarning(_("could not load texture pixmap \"%s\":%s"), file, wraster_current_error_message());
|
||||
wfree(file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -451,7 +451,7 @@ RImage *wTextureRenderImage(WTexture * texture, int width, int height, int relie
|
||||
if (!image) {
|
||||
RColor gray;
|
||||
|
||||
wwarning(_("could not render texture: %s"), RMessageForError(RErrorCode));
|
||||
wwarning(_("could not render texture: %s"), wraster_current_error_message());
|
||||
|
||||
image = RCreateImage(width, height, False);
|
||||
if (image == NULL) {
|
||||
|
||||
@@ -433,7 +433,7 @@ RImage *get_rimage_from_file(WScreen *scr, const char *file_name, int max_size)
|
||||
image = RLoadImage(scr->rcontext, file_name, 0);
|
||||
if (!image)
|
||||
wwarning(_("error loading image file \"%s\": %s"), file_name,
|
||||
RMessageForError(RErrorCode));
|
||||
wraster_current_error_message());
|
||||
|
||||
image = wIconValidateIconSize(image, max_size);
|
||||
|
||||
|
||||
@@ -488,7 +488,7 @@ static int showIconFor(WMScreen *scrPtr, InspectorPanel *panel, const char *wm_i
|
||||
|
||||
buf = wmalloc(len);
|
||||
snprintf(buf, len, _("Could not open specified icon \"%s\":%s"),
|
||||
file, RMessageForError(RErrorCode));
|
||||
file, wraster_current_error_message());
|
||||
wMessageDialog(panel->frame->screen_ptr, _("Error"), buf, _("OK"), NULL, NULL);
|
||||
wfree(buf);
|
||||
wfree(file);
|
||||
|
||||
@@ -1,3 +1,29 @@
|
||||
load("@rules_rust//rust:defs.bzl", "rust_library")
|
||||
|
||||
rust_library(
|
||||
name = "error_code",
|
||||
srcs = ["error_code.rs"],
|
||||
edition = "2021",
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "error_code_cc_test",
|
||||
srcs = ["error_code_test.c"],
|
||||
deps = [":error_code"],
|
||||
)
|
||||
|
||||
rust_library(
|
||||
name = "wrlib_rs",
|
||||
srcs = ["wrlib.rs"],
|
||||
deps = [
|
||||
":ppm",
|
||||
":rimage",
|
||||
":wrlib",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
edition = "2021",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "wrlib",
|
||||
srcs = [
|
||||
@@ -36,6 +62,7 @@ cc_library(
|
||||
"xutil.h",
|
||||
],
|
||||
deps = [
|
||||
":error_code",
|
||||
"//config",
|
||||
"@ImageMagick//:lib",
|
||||
"@MagickWand//:lib",
|
||||
|
||||
@@ -98,7 +98,7 @@ static Bool allocateStandardPseudoColor(RContext * ctx, XStandardColormap * stdc
|
||||
+ stdcmap->green_max * stdcmap->green_mult + stdcmap->blue_max * stdcmap->blue_mult + 1;
|
||||
|
||||
if (ctx->ncolors <= 1) {
|
||||
RErrorCode = RERR_INTERNAL;
|
||||
wraster_report_error_code(RERR_INTERNAL);
|
||||
puts("wraster: bad standard colormap");
|
||||
|
||||
return False;
|
||||
@@ -106,7 +106,7 @@ static Bool allocateStandardPseudoColor(RContext * ctx, XStandardColormap * stdc
|
||||
|
||||
ctx->colors = malloc(sizeof(XColor) * ctx->ncolors);
|
||||
if (!ctx->colors) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
|
||||
return False;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ static Bool allocateStandardPseudoColor(RContext * ctx, XStandardColormap * stdc
|
||||
free(ctx->colors);
|
||||
ctx->colors = NULL;
|
||||
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
|
||||
return False;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ static Bool setupStandardColormap(RContext * ctx, Atom property)
|
||||
#ifdef HAVE_LIBXMU
|
||||
if (!XmuLookupStandardColormap(ctx->dpy, ctx->screen_number,
|
||||
ctx->visual->visualid, ctx->depth, property, True, True)) {
|
||||
RErrorCode = RERR_STDCMAPFAIL;
|
||||
wraster_report_error_code(RERR_STDCMAPFAIL);
|
||||
|
||||
return False;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ static Bool setupStandardColormap(RContext * ctx, Atom property)
|
||||
#else
|
||||
(void) ctx;
|
||||
(void) property;
|
||||
RErrorCode = RERR_STDCMAPFAIL;
|
||||
wraster_report_error_code(RERR_STDCMAPFAIL);
|
||||
return False;
|
||||
#endif
|
||||
}
|
||||
@@ -248,14 +248,14 @@ static Bool allocatePseudoColor(RContext *ctx)
|
||||
|
||||
colors = malloc(sizeof(XColor) * ncolors);
|
||||
if (!colors) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
|
||||
ctx->pixels = malloc(sizeof(unsigned long) * ncolors);
|
||||
if (!ctx->pixels) {
|
||||
free(colors);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ static XColor *allocateGrayScale(RContext * ctx)
|
||||
|
||||
colors = malloc(sizeof(XColor) * ncolors);
|
||||
if (!colors) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
for (i = 0; i < ncolors; i++) {
|
||||
@@ -528,7 +528,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
||||
|
||||
context = malloc(sizeof(RContext));
|
||||
if (!context) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
memset(context, 0, sizeof(RContext));
|
||||
@@ -540,7 +540,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
||||
context->attribs = malloc(sizeof(RContextAttributes));
|
||||
if (!context->attribs) {
|
||||
free(context);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
if (!attribs)
|
||||
@@ -569,7 +569,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
||||
vinfo = XGetVisualInfo(context->dpy, VisualIDMask | VisualScreenMask, &templ, &nret);
|
||||
if (!vinfo || nret == 0) {
|
||||
free(context);
|
||||
RErrorCode = RERR_BADVISUALID;
|
||||
wraster_report_error_code(RERR_BADVISUALID);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -318,7 +318,7 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
|
||||
btable = computeTable(bmask);
|
||||
|
||||
if (rtable == NULL || gtable == NULL || btable == NULL) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -377,7 +377,7 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
|
||||
if (!err || !nerr) {
|
||||
NFREE(err);
|
||||
NFREE(nerr);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -508,7 +508,7 @@ static RXImage *image2PseudoColor(RContext * ctx, RImage * image)
|
||||
btable = computeTable(bmask);
|
||||
|
||||
if (rtable == NULL || gtable == NULL || btable == NULL) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -545,7 +545,7 @@ static RXImage *image2PseudoColor(RContext * ctx, RImage * image)
|
||||
if (!err || !nerr) {
|
||||
NFREE(err);
|
||||
NFREE(nerr);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -592,7 +592,7 @@ static RXImage *image2StandardPseudoColor(RContext * ctx, RImage * image)
|
||||
btable = computeStdTable(ctx->std_rgb_map->blue_mult, ctx->std_rgb_map->blue_max);
|
||||
|
||||
if (rtable == NULL || gtable == NULL || btable == NULL) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -623,7 +623,7 @@ static RXImage *image2StandardPseudoColor(RContext * ctx, RImage * image)
|
||||
if (!err || !nerr) {
|
||||
NFREE(err);
|
||||
NFREE(nerr);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -743,7 +743,7 @@ static RXImage *image2GrayScale(RContext * ctx, RImage * image)
|
||||
table = computeTable(gmask);
|
||||
|
||||
if (table == NULL) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -778,7 +778,7 @@ static RXImage *image2GrayScale(RContext * ctx, RImage * image)
|
||||
if (!gerr || !ngerr) {
|
||||
NFREE(gerr);
|
||||
NFREE(ngerr);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RDestroyXImage(ctx, ximg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1006,7 +1006,7 @@ Bool RGetClosestXColor(RContext * context, const RColor * color, XColor * retCol
|
||||
btable = computeStdTable(context->std_rgb_map->blue_mult, context->std_rgb_map->blue_max);
|
||||
|
||||
if (rtable == NULL || gtable == NULL || btable == NULL) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
|
||||
@@ -1033,7 +1033,7 @@ Bool RGetClosestXColor(RContext * context, const RColor * color, XColor * retCol
|
||||
btable = computeTable(bmask);
|
||||
|
||||
if (rtable == NULL || gtable == NULL || btable == NULL) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
index = rtable[color->red] * cpccpc + gtable[color->green] * cpc + btable[color->blue];
|
||||
@@ -1060,7 +1060,7 @@ Bool RGetClosestXColor(RContext * context, const RColor * color, XColor * retCol
|
||||
|
||||
*retColor = context->colors[index];
|
||||
} else {
|
||||
RErrorCode = RERR_INTERNAL;
|
||||
wraster_report_error_code(RERR_INTERNAL);
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ int RBlurImage(RImage * image)
|
||||
|
||||
pptr = malloc(image->width * ch);
|
||||
if (!pptr) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
#define MASK(prev, cur, next, ch)\
|
||||
|
||||
107
bazel/wrlib/error_code.rs
Normal file
107
bazel/wrlib/error_code.rs
Normal file
@@ -0,0 +1,107 @@
|
||||
use std::{
|
||||
os::raw::{c_char, c_int},
|
||||
sync::RwLock,
|
||||
};
|
||||
|
||||
static ERROR_STATUS: RwLock<ErrorCode> = RwLock::new(ErrorCode::None);
|
||||
|
||||
#[repr(i16)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ErrorCode {
|
||||
/// No known error status.
|
||||
None = 0,
|
||||
|
||||
/// Can't open file.
|
||||
Open = 1,
|
||||
|
||||
/// Error reading from file.
|
||||
Read = 2,
|
||||
|
||||
/// Error writing to file.
|
||||
Write = 3,
|
||||
|
||||
/// Out of memory.
|
||||
NoMemory = 4,
|
||||
|
||||
/// Out of color cells.
|
||||
NoColor = 5,
|
||||
|
||||
/// Image file is corrupted or invalid.
|
||||
BadImageFile = 6,
|
||||
|
||||
/// Image file format is unknown.
|
||||
BadFormat = 7,
|
||||
|
||||
/// No such image index in file.
|
||||
BadIndex = 8,
|
||||
|
||||
/// Invalid visual ID requested for context.
|
||||
BadVisualId = 16,
|
||||
|
||||
/// Failed to create std colormap.
|
||||
StdCmapFail = 17,
|
||||
|
||||
/// Internal X11 error.
|
||||
XError = 127,
|
||||
|
||||
/// Should not happen.
|
||||
Internal = 128,
|
||||
}
|
||||
|
||||
/// Sets the global error status in a thread-safe way. Panics if the error
|
||||
/// status lock has been poisoned.
|
||||
pub fn wraster_set_error_code(code: ErrorCode) {
|
||||
*ERROR_STATUS.write().unwrap() = code;
|
||||
}
|
||||
|
||||
/// Sets the global error status to a literal `value`. Panics if `value` does
|
||||
/// not correspond to a valid error value.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wraster_report_error_code(value: c_int) {
|
||||
let value = match value {
|
||||
0 => ErrorCode::None,
|
||||
1 => ErrorCode::Open,
|
||||
2 => ErrorCode::Read,
|
||||
3 => ErrorCode::Write,
|
||||
4 => ErrorCode::NoMemory,
|
||||
5 => ErrorCode::NoColor,
|
||||
6 => ErrorCode::BadImageFile,
|
||||
7 => ErrorCode::BadFormat,
|
||||
8 => ErrorCode::BadIndex,
|
||||
16 => ErrorCode::BadVisualId,
|
||||
17 => ErrorCode::StdCmapFail,
|
||||
127 => ErrorCode::XError,
|
||||
128 => ErrorCode::Internal,
|
||||
_ => panic!("unknown error code: {}", value),
|
||||
};
|
||||
*ERROR_STATUS.write().unwrap() = value;
|
||||
}
|
||||
|
||||
/// Returns the current error status. Panics if the error status lock has been
|
||||
/// poisoned.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wraster_current_error_code() -> i16 {
|
||||
*ERROR_STATUS.read().unwrap() as i16
|
||||
}
|
||||
|
||||
/// Returns a human-readable description of the current error status. Panics if
|
||||
/// the error status lock has been poisoned.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wraster_current_error_message() -> *const c_char {
|
||||
// TODO: i18n of these messages.
|
||||
match *ERROR_STATUS.read().unwrap() {
|
||||
ErrorCode::None => c"no error".as_ptr(),
|
||||
ErrorCode::Open => c"could not open file".as_ptr(),
|
||||
ErrorCode::Read => c"error reading from file".as_ptr(),
|
||||
ErrorCode::Write => c"error writing to file".as_ptr(),
|
||||
ErrorCode::NoMemory => c"out of memory".as_ptr(),
|
||||
ErrorCode::NoColor => c"out of color cells".as_ptr(),
|
||||
ErrorCode::BadImageFile => c"invalid or corrupted image file".as_ptr(),
|
||||
ErrorCode::BadFormat => c"image format is not supported".as_ptr(),
|
||||
ErrorCode::BadIndex => c"file does not contain requested image index".as_ptr(),
|
||||
ErrorCode::BadVisualId => c"request for an invalid Visual ID".as_ptr(),
|
||||
ErrorCode::StdCmapFail => c"failed to create X standard colormap".as_ptr(),
|
||||
ErrorCode::XError => c"internal X error".as_ptr(),
|
||||
ErrorCode::Internal => c"internal error".as_ptr(),
|
||||
}
|
||||
}
|
||||
40
bazel/wrlib/error_code_test.c
Normal file
40
bazel/wrlib/error_code_test.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
/* error codes */
|
||||
#define RERR_NONE 0
|
||||
#define RERR_OPEN 1 /* cant open file */
|
||||
#define RERR_READ 2 /* error reading from file */
|
||||
#define RERR_WRITE 3 /* error writing to file */
|
||||
#define RERR_NOMEMORY 4 /* out of memory */
|
||||
#define RERR_NOCOLOR 5 /* out of color cells */
|
||||
#define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
|
||||
#define RERR_BADFORMAT 7 /* image file format is unknown */
|
||||
#define RERR_BADINDEX 8 /* no such image index in file */
|
||||
|
||||
#define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
|
||||
#define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
|
||||
|
||||
#define RERR_XERROR 127 /* internal X error */
|
||||
#define RERR_INTERNAL 128 /* should not happen */
|
||||
|
||||
void wraster_report_error_code(int value);
|
||||
|
||||
const char* wraster_current_error_message();
|
||||
|
||||
int wraster_current_error_code();
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
assert(wraster_current_error_code() == RERR_NONE);
|
||||
assert(strcmp(wraster_current_error_message(), "no error") == 0);
|
||||
|
||||
wraster_report_error_code(RERR_WRITE);
|
||||
|
||||
assert(wraster_current_error_code() == RERR_WRITE);
|
||||
assert(strcmp(wraster_current_error_message(), "error writing to file") == 0);
|
||||
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
|
||||
assert(wraster_current_error_code() == RERR_OPEN);
|
||||
assert(strcmp(wraster_current_error_message(), "could not open file") == 0);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
|
||||
image = RLoadMagick(file);
|
||||
break;
|
||||
#else
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
@@ -236,7 +236,7 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
|
||||
break;
|
||||
|
||||
default:
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ static WRImgFormat identFile(const char *path)
|
||||
if (file != NULL)
|
||||
break;
|
||||
if (errno != EINTR) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return IM_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -344,7 +344,7 @@ static WRImgFormat identFile(const char *path)
|
||||
nread = fread(buffer, 1, sizeof(buffer), file);
|
||||
if (nread < sizeof(buffer) || ferror(file)) {
|
||||
fclose(file);
|
||||
RErrorCode = RERR_READ;
|
||||
wraster_report_error_code(RERR_READ);
|
||||
return IM_ERROR;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
@@ -56,7 +56,7 @@ RImage *RLoadGIF(const char *file, int index)
|
||||
index = 0;
|
||||
|
||||
/* default error message */
|
||||
RErrorCode = RERR_BADINDEX;
|
||||
wraster_report_error_code(RERR_BADINDEX);
|
||||
|
||||
#if USE_GIF == 4
|
||||
gif = DGifOpenFileName(file);
|
||||
@@ -70,13 +70,13 @@ RImage *RLoadGIF(const char *file, int index)
|
||||
#endif
|
||||
switch (gif_error) {
|
||||
case D_GIF_ERR_OPEN_FAILED:
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
break;
|
||||
case D_GIF_ERR_READ_FAILED:
|
||||
RErrorCode = RERR_READ;
|
||||
wraster_report_error_code(RERR_READ);
|
||||
break;
|
||||
default:
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
@@ -88,7 +88,7 @@ RImage *RLoadGIF(const char *file, int index)
|
||||
#else
|
||||
DGifCloseFile(gif);
|
||||
#endif
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ RImage *RLoadGIF(const char *file, int index)
|
||||
|
||||
buffer = malloc(width * sizeof(GifPixelType));
|
||||
if (!buffer) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
goto bye;
|
||||
}
|
||||
|
||||
@@ -199,18 +199,18 @@ RImage *RLoadGIF(const char *file, int index)
|
||||
#if USE_GIF == 4
|
||||
switch (GifLastError()) {
|
||||
case D_GIF_ERR_OPEN_FAILED:
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
break;
|
||||
case D_GIF_ERR_READ_FAILED:
|
||||
RErrorCode = RERR_READ;
|
||||
wraster_report_error_code(RERR_READ);
|
||||
break;
|
||||
default:
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
/* With gif_lib v5 there's no way to know what went wrong */
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
#endif
|
||||
bye:
|
||||
if (image)
|
||||
|
||||
@@ -105,7 +105,7 @@ static RImage *do_read_jpeg_file(struct jpeg_decompress_struct *cinfo, const cha
|
||||
|
||||
file = fopen(file_name, "rb");
|
||||
if (!file) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -115,13 +115,13 @@ static RImage *do_read_jpeg_file(struct jpeg_decompress_struct *cinfo, const cha
|
||||
|
||||
if (cinfo->image_width < 1 || cinfo->image_height < 1) {
|
||||
buffer[0] = NULL; /* Initialize pointer to avoid spurious free in cleanup code */
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
goto abort_and_release_resources;
|
||||
}
|
||||
|
||||
buffer[0] = (JSAMPROW) malloc(cinfo->image_width * cinfo->num_components);
|
||||
if (!buffer[0]) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
goto abort_and_release_resources;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ static RImage *do_read_jpeg_file(struct jpeg_decompress_struct *cinfo, const cha
|
||||
jpeg_calc_output_dimensions(cinfo);
|
||||
image = RCreateImage(cinfo->image_width, cinfo->image_height, False);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
goto abort_and_release_resources;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ RImage *RLoadMagick(const char *file_name)
|
||||
PixelWand *bg_wand = NULL;
|
||||
|
||||
if (RInitMagickIfNeeded()) {
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ RImage *RLoadMagick(const char *file_name)
|
||||
|
||||
/* Read the input image */
|
||||
if (!MagickReadImage(m_wand, file_name)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
goto bye;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ RImage *RLoadMagick(const char *file_name)
|
||||
|
||||
image = RCreateImage(w, h, (unsigned int) hasAlfa);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
goto bye;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ RImage *RLoadMagick(const char *file_name)
|
||||
mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, (size_t)h, "RGBA", CharPixel, ptr);
|
||||
|
||||
if (mrc == MagickFalse) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
RReleaseImage(image);
|
||||
image = NULL;
|
||||
goto bye;
|
||||
|
||||
@@ -51,19 +51,19 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
||||
|
||||
f = fopen(file, "rb");
|
||||
if (!f) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return NULL;
|
||||
}
|
||||
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, (png_error_ptr) NULL, (png_error_ptr) NULL);
|
||||
if (!png) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pinfo = png_create_info_struct(png);
|
||||
if (!pinfo) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
fclose(f);
|
||||
png_destroy_read_struct(&png, NULL, NULL);
|
||||
return NULL;
|
||||
@@ -71,13 +71,13 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
||||
|
||||
einfo = png_create_info_struct(png);
|
||||
if (!einfo) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
fclose(f);
|
||||
png_destroy_read_struct(&png, &pinfo, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RErrorCode = RERR_INTERNAL;
|
||||
wraster_report_error_code(RERR_INTERNAL);
|
||||
#if PNG_LIBPNG_VER - 0 < 10400
|
||||
if (setjmp(png->jmpbuf)) {
|
||||
#else
|
||||
@@ -100,7 +100,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
||||
if (width < 1 || height < 1) {
|
||||
fclose(f);
|
||||
png_destroy_read_struct(&png, &pinfo, &einfo);
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
||||
|
||||
png_rows = calloc(height, sizeof(png_bytep));
|
||||
if (!png_rows) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
fclose(f);
|
||||
RReleaseImage(image);
|
||||
png_destroy_read_struct(&png, &pinfo, &einfo);
|
||||
@@ -176,7 +176,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
|
||||
for (y = 0; y < height; y++) {
|
||||
png_rows[y] = malloc(png_get_rowbytes(png, pinfo));
|
||||
if (!png_rows[y]) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
fclose(f);
|
||||
RReleaseImage(image);
|
||||
png_destroy_read_struct(&png, &pinfo, &einfo);
|
||||
|
||||
@@ -126,13 +126,13 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
|
||||
int x, y;
|
||||
|
||||
if (raw != '2' && raw != '5') {
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = RCreateImage(w, h, 0);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
|
||||
val = pm_getuint(file, filename);
|
||||
|
||||
if (val > max || val < 0) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
RReleaseImage(image);
|
||||
return NULL;
|
||||
}
|
||||
@@ -163,14 +163,14 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
|
||||
|
||||
buf = malloc(w + 1);
|
||||
if (!buf) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
RReleaseImage(image);
|
||||
return NULL;
|
||||
}
|
||||
for (y = 0; y < h; y++) {
|
||||
if (!fread(buf, w, 1, file)) {
|
||||
free(buf);
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
RReleaseImage(image);
|
||||
return NULL;
|
||||
}
|
||||
@@ -196,13 +196,13 @@ static RImage *load_pixmap(FILE *file, int w, int h, int max, int raw, const cha
|
||||
unsigned char *ptr;
|
||||
|
||||
if (raw != '3' && raw != '6') {
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = RCreateImage(w, h, 0);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ static RImage *load_pixmap(FILE *file, int w, int h, int max, int raw, const cha
|
||||
val = pm_getuint(file, filename);
|
||||
|
||||
if (val > max || val < 0) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
RReleaseImage(image);
|
||||
return NULL;
|
||||
}
|
||||
@@ -233,7 +233,7 @@ static RImage *load_pixmap(FILE *file, int w, int h, int max, int raw, const cha
|
||||
i = 0;
|
||||
while (i < w * h) {
|
||||
if (fread(buf, 1, 3, file) != 3) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
RReleaseImage(image);
|
||||
return NULL;
|
||||
}
|
||||
@@ -256,13 +256,13 @@ static RImage *load_bitmap(FILE *file, int w, int h, int max, int raw, const cha
|
||||
unsigned char *ptr;
|
||||
|
||||
if (raw != '1' && raw != '4') {
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = RCreateImage(w, h, 0);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ static RImage *load_bitmap(FILE *file, int w, int h, int max, int raw, const cha
|
||||
val = pm_getuint(file, filename);
|
||||
|
||||
if (val > max || val < 0) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
RReleaseImage(image);
|
||||
return NULL;
|
||||
}
|
||||
@@ -321,20 +321,20 @@ RImage *RLoadPPM(const char *file_name)
|
||||
|
||||
file = fopen(file_name, "rb");
|
||||
if (!file) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* get signature */
|
||||
if (!fgets(buffer, 255, file)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* accept bitmaps, pixmaps or graymaps */
|
||||
if (buffer[0] != 'P' || (buffer[1] < '1' || buffer[1] > '6')) {
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -344,7 +344,7 @@ RImage *RLoadPPM(const char *file_name)
|
||||
/* skip comments */
|
||||
while (1) {
|
||||
if (!fgets(buffer, 255, file)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -356,21 +356,21 @@ RImage *RLoadPPM(const char *file_name)
|
||||
/* get size */
|
||||
if (sscanf(buffer, "%i %i", &w, &h) != 2 || w < 1 || h < 1) {
|
||||
/* Short file */
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (type != '1' && type != '4') {
|
||||
if (!fgets(buffer, 255, file)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
/* get max value */
|
||||
if (sscanf(buffer, "%i", &m) != 1 || m < 1) {
|
||||
/* Short file */
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ RImage *RLoadTIFF(const char *file, int index)
|
||||
i = index;
|
||||
while (i > 0) {
|
||||
if (!TIFFReadDirectory(tif)) {
|
||||
RErrorCode = RERR_BADINDEX;
|
||||
wraster_report_error_code(RERR_BADINDEX);
|
||||
TIFFClose(tif);
|
||||
return NULL;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ RImage *RLoadTIFF(const char *file, int index)
|
||||
amode = (extrasamples == 1 && sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
|
||||
|
||||
if (width < 1 || height < 1) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
TIFFClose(tif);
|
||||
return NULL;
|
||||
}
|
||||
@@ -92,10 +92,10 @@ RImage *RLoadTIFF(const char *file, int index)
|
||||
#endif
|
||||
|
||||
if (!data) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
} else {
|
||||
if (!TIFFReadRGBAImage(tif, width, height, data, 0)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
} else {
|
||||
|
||||
/* convert data */
|
||||
|
||||
@@ -76,12 +76,12 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
|
||||
file = fopen(file_name, "rb");
|
||||
if (!file) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!fread(buffer, sizeof(buffer), 1, file)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
#else
|
||||
(buffer[15] == ' ' || buffer[15] == 'X' || buffer[15] == 'L'))) {
|
||||
#endif
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
if (raw_data_size <= 0) {
|
||||
fprintf(stderr, _("wrlib: could not get size of WebP file \"%s\", %s\n"),
|
||||
file_name, strerror(errno));
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
raw_data = (uint8_t *) malloc(raw_data_size);
|
||||
|
||||
if (!raw_data) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
fclose(file);
|
||||
|
||||
if (r != raw_data_size) {
|
||||
RErrorCode = RERR_READ;
|
||||
wraster_report_error_code(RERR_READ);
|
||||
free(raw_data);
|
||||
return NULL;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
if (status != VP8_STATUS_OK) {
|
||||
fprintf(stderr, _("wrlib: could not get features from WebP file \"%s\", %s\n"),
|
||||
file_name, webp_message_from_status(status));
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
free(raw_data);
|
||||
return NULL;
|
||||
}
|
||||
@@ -140,7 +140,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
if (features.has_alpha) {
|
||||
image = RCreateImage(features.width, features.height, True);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
free(raw_data);
|
||||
return NULL;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
} else {
|
||||
image = RCreateImage(features.width, features.height, False);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
free(raw_data);
|
||||
return NULL;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
|
||||
if (!ret) {
|
||||
fprintf(stderr, _("wrlib: failed to decode WebP from file \"%s\"\n"), file_name);
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
RReleaseImage(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -45,12 +45,12 @@ static RImage *create_rimage_from_xpm(RContext *context, XpmImage xpm)
|
||||
int *p;
|
||||
|
||||
if (xpm.height < 1 || xpm.width < 1) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (xpm.colorTable == NULL) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
return NULL;
|
||||
}
|
||||
image = RCreateImage(xpm.width, xpm.height, True);
|
||||
@@ -66,7 +66,7 @@ static RImage *create_rimage_from_xpm(RContext *context, XpmImage xpm)
|
||||
free(color_table[i]);
|
||||
}
|
||||
RReleaseImage(image);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -134,16 +134,16 @@ static int is_xpm_error(int status)
|
||||
|
||||
switch (status) {
|
||||
case XpmOpenFailed:
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
break;
|
||||
case XpmFileInvalid:
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
break;
|
||||
case XpmNoMemory:
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
break;
|
||||
default:
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -104,7 +104,7 @@ RImage *RGetImageFromXPMData(RContext * context, char **data)
|
||||
bsize = csize * w + 16;
|
||||
|
||||
if (!color_table[0] || !color_table[1] || !color_table[2] || !color_table[3] || !symbol_table || !bsize) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
free_color_symbol_table(color_table, symbol_table);
|
||||
return NULL;
|
||||
}
|
||||
@@ -228,7 +228,7 @@ RImage *RGetImageFromXPMData(RContext * context, char **data)
|
||||
return image;
|
||||
|
||||
bad_format:
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
free_color_symbol_table(color_table, symbol_table);
|
||||
if (image)
|
||||
RReleaseImage(image);
|
||||
@@ -258,7 +258,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
||||
|
||||
f = fopen(file, "rb");
|
||||
if (!f) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return NULL;
|
||||
}
|
||||
/* sig */
|
||||
@@ -294,7 +294,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
||||
|
||||
if (!color_table[0] || !color_table[1] || !color_table[2] ||
|
||||
!color_table[3] || !symbol_table || !bsize || !buffer) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
fclose(f);
|
||||
free_color_symbol_table(color_table, symbol_table);
|
||||
if (buffer)
|
||||
@@ -438,7 +438,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
||||
return image;
|
||||
|
||||
bad_format:
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(f);
|
||||
free_color_symbol_table(color_table, symbol_table);
|
||||
if (buffer)
|
||||
@@ -448,7 +448,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
|
||||
return NULL;
|
||||
|
||||
bad_file:
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
wraster_report_error_code(RERR_BADIMAGEFILE);
|
||||
fclose(f);
|
||||
free_color_symbol_table(color_table, symbol_table);
|
||||
if (buffer)
|
||||
|
||||
@@ -200,51 +200,6 @@ void RLightImage(RImage *image, const RColor *color)
|
||||
}
|
||||
}
|
||||
|
||||
const char *RMessageForError(int errorCode)
|
||||
{
|
||||
switch (errorCode) {
|
||||
case RERR_NONE:
|
||||
return _("no error");
|
||||
|
||||
case RERR_OPEN:
|
||||
return _("could not open file");
|
||||
|
||||
case RERR_READ:
|
||||
return _("error reading from file");
|
||||
|
||||
case RERR_WRITE:
|
||||
return _("error writing to file");
|
||||
|
||||
case RERR_NOMEMORY:
|
||||
return _("out of memory");
|
||||
|
||||
case RERR_NOCOLOR:
|
||||
return _("out of color cells");
|
||||
|
||||
case RERR_BADIMAGEFILE:
|
||||
return _("invalid or corrupted image file");
|
||||
|
||||
case RERR_BADFORMAT:
|
||||
return _("image format is not supported");
|
||||
|
||||
case RERR_BADINDEX:
|
||||
return _("file does not contain requested image index");
|
||||
|
||||
case RERR_BADVISUALID:
|
||||
return _("request for an invalid Visual ID");
|
||||
|
||||
case RERR_STDCMAPFAIL:
|
||||
return _("failed to create X standard colormap");
|
||||
|
||||
case RERR_XERROR:
|
||||
return _("internal X error");
|
||||
|
||||
default:
|
||||
case RERR_INTERNAL:
|
||||
return _("internal error");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef I18N
|
||||
/*
|
||||
* Setup internationalization on startup
|
||||
|
||||
@@ -34,8 +34,6 @@
|
||||
|
||||
char *WRasterLibVersion = "0.9";
|
||||
|
||||
int RErrorCode = RERR_NONE;
|
||||
|
||||
#define HAS_ALPHA(I) ((I)->format == RRGBAFormat)
|
||||
|
||||
#define MAX_WIDTH 20000
|
||||
@@ -49,13 +47,13 @@ RImage *RCreateImage(unsigned width, unsigned height, int alpha)
|
||||
assert(width > 0 && height > 0);
|
||||
|
||||
if (width > MAX_WIDTH || height > MAX_HEIGHT) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = malloc(sizeof(RImage));
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -70,7 +68,7 @@ RImage *RCreateImage(unsigned width, unsigned height, int alpha)
|
||||
*/
|
||||
image->data = malloc(width * height * (alpha ? 4 : 3) + 4);
|
||||
if (!image->data) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,6 @@ Bool RSaveTitledImage(RImage *image, const char *filename, const char *format, c
|
||||
if (strcasecmp(format, "XPM") == 0)
|
||||
return RSaveXPM(image, filename);
|
||||
|
||||
RErrorCode = RERR_BADFORMAT;
|
||||
wraster_report_error_code(RERR_BADFORMAT);
|
||||
return False;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ Bool RSaveJPEG(RImage *img, const char *filename, char *title)
|
||||
|
||||
file = fopen(filename, "wb");
|
||||
if (!file) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ Bool RSavePNG(RImage *img, const char *filename, char *title)
|
||||
|
||||
file = fopen(filename, "wb");
|
||||
if (file == NULL) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return False;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ Bool RSavePNG(RImage *img, const char *filename, char *title)
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (png_ptr == NULL) {
|
||||
fclose(file);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ Bool RSavePNG(RImage *img, const char *filename, char *title)
|
||||
png_info_ptr = png_create_info_struct(png_ptr);
|
||||
if (png_info_ptr == NULL) {
|
||||
fclose(file);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return False;
|
||||
}
|
||||
|
||||
/* Setup Exception handling */
|
||||
if (setjmp(png_jmpbuf (png_ptr))) {
|
||||
fclose(file);
|
||||
RErrorCode = RERR_INTERNAL;
|
||||
wraster_report_error_code(RERR_INTERNAL);
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ static Bool addcolor(XPMColor ** list, unsigned r, unsigned g, unsigned b, int *
|
||||
|
||||
if (!newc) {
|
||||
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
|
||||
return False;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ Bool RSaveXPM(RImage * image, const char *filename)
|
||||
|
||||
file = fopen(filename, "wb+");
|
||||
if (!file) {
|
||||
RErrorCode = RERR_OPEN;
|
||||
wraster_report_error_code(RERR_OPEN);
|
||||
return False;
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ Bool RSaveXPM(RImage * image, const char *filename)
|
||||
errno = 0;
|
||||
fclose(file);
|
||||
if (ok && errno == ENOSPC) {
|
||||
RErrorCode = RERR_WRITE;
|
||||
wraster_report_error_code(RERR_WRITE);
|
||||
}
|
||||
|
||||
freecolormap(colormap);
|
||||
|
||||
@@ -568,16 +568,19 @@ void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
|
||||
unsigned width, unsigned height)
|
||||
__wrlib_nonnull(1, 3);
|
||||
|
||||
/* do not free the returned string! */
|
||||
const char *RMessageForError(int errorCode)
|
||||
__wrlib_useresult;
|
||||
|
||||
int RBlurImage(RImage *image)
|
||||
__wrlib_nonnull(1);
|
||||
|
||||
/****** Global Variables *******/
|
||||
/****** From error_code.rs ******/
|
||||
void wraster_report_error_code(int value);
|
||||
/* do not free the returned string! */
|
||||
const char* wraster_current_error_message()
|
||||
__wrlib_useresult;
|
||||
int wraster_current_error_code()
|
||||
__wrlib_useresult;
|
||||
|
||||
extern int RErrorCode;
|
||||
/****** Global Variables *******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
86
bazel/wrlib/wrlib.rs
Normal file
86
bazel/wrlib/wrlib.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
use std::os::raw::{c_char, c_int, c_uchar, c_ulong};
|
||||
|
||||
#[repr(C)]
|
||||
pub enum RImageFormat {
|
||||
RGBAFormat = 0,
|
||||
RRGBAFormat = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RImage {
|
||||
data: *mut c_uchar,
|
||||
width: c_int,
|
||||
height: c_int,
|
||||
format: RImageFormat,
|
||||
ref_count: c_int,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RContext {
|
||||
// display: *mut Display,
|
||||
display: usize,
|
||||
screen_number: c_int,
|
||||
// cmap: Colormap,
|
||||
|
||||
// attribs: *mut RContextAttributes,
|
||||
attribs: usize,
|
||||
|
||||
// copy_gc: GC,
|
||||
|
||||
// visual: *mut Visual,
|
||||
visual: usize,
|
||||
depth: c_int,
|
||||
// drawable: Window,
|
||||
vclass: c_int,
|
||||
|
||||
black: c_ulong,
|
||||
white: c_ulong,
|
||||
|
||||
red_offset: c_int,
|
||||
green_offset: c_int,
|
||||
blue_offset: c_int,
|
||||
|
||||
std_rgb_map: usize,
|
||||
std_gray_map: usize,
|
||||
// std_rgb_map: *mut XStandardColorMap,
|
||||
// std_gray_map: *mut XStandardColorMap,
|
||||
|
||||
ncolors: c_int,
|
||||
colors: usize,
|
||||
// colors: *mut XColor,
|
||||
pixels: *mut c_ulong,
|
||||
|
||||
flags: u8,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum RScalingFilter {
|
||||
RBoxFilter,
|
||||
RTriangleFilter,
|
||||
RBellFilter,
|
||||
RBSplineFilter,
|
||||
RLanczos3Filter,
|
||||
RMitchellFilter,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn r_destroy_conversion_tables() -> ();
|
||||
|
||||
pub fn RLoadPPM(file: *const c_char) -> *mut RImage;
|
||||
|
||||
pub fn RLoadXPM(context: *mut RContext, file: *const c_char) -> *mut RImage;
|
||||
|
||||
pub fn RReleaseCache() -> ();
|
||||
|
||||
pub fn wraster_rotate_image_180(source: *const RImage) -> *mut RImage;
|
||||
|
||||
pub fn wraster_change_filter(ty: RScalingFilter) -> ();
|
||||
|
||||
pub fn RShutdown() -> ();
|
||||
|
||||
#[must_use]
|
||||
pub fn RSupportedFileFormats() -> *mut *const c_char;
|
||||
|
||||
#[must_use]
|
||||
pub fn RGetImageFileFormat(file: *const c_char) -> *mut c_char;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ RImage *RCreateImageFromDrawable(RContext * context, Drawable drawable, Pixmap m
|
||||
pimg = XGetImage(context->dpy, drawable, 0, 0, w, h, AllPlanes, ZPixmap);
|
||||
|
||||
if (!pimg) {
|
||||
RErrorCode = RERR_XERROR;
|
||||
wraster_report_error_code(RERR_XERROR);
|
||||
return NULL;
|
||||
}
|
||||
mimg = NULL;
|
||||
|
||||
@@ -65,21 +65,21 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
|
||||
|
||||
rximg = malloc(sizeof(RXImage));
|
||||
if (!rximg) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
#ifndef USE_XSHM
|
||||
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
|
||||
if (!rximg->image) {
|
||||
free(rximg);
|
||||
RErrorCode = RERR_XERROR;
|
||||
wraster_report_error_code(RERR_XERROR);
|
||||
return NULL;
|
||||
}
|
||||
rximg->image->data = malloc(rximg->image->bytes_per_line * height);
|
||||
if (!rximg->image->data) {
|
||||
XDestroyImage(rximg->image);
|
||||
free(rximg);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
#else /* USE_XSHM */
|
||||
@@ -91,14 +91,14 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
|
||||
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
|
||||
if (!rximg->image) {
|
||||
free(rximg);
|
||||
RErrorCode = RERR_XERROR;
|
||||
wraster_report_error_code(RERR_XERROR);
|
||||
return NULL;
|
||||
}
|
||||
rximg->image->data = malloc(rximg->image->bytes_per_line * height);
|
||||
if (!rximg->image->data) {
|
||||
XDestroyImage(rximg->image);
|
||||
free(rximg);
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
@@ -207,7 +207,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
|
||||
if (!ximg) {
|
||||
ximg = malloc(sizeof(RXImage));
|
||||
if (!ximg) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
ximg->is_shared = 0;
|
||||
@@ -216,7 +216,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
|
||||
#else /* !USE_XSHM */
|
||||
ximg = malloc(sizeof(RXImage));
|
||||
if (!ximg) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
wraster_report_error_code(RERR_NOMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user