Skip to content

Commit

Permalink
* Fixed errors when saving grayscale or indexed images
Browse files Browse the repository at this point in the history
  * Layers are now resized and offset as appropriate when saved as frames/faces/slices
  • Loading branch information
t_edwards@btinternet.com committed May 29, 2011
1 parent fccd53f commit 83b66bd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
55 changes: 43 additions & 12 deletions gimp-vtf/file-vtf-save.c
Expand Up @@ -59,6 +59,9 @@ void save(gint nparams, const GimpParam* param, gint* nreturn_vals)
guint* layer_iterator;

gchar* progress_frame_label;

GimpImageBaseType img_type;
gint colourmap_size;

vlUInt vtf_bindcode;
SVTFCreateOptions vlVTFOpt;
Expand Down Expand Up @@ -132,6 +135,19 @@ void save(gint nparams, const GimpParam* param, gint* nreturn_vals)
if (alpha_layer_ID)
layers_to_export--;

// convert image to RGB. It would be nice if this could happen per-drawable!
img_type = gimp_image_base_type(image_ID);
switch( img_type )
{
case GIMP_RGB:
break;
case GIMP_INDEXED:
gimp_image_get_colormap(image_ID,&colourmap_size);
case GIMP_GRAY:
gimp_image_convert_rgb(image_ID);
break;
}

switch(gimpVTFOpt.FrameMode)
{
case VTF_MERGE_VISIBLE:
Expand Down Expand Up @@ -185,30 +201,32 @@ void save(gint nparams, const GimpParam* param, gint* nreturn_vals)
GimpPixelRgn pixel_rgn;
GimpDrawable* drawable;
vlByte* rgbaBuf;
gboolean added_to_img;

if ( layer_IDs[*layer_iterator] == alpha_layer_ID )
return;

if (gimpVTFOpt.FrameMode != VTF_MERGE_VISIBLE)
{
drawable_ID = gimp_layer_new_from_drawable(layer_IDs[*layer_iterator],image_ID);

gimp_image_add_layer(image_ID,drawable_ID,-1);
gimp_layer_resize_to_image_size(drawable_ID);
added_to_img = TRUE;
}

if (alpha_layer_ID)
{
gimp_image_add_layer(image_ID,drawable_ID,0);
if (!added_to_img)
{
gimp_image_add_layer(image_ID,drawable_ID,0);
added_to_img = TRUE;
}

gimp_layer_add_mask( drawable_ID, gimp_layer_create_mask(alpha_layer_ID,GIMP_ADD_COPY_MASK) );
gimp_layer_remove_mask( drawable_ID, GIMP_MASK_APPLY );
}

switch( gimp_drawable_type(drawable_ID) )
{
default:
gimp_image_convert_rgb(drawable_ID);
case GIMP_RGBA_IMAGE:
case GIMP_RGB_IMAGE:
break;
}

gimp_layer_add_alpha(drawable_ID); // always want to send VTFLib an alpha channel

// Get drawable info
Expand All @@ -234,7 +252,7 @@ void save(gint nparams, const GimpParam* param, gint* nreturn_vals)
rbgaImages[(guint)layers_to_export - *layer_iterator - 1] = rgbaBuf;
gimp_drawable_detach(drawable);

if (alpha_layer_ID)
if (added_to_img)
gimp_image_remove_layer(image_ID,drawable_ID);
}

Expand Down Expand Up @@ -270,6 +288,19 @@ void save(gint nparams, const GimpParam* param, gint* nreturn_vals)
g_free(rbgaImages[i]);
g_free(rbgaImages);
vlDeleteImage(vtf_bindcode);

// restore image colour type
switch( img_type )
{
case GIMP_RGB:
break;
case GIMP_INDEXED:
gimp_image_convert_indexed(image_ID,GIMP_NO_DITHER,GIMP_MAKE_PALETTE,colourmap_size,FALSE,FALSE,"null");
break;
case GIMP_GRAY:
gimp_image_convert_grayscale(image_ID);
break;
}

// loose UI ends
gimp_progress_end();
Expand Down Expand Up @@ -436,7 +467,7 @@ static gboolean show_options(gint32 image_ID)
_("Nothing (merge visible)"), VTF_MERGE_VISIBLE,
_("Animation frames"), VTF_ANIMATION,
_("Environment map faces"), VTF_ENVMAP,
_("Volumetrix texture slices"), VTF_VOLUME,
_("Volumetric texture slices"), VTF_VOLUME,
NULL);

g_signal_connect (LayerUseCombo, "changed", G_CALLBACK (change_frame_use), NULL);
Expand Down
6 changes: 3 additions & 3 deletions gimp-vtf/file-vtf.c
Expand Up @@ -69,7 +69,7 @@ static void query()
"Reads Valve Texture Format files. Uses VTFLib, by Nem and Wunderboy.",
"Tom Edwards (contact@steamreview.org)",
"Tom Edwards (contact@steamreview.org)",
"2010",
"2011",
N_("Valve Texture Format"),
NULL,
GIMP_PLUGIN,
Expand All @@ -85,7 +85,7 @@ static void query()
"Loads a low mipmap from halfway through the VTF's frames/faces/slices. Uses VTFLib, by Nem and Wunderboy.",
"Tom Edwards (contact@steamreview.org)",
"Tom Edwards (contact@steamreview.org)",
"2010",
"2011",
NULL,
NULL,
GIMP_PLUGIN,
Expand All @@ -100,7 +100,7 @@ static void query()
"Writes out Valve Texture Format files with any compression method. Uses VTFLib, by Nem and Wunderboy.",
"Tom Edwards (contact@steamreview.org)",
"Tom Edwards (contact@steamreview.org)",
"2010",
"2011",
N_("Valve Texture Format"),
"*",
GIMP_PLUGIN,
Expand Down
2 changes: 1 addition & 1 deletion gimp-vtf/file-vtf.rc
Expand Up @@ -4,7 +4,7 @@

LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 VERSIONINFO
FILEVERSION 1,0,2,0
FILEVERSION 1,0,3,0
PRODUCTVERSION 2,6,11,0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
Expand Down
11 changes: 8 additions & 3 deletions readme.txt
@@ -1,6 +1,6 @@
GIMP VTF PLUG-IN 1.0.2
Tom Edwards, 29th November 2010
*******************************
GIMP VTF PLUG-IN 1.0.3
Tom Edwards, 29th May 2011
*******************************

To install, extract both the EXE and DLL to your
GIMP plug-ins folder. This is typically at
Expand All @@ -16,6 +16,11 @@ source code, visit <http://code.google.com/p/gimp-vtf/>.
Changes
*******

1.0.3
* Fixed errors when saving grayscale or indexed images
* Layers are now resized and offset as appropriate when
saved as frames/faces/slices

1.0.2
* Fixed GIMP error report on toggling "Use layer as alpha
channel" when there are no suitable layers
Expand Down

0 comments on commit 83b66bd

Please sign in to comment.