From kde-commits Tue Jul 31 22:38:07 2007 From: Cyrille Berger Date: Tue, 31 Jul 2007 22:38:07 +0000 To: kde-commits Subject: koffice/krita/ui Message-Id: <1185921487.920255.14250.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=118592149608418 SVN commit 694858 by berger: fix saving png file to a file M +23 -22 kis_png_converter.cpp --- trunk/koffice/krita/ui/kis_png_converter.cpp #694857:694858 @@ -188,10 +188,10 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod) { - kDebug(41008) <<"Start decoding PNG File"; + kDebug(41008) << "Start decoding PNG File" << endl; if(not iod->open(QIODevice::ReadOnly)) { - kDebug(41008) <<"Failed to open PNG File"; + kDebug(41008) << "Failed to open PNG File" << endl; return (KisImageBuilder_RESULT_FAILURE); } @@ -283,24 +283,24 @@ profile = new KoIccColorProfile(profile_rawdata); Q_CHECK_PTR(profile); if (profile) { -// kDebug(41008) <<"profile name:" << profile->productName() <<" profile description:" << profile->productDescription() <<" information sur le produit:" << profile->productInfo(); +// kDebug(41008) << "profile name: " << profile->productName() << " profile description: " << profile->productDescription() << " information sur le produit: " << profile->productInfo() << endl; if(!profile->isSuitableForOutput()) { - kDebug(41008) <<"the profile is not suitable for output and therefore cannot be used in krita, we need to convert the image to a standard profile"; // TODO: in ko2 popup a selection menu to inform the user + kDebug(41008) << "the profile is not suitable for output and therefore cannot be used in krita, we need to convert the image to a standard profile" << endl; // TODO: in ko2 popup a selection menu to inform the user } } } else { - kDebug(41008) <<"Profile isn't ICC, skiped."; + kDebug(41008) << "Profile isn't ICC, skiped." << endl; } } else { - kDebug(41008) <<"no embedded profile, will use the default profile"; + kDebug(41008) << "no embedded profile, will use the default profile" << endl; } // Retrieve a pointer to the colorspace KoColorSpace* cs; if (profile && profile->isSuitableForOutput()) { - kDebug(41008) <<"image has embedded profile:" << profile -> name() <<""; + kDebug(41008) << "image has embedded profile: " << profile -> name() << "\n"; cs = KoColorSpaceRegistry::instance()->colorSpace(csName, profile); } else @@ -330,10 +330,10 @@ if(m_doc) { KoDocumentInfo * info = m_doc->documentInfo(); - kDebug(41008) <<"There are" << num_comments <<" comments in the text"; + kDebug(41008) << "There are " << num_comments << " comments in the text" << endl; for(int i = 0; i < num_comments; i++) { - kDebug(41008) <<"key is" << text_ptr[i].key <<" containing" << text_ptr[i].text; + kDebug(41008) << "key is " << text_ptr[i].key << " containing " << text_ptr[i].text << endl; if(QString::compare(text_ptr[i].key, "title") == 0) { info->setAboutInfo("title", text_ptr[i].text); @@ -358,7 +358,7 @@ { // new png_byte[] may raise such an exception if the image // is invalid / to large. - kDebug(41008) <<"bad alloc:" << e.what(); + kDebug(41008) << "bad alloc: " << e.what() << endl; // Free only the already allocated png_byte instances. png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); return (KisImageBuilder_RESULT_FAILURE); @@ -494,7 +494,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(const KUrl& uri) { - kDebug(41008) << QFile::encodeName(uri.path()) <<"" << uri.path() <<"" << uri; + kDebug(41008) << QFile::encodeName(uri.path()) << " " << uri.path() << " " << uri << endl; if (uri.isEmpty()) return KisImageBuilder_RESULT_NO_URI; @@ -511,7 +511,7 @@ uriTF.setPath( tmpFile ); // open the file - kDebug(41008) << QFile::encodeName(uriTF.path()) <<"" << uriTF.path() <<"" << uriTF; + kDebug(41008) << QFile::encodeName(uriTF.path()) << " " << uriTF.path() << " " << uriTF << endl; QFile *fp = new QFile(QFile::encodeName(uriTF.path()) ); if (fp->exists()) { @@ -535,15 +535,17 @@ KisImageBuilder_Result KisPNGConverter::buildFile(const KUrl& uri, KisImageSP img, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, int compression, bool interlace, bool alpha) { - kDebug(41008) <<"Start writing PNG File"; + kDebug(41008) << "Start writing PNG File " << uri << endl; if (uri.isEmpty()) return KisImageBuilder_RESULT_NO_URI; if (!uri.isLocalFile()) return KisImageBuilder_RESULT_NOT_LOCAL; // Open a QIODevice for writting - QFile *fp = new QFile(QFile::encodeName(uri.path()) ); - return buildFile(fp, img, device, annotationsStart, annotationsEnd, compression, interlace, alpha); + QFile *fp = new QFile( QFile::encodeName(uri.path()) ); + KisImageBuilder_Result result = buildFile(fp, img, device, annotationsStart, annotationsEnd, compression, interlace, alpha); + delete fp; + return result; // TODO: if failure do KIO::del(uri); // async } @@ -552,7 +554,7 @@ { if(not iodevice->open(QIODevice::WriteOnly)) { - kDebug(41008) <<"Failed to open PNG File for writting"; + kDebug(41008) << "Failed to open PNG File for writting" << endl; return (KisImageBuilder_RESULT_FAILURE); } @@ -651,7 +653,7 @@ } if(!toomuchcolor) { - kDebug(41008) <<"Found a palette of" << num_palette <<" colors"; + kDebug(41008) << "Found a palette of " << num_palette << " colors" << endl; color_type = PNG_COLOR_TYPE_PALETTE; if( num_palette <= 2) { @@ -689,16 +691,16 @@ vKisAnnotationSP_it it = annotationsStart; while(it != annotationsEnd) { if (!(*it) || (*it) -> type() == QString()) { - kDebug(41008) <<"Warning: empty annotation"; + kDebug(41008) << "Warning: empty annotation" << endl; ++it; continue; } - kDebug(41008) <<"Trying to store annotation of type" << (*it) -> type() <<" of size" << (*it) -> annotation() . size(); + kDebug(41008) << "Trying to store annotation of type " << (*it) -> type() << " of size " << (*it) -> annotation() . size() << endl; if ((*it) -> type().startsWith("krita_attribute:")) { // Attribute // FIXME: it should be possible to save krita_attributes in the "CHUNKs" - kDebug(41008) <<"can't save this annotation :" << (*it) -> type(); + kDebug(41008) << "can't save this annotation : " << (*it) -> type() << endl; } else { // Profile char* name = new char[(*it)->type().length()+1]; strcpy(name, (*it)->type().toAscii()); @@ -749,7 +751,6 @@ // Fill the data structure png_byte** row_pointers= new png_byte*[height]; - for (int y = 0; y < height; y++) { KisHLineConstIterator it = device->createHLineConstIterator(0, y, width); row_pointers[y] = new png_byte[width*device->pixelSize()]; @@ -844,7 +845,7 @@ { delete [] palette; } - + iodevice->close(); return KisImageBuilder_RESULT_OK; }