libgeda

o_picture.c File Reference

functions for the picture object More...

#include <config.h>
#include <stdio.h>
#include <math.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gio/gio.h>
#include "libgeda_priv.h"
Include dependency graph for o_picture.c:

Go to the source code of this file.

Functions

OBJECTo_picture_read (TOPLEVEL *toplevel, const char *first_line, TextBuffer *tb, unsigned int release_ver, unsigned int fileformat_ver, GError **err)
 Create picture OBJECT from character string.
char * o_picture_save (TOPLEVEL *toplevel, OBJECT *object)
 Create a character string representation of a picture OBJECT.
OBJECTo_picture_new (TOPLEVEL *toplevel, const gchar *file_content, gsize file_length, const gchar *filename, char type, int x1, int y1, int x2, int y2, int angle, int mirrored, int embedded)
 Create a picture object.
void o_picture_recalc (TOPLEVEL *toplevel, OBJECT *o_current)
 Recalculate picture bounding box.
void world_get_picture_bounds (TOPLEVEL *toplevel, OBJECT *object, int *left, int *top, int *right, int *bottom)
 Get picture bounding rectangle in WORLD coordinates.
gboolean o_picture_get_position (TOPLEVEL *toplevel, gint *x, gint *y, OBJECT *object)
 get the position of the left bottom point
double o_picture_get_ratio (TOPLEVEL *toplevel, OBJECT *object)
 Get the width/height ratio of an image.
void o_picture_modify (TOPLEVEL *toplevel, OBJECT *object, int x, int y, int whichone)
 Modify the description of a picture OBJECT.
void o_picture_modify_all (TOPLEVEL *toplevel, OBJECT *object, int x1, int y1, int x2, int y2)
 Modify a picture object's coordinates.
void o_picture_rotate_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, int angle, OBJECT *object)
 Rotate picture OBJECT using WORLD coordinates.
void o_picture_mirror_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, OBJECT *object)
 Mirror a picture using WORLD coordinates.
void o_picture_translate_world (TOPLEVEL *toplevel, int dx, int dy, OBJECT *object)
 Translate a picture position in WORLD coordinates by a delta.
OBJECTo_picture_copy (TOPLEVEL *toplevel, OBJECT *object)
 Create a copy of a picture.
static guint8 * o_picture_rgb_data (GdkPixbuf *image)
 Get RGB data from image.
static guint8 * o_picture_mask_data (GdkPixbuf *image)
 Get mask data from image.
void o_picture_print (TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current, int origin_x, int origin_y)
 Print picture to Postscript document.
void o_picture_embed (TOPLEVEL *toplevel, OBJECT *object)
 Embed the image file associated with a picture.
void o_picture_unembed (TOPLEVEL *toplevel, OBJECT *object)
 Unembed a picture, reloading the image from disk.
double o_picture_shortest_distance (OBJECT *object, int x, int y, int force_solid)
 Calculates the distance between the given point and the closest point in the picture.
gboolean o_picture_is_embedded (TOPLEVEL *toplevel, OBJECT *object)
 Test whether a picture object is embedded.
GdkPixbuf * o_picture_get_pixbuf (TOPLEVEL *toplevel, OBJECT *object)
 Get a pixel buffer for a picture object.
const char * o_picture_get_data (TOPLEVEL *toplevel, OBJECT *object, size_t *len)
 Get the raw image data from a picture object.
gboolean o_picture_set_from_buffer (TOPLEVEL *toplevel, OBJECT *object, const gchar *filename, const gchar *data, size_t len, GError **error)
 Set a picture object's contents from a buffer.
gboolean o_picture_set_from_file (TOPLEVEL *toplevel, OBJECT *object, const gchar *filename, GError **error)
 Set a picture object's contents from a file.
const gchar * o_picture_get_filename (TOPLEVEL *toplevel, OBJECT *object)
 Get a picture's corresponding filename.
GdkPixbuf * o_picture_get_fallback_pixbuf (TOPLEVEL *toplevel)
 Get fallback pixbuf for displaying pictures.

Detailed Description

Definition in file o_picture.c.


Function Documentation

OBJECT* o_picture_read ( TOPLEVEL toplevel,
const char *  first_line,
TextBuffer tb,
unsigned int  release_ver,
unsigned int  fileformat_ver,
GError **  err 
)
Function Description
Parses first_line and subsequent lines from tb, and returns a newly-created picture OBJECT.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]first_lineCharacter string with picture description.
[in]tbText buffer to load embedded data from.
[in]release_verlibgeda release version number.
[in]fileformat_verlibgeda file format version number.
Returns:
A pointer to the new picture object, or NULL on error.

Definition at line 50 of file o_picture.c.

Here is the call graph for this function:

char* o_picture_save ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
This function formats a string in the buffer *buff to describe the picture object *object.
Parameters:
[in]toplevela TOPLEVEL structure
[in]objectPicture OBJECT to create string from.
Returns:
A pointer to the picture OBJECT character string.
Note:
Caller must g_free returned character string.

Definition at line 180 of file o_picture.c.

Here is the call graph for this function:

OBJECT* o_picture_new ( TOPLEVEL toplevel,
const gchar *  file_content,
gsize  file_length,
const gchar *  filename,
char  type,
int  x1,
int  y1,
int  x2,
int  y2,
int  angle,
int  mirrored,
int  embedded 
)
Function Description
This function creates a new object representing a picture.

The picture is described by its upper left corner (x1, y1) and its lower right corner (x2, ). The type parameter must be equal to OBJ_PICTURE.

If file_content is non-NULL, it must be a pointer to a buffer containing raw image data. If loading data from file_content is unsuccessful, and filename is non-NULL, an image will attempt to be loaded from filename. Otherwise, the picture object will be initially empty.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]file_contentRaw data of the image file, or NULL.
[in]file_lengthLength of raw data buffer
[in]filenameFile name backing this picture, or NULL.
[in]typeMust be OBJ_PICTURE.
[in]x1Upper x coordinate.
[in]y1Upper y coordinate.
[in]x2Lower x coordinate.
[in]y2Lower y coordinate.
[in]anglePicture rotation angle.
[in]mirroredWhether the image should be mirrored or not.
[in]embeddedWhether the embedded flag should be set or not.
Returns:
A pointer to a new picture OBJECT.

Definition at line 273 of file o_picture.c.

Here is the call graph for this function:

void o_picture_recalc ( TOPLEVEL toplevel,
OBJECT o_current 
)
Function Description
This function recalculates the bounding box of the o_current parameter picture object.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in,out]o_currentPicture OBJECT to be recalculated.

Definition at line 341 of file o_picture.c.

Here is the call graph for this function:

void world_get_picture_bounds ( TOPLEVEL toplevel,
OBJECT object,
int *  left,
int *  top,
int *  right,
int *  bottom 
)
Function Description
This function sets the left, top, right and bottom parameters to the boundings of the picture object described in *picture in WORLD units.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objectPicture OBJECT to read coordinates from.
[out]leftLeft picture coordinate in WORLD units.
[out]topTop picture coordinate in WORLD units.
[out]rightRight picture coordinate in WORLD units.
[out]bottomBottom picture coordinate in WORLD units.

Definition at line 372 of file o_picture.c.

gboolean o_picture_get_position ( TOPLEVEL toplevel,
gint *  x,
gint *  y,
OBJECT object 
)
Function Description
This function gets the position of the bottom left point of a picture object.
Parameters:
[in]toplevelThe toplevel environment.
[out]xpointer to the x-position
[out]ypointer to the y-position
[in]objectThe object to get the position.
Returns:
TRUE if successfully determined the position, FALSE otherwise

Definition at line 392 of file o_picture.c.

double o_picture_get_ratio ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description

Returns the width/height ratio of picture object, taking the image rotation into account.

Parameters:
toplevelThe current TOPLEVEL.
objectPicture OBJECT to inspect.
Returns:
width/height ratio for object.

Definition at line 412 of file o_picture.c.

void o_picture_modify ( TOPLEVEL toplevel,
OBJECT object,
int  x,
int  y,
int  whichone 
)
Function Description
This function modifies the coordinates of one of the four corner of the picture. The new coordinates of the corner identified by whichone are given by x and y in world unit.

The coordinates of the corner is modified in the world coordinate system. Screen coordinates and boundings are then updated.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in,out]objectPicture OBJECT to modify.
[in]xNew x coordinate.
[in]yNew y coordinate.
[in]whichoneWhich picture parameter to modify.

whichone can have the following values:

*
PICTURE_UPPER_LEFT
*
PICTURE_LOWER_LEFT
*
PICTURE_UPPER_RIGHT
*
PICTURE_LOWER_RIGHT

Definition at line 456 of file o_picture.c.

Here is the call graph for this function:

void o_picture_modify_all ( TOPLEVEL toplevel,
OBJECT object,
int  x1,
int  y1,
int  x2,
int  y2 
)
Function Description
Modifies the coordinates of all four corners of a picture object. The picture is adjusted to fit the rectangle enclosed by the points (x1, y1) and (x2, y2), and scaled as large as possible to still fit within that rectangle.
Parameters:
[in]toplevelcurrent TOPLEVEL.
[in,out]objectpicture OBJECT to be modified.
[in]x1x coordinate of first corner of box.
[in]y1y coordinate of first corner of box.
[in]x2x coordinate of second corner of box.
[in]y2y coordinate of second corner of box.

Definition at line 539 of file o_picture.c.

Here is the call graph for this function:

void o_picture_rotate_world ( TOPLEVEL toplevel,
int  world_centerx,
int  world_centery,
int  angle,
OBJECT object 
)
Function Description
This function rotates the picture described by *object around the (world_centerx, world_centery) point by angle degrees. The center of rotation is in world units.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]world_centerxRotation center x coordinate in WORLD units.
[in]world_centeryRotation center y coordinate in WORLD units.
[in]angleRotation angle in degrees (See note below).
[in,out]objectPicture OBJECT to rotate.

Definition at line 570 of file o_picture.c.

Here is the call graph for this function:

void o_picture_mirror_world ( TOPLEVEL toplevel,
int  world_centerx,
int  world_centery,
OBJECT object 
)
Function Description
This function mirrors the picture from the point (world_centerx,world_centery) in world unit.

The picture is first translated to the origin, then mirrored and finally translated back at its previous position.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]world_centerxOrigin x coordinate in WORLD units.
[in]world_centeryOrigin y coordinate in WORLD units.
[in,out]objectPicture OBJECT to mirror.

Definition at line 634 of file o_picture.c.

Here is the call graph for this function:

void o_picture_translate_world ( TOPLEVEL toplevel,
int  dx,
int  dy,
OBJECT object 
)
Function Description
This function applies a translation of (x1,y1) to the picture described by *object. x1 and y1 are in world units.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]dxx distance to move.
[in]dyy distance to move.
[in,out]objectPicture OBJECT to translate.

Definition at line 692 of file o_picture.c.

Here is the call graph for this function:

OBJECT* o_picture_copy ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
This function creates a verbatim copy of the object pointed by o_current describing a picture.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objectPicture OBJECT to copy.
Returns:
The new OBJECT

Definition at line 714 of file o_picture.c.

Here is the call graph for this function:

static guint8* o_picture_rgb_data ( GdkPixbuf *  image) [static]
Function Description
This function returns the RGB data of the given image. Function taken from the DIA source code (http://www.gnome.org/projects/dia) and licensed under the GNU GPL version 2.
Parameters:
[in]imageGdkPixbuf image to read RGB data from.
Returns:
Array of rgb data from image.
Note:
Caller must g_free returned guint8 array.

Definition at line 771 of file o_picture.c.

static guint8* o_picture_mask_data ( GdkPixbuf *  image) [static]
Function Description
This function returns the mask data of the given image. Function taken from the DIA source code (http://www.gnome.org/projects/dia) and licensed under the GNU GPL version 2.
Parameters:
[in]imageGdkPixbuf image to get mask data from.
Returns:
Array of mask data from image.
Note:
Caller must g_free returned guint8 array.

Definition at line 811 of file o_picture.c.

void o_picture_print ( TOPLEVEL toplevel,
FILE *  fp,
OBJECT o_current,
int  origin_x,
int  origin_y 
)
Function Description
This function prints a picture object. The picture is defined by the coordinates of its upper left corner in (x,y) and its width and height given by the width and height parameters.

If the picture object was unable to be loaded, prints a crossed box of the same dimensions.

The Postscript document is defined by the file pointer fp. Function based on the DIA source code (http://www.gnome.org/projects/dia) and licensed under the GNU GPL version 2.

All dimensions are in mils.

Parameters:
[in]toplevelThe TOPLEVEL object.
[in]fpFILE pointer to Postscript document.
[in]o_currentPicture OBJECT to write to document.
[in]origin_xPage x coordinate to place picture OBJECT.
[in]origin_yPage y coordinate to place picture OBJECT.

Definition at line 856 of file o_picture.c.

Here is the call graph for this function:

void o_picture_embed ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
Verify that a picture has valid data associated with it, and if so, mark it to be embedded.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objectThe picture OBJECT to embed

Definition at line 949 of file o_picture.c.

Here is the call graph for this function:

void o_picture_unembed ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
Verify that the file associated with object exists on disk and is usable, and if so, reload the picture and mark it as unembedded.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objectThe picture OBJECT to unembed

Definition at line 979 of file o_picture.c.

Here is the call graph for this function:

double o_picture_shortest_distance ( OBJECT object,
int  x,
int  y,
int  force_solid 
)

Interrior points within the picture return a distance of zero.

Parameters:
[in]objectThe picture OBJECT.
[in]xThe x coordinate of the given point.
[in]yThe y coordinate of the given point.
[in]force_solidIf true, force treating the object as solid.
Returns:
The shortest distance from the object to the point. With an invalid parameter, this function returns G_MAXDOUBLE.

Definition at line 1016 of file o_picture.c.

gboolean o_picture_is_embedded ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
Returns TRUE if the picture object will have its data embedded in a schematic or symbol file; returns FALSE if its data will be obtained from a separate file.
Parameters:
toplevelThe current TOPLEVEL.
objectThe picture OBJECT to inspect.
Returns:
TRUE if object is embedded.

Definition at line 1049 of file o_picture.c.

GdkPixbuf* o_picture_get_pixbuf ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
Returns a #GdkPixbuf for the picture object object, or NULL if the picture could not be loaded.

The returned value should have its reference count decremented with g_object_unref() when no longer needed.

Parameters:
toplevelThe current TOPLEVEL.
objectThe picture OBJECT to inspect.
Returns:
A #GdkPixbuf for the picture.

Definition at line 1070 of file o_picture.c.

const char* o_picture_get_data ( TOPLEVEL toplevel,
OBJECT object,
size_t *  len 
)
Function Description
Returns the raw image file data underlying the picture object, or NULL if the picture could not be loaded.
Parameters:
toplevelThe current TOPLEVEL.
objectThe picture OBJECT to inspect.
lenLocation to store buffer length.
Returns:
A read-only buffer of raw image data.

Definition at line 1093 of file o_picture.c.

gboolean o_picture_set_from_buffer ( TOPLEVEL toplevel,
OBJECT object,
const gchar *  filename,
const gchar *  data,
size_t  len,
GError **  error 
)
Function Description
Sets the contents of the picture object by reading image data from a buffer. The buffer should be in on-disk format.
Parameters:
toplevelThe current TOPLEVEL.
objectThe picture OBJECT to modify.
filenameThe new filename for the picture.
dataThe new image data buffer.
lenThe size of the data buffer.
errorLocation to return error information.
Returns:
TRUE on success, FALSE on failure.

Definition at line 1117 of file o_picture.c.

Here is the call graph for this function:

gboolean o_picture_set_from_file ( TOPLEVEL toplevel,
OBJECT object,
const gchar *  filename,
GError **  error 
)
Function Description
Sets the contents of the picture object by reading image data from a file.
Parameters:
toplevelThe current TOPLEVEL.
objectThe picture OBJECT to modify.
filenameThe filename to load image data from.
errorLocation to return error information.
Returns:
TRUE on success, FALSE on failure.

Definition at line 1176 of file o_picture.c.

Here is the call graph for this function:

const gchar* o_picture_get_filename ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
Returns the filename associated with the picture object.
Parameters:
toplevelThe current TOPLEVEL.
objectThe picture OBJECT to inspect.
Returns:
the filename associated with object.

Definition at line 1205 of file o_picture.c.

GdkPixbuf* o_picture_get_fallback_pixbuf ( TOPLEVEL toplevel)
Function Description
Returns a pixbuf containing the fallback image to be used if a picture object fails to load. The returned pixbuf should be freed with g_object_unref() when no longer needed.
Returns:
a #GdkPixbuf containing a warning image.

Definition at line 1222 of file o_picture.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines