From eb26972a11fff243d38dcbce15aeeeaac6530ef7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 29 Mar 2008 04:24:36 +0000 Subject: [PATCH] Renamed filedata to format_options --- src/file/bmp_format.c | 22 +++++----- src/file/file.c | 22 +++++----- src/file/file.h | 10 ++--- src/file/filedata.c | 44 +++++++++---------- src/file/filedata.h | 55 +++++++++++------------- src/file/jpeg_format.c | 95 ++++++++++++++---------------------------- src/raster/sprite.c | 18 ++++---- src/raster/sprite.h | 33 +++++++++++---- 8 files changed, 140 insertions(+), 159 deletions(-) diff --git a/src/file/bmp_format.c b/src/file/bmp_format.c index 33024edce..0502cbd9f 100644 --- a/src/file/bmp_format.c +++ b/src/file/bmp_format.c @@ -589,7 +589,7 @@ static bool load_BMP(FileOp *fop) biSize = fgetl(f); if (biSize == WININFOHEADERSIZE) { - format = BMPDATA_FORMAT_WINDOWS; + format = BMP_OPTIONS_FORMAT_WINDOWS; if (read_win_bminfoheader(f, &infoheader) != 0) { fclose(f); @@ -599,7 +599,7 @@ static bool load_BMP(FileOp *fop) read_bmicolors(fop, fileheader.bfOffBits - 54, f, TRUE); } else if (biSize == OS2INFOHEADERSIZE) { - format = BMPDATA_FORMAT_OS2; + format = BMP_OPTIONS_FORMAT_OS2; if (read_os2_bminfoheader(f, &infoheader) != 0) { fclose(f); @@ -679,17 +679,17 @@ static bool load_BMP(FileOp *fop) } /* setup the file-data */ - if (fop->seq.filedata == NULL) { - BmpData *bmpdata = bmpdata_new(); + if (fop->seq.format_options == NULL) { + BmpOptions *bmp_options = bmp_options_new(); - bmpdata->format = format; - bmpdata->compression = infoheader.biCompression; - bmpdata->bits_per_pixel = infoheader.biBitCount; - bmpdata->red_mask = rmask; - bmpdata->green_mask = gmask; - bmpdata->blue_mask = bmask; + bmp_options->format = format; + bmp_options->compression = infoheader.biCompression; + bmp_options->bits_per_pixel = infoheader.biBitCount; + bmp_options->red_mask = rmask; + bmp_options->green_mask = gmask; + bmp_options->blue_mask = bmask; - fop_sequence_set_filedata(fop, (FileData *)bmpdata); + fop_sequence_set_format_options(fop, (FormatOptions *)bmp_options); } fclose(f); diff --git a/src/file/file.c b/src/file/file.c index a66837630..1cfac13d3 100644 --- a/src/file/file.c +++ b/src/file/file.c @@ -415,17 +415,18 @@ FileOp *fop_to_save_sprite(Sprite *sprite) fop->filename = jstrdup(fop->sprite->filename); /* configure output format? */ - if (fop->format->getdata) { - FileData *data = (fop->format->getdata)(fop); + if (fop->format->get_options != NULL) { + FormatOptions *format_options = (fop->format->get_options)(fop); /* does the user cancelled the operation? */ - if (data == NULL) { + if (format_options == NULL) { fop_free(fop); return NULL; } - fop->seq.filedata = data; - sprite_set_filedata(fop->sprite, data); + fop->seq.format_options = format_options; + sprite_set_format_options(fop->sprite, + format_options); } return fop; @@ -562,7 +563,8 @@ void fop_operate(FileOp *fop) sprite_set_frames(fop->sprite, frame); /* set the frames range */ - sprite_set_filedata(fop->sprite, fop->seq.filedata); + sprite_set_format_options(fop->sprite, + fop->seq.format_options); } } /* direct load from one file */ @@ -704,10 +706,10 @@ void fop_free(FileOp *fop) jfree(fop); } -void fop_sequence_set_filedata(FileOp *fop, FileData *filedata) +void fop_sequence_set_format_options(FileOp *fop, FormatOptions *format_options) { - assert(fop->seq.filedata == NULL); - fop->seq.filedata = filedata; + assert(fop->seq.format_options == NULL); + fop->seq.format_options = format_options; } void fop_sequence_set_color(FileOp *fop, int index, int r, int g, int b) @@ -896,7 +898,7 @@ static void fop_prepare_for_sequence(FileOp *fop) { fop->seq.filename_list = jlist_new(); fop->seq.palette = palette_new(0, MAX_PALETTE_COLORS); - fop->seq.filedata = NULL; + fop->seq.format_options = NULL; } static FileFormat *get_fileformat(const char *extension) diff --git a/src/file/file.h b/src/file/file.h index 2f5ca2c9e..74168bd25 100644 --- a/src/file/file.h +++ b/src/file/file.h @@ -40,7 +40,7 @@ #define FILE_LOAD_ONE_FRAME (1<<3) struct Cel; -struct FileData; +struct FormatOptions; struct Image; struct Layer; struct Palette; @@ -56,7 +56,7 @@ typedef enum { FileOpLoad, typedef bool (*FileLoad)(struct FileOp *fop); typedef bool (*FileSave)(struct FileOp *fop); -typedef struct FileData *(*FileGetData)(struct FileOp *fop); +typedef struct FormatOptions *(*GetFormatOptions)(struct FileOp *fop); /* load or/and save a file format */ typedef struct FileFormat @@ -65,7 +65,7 @@ typedef struct FileFormat const char *exts; /* extensions (e.g. "jpeg,jpg") */ FileLoad load; /* procedure to read a sprite in this format */ FileSave save; /* procedure to write a sprite in this format */ - FileGetData getdata; /* procedure to configure the format to be saved */ + GetFormatOptions get_options; /* procedure to configure the output format */ int flags; } FileFormat; @@ -100,7 +100,7 @@ typedef struct FileOp bool has_alpha; struct Layer *layer; struct Cel *last_cel; - struct FileData *filedata; + struct FormatOptions *format_options; } seq; } FileOp; @@ -123,7 +123,7 @@ void fop_done(FileOp *fop); void fop_stop(FileOp *fop); void fop_free(FileOp *fop); -void fop_sequence_set_filedata(FileOp *fop, struct FileData *filedata); +void fop_sequence_set_format_options(FileOp *fop, struct FormatOptions *format_options); void fop_sequence_set_color(FileOp *fop, int index, int r, int g, int b); void fop_sequence_get_color(FileOp *fop, int index, int *r, int *g, int *b); struct Image *fop_sequence_image(FileOp *fi, int imgtype, int w, int h); diff --git a/src/file/filedata.c b/src/file/filedata.c index 37c4f2957..2b0596752 100644 --- a/src/file/filedata.c +++ b/src/file/filedata.c @@ -24,46 +24,48 @@ #include "file/filedata.h" -FileData *filedata_new(int type, int size) +FormatOptions *format_options_new(int type, int size) { - FileData *filedata; + FormatOptions *format_options; - assert(size >= sizeof(FileData)); + assert(size >= sizeof(FormatOptions)); - filedata = jmalloc0(size); - if (filedata == NULL) + format_options = jmalloc0(size); + if (format_options == NULL) return NULL; - filedata->type = type; - filedata->size = size; + format_options->type = type; + format_options->size = size; - return filedata; + return format_options; } -void filedata_free(FileData *filedata) +void format_options_free(FormatOptions *format_options) { - assert(filedata != NULL); - jfree(filedata); + assert(format_options != NULL); + jfree(format_options); } -BmpData *bmpdata_new(void) +BmpOptions *bmp_options_new(void) { - BmpData *bmpdata = (BmpData *)filedata_new(FILEDATA_BMP, - sizeof(BmpData)); + BmpOptions *bmp_options = (BmpOptions *) + format_options_new(FORMAT_OPTIONS_BMP, + sizeof(BmpOptions)); - if (bmpdata == NULL) + if (bmp_options == NULL) return NULL; - return bmpdata; + return bmp_options; } -JpegData *jpegdata_new(void) +JpegOptions *jpeg_options_new(void) { - JpegData *jpegdata = (JpegData *)filedata_new(FILEDATA_JPEG, - sizeof(JpegData)); + JpegOptions *jpeg_options = (JpegOptions *) + format_options_new(FORMAT_OPTIONS_JPEG, + sizeof(JpegOptions)); - if (jpegdata == NULL) + if (jpeg_options == NULL) return NULL; - return jpegdata; + return jpeg_options; } diff --git a/src/file/filedata.h b/src/file/filedata.h index ad1368c23..dc3140508 100644 --- a/src/file/filedata.h +++ b/src/file/filedata.h @@ -16,68 +16,61 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef FILEDATA_H -#define FILEDATA_H +#ifndef FILE_FORMAT_OPTIONS_H +#define FILE_FORMAT_OPTIONS_H enum { - FILEDATA_BMP, - FILEDATA_JPEG, - FILEDATA_MAX + FORMAT_OPTIONS_BMP, + FORMAT_OPTIONS_JPEG, + FORMAT_OPTIONS_MAX }; /* data that can be in a file and could be useful to save the file later in the same format */ -typedef struct FileData +typedef struct FormatOptions { int type; int size; -} FileData; +} FormatOptions; -FileData *filedata_new(int type, int size); -void filedata_free(FileData *filedata); +FormatOptions *format_options_new(int type, int size); +void format_options_free(FormatOptions *filedata); /********************************************************************* Data for BMP files *********************************************************************/ -#define BMPDATA_FORMAT_WINDOWS 12 -#define BMPDATA_FORMAT_OS2 40 +#define BMP_OPTIONS_FORMAT_WINDOWS 12 +#define BMP_OPTIONS_FORMAT_OS2 40 -#define BMPDATA_COMPRESSION_RGB 0 -#define BMPDATA_COMPRESSION_RLE8 1 -#define BMPDATA_COMPRESSION_RLE4 2 -#define BMPDATA_COMPRESSION_BITFIELDS 3 +#define BMP_OPTIONS_COMPRESSION_RGB 0 +#define BMP_OPTIONS_COMPRESSION_RLE8 1 +#define BMP_OPTIONS_COMPRESSION_RLE4 2 +#define BMP_OPTIONS_COMPRESSION_BITFIELDS 3 -typedef struct BmpData +typedef struct BmpOptions { - FileData head; + FormatOptions head; int format; /* BMP format */ int compression; /* BMP compression */ int bits_per_pixel; /* bits per pixel */ ase_uint32 red_mask; /* mask for red channel */ ase_uint32 green_mask; /* mask for green channel */ ase_uint32 blue_mask; /* mask for blue channel */ -} BmpData; +} BmpOptions; -BmpData *bmpdata_new(void); +BmpOptions *bmp_options_new(void); /********************************************************************* Data for JPEG files *********************************************************************/ -#define JPEGDATA_METHOD_SLOW 0 /* slow but accurate integer algorithm */ -#define JPEGDATA_METHOD_FAST 1 /* faster, less accurate integer method */ -#define JPEGDATA_METHOD_FLOAT 2 /* floating-point: accurate, fast on fast HW */ -#define JPEGDATA_METHOD_DEFAULT JPEGDATA_METHOD_SLOW - -typedef struct JpegData +typedef struct JpegOptions { - FileData head; + FormatOptions head; float quality; /* 1.0 maximum quality */ - float smooth; /* 1.0 maximum smooth */ - int method; -} JpegData; +} JpegOptions; -JpegData *jpegdata_new(void); +JpegOptions *jpeg_options_new(void); -#endif /* FILEDATA_H */ +#endif /* FILE_FORMAT_OPTIONS_H */ diff --git a/src/file/jpeg_format.c b/src/file/jpeg_format.c index f202e1160..9b34b323f 100644 --- a/src/file/jpeg_format.c +++ b/src/file/jpeg_format.c @@ -29,6 +29,7 @@ #include "core/core.h" #include "file/file.h" #include "file/filedata.h" +#include "modules/gui.h" #include "raster/raster.h" #include "script/script.h" @@ -36,7 +37,7 @@ static bool load_JPEG(FileOp *fop); static bool save_JPEG(FileOp *fop); -static JpegData *getdata_JPEG(FileOp *fop); +static FormatOptions *get_options_JPEG(FileOp *fop); FileFormat format_jpeg = { @@ -44,7 +45,7 @@ FileFormat format_jpeg = "jpeg,jpg", load_JPEG, save_JPEG, - getdata_JPEG, + get_options_JPEG, FILE_SUPPORT_RGB | FILE_SUPPORT_GRAY | FILE_SUPPORT_SEQUENCES @@ -229,7 +230,7 @@ static bool save_JPEG(FileOp *fop) FILE *file; JSAMPARRAY buffer; JDIMENSION buffer_height; - JpegData *jpegdata = (JpegData *)fop->seq.filedata; + JpegOptions *jpeg_options = (JpegOptions *)fop->seq.format_options; int c; /* Open the file for write in it. */ @@ -261,9 +262,9 @@ static bool save_JPEG(FileOp *fop) } jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, (int)MID(0, 100.0f * jpegdata->quality, 100), TRUE); - cinfo.dct_method = jpegdata->method; - cinfo.smoothing_factor = (int)MID(0, 100.0f * jpegdata->smooth, 100); + jpeg_set_quality(&cinfo, (int)MID(0, 100.0f * jpeg_options->quality, 100), TRUE); + cinfo.dct_method = JDCT_ISLOW; + cinfo.smoothing_factor = 0; /* Start compressor. */ jpeg_start_compress(&cinfo, TRUE); @@ -348,80 +349,46 @@ static bool save_JPEG(FileOp *fop) /** * Shows the JPEG configuration dialog. */ -static JpegData *getdata_JPEG(FileOp *fop) +static FormatOptions *get_options_JPEG(FileOp *fop) { - JWidget window, box1, box2, box3, box4, box5; - JWidget label_quality, label_smooth, label_method; - JWidget slider_quality, slider_smooth, view_method; - JWidget list_method, button_ok, button_cancel; - JpegData *jpegdata = jpegdata_new(); + JWidget window, slider_quality, ok; + JpegOptions *jpeg_options = jpeg_options_new(); /* configuration parameters */ - jpegdata->quality = get_config_float("JPEG", "Quality", 0.6f); - jpegdata->smooth = 0.0f; - jpegdata->method = JPEGDATA_METHOD_DEFAULT; + jpeg_options->quality = get_config_float("JPEG", "Quality", 0.6f); /* interactive mode */ if (!is_interactive()) - return jpegdata; + return (FormatOptions *)jpeg_options; /* widgets */ - window = jwindow_new(_("JPEG Options")); - box1 = jbox_new(JI_VERTICAL); - box2 = jbox_new(JI_HORIZONTAL); - box3 = jbox_new(JI_VERTICAL + JI_HOMOGENEOUS); - box4 = jbox_new(JI_VERTICAL + JI_HOMOGENEOUS); - box5 = jbox_new(JI_HORIZONTAL + JI_HOMOGENEOUS); - label_quality = jlabel_new(_("Quality:")); - label_smooth = jlabel_new(_("Smooth:")); - label_method = jlabel_new(_("Method:")); - slider_quality = jslider_new(0, 10, jpegdata->quality*10); - slider_smooth = jslider_new(0, 10, jpegdata->smooth*10); - view_method = jview_new(); - list_method = jlistbox_new(); - button_ok = jbutton_new(_("&OK")); - button_cancel = jbutton_new(_("&Cancel")); + window = load_widget("jpeg_options.jid", "jpeg_options"); + if (!window) { + format_options_free((FormatOptions *)jpeg_options); + return NULL; + } - jwidget_add_child(list_method, jlistitem_new(_("Slow"))); - jwidget_add_child(list_method, jlistitem_new(_("Fast"))); - jwidget_add_child(list_method, jlistitem_new(_("Float"))); - jlistbox_select_index(list_method, jpegdata->method); + if (!get_widgets(window, + "quality", &slider_quality, + "ok", &ok, NULL)) { + jwidget_free(window); + format_options_free((FormatOptions *)jpeg_options); + return NULL; + } - jview_attach(view_method, list_method); - jview_maxsize(view_method); - - jwidget_expansive(box4, TRUE); - jwidget_expansive(view_method, TRUE); - jwidget_magnetic(button_ok, TRUE); - - jwidget_add_child(box3, label_quality); - jwidget_add_child(box3, label_smooth); - jwidget_add_child(box4, slider_quality); - jwidget_add_child(box4, slider_smooth); - jwidget_add_child(box2, box3); - jwidget_add_child(box2, box4); - jwidget_add_child(box1, box2); - jwidget_add_child(box1, label_method); - jwidget_add_child(box1, view_method); - jwidget_add_child(box5, button_ok); - jwidget_add_child(box5, button_cancel); - jwidget_add_child(box1, box5); - jwidget_add_child(window, box1); + jslider_set_value(slider_quality, jpeg_options->quality * 10.0f); jwindow_open_fg(window); - if (jwindow_get_killer(window) == button_ok) { - jpegdata->quality = jslider_get_value(slider_quality) / 10.0f; - jpegdata->smooth = jslider_get_value(slider_smooth) / 10.0f; - jpegdata->method = jlistbox_get_selected_index(list_method); - - set_config_float("JPEG", "Quality", jpegdata->quality); + if (jwindow_get_killer(window) == ok) { + jpeg_options->quality = jslider_get_value(slider_quality) / 10.0f; + set_config_float("JPEG", "Quality", jpeg_options->quality); } else { - filedata_free((FileData *)jpegdata); - jpegdata = NULL; + format_options_free((FormatOptions *)jpeg_options); + jpeg_options = NULL; } jwidget_free(window); - return jpegdata; + return (FormatOptions *)jpeg_options; } diff --git a/src/raster/sprite.c b/src/raster/sprite.c index d21d2d277..19a513e29 100644 --- a/src/raster/sprite.c +++ b/src/raster/sprite.c @@ -98,8 +98,8 @@ Sprite *sprite_new(int imgtype, int w, int h) sprite->locked = FALSE; sprite->mutex = jmutex_new(); - /* file format data */ - sprite->filedata = NULL; + /* file format options */ + sprite->format_options = NULL; /* free the temporary palette */ palette_free(pal); @@ -278,9 +278,9 @@ void sprite_free(Sprite *sprite) /* destroy mutex */ jmutex_free(sprite->mutex); - /* destroy file-data */ - if (sprite->filedata) - filedata_free(sprite->filedata); + /* destroy file format options */ + if (sprite->format_options) + format_options_free(sprite->format_options); /* destroy gfxobj */ gfxobj_free((GfxObj *)sprite); @@ -436,12 +436,12 @@ void sprite_set_filename(Sprite *sprite, const char *filename) strcpy(sprite->filename, filename); } -void sprite_set_filedata(Sprite *sprite, struct FileData *filedata) +void sprite_set_format_options(Sprite *sprite, struct FormatOptions *format_options) { - if (sprite->filedata) - jfree(sprite->filedata); + if (sprite->format_options) + jfree(sprite->format_options); - sprite->filedata = filedata; + sprite->format_options = format_options; } void sprite_set_size(Sprite *sprite, int w, int h) diff --git a/src/raster/sprite.h b/src/raster/sprite.h index 3efc472bf..174be8a9a 100644 --- a/src/raster/sprite.h +++ b/src/raster/sprite.h @@ -22,7 +22,7 @@ #include "jinete/jbase.h" #include "raster/gfxobj.h" -struct FileData; +struct FormatOptions; struct Image; struct Layer; struct Mask; @@ -33,6 +33,9 @@ struct Undo; typedef struct Sprite Sprite; +/** + * The main structure used in the whole program to handle a sprite. + */ struct Sprite { GfxObj gfxobj; @@ -55,20 +58,34 @@ struct Sprite JList paths; /* paths */ JList masks; /* masks */ } repository; + + /** + * Selected mask region boundaries + */ struct { int nseg; struct _BoundSeg *seg; - } bound; /* selected mask region boundaries */ + } bound; struct { int scroll_x; int scroll_y; int zoom; } preferred; - JMutex mutex; /* mutex to modify the 'locked' flag */ - bool locked; /* true when a thread is - reading/writing the sprite */ - struct FileData *filedata; /* data to save the file in the same - format that it was loaded */ + + /** + * Mutex to modify the 'locked' flag. + */ + JMutex mutex; + + /** + * True when a thread is reading/writing the sprite. + */ + bool locked; + + /** + * Data to save the file in the same format that it was loaded + */ + struct FormatOptions *format_options; }; Sprite *sprite_new(int imgtype, int w, int h); @@ -92,7 +109,7 @@ void sprite_set_palette(Sprite *sprite, struct Palette *pal, bool truncate); void sprite_reset_palettes(Sprite *sprite); void sprite_set_filename(Sprite *sprite, const char *filename); -void sprite_set_filedata(Sprite *sprite, struct FileData *filedata); +void sprite_set_format_options(Sprite *sprite, struct FormatOptions *format_options); void sprite_set_size(Sprite *sprite, int w, int h); void sprite_set_frames(Sprite *sprite, int frames); void sprite_set_frlen(Sprite *sprite, int msecs, int frame);