GrafX2 2.9.3227
The ultimate 256-color painting program
brush.c File Reference
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "global.h"
#include "graph.h"
#include "misc.h"
#include "errors.h"
#include "windows.h"
#include "screen.h"
#include "brush.h"
#include "tiles.h"
+ Include dependency graph for brush.c:

Macros

#define NAN   (-1.0e20F)
 
#define isnan(x)   ((x)==NAN)
 

Functions

void Compute_clipped_dimensions (short *x, short *y, short *width, short *height)
 
void Compute_clipped_dimensions_zoom (short *x, short *y, short *width, short *height)
 
void Display_paintbrush (short x, short y, byte color)
 Display the paintbrush (preview : on screen only) More...
 
void Draw_paintbrush (short x, short y, byte color)
 Draw the paintbrush in the image buffer. More...
 
byte Realloc_brush (word new_brush_width, word new_brush_height, byte *new_brush, byte **old_brush)
 Allocates memory for a brush size change. More...
 
void Hide_paintbrush (short x, short y)
 
void Capture_brush (short start_x, short start_y, short end_x, short end_y, short clear)
 Gets the brush from the picture. More...
 
void Rotate_90_deg (void)
 Rotates the brush to the right. More...
 
void Remap_brush (void)
 
void Outline_brush (void)
 Outline the brush, add 1 foreground-colored pixel on the edges. More...
 
void Nibble_brush (void)
 Nibble the brush, remove 1 pixel on the edges and make it transparent (ie filled with back color). More...
 
void Capture_brush_with_lasso (int vertices, short *points, short clear)
 Get brush from picture according to a freehand form. More...
 
void Stretch_brush (short x1, short y1, short x2, short y2)
 Stretch the brush to fit the given rectangle. More...
 
void Stretch_brush_preview (short x1, short y1, short x2, short y2)
 Stretch the brush to fit the given rectangle. More...
 
int Min4 (long int a, long int b, long int c, long int d)
 Returns the minimum of 4 integers. More...
 
void Pixel_in_distort_buffer (word x_pos, word y_pos, byte color)
 Draw a pixel in the target buffer. No clipping. More...
 
int Max4 (long int a, long int b, long int c, long int d)
 Returns the maximum of 4 integers. More...
 
void Draw_brush_linear_distort (unsigned long int tex_min_x, unsigned long int tex_min_y, unsigned long int tex_max_x, unsigned long int tex_max_y, long int x1, long int y1, long int x2, long int y2, long int x3, long int y3, long int x4, long int y4)
 
void Distort_brush_preview (short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4)
 Draws a distorted version of the brush, mapped over the given quad (picture coordinates). More...
 
void Distort_brush (short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4)
 Modifies the current brush, mapping it over the given quad. More...
 
void Interpolate_texture (int start_x, int start_y, int xt1, int yt1, int end_x, int end_y, int xt2, int yt2, int height)
 
void Compute_quad_texture (byte *texture, int texture_width, int x1, int y1, int xt1, int yt1, int x2, int y2, int xt2, int yt2, int x3, int y3, int xt3, int yt3, int x4, int y4, int xt4, int yt4, byte *buffer, int width, int height)
 
void Scale2x (byte **bitmap, int *width, int *height)
 
void Begin_brush_rotation (void)
 
void End_brush_rotation (void)
 
void Rotate_brush (float angle)
 Rotates the brush to the right from the given angle. More...
 
void Draw_quad_texture_preview (byte *texture, int texture_width, int x1, int y1, int xt1, int yt1, int x2, int y2, int xt2, int yt2, int x3, int y3, int xt3, int yt3, int x4, int y4, int xt4, int yt4)
 
void Rotate_brush_preview (float angle)
 Stretch the brush to fit the given rectangle. More...
 

Variables

static byteBrush_rotate_buffer
 
static int Brush_rotate_width
 
static int Brush_rotate_height
 
static Func_pixel Pixel_for_distort
 
static byteDistort_source
 
static byteDistort_buffer
 
static short Distort_buffer_width
 
float * ScanY_Xt [2]
 
float * ScanY_Yt [2]
 
float * ScanY_X [2]
 

Macro Definition Documentation

◆ NAN

#define NAN   (-1.0e20F)

◆ isnan

#define isnan (   x)    ((x)==NAN)

Function Documentation

◆ Compute_clipped_dimensions()

void Compute_clipped_dimensions ( short *  x,
short *  y,
short *  width,
short *  height 
)

◆ Compute_clipped_dimensions_zoom()

void Compute_clipped_dimensions_zoom ( short *  x,
short *  y,
short *  width,
short *  height 
)

◆ Display_paintbrush()

◆ Draw_paintbrush()

void Draw_paintbrush ( short  x,
short  y,
byte  color 
)

Draw the paintbrush in the image buffer.

References Back_color, T_Document::backups, Brush_height, Brush_offset_X, Brush_offset_Y, Brush_width, Clear_brush, Clear_brush_scaled, Compute_clipped_dimensions(), Compute_clipped_dimensions_zoom(), Copy_part_of_image_to_another(), T_Document::current_layer, Display_pixel(), Effect_function, Horizontal_line_buffer, T_Document::image_height, T_Page::Image_mode, IMAGE_MODE_C64FLI, IMAGE_MODE_MODE5, IMAGE_MODE_RASTER, T_Document::image_width, T_Document::magnifier_factor, T_Document::magnifier_mode, T_Document::magnifier_offset_X, T_Document::magnifier_offset_Y, Main, Main_screen, Mask_mode, Mask_table, MAX_PAINTBRUSH_SIZE, Menu_Y, T_Document::offset_X, T_Document::offset_Y, T_List_of_pages::Pages, Paintbrush_height, Paintbrush_offset_X, Paintbrush_offset_Y, Paintbrush_shape, PAINTBRUSH_SHAPE_COLOR_BRUSH, PAINTBRUSH_SHAPE_MONO_BRUSH, PAINTBRUSH_SHAPE_NONE, PAINTBRUSH_SHAPE_POINT, Paintbrush_sprite, Paintbrush_width, Pixel_in_current_screen, Read_pixel_from_brush(), Read_pixel_from_current_layer(), Read_pixel_from_current_screen(), Read_pixel_from_spare_screen(), Shade_table, Shade_table_left, Smear_brush, Smear_brush_width, Smear_max_X, Smear_max_Y, Smear_min_X, Smear_min_Y, Smear_mode, Smear_start, Stencil, Stencil_mode, Update_part_of_screen(), and T_Document::X_zoom.

Referenced by Airbrush(), Centered_lines_12_7(), Freehand_mode1_1_0(), Freehand_mode1_2_0(), Freehand_mode2_1_0(), Freehand_mode2_1_2(), Freehand_mode2_2_0(), Freehand_mode2_2_2(), Freehand_mode3_1_0(), Freehand_Mode3_2_0(), K_line_0_6(), Line_0_5(), Pixel_figure_permanent(), and Polyform_12_0().

◆ Realloc_brush()

byte Realloc_brush ( word  new_brush_width,
word  new_brush_height,
byte new_brush,
byte **  old_brush 
)

Allocates memory for a brush size change.

This function can return the old brush pixels which can then be used by the caller to fill the new brush. Data is not automatically copied or converted from the old brush to the new one here.

Parameters
new_brush_widthnew width of the brush
new_brush_heightnew height of the brush
new_brushOptionally, you can provide an already allocated new brush - otherwise, this function performs the allocation.
old_brushIf the caller passes NULL, this function will free the old pixel data. If the caller provides the address of a (free) byte pointer, the function will make it point to the original pixel data, in this case it will be the caller's responsibility to free() it (after transferring pixels to Brush, usually).
Returns
0 on success, non-zero when running out of memory.

References Back_color, Brush, Brush_height, Brush_original_back_color, Brush_original_pixels, Brush_width, Error, MAX_PAINTBRUSH_SIZE, NULL, Smear_brush, Smear_brush_height, and Smear_brush_width.

Referenced by Button_Sieve_menu(), Button_Text(), Capture_brush(), Capture_brush_with_lasso(), Distort_brush(), Load_image(), Nibble_brush(), Outline_brush(), Restore_brush(), Rotate_90_deg(), Rotate_brush(), and Stretch_brush().

◆ Hide_paintbrush()

◆ Capture_brush()

void Capture_brush ( short  start_x,
short  start_y,
short  end_x,
short  end_y,
short  clear 
)

Gets the brush from the picture.

Parameters
start_xleft edge coordinate in the picture
start_yupper edge coordinate in the picture
end_xright edge coordinate in the picture
end_ybottom edge coordinate in the picture
clearIf 1, the area is also cleared from the picture.

References Back_color, Brush_height, Brush_offset_X, Brush_offset_Y, Brush_original_palette, Brush_width, Copy_image_to_brush(), T_Document::image_height, T_Document::image_width, Main, NULL, T_Document::palette, Pixel_in_current_screen_with_preview, Realloc_brush(), Remap_brush(), Tilemap_draw(), T_Document::tilemap_mode, Tiling_offset_X, Tiling_offset_Y, and Update_part_of_screen().

Referenced by Brush_0_5(), and Init_program().

◆ Rotate_90_deg()

◆ Remap_brush()

◆ Outline_brush()

void Outline_brush ( void  )

Outline the brush, add 1 foreground-colored pixel on the edges.

Edges are detected considering the backcolor as transparent.

References Back_color, Brush, Brush_colormap, Brush_height, Brush_offset_X, Brush_offset_Y, Brush_original_palette, Brush_original_pixels, Brush_width, Copy_part_of_image_to_another(), Error, Fore_color, Main, NULL, T_Document::palette, Pixel_in_brush(), Realloc_brush(), and SWAP_PBYTES.

Referenced by Button_Brush_FX(), and Main_handler().

◆ Nibble_brush()

void Nibble_brush ( void  )

Nibble the brush, remove 1 pixel on the edges and make it transparent (ie filled with back color).

Edges are detected considering the backcolor as transparent.

References Back_color, Brush, Brush_colormap, Brush_height, Brush_offset_X, Brush_offset_Y, Brush_original_palette, Brush_original_pixels, Brush_width, Copy_part_of_image_to_another(), Error, Main, NULL, T_Document::palette, Pixel_in_brush(), Realloc_brush(), and SWAP_PBYTES.

Referenced by Button_Brush_FX(), and Main_handler().

◆ Capture_brush_with_lasso()

void Capture_brush_with_lasso ( int  vertices,
short *  points,
short  clear 
)

◆ Stretch_brush()

void Stretch_brush ( short  x1,
short  y1,
short  x2,
short  y2 
)

◆ Stretch_brush_preview()

void Stretch_brush_preview ( short  x1,
short  y1,
short  x2,
short  y2 
)

Stretch the brush to fit the given rectangle.

Uses fast approximation for the preview while drawing the rectangle on screen.

References Back_color, Brush_height, Brush_width, Limit_left, Limit_top, Limit_visible_bottom, Limit_visible_right, Max(), Min(), Pixel_preview, Read_pixel_from_brush(), and Update_part_of_screen().

Referenced by Stretch_brush_0_7(), and Stretch_brush_1_7().

◆ Min4()

int Min4 ( long int  a,
long int  b,
long int  c,
long int  d 
)

Returns the minimum of 4 integers.

Referenced by Distort_brush(), and Draw_brush_linear_distort().

◆ Pixel_in_distort_buffer()

void Pixel_in_distort_buffer ( word  x_pos,
word  y_pos,
byte  color 
)

Draw a pixel in the target buffer. No clipping.

References Distort_buffer, and Distort_buffer_width.

Referenced by Distort_brush().

◆ Max4()

int Max4 ( long int  a,
long int  b,
long int  c,
long int  d 
)

Returns the maximum of 4 integers.

Referenced by Distort_brush(), and Draw_brush_linear_distort().

◆ Draw_brush_linear_distort()

void Draw_brush_linear_distort ( unsigned long int  tex_min_x,
unsigned long int  tex_min_y,
unsigned long int  tex_max_x,
unsigned long int  tex_max_y,
long int  x1,
long int  y1,
long int  x2,
long int  y2,
long int  x3,
long int  y3,
long int  x4,
long int  y4 
)

◆ Distort_brush_preview()

void Distort_brush_preview ( short  x1,
short  y1,
short  x2,
short  y2,
short  x3,
short  y3,
short  x4,
short  y4 
)

Draws a distorted version of the brush, mapped over the given quad (picture coordinates).

Remap the brush palette to the nearest color in the picture one.

References Brush, Brush_height, Brush_width, Distort_source, Draw_brush_linear_distort(), Pixel_figure_preview(), and Pixel_for_distort.

Referenced by Distort_brush_1_0(), and Distort_brush_1_9().

◆ Distort_brush()

void Distort_brush ( short  x1,
short  y1,
short  x2,
short  y2,
short  x3,
short  y3,
short  x4,
short  y4 
)

◆ Interpolate_texture()

void Interpolate_texture ( int  start_x,
int  start_y,
int  xt1,
int  yt1,
int  end_x,
int  end_y,
int  xt2,
int  yt2,
int  height 
)

◆ Compute_quad_texture()

void Compute_quad_texture ( byte texture,
int  texture_width,
int  x1,
int  y1,
int  xt1,
int  yt1,
int  x2,
int  y2,
int  xt2,
int  yt2,
int  x3,
int  y3,
int  xt3,
int  yt3,
int  x4,
int  y4,
int  xt4,
int  yt4,
byte buffer,
int  width,
int  height 
)

◆ Scale2x()

void Scale2x ( byte **  bitmap,
int *  width,
int *  height 
)

Referenced by Begin_brush_rotation().

◆ Begin_brush_rotation()

◆ End_brush_rotation()

void End_brush_rotation ( void  )

◆ Rotate_brush()

◆ Draw_quad_texture_preview()

void Draw_quad_texture_preview ( byte texture,
int  texture_width,
int  x1,
int  y1,
int  xt1,
int  yt1,
int  x2,
int  y2,
int  xt2,
int  yt2,
int  x3,
int  y3,
int  xt3,
int  yt3,
int  x4,
int  y4,
int  xt4,
int  yt4 
)

◆ Rotate_brush_preview()

void Rotate_brush_preview ( float  angle)

Stretch the brush to fit the given rectangle.

Uses fast approximation for the preview while changing the angle.

References Brush_height, Brush_rotate_buffer, Brush_rotate_height, Brush_rotate_width, Brush_rotation_center_X, Brush_rotation_center_Y, Brush_width, Draw_quad_texture_preview(), Max(), Min(), Transform_point(), and Update_part_of_screen().

Referenced by Rotate_brush_0_5(), and Rotate_brush_1_5().

Variable Documentation

◆ Brush_rotate_buffer

byte* Brush_rotate_buffer
static

◆ Brush_rotate_width

int Brush_rotate_width
static

◆ Brush_rotate_height

int Brush_rotate_height
static

◆ Pixel_for_distort

Func_pixel Pixel_for_distort
static

◆ Distort_source

byte* Distort_source
static

◆ Distort_buffer

byte* Distort_buffer
static

◆ Distort_buffer_width

short Distort_buffer_width
static

◆ ScanY_Xt

◆ ScanY_Yt

◆ ScanY_X