Merge branch 'StefanSchippers:master' into master

This commit is contained in:
Rafmag Cabrera 2023-01-17 20:00:38 +00:00 committed by GitHub
commit 56867cf88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 28 deletions

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
HostUrl=https://raw.githubusercontent.com/rahra/cairo_jpg/master/src/cairo_jpg.c

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
HostUrl=https://raw.githubusercontent.com/rahra/cairo_jpg/master/src/cairo_jpg.h

View File

@ -3061,7 +3061,7 @@ typedef struct
size_t size;
} png_to_byte_closure_t;
static cairo_status_t png_reader(void *in_closure, unsigned char *out_data, unsigned int length)
cairo_status_t png_reader(void *in_closure, unsigned char *out_data, unsigned int length)
{
png_to_byte_closure_t *closure = (png_to_byte_closure_t *) in_closure;
if(!closure->buffer) return CAIRO_STATUS_READ_ERROR;
@ -3133,6 +3133,7 @@ void draw_image(int dr, xRect *r, double *x1, double *y1, double *x2, double *y2
if(filter) {
size_t filtersize = 0;
char *filterdata = NULL;
dbg(1, "draw_image(): filter=%s, image_data=%s\n", filter, attr);
closure.buffer = NULL;
filterdata = (char *)base64_decode(attr, strlen(attr), &filtersize);
filter_data(filterdata, filtersize, (char **)&closure.buffer, &data_size, filter);

View File

@ -25,7 +25,7 @@
#define Y_TO_PS(y) ( (y+xctx->yorigin)* xctx->mooz )
/* FIXME This must be investigated, without some fflushes the ps file is corrupted */
//#define FFLUSH_PS
#define FFLUSH_PS
#if 0
* /* FIXME: overflow check. Not used, BTW */
@ -108,15 +108,6 @@ typedef struct
size_t size;
} png_to_byte_closure_t;
cairo_status_t png_reader(void* in_closure, unsigned char* out_data, unsigned int length)
{
png_to_byte_closure_t* closure = (png_to_byte_closure_t*)in_closure;
if (!closure->buffer) return CAIRO_STATUS_READ_ERROR;
memcpy(out_data, closure->buffer + closure->pos, length);
closure->pos += length;
return CAIRO_STATUS_SUCCESS;
}
unsigned char* bin2hex(const unsigned char* bin, size_t len)
{
unsigned char* out;
@ -167,16 +158,16 @@ void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2, int rot, i
else {
closure.buffer = base64_decode(image_data64_ptr, strlen(image_data64_ptr), &data_size);
}
my_free(1663, &filter);
my_free(1664, &filter);
my_free(1184, &image_data64_ptr);
closure.pos = 0;
closure.size = data_size; /* should not be necessary */
surface = cairo_image_surface_create_from_png_stream(png_reader, &closure);
my_free(1666, &closure.buffer);
png_size_x = cairo_image_surface_get_width(surface);
png_size_y = cairo_image_surface_get_height(surface);
cairo_surface_flush(surface);
my_free(1667, &closure.buffer);
png_data = cairo_image_surface_get_data(surface);
invertImage = !strcmp(get_tok_value(r->prop_ptr, "InvertOnExport", 0), "true");
@ -192,9 +183,9 @@ void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2, int rot, i
if(invertImage)
{
png_data[i + 0] = (0xFF-png_r) + (unsigned char)((double)BG_r * ainv);
png_data[i + 1] = (0xFF-png_g) + (unsigned char)((double)BG_g * ainv);
png_data[i + 2] = (0xFF-png_b) + (unsigned char)((double)BG_b * ainv);
png_data[i + 0] = (unsigned char)(0xFF-png_r) + (unsigned char)((double)BG_r * ainv);
png_data[i + 1] = (unsigned char)(0xFF-png_g) + (unsigned char)((double)BG_g * ainv);
png_data[i + 2] = (unsigned char)(0xFF-png_b) + (unsigned char)((double)BG_b * ainv);
png_data[i + 3] = 0xFF;
}else
{
@ -218,6 +209,7 @@ void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2, int rot, i
* fclose(fp);
*/
hexEncodedJPG = bin2hex(jpgData, fileSize);
free(jpgData);
fprintf(fd, "gsave\n");
fprintf(fd, "%g %g translate\n", X_TO_PS(x1), Y_TO_PS(y1));
if(rot==1) fprintf(fd, "90 rotate\n");
@ -254,10 +246,11 @@ void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2, int rot, i
fprintf(fd, "3\n");
fprintf(fd, "colorimage\n");
fprintf(fd, "grestore\n");
my_free(1663, &hexEncodedJPG);
free(jpgData);
#ifdef FFLUSH_PS /* FIXME: why is this needed? */
fflush(fd);
#endif
cairo_surface_destroy(surface);
my_free(1663, &hexEncodedJPG);
}
@ -336,6 +329,7 @@ void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2)
*/
hexEncodedJPG = bin2hex(jpgData, fileSize);
free(jpgData);
cairo_surface_destroy(png_sfc);
xctx->draw_pixmap = 1;
@ -365,10 +359,11 @@ void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2)
fprintf(fd, "3\n");
fprintf(fd, "colorimage\n");
fprintf(fd, "grestore\n");
my_free(1666, &hexEncodedJPG);
free(jpgData);
#ifdef FFLUSH_PS /* FIXME: why is this needed? */
fflush(fd);
#endif
my_free(1666, &hexEncodedJPG);
#endif
}
static void set_lw(void)

View File

@ -54,10 +54,18 @@ int filter_data(const char *din, const size_t ilen,
/* child */
close(p1[1]); /* only read from p1 */
close(p2[0]); /* only write to p2 */
#if 0
dup2(p1[0],0); /* some systems lack this function */
#else
close(0); /* dup2(p1[0],0); */ /* connect read side of read pipe to stdin */
dup(p1[0]);
#endif
#if 0
dup2(p2[1],1); /* some systems lack this function */
#else
close(1); /* dup2(p2[1],1); */ /* connect write side of write pipe to stdout */
dup(p2[1]);
#endif
/* execlp("gm", "gm", "convert", "-", "-quality", "50", "jpg:-", NULL); */
if(system(cmd)) {
fprintf(stderr, "error: conversion failed\n");
@ -74,6 +82,7 @@ int filter_data(const char *din, const size_t ilen,
fprintf(stderr, "filter_data() write to pipe failed or not completed\n");
ret = 1;
}
fsync(p1[1]);
close(p1[1]);
if(!ret) {
oalloc = bufsize + 1; /* add extra space for final '\0' */
@ -81,6 +90,7 @@ int filter_data(const char *din, const size_t ilen,
*olen = 0;
while( (n = read(p2[0], *dout + *olen, bufsize)) > 0) {
*olen += n;
dbg(1, "filter_data(): olen=%d, oalloc=%d\n", *olen, oalloc);
if(*olen + bufsize + 1 >= oalloc) { /* allocate for next read */
oalloc = *olen + bufsize + 1; /* add extra space for final '\0' */
oalloc = ((oalloc << 2) + oalloc) >> 2; /* size up 1.25x */

View File

@ -75,7 +75,7 @@ END{
leak+= address[i]
print " address[ " i ", " idx[i] " ]= " address[i]
if(show_source) {
pipe = "egrep -n 'my_(malloc|calloc|realloc|free|strdup|strdup2)\\(" idx[i] ",' *.c xschem.h"
pipe = "egrep -n '^my_(malloc|calloc|realloc|free|strdup|strdup2)\\(" idx[i] ",' *.c xschem.h"
while( pipe | getline a) print " " a
close(pipe)
}

View File

@ -1077,6 +1077,7 @@ extern Xschem_ctx *xctx;
extern void draw_image(int dr, xRect *r, double *x1, double *y1, double *x2, double *y2, int rot, int flip);
extern int filter_data(const char *din, const size_t ilen,
char **dout, size_t *olen, const char *cmd);
extern cairo_status_t png_reader(void* in_closure, unsigned char* out_data, unsigned int length);
extern int embed_rawfile(const char *rawfile);
extern int read_rawfile_from_attr(const char *b64s, size_t length, const char *type);
extern int raw_read_from_attr(const char *type);