app/gimpbrushhose.c removed. app/gimpbrushpipe.c New files to replace the

Mon Aug 23 00:56:59 EDT 1999 Adrian Likins <alikins@redhat.com>

        * app/gimpbrushhose.c
        * app/gimpbrushhose.h:
                removed.
        * app/gimpbrushpipe.c
        * app/gimpbrushpipe.h:
                New files to replace the above
        * app/gimpbrushlist.c
        * app/paintbrush.c
        * app/pixmapbrush.c
        * app/Makefile.am:
                s/hose/pipe. Seems someone else uses that name,
        so change it to pipe.

        * app/gimpbrush.c
        * app/gimpbrush.h
        * app/gimpbrushpixmap.c
        * app/patterns.c
        * app/patterns.h
        * app/pixmapbrush.c:
                Added functions to do the actual loading of
        brush/pattern data. Use them where approriate instead
        of cut&pasting the same code all over the place.

        * app/pixmapbrush.c: Fix the bug where masks and brush
        data werent aligned. I didnt quite notice that
        paint_core_get_paint_area returns an area with a 1 pixel
        border larger than the brush. Ooops.

        * TODO: just update a few things while I'm at it
        (pixmap/pipe stuff in particular)
This commit is contained in:
EDT 1999 Adrian Likins 1999-08-23 06:06:12 +00:00 committed by Adrian Likins
parent 3f00c01bd5
commit 5c61305f24
20 changed files with 809 additions and 292 deletions

View file

@ -1,3 +1,36 @@
Mon Aug 23 00:56:59 EDT 1999 Adrian Likins <alikins@redhat.com>
* app/gimpbrushhose.c
* app/gimpbrushhose.h:
removed.
* app/gimpbrushpipe.c
* app/gimpbrushpipe.h:
New files to replace the above
* app/gimpbrushlist.c
* app/paintbrush.c
* app/pixmapbrush.c
* app/Makefile.am:
s/hose/pipe. Seems someone else uses that name,
so change it to pipe.
* app/gimpbrush.c
* app/gimpbrush.h
* app/gimpbrushpixmap.c
* app/patterns.c
* app/patterns.h
* app/pixmapbrush.c:
Added functions to do the actual loading of
brush/pattern dialog. Use them where approriate instead
of c&p the same code all over the place.
* app/pixmapbrush.c: Fix the bug where masks and brush
data werent aligned. I didnt quite notice that
paint_core_get_paint_area returns an area with a 1 pixel
border larger than the brush. Ooops.
* TODO: just update a few things while I'm at it
(pixmap/pipe stuff in particular)
Sun Aug 22 15:49:10 PDT 1999 Manish Singh <yosh@gimp.org>
* configure.in: add check for zlib for building psp plugin

32
TODO
View file

@ -8,6 +8,20 @@ Add Unsharp Mask to the distribution. The filter is just way too basic
to leave out.
For the pixmap/hose stuff:
a loader/saver plugin for the hose types
(tml has a gpb saver, and a .tub loader...getting close)
add a "pipe edit" option to the brush dialog so we can
call up a hose editor (to reorder images, scale them, etc)
"selection to brush" and as part of that, some general
TileManager->TempBuf functions.
Load pipes as xcf maybe? would need above functiosn first
A few GUI things suggestions...
1) Crop tool could have an optional shader for the outside area
@ -181,6 +195,8 @@ drag & drop for layers:
raise by one, and lower by one. It would be much nicer to be
able to click & drag a layer to its new spot in the stack.
Done, by Michael Natterer 8/22/99
Handle Out of Space Better!
Also should handle out-of-space on swap device better.
@ -242,7 +258,7 @@ active brushes:
Maybe really want to define new tool types, rather than new brush
types.
pixmap brushes:
*pixmap brushes:
Should be simple. maybe need a new format that would include
data/mask (probabaly just use a xcf). Once its loaded in as a
@ -250,12 +266,16 @@ pixmap brushes:
it. Should it be a new tool? jsut a new brush type for old
paint to ls?
Quickmask/paintable selections:
Just about done: Adrian Likins 8/23/99
*Quickmask/paintable selections:
Any ideas on the best way to do the ui? The fundamentals of
beng able to do this are already there. Just need a good way to
present it.
Done: Seth Burgess
let pdb stuff register under the layers_dialog menu:
Lots of potential in scripts to do layer/channel manip. Might
@ -405,3 +425,11 @@ Grid
intersection.
(this was suggested to me by email -- Sven)
"font" brush?
a brush that could use chars rendered from fonts as the brush
bitmap. limited utility for char's, but a couple of nice sets
of winding fonts could make it interestings. And you could
use words or strings.

View file

@ -185,8 +185,8 @@ gimp_SOURCES = \
gimpbrush.h \
gimpbrushgenerated.c \
gimpbrushgenerated.h \
gimpbrushhose.c \
gimpbrushhose.h \
gimpbrushpipe.c \
gimpbrushpipe.h \
gimpbrushpixmap.c \
gimpbrushpixmap.h \
gimpbrushlist.c \

View file

@ -165,11 +165,6 @@ void
gimp_brush_load(GimpBrush *brush, char *filename)
{
FILE * fp;
int bn_size;
unsigned char buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
brush->filename = g_strdup (filename);
@ -180,12 +175,32 @@ gimp_brush_load(GimpBrush *brush, char *filename)
return;
}
gimp_brush_load_brush(brush,fp,filename);
/* Clean up */
fclose (fp);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (brush->mask);
}
int
gimp_brush_load_brush(GimpBrush *brush, FILE* fp, char* filename)
{
int bn_size;
unsigned char buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
/* Read in the header size */
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
{
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
/* rearrange the bytes in each unsigned int */
@ -197,25 +212,26 @@ gimp_brush_load(GimpBrush *brush, char *filename)
/* Check for correct file format */
if (header.magic_number != GBRUSH_MAGIC)
{
/* One thing that can save this error is if the brush is version 1 */
if (header.version != 1)
{
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
}
if (header.version == 1)
{
/* If this is a version 1 brush, set the fp back 8 bytes */
fseek (fp, -8, SEEK_CUR);
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
}
{
/* If this is a version 1 brush, set the fp back 8 bytes */
fseek (fp, -8, SEEK_CUR);
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
}
/* Read in the brush name */
/* Read in the brush name */
if ((bn_size = (header.header_size - sz_BrushHeader)))
{
brush->name = (char *) g_malloc (sizeof (char) * bn_size);
@ -224,7 +240,7 @@ gimp_brush_load(GimpBrush *brush, char *filename)
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
}
else
@ -253,20 +269,8 @@ gimp_brush_load(GimpBrush *brush, char *filename)
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
/* Clean up */
fclose (fp);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (brush->mask);
/* Check if the current brush is the default one */
/* lets see if it works with out this for now */
/* if (strcmp(default_brush, g_basename(filename)) == 0) {
active_brush = brush;
have_default_brush = 1;
}*/ /* if */
return 1;
}

View file

@ -165,11 +165,6 @@ void
gimp_brush_load(GimpBrush *brush, char *filename)
{
FILE * fp;
int bn_size;
unsigned char buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
brush->filename = g_strdup (filename);
@ -180,12 +175,32 @@ gimp_brush_load(GimpBrush *brush, char *filename)
return;
}
gimp_brush_load_brush(brush,fp,filename);
/* Clean up */
fclose (fp);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (brush->mask);
}
int
gimp_brush_load_brush(GimpBrush *brush, FILE* fp, char* filename)
{
int bn_size;
unsigned char buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
/* Read in the header size */
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
{
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
/* rearrange the bytes in each unsigned int */
@ -197,25 +212,26 @@ gimp_brush_load(GimpBrush *brush, char *filename)
/* Check for correct file format */
if (header.magic_number != GBRUSH_MAGIC)
{
/* One thing that can save this error is if the brush is version 1 */
if (header.version != 1)
{
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
}
if (header.version == 1)
{
/* If this is a version 1 brush, set the fp back 8 bytes */
fseek (fp, -8, SEEK_CUR);
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
}
{
/* If this is a version 1 brush, set the fp back 8 bytes */
fseek (fp, -8, SEEK_CUR);
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
}
/* Read in the brush name */
/* Read in the brush name */
if ((bn_size = (header.header_size - sz_BrushHeader)))
{
brush->name = (char *) g_malloc (sizeof (char) * bn_size);
@ -224,7 +240,7 @@ gimp_brush_load(GimpBrush *brush, char *filename)
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
}
else
@ -253,20 +269,8 @@ gimp_brush_load(GimpBrush *brush, char *filename)
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
/* Clean up */
fclose (fp);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (brush->mask);
/* Check if the current brush is the default one */
/* lets see if it works with out this for now */
/* if (strcmp(default_brush, g_basename(filename)) == 0) {
active_brush = brush;
have_default_brush = 1;
}*/ /* if */
return 1;
}

View file

@ -19,6 +19,7 @@
#ifndef __GIMPBRUSH_H__
#define __GIMPBRUSH_H__
#include <stdio.h>
#include "gimpobjectP.h"
#include "temp_buf.h"
#include "vector2d.h"
@ -51,6 +52,7 @@ typedef struct _GimpBrushClass GimpBrushClass;
GimpBrush * gimp_brush_new (char *filename);
void gimp_brush_load (GimpBrush *brush, char *filename);
int gimp_brush_load_brush (GimpBrush *brush, FILE* fp, char* filename);
GtkType gimp_brush_get_type (void);
TempBuf * gimp_brush_get_mask (GimpBrush *brush);
char * gimp_brush_get_name (GimpBrush *brush);

View file

@ -0,0 +1,150 @@
#include "config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "appenv.h"
#include "brush_header.h"
#include "pattern_header.h"
#include "patterns.h"
#include "gimpbrush.h"
#include "gimpbrushpixmap.h"
#include "gimpbrushlist.h"
#include "paint_core.h"
#include "gimprc.h"
#include "gimpbrushpipe.h"
#include "libgimp/gimpintl.h"
static void
gimp_brush_pipe_generate(GimpBrushPipe *brush);
static GimpObjectClass* parent_class;
static void
gimp_brush_pipe_destroy(GtkObject *object)
{
GTK_OBJECT_CLASS(parent_class)->destroy (object);
}
static void
gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS(klass);
parent_class = gtk_type_class (GIMP_TYPE_BRUSH_PIXMAP);
object_class->destroy = gimp_brush_pipe_destroy;
}
void
gimp_brush_pipe_init(GimpBrushPipe *brush)
{
brush->name = NULL;
brush->filename = NULL;
brush->brush_list = gimp_brush_list_new();
}
GtkType gimp_brush_pipe_get_type(void)
{
static GtkType type=0;
if(!type){
GtkTypeInfo info={
"GimpBrushPipe",
sizeof(GimpBrushPipe),
sizeof(GimpBrushPipeClass),
(GtkClassInitFunc)gimp_brush_pipe_class_init,
(GtkObjectInitFunc)gimp_brush_pipe_init,
/* reserved_1 */ NULL,
/* reserver_2 */ NULL,
(GtkClassInitFunc) NULL};
type=gtk_type_unique(GIMP_TYPE_BRUSH_PIXMAP, &info);
}
return type;
}
GimpBrushPipe *
gimp_brush_pipe_load (char *file_name)
{
GimpBrushPipe *pipe;
GimpBrushPixmap *brush;
GimpBrushList *list;
GPatternP pattern;
FILE *fp;
gchar buf2[1024];
int num_of_brushes;
int brush_count=0;
pipe = GIMP_BRUSH_PIPE(gimp_type_new(gimp_brush_pipe_get_type()));
GIMP_BRUSH_PIPE(pipe)->filename = g_strdup(file_name);
pattern = (GPatternP) g_malloc (sizeof (GPattern));
pattern->filename = g_strdup (file_name);
pattern->name = NULL;
pattern->mask = NULL;
brush = GIMP_BRUSH_PIXMAP (pipe);
list = gimp_brush_list_new();
if ((fp = fopen(file_name, "rb")) == NULL)
return NULL;
/* the file format starts with a painfully simple text header
and we use a painfully simple way to read it */
if(fgets (buf2, 1024, fp) == NULL)
return NULL;
buf2[strlen(buf2) - 1] = '\0';
pipe->name = g_strdup(buf2);
/* get the number of brushes */
if(fgets (buf2, 1024, fp) == NULL)
return NULL;
num_of_brushes = strtol(buf2,NULL,10);
while(brush_count < num_of_brushes)
{
if (brush_count > 0)
brush = GIMP_BRUSH_PIXMAP(gimp_type_new(gimp_brush_pixmap_get_type()));
GIMP_BRUSH(brush)->filename = g_strdup(file_name);
/* load the brush */
if(!gimp_brush_load_brush(GIMP_BRUSH(brush),fp,file_name))
{
g_message (_("failed to load a brush mask in the pipe"));
return NULL;
}
/* load the pattern data*/
if(!load_pattern_pattern(pattern, fp, file_name))
{
g_message (_("failed to load a section of pixmap mask in the pipe"));
return NULL;
}
brush->pixmap_mask = pattern->mask;
gimp_brush_list_add(list,GIMP_BRUSH(brush));
brush_count++;
}
fclose (fp);
if (!GIMP_IS_BRUSH_PIPE(pipe))
g_print ("Is not BRUSH_PIPE???\n");
pipe->brush_list = list;
return pipe;
}

150
app/core/gimpbrushpipe.c Normal file
View file

@ -0,0 +1,150 @@
#include "config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "appenv.h"
#include "brush_header.h"
#include "pattern_header.h"
#include "patterns.h"
#include "gimpbrush.h"
#include "gimpbrushpixmap.h"
#include "gimpbrushlist.h"
#include "paint_core.h"
#include "gimprc.h"
#include "gimpbrushpipe.h"
#include "libgimp/gimpintl.h"
static void
gimp_brush_pipe_generate(GimpBrushPipe *brush);
static GimpObjectClass* parent_class;
static void
gimp_brush_pipe_destroy(GtkObject *object)
{
GTK_OBJECT_CLASS(parent_class)->destroy (object);
}
static void
gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS(klass);
parent_class = gtk_type_class (GIMP_TYPE_BRUSH_PIXMAP);
object_class->destroy = gimp_brush_pipe_destroy;
}
void
gimp_brush_pipe_init(GimpBrushPipe *brush)
{
brush->name = NULL;
brush->filename = NULL;
brush->brush_list = gimp_brush_list_new();
}
GtkType gimp_brush_pipe_get_type(void)
{
static GtkType type=0;
if(!type){
GtkTypeInfo info={
"GimpBrushPipe",
sizeof(GimpBrushPipe),
sizeof(GimpBrushPipeClass),
(GtkClassInitFunc)gimp_brush_pipe_class_init,
(GtkObjectInitFunc)gimp_brush_pipe_init,
/* reserved_1 */ NULL,
/* reserver_2 */ NULL,
(GtkClassInitFunc) NULL};
type=gtk_type_unique(GIMP_TYPE_BRUSH_PIXMAP, &info);
}
return type;
}
GimpBrushPipe *
gimp_brush_pipe_load (char *file_name)
{
GimpBrushPipe *pipe;
GimpBrushPixmap *brush;
GimpBrushList *list;
GPatternP pattern;
FILE *fp;
gchar buf2[1024];
int num_of_brushes;
int brush_count=0;
pipe = GIMP_BRUSH_PIPE(gimp_type_new(gimp_brush_pipe_get_type()));
GIMP_BRUSH_PIPE(pipe)->filename = g_strdup(file_name);
pattern = (GPatternP) g_malloc (sizeof (GPattern));
pattern->filename = g_strdup (file_name);
pattern->name = NULL;
pattern->mask = NULL;
brush = GIMP_BRUSH_PIXMAP (pipe);
list = gimp_brush_list_new();
if ((fp = fopen(file_name, "rb")) == NULL)
return NULL;
/* the file format starts with a painfully simple text header
and we use a painfully simple way to read it */
if(fgets (buf2, 1024, fp) == NULL)
return NULL;
buf2[strlen(buf2) - 1] = '\0';
pipe->name = g_strdup(buf2);
/* get the number of brushes */
if(fgets (buf2, 1024, fp) == NULL)
return NULL;
num_of_brushes = strtol(buf2,NULL,10);
while(brush_count < num_of_brushes)
{
if (brush_count > 0)
brush = GIMP_BRUSH_PIXMAP(gimp_type_new(gimp_brush_pixmap_get_type()));
GIMP_BRUSH(brush)->filename = g_strdup(file_name);
/* load the brush */
if(!gimp_brush_load_brush(GIMP_BRUSH(brush),fp,file_name))
{
g_message (_("failed to load a brush mask in the pipe"));
return NULL;
}
/* load the pattern data*/
if(!load_pattern_pattern(pattern, fp, file_name))
{
g_message (_("failed to load a section of pixmap mask in the pipe"));
return NULL;
}
brush->pixmap_mask = pattern->mask;
gimp_brush_list_add(list,GIMP_BRUSH(brush));
brush_count++;
}
fclose (fp);
if (!GIMP_IS_BRUSH_PIPE(pipe))
g_print ("Is not BRUSH_PIPE???\n");
pipe->brush_list = list;
return pipe;
}

37
app/core/gimpbrushpipe.h Normal file
View file

@ -0,0 +1,37 @@
#ifndef __GIMP_BRUSH_PIPE_H__
#define __GIMP_BRUSH_PIPE_H__
#include "gimpbrush.h"
#include "gimpbrushpixmap.h"
#include "gimpbrush.h"
#include "gimpbrushlist.h"
#include "gimpbrushlistP.h"
typedef struct _GimpBrushPipe
{
GimpBrushPixmap pixmap_brush;
GimpBrushList *brush_list;
char * name;
char * filename;
} GimpBrushPipe;
typedef struct _GimpBrushPipeClass
{
GimpBrushPixmapClass parent_class;
void (* generate) (GimpBrushPipe *brush);
} GimpBrushPipeClass;
/* object stuff */
#define GIMP_TYPE_BRUSH_PIPE (gimp_brush_pipe_get_type ())
#define GIMP_BRUSH_PIPE(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipe))
#define GIMP_IS_BRUSH_PIPE(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIPE))
GtkType gimp_brush_pipe_get_type (void);
GimpBrushPipe * gimp_brush_pipe_new (char *file_name);
GimpBrushPipe * gimp_brush_pipe_load (char *file_name);
#endif /* __GIMPBRUSHPIPE_H__ */

View file

@ -165,11 +165,6 @@ void
gimp_brush_load(GimpBrush *brush, char *filename)
{
FILE * fp;
int bn_size;
unsigned char buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
brush->filename = g_strdup (filename);
@ -180,12 +175,32 @@ gimp_brush_load(GimpBrush *brush, char *filename)
return;
}
gimp_brush_load_brush(brush,fp,filename);
/* Clean up */
fclose (fp);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (brush->mask);
}
int
gimp_brush_load_brush(GimpBrush *brush, FILE* fp, char* filename)
{
int bn_size;
unsigned char buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
/* Read in the header size */
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
{
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
/* rearrange the bytes in each unsigned int */
@ -197,25 +212,26 @@ gimp_brush_load(GimpBrush *brush, char *filename)
/* Check for correct file format */
if (header.magic_number != GBRUSH_MAGIC)
{
/* One thing that can save this error is if the brush is version 1 */
if (header.version != 1)
{
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
}
if (header.version == 1)
{
/* If this is a version 1 brush, set the fp back 8 bytes */
fseek (fp, -8, SEEK_CUR);
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
}
{
/* If this is a version 1 brush, set the fp back 8 bytes */
fseek (fp, -8, SEEK_CUR);
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
}
/* Read in the brush name */
/* Read in the brush name */
if ((bn_size = (header.header_size - sz_BrushHeader)))
{
brush->name = (char *) g_malloc (sizeof (char) * bn_size);
@ -224,7 +240,7 @@ gimp_brush_load(GimpBrush *brush, char *filename)
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
}
else
@ -253,20 +269,8 @@ gimp_brush_load(GimpBrush *brush, char *filename)
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return;
return 0;
}
/* Clean up */
fclose (fp);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (brush->mask);
/* Check if the current brush is the default one */
/* lets see if it works with out this for now */
/* if (strcmp(default_brush, g_basename(filename)) == 0) {
active_brush = brush;
have_default_brush = 1;
}*/ /* if */
return 1;
}

View file

@ -19,6 +19,7 @@
#ifndef __GIMPBRUSH_H__
#define __GIMPBRUSH_H__
#include <stdio.h>
#include "gimpobjectP.h"
#include "temp_buf.h"
#include "vector2d.h"
@ -51,6 +52,7 @@ typedef struct _GimpBrushClass GimpBrushClass;
GimpBrush * gimp_brush_new (char *filename);
void gimp_brush_load (GimpBrush *brush, char *filename);
int gimp_brush_load_brush (GimpBrush *brush, FILE* fp, char* filename);
GtkType gimp_brush_get_type (void);
TempBuf * gimp_brush_get_mask (GimpBrush *brush);
char * gimp_brush_get_name (GimpBrush *brush);

View file

@ -34,7 +34,7 @@
#include "appenv.h"
#include "gimpbrushpixmap.h"
#include "gimpbrushgenerated.h"
#include "gimpbrushhose.h"
#include "gimpbrushpipe.h"
#include "brush_header.h"
#include "brush_select.h"
#include "colormaps.h"
@ -182,12 +182,12 @@ brush_load(char *filename)
}
else if (strcmp(&filename[strlen(filename) - 4], ".gih") == 0)
{
GimpBrushHose *brush;
brush = gimp_brush_hose_load(filename);
GimpBrushPipe *brush;
brush = gimp_brush_pipe_load(filename);
if (brush != NULL)
gimp_brush_list_add(brush_list, GIMP_BRUSH(brush));
else
g_message("Warning: failed to load brush \"%s\"", filename);
g_message("Warning: failed to load pipe \"%s\"", filename);
}
}

150
app/gimpbrushpipe.c Normal file
View file

@ -0,0 +1,150 @@
#include "config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "appenv.h"
#include "brush_header.h"
#include "pattern_header.h"
#include "patterns.h"
#include "gimpbrush.h"
#include "gimpbrushpixmap.h"
#include "gimpbrushlist.h"
#include "paint_core.h"
#include "gimprc.h"
#include "gimpbrushpipe.h"
#include "libgimp/gimpintl.h"
static void
gimp_brush_pipe_generate(GimpBrushPipe *brush);
static GimpObjectClass* parent_class;
static void
gimp_brush_pipe_destroy(GtkObject *object)
{
GTK_OBJECT_CLASS(parent_class)->destroy (object);
}
static void
gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS(klass);
parent_class = gtk_type_class (GIMP_TYPE_BRUSH_PIXMAP);
object_class->destroy = gimp_brush_pipe_destroy;
}
void
gimp_brush_pipe_init(GimpBrushPipe *brush)
{
brush->name = NULL;
brush->filename = NULL;
brush->brush_list = gimp_brush_list_new();
}
GtkType gimp_brush_pipe_get_type(void)
{
static GtkType type=0;
if(!type){
GtkTypeInfo info={
"GimpBrushPipe",
sizeof(GimpBrushPipe),
sizeof(GimpBrushPipeClass),
(GtkClassInitFunc)gimp_brush_pipe_class_init,
(GtkObjectInitFunc)gimp_brush_pipe_init,
/* reserved_1 */ NULL,
/* reserver_2 */ NULL,
(GtkClassInitFunc) NULL};
type=gtk_type_unique(GIMP_TYPE_BRUSH_PIXMAP, &info);
}
return type;
}
GimpBrushPipe *
gimp_brush_pipe_load (char *file_name)
{
GimpBrushPipe *pipe;
GimpBrushPixmap *brush;
GimpBrushList *list;
GPatternP pattern;
FILE *fp;
gchar buf2[1024];
int num_of_brushes;
int brush_count=0;
pipe = GIMP_BRUSH_PIPE(gimp_type_new(gimp_brush_pipe_get_type()));
GIMP_BRUSH_PIPE(pipe)->filename = g_strdup(file_name);
pattern = (GPatternP) g_malloc (sizeof (GPattern));
pattern->filename = g_strdup (file_name);
pattern->name = NULL;
pattern->mask = NULL;
brush = GIMP_BRUSH_PIXMAP (pipe);
list = gimp_brush_list_new();
if ((fp = fopen(file_name, "rb")) == NULL)
return NULL;
/* the file format starts with a painfully simple text header
and we use a painfully simple way to read it */
if(fgets (buf2, 1024, fp) == NULL)
return NULL;
buf2[strlen(buf2) - 1] = '\0';
pipe->name = g_strdup(buf2);
/* get the number of brushes */
if(fgets (buf2, 1024, fp) == NULL)
return NULL;
num_of_brushes = strtol(buf2,NULL,10);
while(brush_count < num_of_brushes)
{
if (brush_count > 0)
brush = GIMP_BRUSH_PIXMAP(gimp_type_new(gimp_brush_pixmap_get_type()));
GIMP_BRUSH(brush)->filename = g_strdup(file_name);
/* load the brush */
if(!gimp_brush_load_brush(GIMP_BRUSH(brush),fp,file_name))
{
g_message (_("failed to load a brush mask in the pipe"));
return NULL;
}
/* load the pattern data*/
if(!load_pattern_pattern(pattern, fp, file_name))
{
g_message (_("failed to load a section of pixmap mask in the pipe"));
return NULL;
}
brush->pixmap_mask = pattern->mask;
gimp_brush_list_add(list,GIMP_BRUSH(brush));
brush_count++;
}
fclose (fp);
if (!GIMP_IS_BRUSH_PIPE(pipe))
g_print ("Is not BRUSH_PIPE???\n");
pipe->brush_list = list;
return pipe;
}

37
app/gimpbrushpipe.h Normal file
View file

@ -0,0 +1,37 @@
#ifndef __GIMP_BRUSH_PIPE_H__
#define __GIMP_BRUSH_PIPE_H__
#include "gimpbrush.h"
#include "gimpbrushpixmap.h"
#include "gimpbrush.h"
#include "gimpbrushlist.h"
#include "gimpbrushlistP.h"
typedef struct _GimpBrushPipe
{
GimpBrushPixmap pixmap_brush;
GimpBrushList *brush_list;
char * name;
char * filename;
} GimpBrushPipe;
typedef struct _GimpBrushPipeClass
{
GimpBrushPixmapClass parent_class;
void (* generate) (GimpBrushPipe *brush);
} GimpBrushPipeClass;
/* object stuff */
#define GIMP_TYPE_BRUSH_PIPE (gimp_brush_pipe_get_type ())
#define GIMP_BRUSH_PIPE(obj) (GIMP_CHECK_CAST ((obj), GIMP_TYPE_BRUSH_PIPE, GimpBrushPipe))
#define GIMP_IS_BRUSH_PIPE(obj) (GIMP_CHECK_TYPE ((obj), GIMP_TYPE_BRUSH_PIPE))
GtkType gimp_brush_pipe_get_type (void);
GimpBrushPipe * gimp_brush_pipe_new (char *file_name);
GimpBrushPipe * gimp_brush_pipe_load (char *file_name);
#endif /* __GIMPBRUSHPIPE_H__ */

View file

@ -7,10 +7,12 @@
#include "appenv.h"
#include "brush_header.h"
#include "pattern_header.h"
#include "patterns.h"
#include "gimpbrush.h"
#include "gimpbrushpixmap.h"
#include "paint_core.h"
#include "gimprc.h"
#include "libgimp/gimpintl.h"
static void
gimp_brush_pixmap_generate(GimpBrushPixmap *brush);
@ -67,159 +69,43 @@ gimp_brush_pixmap_get_pixmap (GimpBrushPixmap* brush)
}
GimpBrushPixmap *
gimp_brush_pixmap_load (char *file_name)
gimp_brush_pixmap_load (char *filename)
{
GimpBrushPixmap *brush;
GPatternP pattern;
FILE *fp;
char string[256];
float fl;
float version;
unsigned char buf[sz_BrushHeader];
BrushHeader header;
int bn_size;
unsigned int * hp;
char * nothing;
int i;
brush = GIMP_BRUSH_PIXMAP(gimp_type_new(gimp_brush_pixmap_get_type()));
GIMP_BRUSH(brush)->filename = g_strdup (file_name);
GIMP_BRUSH(brush)->filename = g_strdup (filename);
if ((fp =fopen(file_name, "rb")) == NULL)
pattern = (GPatternP) g_malloc (sizeof (GPattern));
pattern->filename = g_strdup (filename);
pattern->name = NULL;
pattern->mask = NULL;
if ((fp =fopen(filename, "rb")) == NULL)
return NULL;
/* we read in the brush mask first */
/* Read in the header size */
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
if(!gimp_brush_load_brush(GIMP_BRUSH(brush),fp,filename))
{
fclose (fp);
gimp_object_destroy (brush);
g_message (_("failed to load a brush mask in the pixmap brush"));
return NULL;
}
/* rearrange the bytes in each unsigned int */
hp = (unsigned int *) &header;
for (i = 0; i < (sz_BrushHeader / 4); i++)
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
/* Check for correct file format */
if (header.magic_number != GBRUSH_MAGIC)
if(!load_pattern_pattern(pattern, fp, filename))
{
/* One thing that can save this error is if the brush is version 1 */
if (header.version != 1)
{
fclose (fp);
gimp_object_destroy (brush);
return NULL;
}
g_message (_("failed to load a section of pixmap mask in the pixmap brush"));
return NULL;
}
if (header.version == 1)
{
/* If this is a version 1 brush, set the fp back 8 bytes */
fseek (fp, -8, SEEK_CUR);
header.header_size += 8;
/* spacing is not defined in version 1 */
header.spacing = 25;
}
/* Read in the brush name */
if ((bn_size = (header.header_size - sz_BrushHeader)))
{
GIMP_BRUSH(brush)->name = (char *) g_malloc (sizeof (char) * bn_size);
if ((fread (GIMP_BRUSH(brush)->name, 1, bn_size, fp)) < bn_size)
{
g_message ("Error in GIMP brush file...aborting.");
fclose (fp);
gimp_object_destroy (brush);
return NULL;
}
}
switch(header.version)
{
case 1:
case 2:
/* Get a new brush mask */
GIMP_BRUSH(brush)->mask = temp_buf_new (header.width, header.height, header.bytes,
0, 0, NULL);
GIMP_BRUSH(brush)->spacing = header.spacing;
/* set up spacing axis */
GIMP_BRUSH(brush)->x_axis.x = header.width / 2.0;
GIMP_BRUSH(brush)->x_axis.y = 0.0;
GIMP_BRUSH(brush)->y_axis.x = 0.0;
GIMP_BRUSH(brush)->y_axis.y = header.height / 2.0;
/* Read the brush mask data */
if ((fread (temp_buf_data (GIMP_BRUSH(brush)->mask), 1, header.width * header.height,
fp)) < header.width * header.height)
g_message ("GIMP brush file appears to be truncated.");
break;
default:
g_message ("Unknown brush format version #%d in \"%s\"\n",
header.version, file_name);
fclose (fp);
gimp_object_destroy (brush);
return NULL;
}
/* PATTERN STUFF HERE */
/* Read in the header size */
if ((fread (buf, 1, sz_PatternHeader, fp)) < sz_PatternHeader)
{
fclose (fp);
return NULL;
}
hp = (unsigned int *) &header;
for (i = 0; i < (sz_PatternHeader / 4); i++)
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
brush->pixmap_mask = temp_buf_new (header.width, header.height, header.bytes, 0, 0, NULL);
/* Read in the pattern name */
if ((bn_size = (header.header_size - sz_PatternHeader)))
{
nothing = (char *) g_malloc (sizeof (char) * bn_size);
if ((fread (nothing, 1, bn_size, fp)) < bn_size)
{
g_message ("Error in GIMP pattern file...aborting.");
fclose (fp);
return NULL;
}
}
else
{
nothing = g_strdup ("Unnamed");
}
if ((fread (temp_buf_data (brush->pixmap_mask), 1,
header.width * header.height * header.bytes, fp))
< header.width * header.height * header.bytes)
g_message ("GIMP pattern file appears to be truncated.");
brush->pixmap_mask = pattern->mask;
/* Clean up */
fclose (fp);
g_free(pattern);
return brush;
}

View file

@ -23,7 +23,7 @@
#include "drawable.h"
#include "errors.h"
#include "gdisplay.h"
#include "gimpbrushhose.h"
#include "gimpbrushpipe.h"
#include "gimpbrushlist.h"
#include "gradient.h"
#include "paint_funcs.h"
@ -450,8 +450,7 @@ paintbrush_motion (PaintCore *paint_core,
color_pixels (temp_buf_data (area), col,
area->width * area->height, area->bytes);
}
paint_core_paste_canvas (paint_core, drawable, temp_blend,
(int) (gimp_context_get_opacity (NULL) * 255),
gimp_context_get_paint_mode (NULL),

View file

@ -164,11 +164,6 @@ load_pattern (gchar *filename)
{
GPatternP pattern;
FILE * fp;
gint bn_size;
guchar buf [sz_PatternHeader];
PatternHeader header;
guint * hp;
gint i;
pattern = (GPatternP) g_malloc (sizeof (GPattern));
@ -183,12 +178,45 @@ load_pattern (gchar *filename)
return;
}
if(!load_pattern_pattern(pattern, fp, filename))
{
g_message (_("Pattern load failed"));
return;
}
/* Clean up */
fclose (fp);
/*temp_buf_swap (pattern->mask);*/
pattern_list = insert_pattern_in_list (pattern_list, pattern);
/* Check if the current pattern is the default one */
if (strcmp (default_pattern, g_basename (filename)) == 0)
{
active_pattern = pattern;
have_default_pattern = 1;
}
}
int
load_pattern_pattern(GPatternP pattern, FILE* fp, gchar* filename)
{
gint bn_size;
guchar buf [sz_PatternHeader];
PatternHeader header;
guint * hp;
gint i;
/* Read in the header size */
if ((fread (buf, 1, sz_PatternHeader, fp)) < sz_PatternHeader)
{
fclose (fp);
free_pattern (pattern);
return;
return 0;
}
/* rearrange the bytes in each unsigned int */
@ -205,7 +233,7 @@ load_pattern (gchar *filename)
{
fclose (fp);
free_pattern (pattern);
return;
return 0;
}
}
/* Check for correct version */
@ -215,7 +243,7 @@ load_pattern (gchar *filename)
filename);
fclose (fp);
free_pattern (pattern);
return;
return 0;
}
/* Get a new pattern mask */
@ -231,7 +259,7 @@ load_pattern (gchar *filename)
g_message (_("Error in GIMP pattern file...aborting."));
fclose (fp);
free_pattern (pattern);
return;
return 0;
}
}
else
@ -244,20 +272,9 @@ load_pattern (gchar *filename)
header.width * header.height * header.bytes)
g_message (_("GIMP pattern file appears to be truncated."));
/* Clean up */
fclose (fp);
/* success */
return 1;
/*temp_buf_swap (pattern->mask);*/
pattern_list = insert_pattern_in_list (pattern_list, pattern);
/* Check if the current pattern is the default one */
if (strcmp (default_pattern, g_basename (filename)) == 0)
{
active_pattern = pattern;
have_default_pattern = 1;
}
}
GPatternP

View file

@ -19,6 +19,7 @@
#define __PATTERNS_H__
#include <glib.h>
#include <stdio.h>
#include "temp_buf.h"
typedef struct _GPattern GPattern, * GPatternP;
@ -43,6 +44,10 @@ GPatternP pattern_list_get_pattern (GSList *list,
void create_pattern_dialog (void);
void pattern_select_dialog_free (void);
/* this is useful for pixmap brushes etc */
int load_pattern_pattern (GPatternP pattern,
FILE* fp,
gchar* filename);
/* global variables */
extern GSList * pattern_list;

View file

@ -22,7 +22,7 @@
#include "appenv.h"
#include "gimpbrushpixmap.h"
#include "gimpbrushlist.h"
#include "gimpbrushhose.h"
#include "gimpbrushpipe.h"
#include "drawable.h"
#include "errors.h"
#include "gdisplay.h"
@ -44,7 +44,7 @@ static void pixmapbrush_motion (PaintCore *, GimpDrawable *);
/* static Argument * pixmapbrush_extended_invoker (Argument *); */
/* static Argument * pixmapbrush_extended_gradient_invoker (Argument *); */
#if 0
static void paint_line_pixmap_mask (GImage *dest,
GimpDrawable *drawable,
GimpBrushPixmap *brush,
@ -56,7 +56,8 @@ static void paint_line_pixmap_mask (GImage *dest,
int bytes,
int width);
#endif
/* defines */
#define PAINT_LEFT_THRESHOLD 0.05
@ -214,12 +215,13 @@ pixmapbrush_motion (PaintCore *paint_core,
TempBuf * area;
int opacity;
static int index = 0;
gboolean RANDOM=1;
/* We always need a destination image */
if (! (gimage = drawable_gimage (drawable)))
return;
if(!( GIMP_IS_BRUSH_HOSE(paint_core->brush)))
if(!( GIMP_IS_BRUSH_PIPE(paint_core->brush)))
{
return;
}
@ -229,8 +231,17 @@ pixmapbrush_motion (PaintCore *paint_core,
/* Set paint_core->brush, restore below before returning.
* I wonder if this is wise?
*/
paint_core->brush = gimp_brush_list_get_brush_by_index(GIMP_BRUSH_HOSE(paint_core->brush)->brush_list, index++);
if (index == gimp_brush_list_length (GIMP_BRUSH_HOSE(saved_brush)->brush_list))
if(RANDOM)
{
/* eeek, what a ugly line */
paint_core->brush =
gimp_brush_list_get_brush_by_index(GIMP_BRUSH_PIPE(paint_core->brush)->brush_list,
(rand()%gimp_brush_list_length
(GIMP_BRUSH_PIPE(paint_core->brush)->brush_list)));
}
else
paint_core->brush = gimp_brush_list_get_brush_by_index(GIMP_BRUSH_PIPE(paint_core->brush)->brush_list, index++);
if (index == gimp_brush_list_length (GIMP_BRUSH_PIPE(saved_brush)->brush_list))
index = 0;
}
@ -306,25 +317,26 @@ color_area_with_pixmap (GImage *dest,
/* register this pixel region */
pr = pixel_regions_register (1, &destPR);
/* to handle the case of the left side of the image */
if(area->x == 0)
offset_x = destPR.w;
else
offset_x = 0;
/* maybe its not so bizare. area is always 2 wider and
2 taller than the brush image. No idea why */
if (area->y == 0)
offset_y = pixmapbrush->pixmap_mask->height - destPR.h;
offset_y = pixmapbrush->pixmap_mask->height - destPR.h + 1;
else
offset_y = 0;
offset_y = -1;
if(area->x == 0)
{
offset_x = destPR.w -1;
offset_y++; /* uh, i havent a clue. but it works */
}
else
offset_x = 1;
for (; pr != NULL; pr = pixel_regions_process (pr))
{
d = destPR.data;
for(y = 0; y < destPR.h; y++)
for(y = 0; y < destPR.h ; y++)
{
/* printf(" brush->width: %i offset_x: %i", brush->pixmap_mask->width, offset_x); */
/* printf(" area->y: %i destPR.h: %i area->x: %i destPR.w: %i ",area->y, destPR.h, area->x, destPR.w); */
paint_line_pixmap_mask(dest, drawable, pixmapbrush,
d, area->x,offset_x, y, offset_y,
destPR.bytes, destPR.w);
@ -335,7 +347,7 @@ color_area_with_pixmap (GImage *dest,
}
static void
void
paint_line_pixmap_mask (GImage *dest,
GimpDrawable *drawable,
GimpBrushPixmap *brush,
@ -350,26 +362,24 @@ paint_line_pixmap_mask (GImage *dest,
unsigned char *pat, *p;
int color, alpha;
int i;
int temp;
/* point to the approriate scanline */
/* use "pat" here because i'm c&p from pattern clone */
pat = temp_buf_data (brush->pixmap_mask) +
(( y + offset_y ) * brush->pixmap_mask->width * brush->pixmap_mask->bytes);
/* dest = d + (y * brush->pixmap_mask->width * brush->pixmap_mask->bytes); */
color = RGB;
alpha = bytes -1;
/* printf("x: %i y: %i y2: %i \n",x,y,y2); */
for (i = 0; i < width; i++)
{
p = pat + ((i-offset_x) % brush->pixmap_mask->width) * brush->pixmap_mask->bytes;
/* printf("d->r: %i d->g: %i d->b: %i d->a: %i\n",(int)d[0], (int)d[1], (int)d[2], (int)d[3]); */
gimage_transform_color (dest, drawable, p, d, color);
p = pat + (i-offset_x) * brush->pixmap_mask->bytes;
/* pretty sure this is wrong. I think we get artifacts because of it */
d[alpha] = 255;
/* printf("i: %i d->r: %i d->g: %i d->b: %i d->a: %i\n",i,(int)d[0], (int)d[1], (int)d[2], (int)d[3]); */
gimage_transform_color (dest, drawable, p, d, color);
d += bytes;
}

View file

@ -23,7 +23,7 @@
#include "drawable.h"
#include "errors.h"
#include "gdisplay.h"
#include "gimpbrushhose.h"
#include "gimpbrushpipe.h"
#include "gimpbrushlist.h"
#include "gradient.h"
#include "paint_funcs.h"
@ -450,8 +450,7 @@ paintbrush_motion (PaintCore *paint_core,
color_pixels (temp_buf_data (area), col,
area->width * area->height, area->bytes);
}
paint_core_paste_canvas (paint_core, drawable, temp_blend,
(int) (gimp_context_get_opacity (NULL) * 255),
gimp_context_get_paint_mode (NULL),