From: Dominic L. <ma...@us...> - 2004-06-10 15:18:52
|
Update of /cvsroot/robotflow/RobotFlow/Vision/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21337 Modified Files: JPEGSave.cc Log Message: can now save JPEG data with a determined quality to memory (string) Index: JPEGSave.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/JPEGSave.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JPEGSave.cc 8 Jul 2003 17:18:20 -0000 1.1 --- JPEGSave.cc 10 Jun 2004 15:18:43 -0000 1.2 *************** *** 44,54 **** * @input_description file name to save probe content (JPEG) * ! * @output_name OUTPUT * @output_type Image * @output_description The same as the input image ! * * END*/ class JPEGSave : public BufferedNode { --- 44,72 ---- * @input_description file name to save probe content (JPEG) * ! * @output_name IMAGE * @output_type Image * @output_description The same as the input image ! * ! * @output_name JPEG_DATA ! * @output_type string ! * @output_description Raw (binary) JPEG data. ! * ! * @parameter_name QUALITY ! * @parameter_type string ! * @parameter_value 80 ! * @parameter_description string to indicate the quality of the compression, [0 to 100] (%) * END*/ + + gboolean pixbuf_save_callback(const gchar *buf, gsize count, GError **error, gpointer data_string) { + + string *my_string = reinterpret_cast<string*>(data_string); + + if (my_string) { + *my_string += string(buf,count); + } + } + class JPEGSave : public BufferedNode { *************** *** 58,63 **** --- 76,83 ---- int m_fileID; int m_outputID; + int m_jpegID; GdkPixbuf *m_pixbuf; + String m_quality; *************** *** 72,76 **** //output(s) ! m_outputID = addOutput("OUTPUT"); g_type_init(); --- 92,100 ---- //output(s) ! m_outputID = addOutput("IMAGE"); ! m_jpegID = addOutput("JPEG_DATA"); ! ! //parameters ! m_quality = object_cast<String>(parameters.get("QUALITY")); g_type_init(); *************** *** 78,87 **** } ! void write_pixbuf(Image &my_image, const String &filename) { //create pixbuf m_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, my_image.get_width(), my_image.get_height()); - if (my_image.get_pixelsize() == 1) { --- 102,110 ---- } ! void write_pixbuf(Image &my_image, const String &filename, bool write_mem, bool write_file, string &data_string) { //create pixbuf m_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, my_image.get_width(), my_image.get_height()); if (my_image.get_pixelsize() == 1) { *************** *** 144,153 **** GError *error = & error1; ! //saving pixbuf ! gdk_pixbuf_save (m_pixbuf,filename.c_str(), "jpeg", &error,"quality", "100", NULL); //destroy pixbuf (ref will be decreased and object should be finalized) gdk_pixbuf_unref(m_pixbuf); - } --- 167,193 ---- GError *error = & error1; ! //saving pixbuf to file ! if (write_file) { ! gdk_pixbuf_save (m_pixbuf,filename.c_str(), "jpeg", &error,"quality",m_quality.c_str(), NULL); ! } ! //saving pixbuf to memory ! if (write_mem) { ! ! gboolean retval = gdk_pixbuf_save_to_callback (m_pixbuf, ! pixbuf_save_callback, ! &data_string, ! "jpeg", ! NULL, ! "quality", ! m_quality.c_str(),NULL); ! ! if (!retval) { ! throw new GeneralException("JPEGSave : Unable to save JPEG data to memory",__FILE__,__LINE__); ! } ! ! } //destroy pixbuf (ref will be decreased and object should be finalized) gdk_pixbuf_unref(m_pixbuf); } *************** *** 158,169 **** ObjectRef inputValue = getInput(m_inputID, count); ObjectRef FilenameValue = getInput(m_fileID,count); - - if (!inputValue->isNil() && !FilenameValue->isNil()) { - write_pixbuf(object_cast<Image>(inputValue),object_cast<String>(FilenameValue)); } ! //output the same thing ! out[count] = inputValue; }//try --- 198,221 ---- ObjectRef inputValue = getInput(m_inputID, count); ObjectRef FilenameValue = getInput(m_fileID,count); + String* image_data = new String; + + if (!inputValue->isNil()) { + if (!FilenameValue->isNil()) { + //write JPEG file + write_pixbuf(object_cast<Image>(inputValue),object_cast<String>(FilenameValue), true, true, *image_data); + } + else { + //write JPEG data into memory + write_pixbuf(object_cast<Image>(inputValue),string(""), true, false, *image_data); + } } ! //output the image ! (*outputs[m_outputID].buffer)[count] = inputValue; ! ! ! //output the JPEG data ! (*outputs[m_jpegID].buffer)[count] = ObjectRef (image_data); }//try |