diff --git a/plug-ins/gimpressionist/brush.c b/plug-ins/gimpressionist/brush.c index 33296b24ab..e36d681fef 100644 --- a/plug-ins/gimpressionist/brush.c +++ b/plug-ins/gimpressionist/brush.c @@ -53,6 +53,7 @@ void brushdmenuselect(gint32 id, gpointer data) gint x1, y1, x2, y2; gint row, col; GDrawable *drawable; + int rowstride; if(brushfile == 2) return; /* Not finished GUI-building yet */ @@ -77,6 +78,8 @@ void brushdmenuselect(gint32 id, gpointer data) newppm(&brushppm, x2-x1, y2-y1); p = &brushppm; + rowstride = p->width * 3; + src_row = (guchar *)safemalloc((x2 - x1) * bpp); gimp_pixel_rgn_init (&src_rgn, drawable, 0, 0, x2-x1, y2-y1, FALSE, FALSE); @@ -85,42 +88,44 @@ void brushdmenuselect(gint32 id, gpointer data) int bpr = (x2-x1) * 3; for(row = 0, y = y1; y < y2; row++, y++) { gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); - memcpy(p->col[row], src_row, bpr); + memcpy(p->col + row*rowstride, src_row, bpr); } } else if(bpp > 3) { /* RGBA */ for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; + guchar *tmprow = p->col + row * rowstride; gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); src = src_row; for (col = 0, x = x1; x < x2; col++, x++) { - tmprow[col].r = src[0]; - tmprow[col].g = src[1]; - tmprow[col].b = src[2]; + int k = col * 3; + tmprow[k+0] = src[0]; + tmprow[k+1] = src[1]; + tmprow[k+2] = src[2]; src += src_rgn.bpp; - } } } else if(bpp == 2) { /* GrayA */ for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; + guchar *tmprow = p->col + row * rowstride; gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); src = src_row; for (col = 0, x = x1; x < x2; col++, x++) { - tmprow[col].r = src[0]; - tmprow[col].g = src[0]; - tmprow[col].b = src[0]; + int k = col * 3; + tmprow[k+0] = src[0]; + tmprow[k+1] = src[0]; + tmprow[k+2] = src[0]; src += src_rgn.bpp; } } } else { /* Gray */ for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; + guchar *tmprow = p->col + row * rowstride; gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); src = src_row; for (col = 0, x = x1; x < x2; col++, x++) { - tmprow[col].r = src[0]; - tmprow[col].g = src[0]; - tmprow[col].b = src[0]; + int k = col * 3; + tmprow[k+0] = src[0]; + tmprow[k+1] = src[0]; + tmprow[k+2] = src[0]; src += src_rgn.bpp; } } @@ -220,12 +225,12 @@ void reloadbrush(char *fn, struct ppm *p) void padbrush(struct ppm *p, int width, int height) { - struct rgbcolor black = {0,0,0}; + guchar black[3] = {0,0,0}; int left = (width - p->width) / 2; int right = (width - p->width) - left; int top = (height - p->height) / 2; int bottom = (height - p->height) - top; - pad(p, left, right, top, bottom, &black); + pad(p, left, right, top, bottom, black); } void updatebrushprev(char *fn) @@ -244,7 +249,7 @@ void updatebrushprev(char *fn) } else { double sc; struct ppm p = {0,0,NULL}; - unsigned char gammatable[256]; + guchar gammatable[256]; int newheight; if(brushfile) @@ -268,10 +273,11 @@ void updatebrushprev(char *fn) resize_fast(&p, p.width*sc,newheight*sc); padbrush(&p,100,100); for(i = 0; i < 100; i++) { + int k = i * p.width * 3; memset(buf,0,100); if(i < p.height) for(j = 0; j < p.width; j++) - buf[j] = gammatable[p.col[i][j].r]; + buf[j] = gammatable[p.col[k + j * 3]]; gtk_preview_draw_row (GTK_PREVIEW (brushprev), buf, 0, i, 100); } killppm(&p); diff --git a/plug-ins/gimpressionist/gimp.c b/plug-ins/gimpressionist/gimp.c index cd312c13e0..60b3e2439f 100644 --- a/plug-ins/gimpressionist/gimp.c +++ b/plug-ins/gimpressionist/gimp.c @@ -48,7 +48,7 @@ gimpressionist_vals_t defaultpcvals = { {0,0,0}, 1, 0, - { { 0.5, 0.5, 0.0, 0.0, 1.0, 0 } }, + { { 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 0 } }, 1, 0, 0.0, @@ -184,6 +184,7 @@ void grabarea(void) struct ppm *p; gint x1, y1, x2, y2; gint row, col; + int rowstride; if(standalone) { loadppm(standalone, &infile); @@ -202,6 +203,8 @@ void grabarea(void) newppm(&inalpha, x2-x1, y2-y1); } + rowstride = p->width * 3; + src_row = (guchar *)safemalloc((x2 - x1) * bpp); gimp_pixel_rgn_init (&src_rgn, drawable, 0, 0, x2-x1, y2-y1, FALSE, FALSE); @@ -210,45 +213,48 @@ void grabarea(void) int bpr = (x2-x1) * 3; for(row = 0, y = y1; y < y2; row++, y++) { gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); - memcpy(p->col[row], src_row, bpr); + memcpy(p->col + row * rowstride, src_row, bpr); } } else if(bpp > 3) { /* RGBA */ for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; - struct rgbcolor *tmparow = inalpha.col[row]; + guchar *tmprow = p->col + row * rowstride; + guchar *tmparow = inalpha.col + row * rowstride; gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); src = src_row; for (col = 0, x = x1; x < x2; col++, x++) { - tmprow[col].r = src[0]; - tmprow[col].g = src[1]; - tmprow[col].b = src[2]; - tmparow[col].r = 255 - src[3]; + int k = col * 3; + tmprow[k+0] = src[0]; + tmprow[k+1] = src[1]; + tmprow[k+2] = src[2]; + tmparow[k] = 255 - src[3]; src += src_rgn.bpp; } } } else if(bpp == 2) { /* GrayA */ for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; - struct rgbcolor *tmparow = inalpha.col[row]; + guchar *tmprow = p->col + row * rowstride; + guchar *tmparow = inalpha.col + row * rowstride; gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); src = src_row; for (col = 0, x = x1; x < x2; col++, x++) { - tmprow[col].r = src[0]; - tmprow[col].g = src[0]; - tmprow[col].b = src[0]; - tmparow[col].r = 255 - src[1]; + int k = col * 3; + tmprow[k+0] = src[0]; + tmprow[k+1] = src[0]; + tmprow[k+2] = src[0]; + tmparow[k] = 255 - src[1]; src += src_rgn.bpp; } } } else { /* Gray */ for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; + guchar *tmprow = p->col + row * rowstride; gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); src = src_row; for (col = 0, x = x1; x < x2; col++, x++) { - tmprow[col].r = src[0]; - tmprow[col].g = src[0]; - tmprow[col].b = src[0]; + int k = col * 3; + tmprow[k+0] = src[0]; + tmprow[k+1] = src[0]; + tmprow[k+2] = src[0]; src += src_rgn.bpp; } } @@ -266,6 +272,7 @@ void gimpressionist_main(void) struct ppm *p; gint x1, y1, x2, y2; gint row, col; + int rowstride; gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2); @@ -290,6 +297,8 @@ void gimpressionist_main(void) p = &infile; + rowstride = p->width * 3; + if(bpp == 3) { int bpr = (x2 - x1) * 3; @@ -297,22 +306,23 @@ void gimpressionist_main(void) for(row = 0, y = y1; y < y2; row++, y++) { if(row % 10 == 0) gimp_progress_update(0.8 + 0.2*((double)row / (y2-y1))); - memcpy(dest_row, p->col[row], bpr); + memcpy(dest_row, p->col + row * rowstride, bpr); gimp_pixel_rgn_set_row (&dest_rgn, dest_row, x1, y, (x2 - x1)); } } else if(bpp == 4) { for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; + guchar *tmprow = p->col + row * rowstride; if(row % 10 == 0) gimp_progress_update(0.8 + 0.2*((double)row / (y2-y1))); dest = dest_row; for(col = 0, x = x1; x < x2; col++, x++) { - dest[0] = tmprow[col].r; - dest[1] = tmprow[col].g; - dest[2] = tmprow[col].b; - dest[3] = 255 - inalpha.col[row][col].r; + int k = col * 3; + dest[0] = tmprow[k+0]; + dest[1] = tmprow[k+1]; + dest[2] = tmprow[k+2]; + dest[3] = 255 - inalpha.col[row * rowstride + k]; dest += dest_rgn.bpp; } gimp_pixel_rgn_set_row (&dest_rgn, dest_row, x1, y, (x2 - x1)); @@ -321,13 +331,14 @@ void gimpressionist_main(void) } else if(bpp == 2) { for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; + guchar *tmprow = p->col + row * rowstride; if(row % 10 == 0) gimp_progress_update(0.8 + 0.2*((double)row / (y2-y1))); dest = dest_row; for(col = 0, x = x1; x < x2; col++, x++) { - dest[0] = (tmprow[col].r + tmprow[col].g + tmprow[col].b) / 3; - dest[1] = 255 - inalpha.col[row][col].r; + int k = col * 3; + dest[0] = (tmprow[k] + tmprow[k+1] + tmprow[k+2]) / 3; + dest[1] = 255 - inalpha.col[row*rowstride + k]; dest += dest_rgn.bpp; } gimp_pixel_rgn_set_row (&dest_rgn, dest_row, x1, y, (x2 - x1)); @@ -335,13 +346,15 @@ void gimpressionist_main(void) } else { + for(row = 0, y = y1; y < y2; row++, y++) { - struct rgbcolor *tmprow = p->col[row]; + guchar *tmprow = p->col + row * rowstride; if(row % 10 == 0) gimp_progress_update(0.8 + 0.2*((double)row / (y2-y1))); dest = dest_row; for(col = 0, x = x1; x < x2; col++, x++) { - dest[0] = (tmprow[col].r + tmprow[col].g + tmprow[col].b) / 3; + int k = col * 3; + dest[0] = (tmprow[k] + tmprow[k+1] + tmprow[k+2]) / 3; dest += dest_rgn.bpp; } gimp_pixel_rgn_set_row (&dest_rgn, dest_row, x1, y, (x2 - x1)); diff --git a/plug-ins/gimpressionist/gimpressionist.c b/plug-ins/gimpressionist/gimpressionist.c index 200d44b274..5f4a8ce290 100644 --- a/plug-ins/gimpressionist/gimpressionist.c +++ b/plug-ins/gimpressionist/gimpressionist.c @@ -60,10 +60,6 @@ GList *parsepath(void) gimpdatasubdir = strchr (defaultpath, ':') + 1; #endif -#ifdef DEBUG - fprintf(stderr, "gimp_gimprc_query: "); -#endif - if(standalone) tmps = g_strdup(defaultpath); else { @@ -89,9 +85,6 @@ GList *parsepath(void) tmps = g_strdup(defaultpath); } else { tmps = g_strdup(return_vals[1].data.d_string); -#ifdef DEBUG - fprintf(stderr, "Got \"%s\"\n", tmps); -#endif } gimp_destroy_params (return_vals, nreturn_vals); } @@ -125,10 +118,6 @@ char *findfile(char *fn) static char file[200]; struct stat st; -#ifdef DEBUG - fprintf(stderr, "findfile(%s)\n", fn); -#endif - if(!rcpath) rcpath = parsepath(); thispath = rcpath; @@ -137,9 +126,6 @@ char *findfile(char *fn) if(!stat(file, &st)) return file; thispath = thispath->next; } -#ifdef DEBUG - fprintf(stderr, "findfile(%s) returned NULL\n", fn); -#endif return NULL; } diff --git a/plug-ins/gimpressionist/gimpressionist.h b/plug-ins/gimpressionist/gimpressionist.h index d38f0da97c..8bd0ec678b 100644 --- a/plug-ins/gimpressionist/gimpressionist.h +++ b/plug-ins/gimpressionist/gimpressionist.h @@ -1,7 +1,7 @@ #include #define PLUG_IN_NAME "plug_in_gimpressionist" -#define PLUG_IN_VERSION "v0.99.5, August 1999" +#define PLUG_IN_VERSION "v0.99.6, August 1999" #ifndef DEFAULTPATH #define DEFAULTPATH "~/.gimp/gimpressionist:/usr/local/share/gimp/gimpressionist" @@ -80,6 +80,8 @@ typedef struct { int generalshadowdepth; int generalshadowblur; + + int coloracc; } gimpressionist_vals_t; /* Globals */ @@ -135,6 +137,7 @@ extern GtkObject *generalshadowadjust; extern GtkObject *generalshadowdepth; extern GtkObject *generalshadowblur; extern GtkObject *devthreshadjust; +extern GtkObject *coloraccadjust; extern GtkWidget *placecenter; diff --git a/plug-ins/gimpressionist/orientmap.c b/plug-ins/gimpressionist/orientmap.c index e7b3bae64a..ec298e900b 100644 --- a/plug-ins/gimpressionist/orientmap.c +++ b/plug-ins/gimpressionist/orientmap.c @@ -149,27 +149,26 @@ void updateompreviewprev(void) { int x, y; static struct ppm nbuffer = {0,0,NULL}; - struct rgbcolor black = {0,0,0}; - struct rgbcolor gray = {120,120,120}; - struct rgbcolor white = {255,255,255}; + guchar black[3] = {0,0,0}; + guchar gray[3] = {120,120,120}; + guchar white[3] = {255,255,255}; if(!nbuffer.col) { newppm(&nbuffer,OMWIDTH,OMHEIGHT); } - fill(&nbuffer, &black); + fill(&nbuffer, black); for(y = 6; y < OMHEIGHT-4; y += 10) for(x = 6; x < OMWIDTH-4; x += 10) { double dir = degtorad(getdir(x/(double)OMWIDTH,y/(double)OMHEIGHT,0)); double xo = sin(dir)*4.0; double yo = cos(dir)*4.0; - drawline(&nbuffer, x-xo, y-yo, x+xo, y+yo, &gray); - putrgb(&nbuffer, x-xo, y-yo, &white); + drawline(&nbuffer, x-xo, y-yo, x+xo, y+yo, gray); + putrgb(&nbuffer, x-xo, y-yo, white); } for(y = 0; y < OMHEIGHT; y++) - gtk_preview_draw_row(GTK_PREVIEW(ompreviewprev), (guchar *)nbuffer.col[y], - 0, y, OMWIDTH); + gtk_preview_draw_row(GTK_PREVIEW(ompreviewprev), (guchar *)nbuffer.col + y * OMWIDTH * 3, 0, y, OMWIDTH); gtk_widget_draw(ompreviewprev,NULL); } @@ -184,9 +183,9 @@ void updatevectorprev(void) double dir, xo, yo; double val; static double lastval = 0.0; - struct rgbcolor gray = {120,120,120}; - struct rgbcolor red = {255,0,0}; - struct rgbcolor white = {255,255,255}; + guchar gray[3] = {120,120,120}; + guchar red[3] = {255,0,0}; + guchar white[3] = {255,255,255}; if(vectprevbrightadjust) val = 1.0 - GTK_ADJUSTMENT(vectprevbrightadjust)->value / 100.0; else val = 0.5; @@ -211,14 +210,14 @@ void updatevectorprev(void) xo = sin(dir)*(6.0+100*s); yo = cos(dir)*(6.0+100*s); if(i == selectedvector) - drawline(&buffer, x-xo, y-yo, x+xo, y+yo, &red); + drawline(&buffer, x-xo, y-yo, x+xo, y+yo, red); else - drawline(&buffer, x-xo, y-yo, x+xo, y+yo, &gray); - putrgb(&buffer, x-xo, y-yo, &white); + drawline(&buffer, x-xo, y-yo, x+xo, y+yo, gray); + putrgb(&buffer, x-xo, y-yo, white); } for(y = 0; y < OMHEIGHT; y++) - gtk_preview_draw_row(GTK_PREVIEW(vectorprev), (guchar *)buffer.col[y], 0, y, OMWIDTH); + gtk_preview_draw_row(GTK_PREVIEW(vectorprev), (guchar *)buffer.col + y * OMWIDTH * 3, 0, y, OMWIDTH); gtk_widget_draw(vectorprev,NULL); } @@ -368,46 +367,6 @@ void vectypeclick(GtkWidget *w, gpointer data) updateompreviewprev(); } -#ifdef DEBUG - -void loadclick(void) -{ - readdata(MAPFILE); - selectedvector = 0; - updatevectorprev(); - updateompreviewprev(); -} - -void saveclick(void) -{ - FILE *f = fopen(MAPFILE, "wt"); - int i; - for(i = 0; i < numvect; i++) { - fprintf(f, "%.3f\t%.3f\t%5.1f\t%5.1f\n", - vector[i].x, vector[i].y, vector[i].dir, vector[i].str); - } - fclose(f); -} - -void showpixclick(void) -{ - int x, y; - for(y = 0; y < OMHEIGHT; y++) { - char buf[OMWIDTH*3]; - for(x = 0; x < OMWIDTH; x++) { - int c = pixval(getdir(x/(double)OMWIDTH, y/(double)OMHEIGHT,0)); - buf[x*3] = c; - buf[x*3+1] = c; - buf[x*3+2] = c; - } - gtk_preview_draw_row(GTK_PREVIEW(ompreviewprev), buf, 0, y, OMWIDTH); - } - gtk_widget_draw(ompreviewprev,NULL); -} - -#endif - - void hidewin(GtkWidget *w, GtkWidget **win) { gtk_widget_hide(*win); @@ -726,39 +685,6 @@ void create_orientmap_dialog(void) (GtkSignalFunc)angoffadjmove, NULL); gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), tmpw, "Voronoi-mode makes only the vector closest to the given point have any influence", NULL); - -#ifdef DEBUG - tmpw = hbox = gtk_hbox_new(TRUE,0); - gtk_table_attach_defaults(GTK_TABLE(table1), tmpw, 1,2,3,4); - gtk_container_border_width (GTK_CONTAINER (tmpw), 2); - gtk_widget_show(tmpw); - - tmpw = gtk_button_new_with_label("Save"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(saveclick), NULL); - - tmpw = gtk_button_new_with_label("Load"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(loadclick), NULL); - - tmpw = gtk_button_new_with_label("Show pix"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(showpixclick), NULL); - - tmpw = gtk_button_new_with_label("dumpvect"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(dumpvect), NULL); -#endif - - gtk_widget_show(omwindow); updatevectorprev(); diff --git a/plug-ins/gimpressionist/paper.c b/plug-ins/gimpressionist/paper.c index 1e062985fd..fa2a38508b 100644 --- a/plug-ins/gimpressionist/paper.c +++ b/plug-ins/gimpressionist/paper.c @@ -41,10 +41,11 @@ void updatepaperprev(char *fn) sc = 100.0 / sc; resize(&p, p.width*sc,p.height*sc); for(i = 0; i < 100; i++) { + int k = i * p.width * 3; memset(buf,0,100); if(i < p.height) { for(j = 0; j < p.width; j++) - buf[j] = p.col[i][j].r; + buf[j] = p.col[k + j * 3]; if(GTK_TOGGLE_BUTTON(paperinvert)->active) for(j = 0; j < p.width; j++) buf[j] = 255 - buf[j]; diff --git a/plug-ins/gimpressionist/plasma.c b/plug-ins/gimpressionist/plasma.c index 7ced97fb23..3007251bdc 100644 --- a/plug-ins/gimpressionist/plasma.c +++ b/plug-ins/gimpressionist/plasma.c @@ -10,8 +10,12 @@ int pfix(int n) return n; } +#define PIXEL(y,x,z) p->col[(y)*rowstride+(x)*3+z] + void mkplasma_sub(struct ppm *p, int x1, int x2, int y1, int y2, float turb) { + int rowstride = p->width * 3; + int r=0; int xr, yr, nx, ny; xr = abs(x1-x2); yr = abs(y1-y2); @@ -20,22 +24,22 @@ void mkplasma_sub(struct ppm *p, int x1, int x2, int y1, int y2, float turb) nx = (x1+x2)/2; ny = (y1+y2)/2; - if(!p->col[y1][nx].r) - p->col[y1][nx].r = pfix((p->col[y1][x1].r+p->col[y1][x2].r)/2.0+ + if(!PIXEL(y1,nx,r)) + PIXEL(y1,nx,r) = pfix((PIXEL(y1,x1,r)+PIXEL(y1,x2,r))/2.0+ turb*(rand()%xr-xr/2.0)); - if(!p->col[y2][nx].r) - p->col[y2][nx].r = pfix((p->col[y2][x1].r+p->col[y2][x2].r)/2.0+ + if(!PIXEL(y2,nx,r)) + PIXEL(y2,nx,r) = pfix((PIXEL(y2,x1,r)+PIXEL(y2,x2,r))/2.0+ turb*(rand()%xr-xr/2.0)); - if(!p->col[ny][x1].r) - p->col[ny][x1].r = pfix((p->col[y1][x1].r+p->col[y2][x1].r)/2.0+ + if(!PIXEL(ny,x1,r)) + PIXEL(ny,x1,r) = pfix((PIXEL(y1,x1,r)+PIXEL(y2,x1,r))/2.0+ turb*(rand()%yr-yr/2.0)); - if(!p->col[ny][x2].r) - p->col[ny][x2].r = pfix((p->col[y1][x2].r+p->col[y2][x2].r)/2.0+ + if(!PIXEL(ny,x2,r)) + PIXEL(ny,x2,r) = pfix((PIXEL(y1,x2,r)+PIXEL(y2,x2,r))/2.0+ turb*(rand()%yr-yr/2.0)); - if(!p->col[ny][nx].r) - p->col[ny][nx].r = - pfix((p->col[y1][x1].r+p->col[y1][x2].r+p->col[y2][x1].r+ - p->col[y2][x2].r)/4.0+turb*(rand()%(xr+yr)/2.0-(xr+yr)/4.0)); + if(!PIXEL(ny,nx,r)) + PIXEL(ny,nx,r) = + pfix((PIXEL(y1,x1,r)+PIXEL(y1,x2,r)+PIXEL(y2,x1,r)+ + PIXEL(y2,x2,r))/4.0+turb*(rand()%(xr+yr)/2.0-(xr+yr)/4.0)); if(xr>1) { mkplasma_sub(p,x1,nx,y1,ny, turb); @@ -50,26 +54,25 @@ void mkplasma_sub(struct ppm *p, int x1, int x2, int y1, int y2, float turb) void mkplasma_red(struct ppm *p, float turb) { int x=0, y=0; + int rowstride = p->width * 3; for(x = 0; x < p->width; x++) for(y = 0; y < p->height; y++) - p->col[y][x].r = 0; + PIXEL(y,x,0) = 0; x--; y--; - p->col[0][0].r = 1+rand()%255; - p->col[y][0].r = 1+rand()%255; - p->col[0][x].r = 1+rand()%255; - p->col[y][x].r = 1+rand()%255; + PIXEL(0,0,0) = 1+rand()%255; + PIXEL(y,0,0) = 1+rand()%255; + PIXEL(0,x,0) = 1+rand()%255; + PIXEL(y,x,0) = 1+rand()%255; mkplasma_sub(p, 0, x, 0, y, turb); } void mkgrayplasma(struct ppm *p, float turb) { - int x,y; + int y,l; mkplasma_red(p, turb); - for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; - for(x = 0; x < p->width; x++) - row[x].g = row[x].b = row[x].r; - } + l = p->width * 3 * p->height; + for(y = 0; y < l; y += 3) + p->col[y+1] = p->col[y+2] = p->col[y]; } diff --git a/plug-ins/gimpressionist/ppmtool.c b/plug-ins/gimpressionist/ppmtool.c index 4190c48bed..55bd614343 100644 --- a/plug-ins/gimpressionist/ppmtool.c +++ b/plug-ins/gimpressionist/ppmtool.c @@ -45,10 +45,6 @@ void *safemalloc(int len) void killppm(struct ppm *p) { - int y; - for(y = 0; y < p->height; y++) { - free(p->col[y]); - } free(p->col); p->col = NULL; p->height = p->width = 0; @@ -57,14 +53,8 @@ void killppm(struct ppm *p) void newppm(struct ppm *p, int xs, int ys) { - int x,y; - struct rgbcolor bgcol = {0,0,0}; - -#ifdef DEBUG - if((xs < 1) || (ys < 1)) { - fprintf(stderr, "Illegal size (%dx%d) specified!%c\n",xs, ys, 7); - } -#endif + int x; + guchar bgcol[3] = {0,0,0}; if(xs < 1) xs = 1; @@ -73,24 +63,22 @@ void newppm(struct ppm *p, int xs, int ys) p->width = xs; p->height = ys; - p->col = (struct rgbcolor **)safemalloc(p->height * sizeof(struct rgbcolor *)); - for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y] = (struct rgbcolor *)safemalloc(p->width * sizeof(struct rgbcolor)); - for(x = 0; x < p->width; x++) { - row[x].r = bgcol.r; - row[x].g = bgcol.g; - row[x].b = bgcol.b; - } + p->col = safemalloc(xs * 3 * ys); + for(x = 0; x < xs * 3 * ys; x += 3) { + p->col[x+0] = bgcol[0]; + p->col[x+1] = bgcol[1]; + p->col[x+2] = bgcol[2]; } } -void getrgb(struct ppm *s, float xo, float yo, struct rgbcolor *d) +void getrgb(struct ppm *s, float xo, float yo, guchar *d) { float ix, iy; int x1, x2, y1, y2; float x1y1, x2y1, x1y2, x2y2; float r, g, b; int bail = 0; + int rowstride = s->width * 3; if(xo < 0.0) bail=1; else if(xo >= s->width-1) { xo = s->width-1; } /* bail=1; */ @@ -98,7 +86,7 @@ void getrgb(struct ppm *s, float xo, float yo, struct rgbcolor *d) else if(yo >= s->height-1) { yo= s->height-1; } /* bail=1; */ if(bail) { - d->r = d->g = d->b = 0; + d[0] = d[1] = d[2] = 0; return; } @@ -121,34 +109,25 @@ void getrgb(struct ppm *s, float xo, float yo, struct rgbcolor *d) x1y2 = (1.0-xo+ix)*(yo-iy); x2y2 = (xo-ix)*(yo-iy); - r = s->col[y1][x1].r * x1y1; - if(x2y1 > 0.0) - r += s->col[y1][x2].r * x2y1; - if(x1y2 > 0.0) - r += s->col[y2][x1].r * x1y2; - if(x2y2 > 0.0) - r += s->col[y2][x2].r * x2y2; + r = s->col[y1*rowstride + x1*3 + 0] * x1y1; + g = s->col[y1*rowstride + x1*3 + 1] * x1y1; + b = s->col[y1*rowstride + x1*3 + 2] * x1y1; - g = s->col[y1][x1].g * x1y1; - if(x2y1 > 0.0) - g += s->col[y1][x2].g * x2y1; - if(x1y2 > 0.0) - g += s->col[y2][x1].g * x1y2; - if(x2y2 > 0.0) - g += s->col[y2][x2].g * x2y2; + if(x2y1 > 0.0) r += s->col[y1*rowstride + x2*3 + 0] * x2y1; + if(x2y1 > 0.0) g += s->col[y1*rowstride + x2*3 + 1] * x2y1; + if(x2y1 > 0.0) b += s->col[y1*rowstride + x2*3 + 2] * x2y1; - b = s->col[y1][x1].b * x1y1; - if(x2y1 > 0.0) - b += s->col[y1][x2].b * x2y1; - if(x1y2 > 0.0) - b += s->col[y2][x1].b * x1y2; - if(x2y2 > 0.0) - b += s->col[y2][x2].b * x2y2; + if(x1y2 > 0.0) r += s->col[y2*rowstride + x1*3 + 0] * x1y2; + if(x1y2 > 0.0) g += s->col[y2*rowstride + x1*3 + 1] * x1y2; + if(x1y2 > 0.0) b += s->col[y2*rowstride + x1*3 + 2] * x1y2; - d->r = r; - d->g = g; - d->b = b; + if(x2y2 > 0.0) r += s->col[y2*rowstride + x2*3 + 0] * x2y2; + if(x2y2 > 0.0) g += s->col[y2*rowstride + x2*3 + 1] * x2y2; + if(x2y2 > 0.0) b += s->col[y2*rowstride + x2*3 + 2] * x2y2; + d[0] = r; + d[1] = g; + d[2] = b; } @@ -161,8 +140,9 @@ void resize(struct ppm *p, int nx, int ny) newppm(&tmp, nx, ny); for(y = 0; y < ny; y++) { + guchar *row = tmp.col + y * tmp.width * 3; for(x = 0; x < nx; x++) { - getrgb(p, x*xs, y*ys, &tmp.col[y][x]); + getrgb(p, x*xs, y*ys, &row[x*3]); } } killppm(p); @@ -187,7 +167,7 @@ void resize_fast(struct ppm *p, int nx, int ny) for(y = 0; y < ny; y++) { for(x = 0; x < nx; x++) { int rx = x*xs, ry = y*ys; - memcpy(&tmp.col[y][x], &p->col[ry][rx], 3); + memcpy(&tmp.col[y*tmp.width*3+x*3], &p->col[ry*p->width*3+rx*3], 3); } } killppm(p); @@ -210,7 +190,7 @@ struct _BrushHeader void msb2lsb(unsigned int *i) { - unsigned char *p = (unsigned char *)i, c; + guchar *p = (guchar *)i, c; c = p[1]; p[1] = p[2]; p[2] = c; c = p[0]; p[0] = p[3]; p[3] = c; } @@ -219,7 +199,7 @@ void loadgbr(char *fn, struct ppm *p) { FILE *f; struct _BrushHeader hdr; - unsigned char *ptr; + guchar *ptr; int x, y; f = fopen(fn, "rb"); @@ -248,7 +228,8 @@ void loadgbr(char *fn, struct ppm *p) for(y = 0; y < p->height; y++) { fread(ptr, p->width, 1, f); for(x = 0; x < p->width; x++) { - p->col[y][x].r = p->col[y][x].g = p->col[y][x].b = ptr[x]; + int k = y*p->width*3 + x*3; + p->col[k+0] = p->col[k+1] = p->col[k+2] = ptr[x]; } } fclose(f); @@ -258,7 +239,7 @@ void loadgbr(char *fn, struct ppm *p) void loadppm(char *fn, struct ppm *p) { char line[200]; - int x,y, pgm = 0, c; + int y, pgm = 0; FILE *f; if(!strcmp(&fn[strlen(fn)-4], ".gbr")) { @@ -299,41 +280,37 @@ void loadppm(char *fn, struct ppm *p) return; /* fatal("Aborting!"); */ } - p->col = (struct rgbcolor **)safemalloc(p->height * sizeof(struct rgbcolor *)); + p->col = safemalloc(p->height * p->width * 3); - if(!pgm) - for(y = 0; y < p->height; y++) { - p->col[y] = (struct rgbcolor *)safemalloc(p->width * sizeof(struct rgbcolor)); - fread(p->col[y], p->width * sizeof(struct rgbcolor), 1, f); - } else /* if pgm */ { - for(y = 0; y < p->height; y++) { - p->col[y] = (struct rgbcolor *)safemalloc(p->width * sizeof(struct rgbcolor)); - fread(p->col[y], p->width, 1, f); - for(x = p->width-1; x>=0; x--) { - c = *((unsigned char *)(p->col[y])+x); - p->col[y][x].r = p->col[y][x].g = p->col[y][x].b = c; - } + if(!pgm) { + fread(p->col, p->height * 3 * p->width, 1, f); + } else { + guchar *tmpcol = safemalloc(p->width * p->height); + fread(tmpcol, p->height * p->width, 1, f); + for(y = 0; y < p->width * p->height * 3; y++) { + p->col[y] = tmpcol[y/3]; } } fclose(f); } -void fill(struct ppm *p, struct rgbcolor *c) +void fill(struct ppm *p, guchar *c) { int x, y; - if((c->r == c->g) && (c->r == c->b)) { - unsigned char col = c->r; + if((c[0] == c[1]) && (c[0] == c[2])) { + guchar col = c[0]; for(y = 0; y < p->height; y++) { - memset(p->col[y], col, p->width*3); + memset(p->col + y*p->width*3, col, p->width*3); } } else { for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; + guchar *row = p->col + y * p->width * 3; for(x = 0; x < p->width; x++) { - row[x].r = c->r; - row[x].g = c->g; - row[x].b = c->b; + int k = x * 3; + row[k+0] = c[0]; + row[k+1] = c[1]; + row[k+2] = c[2]; } } } @@ -341,16 +318,12 @@ void fill(struct ppm *p, struct rgbcolor *c) void copyppm(struct ppm *s, struct ppm *p) { - int y; if(p->col) killppm(p); p->width = s->width; p->height = s->height; - p->col = (struct rgbcolor **)safemalloc(p->height * sizeof(struct rgbcolor *)); - for(y = 0; y < p->height; y++) { - p->col[y] = (struct rgbcolor *)safemalloc(p->width * sizeof(struct rgbcolor)); - memcpy(p->col[y], s->col[y], p->width * sizeof(struct rgbcolor)); - } + p->col = safemalloc(p->width * 3 * p->height); + memcpy(p->col, s->col, p->width * 3 * p->height); } void freerotate(struct ppm *p, double amount) @@ -360,6 +333,7 @@ void freerotate(struct ppm *p, double amount) double R, a; struct ppm tmp = {0,0,NULL}; double f = amount*M_PI*2/360.0; + int rowstride = p->width * 3; a = p->width/(float)p->height; R = p->widthheight?p->width/2:p->height/2; @@ -376,7 +350,7 @@ void freerotate(struct ppm *p, double amount) nx = (p->width/2.0 + cos(d-f) * r); ny = (p->height/2.0 + sin(d-f) * r); - getrgb(p, nx, ny, &tmp.col[y][x]); + getrgb(p, nx, ny, tmp.col + y*rowstride+x*3); } } killppm(p); @@ -389,11 +363,15 @@ void crop(struct ppm *p, int lx, int ly, int hx, int hy) { struct ppm tmp = {0,0,NULL}; int x, y; + int srowstride = p->width * 3; + int drowstride; newppm(&tmp, hx-lx, hy-ly); + drowstride = tmp.width * 3; for(y = ly; y < hy; y++) for(x = lx; x < hx; x++) - memcpy(&tmp.col[y-ly][x-lx], &p->col[y][x], sizeof(struct rgbcolor)); + memcpy(&tmp.col[(y-ly)*drowstride+(x-lx)*3], + &p->col[y*srowstride+x*3], 3); killppm(p); p->col = tmp.col; p->width = tmp.width; @@ -404,15 +382,17 @@ void autocrop(struct ppm *p, int room) { int lx = 0, hx = p->width, ly = 0, hy = p->height; int x, y, n = 0; - struct rgbcolor tc; + guchar tc[3]; struct ppm tmp = {0,0,NULL}; + int rowstride = p->width * 3; + int drowstride; /* upper */ - memcpy(&tc, &p->col[0][0], sizeof(struct rgbcolor)); + memcpy(&tc, p->col, 3); for(y = 0; y < p->height; y++) { n = 0; for(x = 0; x < p->width; x++) { - if(memcmp(&tc, &p->col[y][x], sizeof(struct rgbcolor))) { n++; break; } + if(memcmp(&tc, &p->col[y*rowstride+x*3], 3)) { n++; break; } } if(n) break; } @@ -420,11 +400,11 @@ void autocrop(struct ppm *p, int room) /* printf("ly = %d\n", ly); */ /* lower */ - memcpy(&tc, &p->col[p->height-1][0], sizeof(struct rgbcolor)); + memcpy(&tc, &p->col[(p->height-1)*rowstride], 3); for(y = p->height-1; y >= 0; y--) { n = 0; for(x = 0; x < p->width; x++) { - if(memcmp(&tc, &p->col[y][x], sizeof(struct rgbcolor))) { n++; break; } + if(memcmp(&tc, &p->col[y*rowstride+x*3], 3)) { n++; break; } } if(n) break; } @@ -433,11 +413,11 @@ void autocrop(struct ppm *p, int room) /* printf("hy = %d\n", hy); */ /* left */ - memcpy(&tc, &p->col[ly][0], sizeof(struct rgbcolor)); + memcpy(&tc, &p->col[ly*rowstride], 3); for(x = 0; x < p->width; x++) { n = 0; for(y = ly; y <= hy && y < p->height; y++) { - if(memcmp(&tc, &p->col[y][x], sizeof(struct rgbcolor))) { n++; break; } + if(memcmp(&tc, &p->col[y*rowstride+x*3], 3)) { n++; break; } } if(n) break; } @@ -445,11 +425,11 @@ void autocrop(struct ppm *p, int room) /* printf("lx = %d\n", lx); */ /* right */ - memcpy(&tc, &p->col[ly][p->width-1], sizeof(struct rgbcolor)); + memcpy(&tc, &p->col[ly*rowstride + (p->width-1)*3], 3); for(x = p->width-1; x >= 0; x--) { n = 0; for(y = ly; y <= hy; y++) { - if(memcmp(&tc, &p->col[y][x], sizeof(struct rgbcolor))) { n++; break; } + if(memcmp(&tc, &p->col[y*rowstride+x*3], 3)) { n++; break; } } if(n) break; } @@ -462,47 +442,53 @@ void autocrop(struct ppm *p, int room) hy += room; if(hy>=p->height) hy = p->height-1; newppm(&tmp, hx-lx, hy-ly); + drowstride = tmp.width * 3; for(y = ly; y < hy; y++) for(x = lx; x < hx; x++) - memcpy(&tmp.col[y-ly][x-lx], &p->col[y][x], sizeof(struct rgbcolor)); + memcpy(&tmp.col[(y-ly)*drowstride+(x-lx)*3], + &p->col[y*rowstride+x*3], 3); killppm(p); p->col = tmp.col; p->width = tmp.width; p->height = tmp.height; } -void pad(struct ppm *p, int left,int right, int top, int bottom, struct rgbcolor *bg) +void pad(struct ppm *p, int left,int right, int top, int bottom, guchar *bg) { int x, y; struct ppm tmp = {0,0,NULL}; newppm(&tmp, p->width+left+right, p->height+top+bottom); for(y = 0; y < tmp.height; y++) { - struct rgbcolor *row, *srcrow; - row = tmp.col[y]; + guchar *row, *srcrow; + row = tmp.col + y * tmp.width * 3; if((y < top) || (y >= tmp.height-bottom)) { for(x = 0; x < tmp.width; x++) { - row[x].r = bg->r; - row[x].g = bg->g; - row[x].b = bg->b; + int k = x * 3; + row[k+0] = bg[0]; + row[k+1] = bg[1]; + row[k+2] = bg[2]; } continue; } - srcrow = p->col[y-top]; + srcrow = p->col + (y-top) * p->width * 3; for(x = 0; x < left; x++) { - row[x].r = bg->r; - row[x].g = bg->g; - row[x].b = bg->b; + int k = x * 3; + row[k+0] = bg[0]; + row[k+1] = bg[1]; + row[k+2] = bg[2]; } for(; x < tmp.width-right; x++) { - tmp.col[y][x].r = srcrow[x-left].r; - tmp.col[y][x].g = srcrow[x-left].g; - tmp.col[y][x].b = srcrow[x-left].b; + int k = y * tmp.width * 3 + x * 3; + tmp.col[k+0] = srcrow[(x-left)*3+0]; + tmp.col[k+1] = srcrow[(x-left)*3+1]; + tmp.col[k+2] = srcrow[(x-left)*3+2]; } for(; x < tmp.width; x++) { - row[x].r = bg->r; - row[x].g = bg->g; - row[x].b = bg->b; + int k = x * 3; + row[k+0] = bg[0]; + row[k+1] = bg[1]; + row[k+2] = bg[2]; } } killppm(p); @@ -513,11 +499,9 @@ void pad(struct ppm *p, int left,int right, int top, int bottom, struct rgbcolor void saveppm(struct ppm *p, char *fn) { - int y; FILE *f = fopen(fn, "wb"); fprintf(f, "P6\n%d %d\n255\n", p->width, p->height); - for(y = 0; y < p->height; y++) - fwrite(p->col[y], p->width, 3, f); + fwrite(p->col, p->width * 3 * p->height, 1, f); fclose(f); } @@ -525,33 +509,36 @@ void edgepad(struct ppm *p, int left,int right, int top, int bottom) { int x,y; struct ppm tmp = {0,0,NULL}; - struct rgbcolor testcol = {0,255,0}; + guchar testcol[3] = {0,255,0}; + int srowstride, drowstride; newppm(&tmp, p->width+left+right, p->height+top+bottom); - fill(&tmp, &testcol); + fill(&tmp, testcol); + + srowstride = p->width * 3; + drowstride = tmp.width * 3; + for(y = 0; y < top; y++) { - memcpy(&tmp.col[y][left], &p->col[0][0], p->width * sizeof(struct rgbcolor)); + memcpy(&tmp.col[y*drowstride+left*3], p->col, srowstride); } for(; y-top < p->height; y++) { - memcpy(&tmp.col[y][left], &p->col[y-top][0], p->width * sizeof(struct rgbcolor)); + memcpy(&tmp.col[y*drowstride+left*3], p->col + (y-top)*srowstride, srowstride); } for(; y < tmp.height; y++) { - memcpy(&tmp.col[y][left], &p->col[p->height-1][0], p->width * sizeof(struct rgbcolor)); + memcpy(&tmp.col[y*drowstride+left*3], p->col + (p->height-1)*srowstride, srowstride); } for(y = 0; y < tmp.height; y++) { - struct rgbcolor *col; - struct rgbcolor *tmprow; + guchar *col, *tmprow; - tmprow = tmp.col[y]; + tmprow = tmp.col + y*drowstride; + col = tmp.col + y*drowstride + left*3; - col = &tmp.col[y][left]; for(x = 0; x < left; x++) { - memcpy(&tmprow[x], col, sizeof(struct rgbcolor)); + memcpy(&tmprow[x*3], col, 3); } - - col = &tmp.col[y][tmp.width-right-1]; + col = tmp.col + y*drowstride + (tmp.width-right-1)*3; for(x = 0; x < right; x++) { - memcpy(&tmprow[x+tmp.width-right-1], col, sizeof(struct rgbcolor)); + memcpy(&tmprow[(x+tmp.width-right-1)*3], col, 3); } } killppm(p); @@ -562,69 +549,42 @@ void edgepad(struct ppm *p, int left,int right, int top, int bottom) void ppmgamma(struct ppm *p, float e, int r, int g, int b) { - int x, y; - unsigned char xlat[256]; + int x, l = p->width * 3 * p->height; + guchar xlat[256], *pix; if(e > 0.0) for(x = 0; x < 256; x++) { xlat[x] = pow((x/255.0),(1.0/e))*255.0; } else if(e < 0.0) for(x = 0; x < 256; x++) { xlat[255-x] = pow((x/255.0),(-1.0/e))*255.0; } else for(x = 0; x < 256; x++) { xlat[x] = 0; } - if(r) for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; - for(x = 0; x < p->width; x++) { - row[x].r = xlat[row[x].r]; - } - } - if(g) for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; - for(x = 0; x < p->width; x++) { - row[x].g = xlat[row[x].g]; - } - } - if(b) for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; - for(x = 0; x < p->width; x++) { - row[x].b = xlat[row[x].b]; - } - } + pix = p->col; + if(r) for(x = 0; x < l; x += 3) pix[x] = xlat[pix[x]]; + if(g) for(x = 1; x < l; x += 3) pix[x] = xlat[pix[x]]; + if(b) for(x = 2; x < l; x += 3) pix[x] = xlat[pix[x]]; } void ppmbrightness(struct ppm *p, float e, int r, int g, int b) { - int x, y; - unsigned char xlat[256]; + int x, l = p->width * 3 * p->height; + guchar xlat[256], *pix; for(x = 0; x < 256; x++) { xlat[x] = x*e; } - if(r) for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; - for(x = 0; x < p->width; x++) { - row[x].r = xlat[row[x].r]; - } - } - if(g) for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; - for(x = 0; x < p->width; x++) { - row[x].g = xlat[row[x].g]; - } - } - if(b) for(y = 0; y < p->height; y++) { - struct rgbcolor *row = p->col[y]; - for(x = 0; x < p->width; x++) { - row[x].b = xlat[row[x].b]; - } - } + pix = p->col; + if(r) for(x = 0; x < l; x += 3) pix[x] = xlat[pix[x]]; + if(g) for(x = 1; x < l; x += 3) pix[x] = xlat[pix[x]]; + if(b) for(x = 2; x < l; x += 3) pix[x] = xlat[pix[x]]; } void blur(struct ppm *p, int xrad, int yrad) { - int x, y; + int x, y, k; int tx, ty; struct ppm tmp = {0,0,NULL}; int r, g, b, n; + int rowstride = p->width * 3; newppm(&tmp, p->width, p->height); for(y = 0; y < p->height; y++) { @@ -636,15 +596,17 @@ void blur(struct ppm *p, int xrad, int yrad) if(ty>=p->height) continue; if(tx<0) continue; if(tx>=p->width) continue; - r += p->col[ty][tx].r; - g += p->col[ty][tx].g; - b += p->col[ty][tx].b; + k = ty*rowstride + tx*3; + r += p->col[k+0]; + g += p->col[k+1]; + b += p->col[k+2]; n++; } } - tmp.col[y][x].r = r / n; - tmp.col[y][x].g = g / n; - tmp.col[y][x].b = b / n; + k = y*rowstride + x*3; + tmp.col[k+0] = r / n; + tmp.col[k+1] = g / n; + tmp.col[k+2] = b / n; } } killppm(p); @@ -653,18 +615,20 @@ void blur(struct ppm *p, int xrad, int yrad) p->col = tmp.col; } -void putrgb_fast(struct ppm *s, float xo, float yo, struct rgbcolor *d) +void putrgb_fast(struct ppm *s, float xo, float yo, guchar *d) { - struct rgbcolor *tp = &s->col[(int)(yo+0.5)][(int)(xo+0.5)]; - tp->r = d->r; - tp->g = d->g; - tp->b = d->b; + guchar *tp; + tp = s->col + s->width * 3 * (int)(yo+0.5) + 3 * (int)(xo+0.5); + tp[0] = d[0]; + tp[1] = d[1]; + tp[2] = d[2]; } -void putrgb(struct ppm *s, float xo, float yo, struct rgbcolor *d) +void putrgb(struct ppm *s, float xo, float yo, guchar *d) { int x, y; float aa, ab, ba, bb; + int k, rowstride = s->width * 3; x = xo; y = yo; @@ -680,34 +644,38 @@ void putrgb(struct ppm *s, float xo, float yo, struct rgbcolor *d) ba = (1.0-xo)*yo; bb = xo*yo; - s->col[y][x].r *= (1.0-aa); - s->col[y][x].g *= (1.0-aa); - s->col[y][x].b *= (1.0-aa); - s->col[y][x+1].r *= (1.0-ab); - s->col[y][x+1].g *= (1.0-ab); - s->col[y][x+1].b *= (1.0-ab); - s->col[y+1][x].r *= (1.0-ba); - s->col[y+1][x].g *= (1.0-ba); - s->col[y+1][x].b *= (1.0-ba); - s->col[y+1][x+1].r *= (1.0-bb); - s->col[y+1][x+1].g *= (1.0-bb); - s->col[y+1][x+1].b *= (1.0-bb); + k = y*rowstride + x*3; + s->col[k+0] *= (1.0-aa); + s->col[k+1] *= (1.0-aa); + s->col[k+2] *= (1.0-aa); + + s->col[k+3] *= (1.0-ab); + s->col[k+4] *= (1.0-ab); + s->col[k+5] *= (1.0-ab); - s->col[y][x].r += aa * d->r; - s->col[y][x].g += aa * d->g; - s->col[y][x].b += aa * d->b; - s->col[y][x+1].r += ab * d->r; - s->col[y][x+1].g += ab * d->g; - s->col[y][x+1].b += ab * d->b; - s->col[y+1][x].r += ba * d->r; - s->col[y+1][x].g += ba * d->g; - s->col[y+1][x].b += ba * d->b; - s->col[y+1][x+1].r += bb * d->r; - s->col[y+1][x+1].g += bb * d->g; - s->col[y+1][x+1].b += bb * d->b; + s->col[k+rowstride+0] *= (1.0-ba); + s->col[k+rowstride+1] *= (1.0-ba); + s->col[k+rowstride+2] *= (1.0-ba); + + s->col[k+rowstride+3] *= (1.0-bb); + s->col[k+rowstride+4] *= (1.0-bb); + s->col[k+rowstride+5] *= (1.0-bb); + + s->col[k+0] += aa * d[0]; + s->col[k+1] += aa * d[1]; + s->col[k+2] += aa * d[2]; + s->col[k+3] += ab * d[0]; + s->col[k+4] += ab * d[1]; + s->col[k+5] += ab * d[2]; + s->col[k+rowstride+0] += ba * d[0]; + s->col[k+rowstride+1] += ba * d[1]; + s->col[k+rowstride+2] += ba * d[2]; + s->col[k+rowstride+3] += bb * d[0]; + s->col[k+rowstride+4] += bb * d[1]; + s->col[k+rowstride+5] += bb * d[2]; } -void drawline(struct ppm *p, float fx, float fy, float tx, float ty, struct rgbcolor *col) +void drawline(struct ppm *p, float fx, float fy, float tx, float ty, guchar *col) { float i; float d, x, y; diff --git a/plug-ins/gimpressionist/ppmtool.h b/plug-ins/gimpressionist/ppmtool.h index 6a9438d562..7aa9e7d75a 100644 --- a/plug-ins/gimpressionist/ppmtool.h +++ b/plug-ins/gimpressionist/ppmtool.h @@ -1,35 +1,33 @@ -struct rgbcolor { - unsigned char r, g, b; -}; +#include struct ppm { int width; int height; - struct rgbcolor **col; + unsigned char *col; }; void fatal(char *s); void *safemalloc(int len); void killppm(struct ppm *p); void newppm(struct ppm *p, int xs, int ys); -void getrgb(struct ppm *s, float xo, float yo, struct rgbcolor *d); +void getrgb(struct ppm *s, float xo, float yo, unsigned char *d); void resize(struct ppm *p, int nx, int ny); void rescale(struct ppm *p, double scale); void resize_fast(struct ppm *p, int nx, int ny); void loadppm(char *fn, struct ppm *p); void saveppm(struct ppm *p, char *fn); void copyppm(struct ppm *s, struct ppm *p); -void fill(struct ppm *p, struct rgbcolor *c); +void fill(struct ppm *p, guchar *c); void freerotate(struct ppm *p, double amount); -void pad(struct ppm *p, int left,int right, int top, int bottom, struct rgbcolor *bg); +void pad(struct ppm *p, int left,int right, int top, int bottom, guchar *); void edgepad(struct ppm *p, int left,int right, int top, int bottom); void autocrop(struct ppm *p, int room); void crop(struct ppm *p, int lx, int ly, int hx, int hy); void ppmgamma(struct ppm *p, float e, int r, int g, int b); void ppmbrightness(struct ppm *p, float e, int r, int g, int b); -void putrgb_fast(struct ppm *s, float xo, float yo, struct rgbcolor *d); -void putrgb(struct ppm *s, float xo, float yo, struct rgbcolor *d); -void drawline(struct ppm *p, float fx, float fy, float tx, float ty, struct rgbcolor *col); +void putrgb_fast(struct ppm *s, float xo, float yo, guchar *d); +void putrgb(struct ppm *s, float xo, float yo, guchar *d); +void drawline(struct ppm *p, float fx, float fy, float tx, float ty, guchar *col); void repaint(struct ppm *p, struct ppm *a); diff --git a/plug-ins/gimpressionist/presets.c b/plug-ins/gimpressionist/presets.c index 713b9fadac..43eae5be6e 100644 --- a/plug-ins/gimpressionist/presets.c +++ b/plug-ins/gimpressionist/presets.c @@ -323,7 +323,7 @@ void savepreset(GtkWidget *wg, GtkWidget *p); void presetdesccallback(GtkWidget *widget, gpointer data) { - unsigned char *s; + guchar *s; char *d, *str; str = gtk_editable_get_chars(GTK_EDITABLE (widget),0,-1); s = str; diff --git a/plug-ins/gimpressionist/preview.c b/plug-ins/gimpressionist/preview.c index 0b99f2c52c..37cfe25a80 100644 --- a/plug-ins/gimpressionist/preview.c +++ b/plug-ins/gimpressionist/preview.c @@ -21,19 +21,21 @@ void drawalpha(struct ppm *p, struct ppm *a) int x, y, g; double v; int gridsize = 16; + int rowstride = p->width * 3; for(y = 0; y < p->height; y++) { for(x = 0; x < p->width; x++) { - if(!a->col[y][x].r) continue; - v = 1.0 - a->col[y][x].r / 255.0; + int k = y*rowstride + x*3; + if(!a->col[k]) continue; + v = 1.0 - a->col[k] / 255.0; g = ((x/gridsize+y/gridsize)%2)*60+100; - p->col[y][x].r *= v; - p->col[y][x].g *= v; - p->col[y][x].b *= v; + p->col[k+0] *= v; + p->col[k+1] *= v; + p->col[k+2] *= v; v = 1.0-v; - p->col[y][x].r += g*v; - p->col[y][x].g += g*v; - p->col[y][x].b += g*v; + p->col[k+0] += g*v; + p->col[k+1] += g*v; + p->col[k+2] += g*v; } } @@ -42,7 +44,7 @@ void drawalpha(struct ppm *p, struct ppm *a) void updatepreviewprev(GtkWidget *wg, void *d) { - int i, j; + int i; char buf[PREVIEWSIZE*3]; static struct ppm p = {0,0,NULL}; static struct ppm a = {0,0,NULL}; @@ -83,9 +85,8 @@ void updatepreviewprev(GtkWidget *wg, void *d) for(i = 0; i < PREVIEWSIZE; i++) { memset(buf,0,PREVIEWSIZE*3); - for(j = 0; j < p.width; j++) - gtk_preview_draw_row(GTK_PREVIEW(previewprev), (guchar *)p.col[i], - 0, i, PREVIEWSIZE); + //for(j = 0; j < p.width; j++) + gtk_preview_draw_row(GTK_PREVIEW(previewprev), (guchar *)&p.col[i*PREVIEWSIZE*3], 0, i, PREVIEWSIZE); } killppm(&p); if(img_has_alpha) diff --git a/plug-ins/gimpressionist/repaint.c b/plug-ins/gimpressionist/repaint.c index 37bbf25361..eadf2f7153 100644 --- a/plug-ins/gimpressionist/repaint.c +++ b/plug-ins/gimpressionist/repaint.c @@ -22,51 +22,50 @@ gimpressionist_vals_t runningvals; void prepbrush(struct ppm *p) { int x, y; + int rowstride = p->width * 3; for(y = 0; y< p->height; y++) { for(x = 0; x < p->width; x++) { - p->col[y][x].g = 0; + p->col[y*rowstride+x*3+1] = 0; } } for(y = 1; y< p->height; y++) { for(x = 1; x < p->width; x++) { - int v = p->col[y][x].r - p->col[y-1][x-1].r; + int v = p->col[y*rowstride+x*3] - p->col[(y-1)*rowstride+(x-1)*3]; if(v < 0) v = 0; - p->col[y][x].g = v; + p->col[y*rowstride+x*3+1] = v; } } } double sumbrush(struct ppm *p) { - int x, y; double sum = 0; - for(y = 0; y< p->height; y++) { - for(x = 0; x < p->width; x++) { - sum += p->col[y][x].r; - } - } + int i; + + for(i = 0; i < p->width*3*p->height; i += 3) + sum += p->col[i]; return sum; } -int gethue(struct rgbcolor *rgb) +int gethue(guchar *rgb) { double h, v, temp, diff; - if((rgb->r == rgb->g) && (rgb->r == rgb->b)) /* Gray */ + if((rgb[0] == rgb[1]) && (rgb[0] == rgb[2])) /* Gray */ return 0; - v = (rgb->r > rgb->g ? rgb->r : rgb->g); /* v = strste verdi */ - if(rgb->b > v) v = rgb->b; - temp = (rgb->r > rgb->g ? rgb->g : rgb->r ); /* temp = minste */ - if(rgb->b < temp) temp = rgb->b; + v = (rgb[0] > rgb[1] ? rgb[0] : rgb[1]); /* v = strste verdi */ + if(rgb[2] > v) v = rgb[2]; + temp = (rgb[0] > rgb[1] ? rgb[1] : rgb[0] ); /* temp = minste */ + if(rgb[2] < temp) temp = rgb[2]; diff = v - temp; - if(v == rgb->r) - h = ((double)rgb->g - rgb->b) / diff; - else if(v == rgb->g) - h = ((double)rgb->b - rgb->r) / diff + 2; - else /* v == rgb->b */ - h = ((double)rgb->r - rgb->g) / diff + 4; + if(v == rgb[0]) + h = ((double)rgb[1] - rgb[2]) / diff; + else if(v == rgb[1]) + h = ((double)rgb[2] - rgb[0]) / diff + 2; + else /* v == rgb[2] */ + h = ((double)rgb[0] - rgb[1]) / diff + 4; if(h < 0) h += 6; return h * 255.0 / 6.0; } @@ -90,15 +89,16 @@ int bestbrush(struct ppm *p, struct ppm *a, int tx, int ty, r = g = b = 0.0; for(y = 0; y < brush->height; y++) { - struct rgbcolor *row = p->col[ty+y]; + guchar *row = p->col + (ty+y)*p->width*3; for(x = 0; x < brush->width; x++) { + int k = (tx+x)*3; double v; - if((h = brush->col[y][x].r)) { + if((h = brush->col[(y*brush->width*3)+x*3])) { /* thissum += h; */ v = h / 255.0; - r += row[tx+x].r * v; - g += row[tx+x].g * v; - b += row[tx+x].b * v; + r += row[k+0] * v; + g += row[k+1] * v; + b += row[k+2] * v; } } } @@ -108,16 +108,17 @@ int bestbrush(struct ppm *p, struct ppm *a, int tx, int ty, dev = 0.0; for(y = 0; y < brush->height; y++) { - struct rgbcolor *row = p->col[ty+y]; + guchar *row = p->col + (ty+y)*p->width*3; for(x = 0; x < brush->width; x++) { + int k = (tx+x)*3; double v; - if((h = brush->col[y][x].r)) { + if((h = brush->col[(y*brush->width*3)+x*3])) { v = h / 255.0; - dev += abs(row[tx+x].r - r) * v; - dev += abs(row[tx+x].g - g) * v; - dev += abs(row[tx+x].b - b) * v; + dev += abs(row[k+0] - r) * v; + dev += abs(row[k+1] - g) * v; + dev += abs(row[k+2] - b) * v; if(img_has_alpha) - dev += a->col[ty+y][tx+x].r * v; + dev += a->col[(ty+y)*a->width*3+(tx+x)*3] * v; } } } @@ -177,63 +178,66 @@ void applybrush(struct ppm *brush, int sx = tx + shadowdepth - shadowblur*2; int sy = ty + shadowdepth - shadowblur*2; for(y = 0; y < shadow->height; y++) { - struct rgbcolor *row, *arow = NULL; + guchar *row, *arow = NULL; if((sy + y) < 0) continue; if((sy + y) >= tmp.height) break; - row = tmp.col[sy+y]; - if(img_has_alpha) arow = atmp.col[sy+y]; + row = tmp.col + (sy+y) * tmp.width * 3; + if(img_has_alpha) arow = atmp.col + (sy+y) * atmp.width * 3; for(x = 0; x < shadow->width; x++) { + int k = (sx + x) * 3; if((sx + x) < 0) continue; if((sx + x) >= tmp.width) break; - h = shadow->col[y][x].b; + h = shadow->col[y*shadow->width*3+x*3+2]; if(!h) continue; v = 1.0 - (h / 255.0 * runningvals.generalshadowdarkness / 100.0); - row[sx+x].r *= v; - row[sx+x].g *= v; - row[sx+x].b *= v; - if(img_has_alpha) arow[sx+x].r *= v; + row[k+0] *= v; + row[k+1] *= v; + row[k+2] *= v; + if(img_has_alpha) arow[k] *= v; } } } for(y = 0; y < brush->height; y++) { - struct rgbcolor *row = tmp.col[ty+y]; - struct rgbcolor *arow = NULL; - if(img_has_alpha) arow = atmp.col[ty+y]; + guchar *row = tmp.col + (ty+y)*tmp.width*3; + guchar *arow = NULL; + if(img_has_alpha) arow = atmp.col + (ty+y)*atmp.width*3; for(x = 0; x < brush->width; x++) { - h = brush->col[y][x].r; + int k = (tx + x) * 3; + h = brush->col[y*brush->width*3+x*3]; if(!h) continue; if(runningvals.colorbrushes) { - v = 1.0 - brush->col[y][x].b / 255.0; - row[tx+x].r *= v; - row[tx+x].g *= v; - row[tx+x].b *= v; - if(img_has_alpha) arow[tx+x].r *= v; + v = 1.0 - brush->col[y*brush->width*3+x*3+2] / 255.0; + row[k+0] *= v; + row[k+1] *= v; + row[k+2] *= v; + if(img_has_alpha) arow[(tx+x)*3] *= v; } v = (1.0 - h / 255.0) * edgedarken; - row[tx+x].r *= v; - row[tx+x].g *= v; - row[tx+x].b *= v; - if(img_has_alpha) arow[tx+x].r *= v; + row[k+0] *= v; + row[k+1] *= v; + row[k+2] *= v; + if(img_has_alpha) arow[k] *= v; v = h / 255.0; - row[tx+x].r += r * v; - row[tx+x].g += g * v; - row[tx+x].b += b * v; + row[k+0] += r * v; + row[k+1] += g * v; + row[k+2] += b * v; } } if(relief > 0.001) { for(y = 1; y < brush->height; y++) { - struct rgbcolor *row = tmp.col[ty+y]; + guchar *row = tmp.col + (ty+y)*tmp.width*3; for(x = 1; x < brush->width; x++) { - h = brush->col[y][x].g * relief; + int k = (tx + x) * 3; + h = brush->col[y*brush->width*3+x*3+1] * relief; if(h < 0.001) continue; if(h > 255) h = 255; - row[tx+x].r = (row[tx+x].r * (255-h) + 255 * h) / 255; - row[tx+x].g = (row[tx+x].g * (255-h) + 255 * h) / 255; - row[tx+x].b = (row[tx+x].b * (255-h) + 255 * h) / 255; + row[k+0] = (row[k+0] * (255-h) + 255 * h) / 255; + row[k+1] = (row[k+1] * (255-h) + 255 * h) / 255; + row[k+2] = (row[k+2] * (255-h) + 255 * h) / 255; } } } @@ -247,7 +251,7 @@ void repaint(struct ppm *p, struct ppm *a) struct ppm atmp = {0,0,NULL}; int r, g, b, n, h, i, j, on, sn; int numbrush, maxbrushwidth, maxbrushheight; - struct rgbcolor back = {0,0,0}; + guchar back[3] = {0,0,0}; struct ppm *brushes, *shadows; struct ppm *brush, *shadow = NULL; double *brushsum; @@ -315,7 +319,7 @@ void repaint(struct ppm *p, struct ppm *a) i = 1 + sqrt(brushes[0].width * brushes[0].width + brushes[0].height * brushes[0].height); pad(&brushes[0], i-brushes[0].width, i-brushes[0].width, - i-brushes[0].height, i-brushes[0].height, &back); + i-brushes[0].height, i-brushes[0].height, back); for(i = 1; i < numbrush; i++) { brushes[i].col = NULL; @@ -362,12 +366,12 @@ void repaint(struct ppm *p, struct ppm *a) for(i = 0; i < numbrush; i++) { int xp, yp; - struct rgbcolor blk = {0,0,0}; + guchar blk[3] = {0,0,0}; xp = maxbrushwidth - brushes[i].width; yp = maxbrushheight - brushes[i].height; if(xp || yp) - pad(&brushes[i], xp/2, xp-xp/2, yp/2, yp-yp/2, &blk); + pad(&brushes[i], xp/2, xp-xp/2, yp/2, yp-yp/2, blk); } if(dropshadow) { @@ -376,7 +380,7 @@ void repaint(struct ppm *p, struct ppm *a) copyppm(&brushes[i], &shadows[i]); ppmgamma(&shadows[i], 0, 1,1,0); pad(&shadows[i], shadowblur*2, shadowblur*2, - shadowblur*2, shadowblur*2, &back); + shadowblur*2, shadowblur*2, back); for(j = 0; j < shadowblur; j++) blur(&shadows[i], 2, 2); /* autocrop(&shadows[i],1); */ @@ -403,19 +407,19 @@ void repaint(struct ppm *p, struct ppm *a) if(img_has_alpha) { /* Initially fully transparent */ if(runningvals.generalbgtype == 3) { - struct rgbcolor tmpcol = {255,255,255}; + guchar tmpcol[3] = {255,255,255}; newppm(&atmp, a->width, a->height); - fill(&atmp, &tmpcol); + fill(&atmp, tmpcol); } else { copyppm(a, &atmp); } } if(runningvals.generalbgtype == 0) { - struct rgbcolor tmpcol; + guchar tmpcol[3]; newppm(&tmp, p->width, p->height); memcpy(&tmpcol, runningvals.color, 3); - fill(&tmp, &tmpcol); + fill(&tmp, tmpcol); } else if(runningvals.generalbgtype == 1) { copyppm(p, &tmp); } else { @@ -429,7 +433,7 @@ void repaint(struct ppm *p, struct ppm *a) int rx = x % paperppm.width; for(y = 0; y < tmp.height; y++) { int ry = y % paperppm.height; - memcpy(&tmp.col[y][x], &paperppm.col[ry][rx], 3); + memcpy(&tmp.col[y*tmp.width*3+x*3], &paperppm.col[ry*paperppm.width*3+rx*3], 3); } } } @@ -441,27 +445,27 @@ void repaint(struct ppm *p, struct ppm *a) if(runningvals.orienttype == 0) { /* Value */ newppm(&dirmap, p->width, p->height); for(y = 0; y < dirmap.height; y++) { - struct rgbcolor *dstrow = dirmap.col[y]; - struct rgbcolor *srcrow = p->col[y]; + guchar *dstrow = &dirmap.col[y*dirmap.width*3]; + guchar *srcrow = &p->col[y*p->width*3]; for(x = 0; x < dirmap.width; x++) { - dstrow[x].r = (srcrow[x].r + srcrow[x].g + srcrow[x].b) / 3; + dstrow[x*3] = (srcrow[x*3] + srcrow[x*3+1] + srcrow[x*3+2]) / 3; } } } else if(runningvals.orienttype == 1) { /* Radius */ newppm(&dirmap, p->width, p->height); for(y = 0; y < dirmap.height; y++) { - struct rgbcolor *dstrow = dirmap.col[y]; + guchar *dstrow = &dirmap.col[y*dirmap.width*3]; double ysqr = (cy-y)*(cy-y); for(x = 0; x < dirmap.width; x++) { - dstrow[x].r = sqrt((cx-x)*(cx-x)+ysqr) * 255 / maxdist; + dstrow[x*3] = sqrt((cx-x)*(cx-x)+ysqr) * 255 / maxdist; } } } else if(runningvals.orienttype == 3) { /* Radial */ newppm(&dirmap, p->width, p->height); for(y = 0; y < dirmap.height; y++) { - struct rgbcolor *dstrow = dirmap.col[y]; + guchar *dstrow = &dirmap.col[y*dirmap.width*3]; for(x = 0; x < dirmap.width; x++) { - dstrow[x].r = (M_PI + atan2(cy-y, cx-x)) * 255.0 / (M_PI*2); + dstrow[x*3] = (M_PI + atan2(cy-y, cx-x)) * 255.0 / (M_PI*2); } } } else if(runningvals.orienttype == 4) { /* Flowing */ @@ -476,24 +480,24 @@ void repaint(struct ppm *p, struct ppm *a) } else if(runningvals.orienttype == 5) { /* Hue */ newppm(&dirmap, p->width, p->height); for(y = 0; y < dirmap.height; y++) { - struct rgbcolor *dstrow = dirmap.col[y]; - struct rgbcolor *srcrow = p->col[y]; + guchar *dstrow = &dirmap.col[y*dirmap.width*3]; + guchar *srcrow = &p->col[y*p->width*3]; for(x = 0; x < dirmap.width; x++) { - dstrow[x].r = gethue(&srcrow[x]); + dstrow[x*3] = gethue(&srcrow[x*3]); } } } else if(runningvals.orienttype == 6) { - struct rgbcolor tmpcol = {0,0,0}; + guchar tmpcol[3] = {0,0,0}; newppm(&dirmap, p->width, p->height); - fill(&dirmap, &tmpcol); + fill(&dirmap, tmpcol); } else if(runningvals.orienttype == 7) { /* Manual */ newppm(&dirmap, p->width-maxbrushwidth*2, p->height-maxbrushheight*2); for(y = 0; y < dirmap.height; y++) { - struct rgbcolor *dstrow = dirmap.col[y]; + guchar *dstrow = &dirmap.col[y*dirmap.width*3]; double tmpy = y / (double)dirmap.height; for(x = 0; x < dirmap.width; x++) { - dstrow[x].r = pixval(90-getdir(x / (double)dirmap.width, tmpy, 1)); + dstrow[x*3] = pixval(90-getdir(x / (double)dirmap.width, tmpy, 1)); } } edgepad(&dirmap, maxbrushwidth, maxbrushwidth, maxbrushheight, maxbrushheight); @@ -502,27 +506,27 @@ void repaint(struct ppm *p, struct ppm *a) if(runningvals.sizetype == 0) { /* Value */ newppm(&sizmap, p->width, p->height); for(y = 0; y < sizmap.height; y++) { - struct rgbcolor *dstrow = sizmap.col[y]; - struct rgbcolor *srcrow = p->col[y]; + guchar *dstrow = &sizmap.col[y*sizmap.width*3]; + guchar *srcrow = &p->col[y*p->width*3]; for(x = 0; x < sizmap.width; x++) { - dstrow[x].r = (srcrow[x].r + srcrow[x].g + srcrow[x].b) / 3; + dstrow[x*3] = (srcrow[x*3] + srcrow[x*3+1] + srcrow[x*3+2]) / 3; } } } else if(runningvals.sizetype == 1) { /* Radius */ newppm(&sizmap, p->width, p->height); for(y = 0; y < sizmap.height; y++) { - struct rgbcolor *dstrow = sizmap.col[y]; + guchar *dstrow = &sizmap.col[y*sizmap.width*3]; double ysqr = (cy-y)*(cy-y); for(x = 0; x < sizmap.width; x++) { - dstrow[x].r = sqrt((cx-x)*(cx-x)+ysqr) * 255 / maxdist; + dstrow[x*3] = sqrt((cx-x)*(cx-x)+ysqr) * 255 / maxdist; } } } else if(runningvals.sizetype == 3) { /* Radial */ newppm(&sizmap, p->width, p->height); for(y = 0; y < sizmap.height; y++) { - struct rgbcolor *dstrow = sizmap.col[y]; + guchar *dstrow = &sizmap.col[y*sizmap.width*3]; for(x = 0; x < sizmap.width; x++) { - dstrow[x].r = (M_PI + atan2(cy-y, cx-x)) * 255.0 / (M_PI*2); + dstrow[x*3] = (M_PI + atan2(cy-y, cx-x)) * 255.0 / (M_PI*2); } } } else if(runningvals.sizetype == 4) { /* Flowing */ @@ -537,24 +541,24 @@ void repaint(struct ppm *p, struct ppm *a) } else if(runningvals.sizetype == 5) { /* Hue */ newppm(&sizmap, p->width, p->height); for(y = 0; y < sizmap.height; y++) { - struct rgbcolor *dstrow = sizmap.col[y]; - struct rgbcolor *srcrow = p->col[y]; + guchar *dstrow = &sizmap.col[y*sizmap.width*3]; + guchar *srcrow = &p->col[y*p->width*3]; for(x = 0; x < sizmap.width; x++) { - dstrow[x].r = gethue(&srcrow[x]); + dstrow[x*3] = gethue(&srcrow[x*3]); } } } else if(runningvals.sizetype == 6) { - struct rgbcolor tmpcol = {0,0,0}; + guchar tmpcol[3] = {0,0,0}; newppm(&sizmap, p->width, p->height); - fill(&sizmap, &tmpcol); + fill(&sizmap, tmpcol); } else if(runningvals.sizetype == 7) { /* Manual */ newppm(&sizmap, p->width-maxbrushwidth*2, p->height-maxbrushheight*2); for(y = 0; y < sizmap.height; y++) { - struct rgbcolor *dstrow = sizmap.col[y]; + guchar *dstrow = &sizmap.col[y*sizmap.width*3]; double tmpy = y / (double)sizmap.height; for(x = 0; x < sizmap.width; x++) { - dstrow[x].r = 255 * (1.0 - getsiz(x / (double)sizmap.width, tmpy, 1)); + dstrow[x*3] = 255 * (1.0 - getsiz(x / (double)sizmap.width, tmpy, 1)); } } edgepad(&sizmap, maxbrushwidth, maxbrushwidth, maxbrushheight, maxbrushheight); @@ -639,7 +643,7 @@ void repaint(struct ppm *p, struct ppm *a) } if(img_has_alpha) { - if(a->col[ty][tx].r > 128) + if(a->col[ty*a->width*3+tx*3] > 128) continue; } @@ -655,7 +659,7 @@ void repaint(struct ppm *p, struct ppm *a) case 4: /* Flowing */ case 5: /* Hue */ case 7: /* Manual */ - on = runningvals.orientnum * dirmap.col[ty][tx].r / 255; + on = runningvals.orientnum * dirmap.col[ty*dirmap.width*3+tx*3] / 255; break; case 6: /* Adaptive */ break; /* Handled below */ @@ -675,7 +679,7 @@ void repaint(struct ppm *p, struct ppm *a) case 4: /* Flowing */ case 5: /* Hue */ case 7: /* Manual */ - sn = runningvals.sizenum * sizmap.col[ty][tx].r / 255; + sn = runningvals.sizenum * sizmap.col[ty*sizmap.width*3+tx*3] / 255; break; case 6: /* Adaptive */ break; /* Handled below */ @@ -715,14 +719,15 @@ void repaint(struct ppm *p, struct ppm *a) /* Calculate color - avg. of in-brush pixels */ r = g = b = 0; for(y = 0; y < brush->height; y++) { - struct rgbcolor *row = p->col[ty+y]; + guchar *row = &p->col[(ty+y)*p->width*3]; for(x = 0; x < brush->width; x++) { + int k = (tx+x) * 3; double v; - if((h = brush->col[y][x].r)) { + if((h = brush->col[y*brush->width*3+x*3])) { v = h / 255.0; - r += row[tx+x].r * v; - g += row[tx+x].g * v; - b += row[tx+x].b * v; + r += row[k+0] * v; + g += row[k+1] * v; + b += row[k+2] * v; } } } @@ -808,23 +813,24 @@ void repaint(struct ppm *p, struct ppm *a) double h, v; int px = x % tmp.width, py; for(y = 0; y < p->height; y++) { + int k = y * tmp.width * 3 + x * 3; py = y % tmp.height; if(runningvals.paperoverlay) - h = (tmp.col[py][px].r-128) * relief; + h = (tmp.col[py*tmp.width*3+px*3]-128) * relief; else - h = (tmp.col[py][px].r - (int)tmp.col[(py+1)%tmp.height][(px+1)%tmp.width].r) / -2.0 * relief; + h = (tmp.col[py*tmp.width*3+px*3] - (int)tmp.col[((py+1)%tmp.height)*tmp.width*3+((px+1)%tmp.width)*3]) / -2.0 * relief; if(h <= 0.0) { v = 1.0 + h/128.0; if(v < 0.0) v = 0.0; else if(v > 1.0) v = 1.0; - p->col[y][x].r *= v; - p->col[y][x].g *= v; - p->col[y][x].b *= v; + p->col[k+0] *= v; + p->col[k+1] *= v; + p->col[k+2] *= v; } else { v = h/128.0; if(v < 0.0) v = 0.0; else if(v > 1.0) v = 1.0; - p->col[y][x].r = p->col[y][x].r * (1.0-v) + 255 * v; - p->col[y][x].g = p->col[y][x].g * (1.0-v) + 255 * v; - p->col[y][x].b = p->col[y][x].b * (1.0-v) + 255 * v; + p->col[k+0] = p->col[k+0] * (1.0-v) + 255 * v; + p->col[k+1] = p->col[k+1] * (1.0-v) + 255 * v; + p->col[k+2] = p->col[k+2] * (1.0-v) + 255 * v; } } } diff --git a/plug-ins/gimpressionist/sizemap.c b/plug-ins/gimpressionist/sizemap.c index 74fa8b7842..15804bd795 100644 --- a/plug-ins/gimpressionist/sizemap.c +++ b/plug-ins/gimpressionist/sizemap.c @@ -92,26 +92,25 @@ void updatesmpreviewprev(void) { int x, y; static struct ppm nsbuffer = {0,0,NULL}; - struct rgbcolor black = {0,0,0}; - struct rgbcolor gray = {120,120,120}; + guchar black[3] = {0,0,0}; + guchar gray[3] = {120,120,120}; if(!nsbuffer.col) { newppm(&nsbuffer,OMWIDTH,OMHEIGHT); } - fill(&nsbuffer, &black); + fill(&nsbuffer, black); for(y = 6; y < OMHEIGHT-4; y += 10) for(x = 6; x < OMWIDTH-4; x += 10) { double siz = 5 * getsiz(x/(double)OMWIDTH,y/(double)OMHEIGHT,0); - drawline(&nsbuffer, x-siz, y-siz, x+siz, y-siz, &gray); - drawline(&nsbuffer, x+siz, y-siz, x+siz, y+siz, &gray); - drawline(&nsbuffer, x+siz, y+siz, x-siz, y+siz, &gray); - drawline(&nsbuffer, x-siz, y+siz, x-siz, y-siz, &gray); + drawline(&nsbuffer, x-siz, y-siz, x+siz, y-siz, gray); + drawline(&nsbuffer, x+siz, y-siz, x+siz, y+siz, gray); + drawline(&nsbuffer, x+siz, y+siz, x-siz, y+siz, gray); + drawline(&nsbuffer, x-siz, y+siz, x-siz, y-siz, gray); } for(y = 0; y < OMHEIGHT; y++) - gtk_preview_draw_row(GTK_PREVIEW(smpreviewprev), (guchar *)nsbuffer.col[y], - 0, y, OMWIDTH); + gtk_preview_draw_row(GTK_PREVIEW(smpreviewprev), &nsbuffer.col[y*nsbuffer.width*3], 0, y, OMWIDTH); gtk_widget_draw(smpreviewprev,NULL); } @@ -125,9 +124,9 @@ void updatesmvectorprev(void) int i, x, y; double val; static double lastval = 0.0; - struct rgbcolor gray = {120,120,120}; - struct rgbcolor red = {255,0,0}; - struct rgbcolor white = {255,255,255}; + guchar gray[3] = {120,120,120}; + guchar red[3] = {255,0,0}; + guchar white[3] = {255,255,255}; if(smvectprevbrightadjust) val = 1.0 - GTK_ADJUSTMENT(smvectprevbrightadjust)->value / 100.0; else val = 0.5; @@ -147,17 +146,17 @@ void updatesmvectorprev(void) x = smvector[i].x * OMWIDTH; y = smvector[i].y * OMHEIGHT; if(i == selectedsmvector) { - drawline(&sbuffer, x-5, y, x+5, y, &red); - drawline(&sbuffer, x, y-5, x, y+5, &red); + drawline(&sbuffer, x-5, y, x+5, y, red); + drawline(&sbuffer, x, y-5, x, y+5, red); } else { - drawline(&sbuffer, x-5, y, x+5, y, &gray); - drawline(&sbuffer, x, y-5, x, y+5, &gray); + drawline(&sbuffer, x-5, y, x+5, y, gray); + drawline(&sbuffer, x, y-5, x, y+5, gray); } - putrgb(&sbuffer, x, y, &white); + putrgb(&sbuffer, x, y, white); } for(y = 0; y < OMHEIGHT; y++) - gtk_preview_draw_row(GTK_PREVIEW(smvectorprev), (guchar *)sbuffer.col[y], 0, y, OMWIDTH); + gtk_preview_draw_row(GTK_PREVIEW(smvectorprev), &sbuffer.col[y*sbuffer.width*3], 0, y, OMWIDTH); gtk_widget_draw(smvectorprev,NULL); } @@ -533,39 +532,6 @@ void create_sizemap_dialog(void) (GtkSignalFunc)smstrexpsmadjmove, NULL); gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), tmpw, "Voronoi-mode makes only the smvector closest to the given point have any influence", NULL); - -#ifdef DEBUG - tmpw = hbox = gtk_hbox_new(TRUE,0); - gtk_table_attach_defaults(GTK_TABLE(table1), tmpw, 1,2,3,4); - gtk_container_border_width (GTK_CONTAINER (tmpw), 2); - gtk_widget_show(tmpw); - - tmpw = gtk_button_new_with_label("Save"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(saveclick), NULL); - - tmpw = gtk_button_new_with_label("Load"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(loadclick), NULL); - - tmpw = gtk_button_new_with_label("Show pix"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(showpixclick), NULL); - - tmpw = gtk_button_new_with_label("dumpvect"); - gtk_box_pack_start(GTK_BOX(hbox), tmpw, FALSE, TRUE, 0); - gtk_widget_show(tmpw); - gtk_signal_connect (GTK_OBJECT(tmpw), "clicked", - GTK_SIGNAL_FUNC(dumpvect), NULL); -#endif - - gtk_widget_show(smwindow); updatesmvectorprev();