Commit e1cbe6f1 authored by Murray Cumming's avatar Murray Cumming
Browse files

ImageGlom: Do not transform to PNG output when saving.

* glom/utility_widgets/dialog_image_save_progress.[h|cc]: Replace set_pixbuf()
with set_image_data().
save(): Save the original data, instead of saving the data from the pixbuf.
* glom/utility_widgets/imageglom.cc: Adapt.
This means, for instance, that if the user loads the a JPG in then they will
get exactly the same JPG out.
parent b9ed12fd
2011-07-12 Murray Cumming <murrayc@murrayc.com>
ImageGlom: Do not transform to PNG output when saving.
* glom/utility_widgets/dialog_image_save_progress.[h|cc]: Replace set_pixbuf()
with set_image_data().
save(): Save the original data, instead of saving the data from the pixbuf.
* glom/utility_widgets/imageglom.cc: Adapt.
This means, for instance, that if the user loads the a JPG in then they will
get exactly the same JPG out.
2011-07-12 Murray Cumming <murrayc@murrayc.com>
Some minor signed type corrections.
......
......@@ -31,7 +31,8 @@ const char* DialogImageSaveProgress::glade_id("dialog_image_save_progress");
const bool DialogImageSaveProgress::glade_developer(false);
DialogImageSaveProgress::DialogImageSaveProgress(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
: Gtk::Dialog(cobject)
: Gtk::Dialog(cobject),
m_data(0)
{
builder->get_widget("progress_bar", m_progress_bar);
......@@ -45,22 +46,59 @@ DialogImageSaveProgress::~DialogImageSaveProgress()
void DialogImageSaveProgress::save(const Glib::ustring& uri)
{
//TODO: Support non-local URIs when we do this properly, using Gio::File.
const std::string filepath = Glib::filename_from_uri(uri);
m_progress_bar->set_text(Glib::ustring::compose("Saving %1...",
Glib::filename_display_basename(filepath)));
g_assert(m_data);
if(m_data->data == 0)
return;
if(m_data->binary_length == 0)
return;
m_file = Gio::File::create_for_uri(uri);
m_progress_bar->set_text(Glib::ustring::compose("Saving %1...", m_file->get_parse_name()));
m_stream.reset();
try
{
// Open the file for reading:
m_pixbuf->save(filepath, GLOM_IMAGE_FORMAT);
if(m_file->query_exists())
{
m_stream = m_file->replace(); //Instead of append_to().
}
else
{
//By default files created are generally readable by everyone, but if we pass FILE_CREATE_PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.
//TODO: Do we want to specify 0660 exactly? (means "this user and his group can read and write this non-executable file".)
m_stream = m_file->create_file();
}
}
catch(const Gio::Error& ex)
{
std::cerr << G_STRFUNC << ": exception: " << ex.what() << std::endl;
response(Gtk::RESPONSE_REJECT);
return;
}
catch(const Glib::Error& ex)
//Write the data to the output uri
gssize bytes_written = 0;
try
{
bytes_written = m_stream->write(m_data->data, m_data->binary_length);
}
catch(const Gio::Error& ex)
{
std::cerr << G_STRFUNC << ": exception: " << ex.what() << std::endl;
response(Gtk::RESPONSE_REJECT);
return;
}
if(bytes_written != m_data->binary_length)
{
error(ex.what());
std::cerr << G_STRFUNC << ": unexpected number of bytes written: bytes_written=" << bytes_written <<
", binary_length=" << m_data->binary_length << std::endl;
}
//response(Gtk::RESPONSE_ACCEPT);
response(Gtk::RESPONSE_ACCEPT);
}
void DialogImageSaveProgress::error(const Glib::ustring& error_message)
......@@ -74,9 +112,9 @@ void DialogImageSaveProgress::error(const Glib::ustring& error_message)
}
void DialogImageSaveProgress::set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)
void DialogImageSaveProgress::set_image_data(const GdaBinary& data)
{
m_pixbuf = pixbuf;
m_data = &data;
}
} // namespace Glom
......@@ -24,8 +24,9 @@
#include <gtkmm/dialog.h>
#include <gtkmm/builder.h>
#include <gtkmm/progressbar.h>
#include <libglom/data_structure/layout/layoutitem_image.h> //For the file formats.
//#include <memory>
#include <giomm/file.h>
#include <giomm/fileoutputstream.h>
#include <libgda/libgda.h>
namespace Glom
{
......@@ -41,13 +42,16 @@ public:
void save(const Glib::ustring& uri);
void set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
void set_image_data(const GdaBinary& data);
private:
void error(const Glib::ustring& error_message);
Glib::RefPtr<Gdk::Pixbuf> m_pixbuf;
Gtk::ProgressBar* m_progress_bar;
const GdaBinary* m_data;
Glib::RefPtr<Gio::File> m_file;
Glib::RefPtr<Gio::FileOutputStream> m_stream;
};
} //namespace Glom
......
......@@ -442,7 +442,11 @@ bool ImageGlom::save_file(const Glib::ustring& uri)
if(pApp)
dialog_save->set_transient_for(*pApp);
dialog_save->set_pixbuf(m_pixbuf_original);
const GdaBinary* gda_binary = gda_value_get_binary(m_original_data.gobj());
if(!gda_binary)
return false;
dialog_save->set_image_data(*gda_binary);
dialog_save->save(uri);
//TODO: Use this when we do async saving:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment