From 9cb94c1d1271bccb7e3847111069f2fe53a665e8 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Wed, 7 Aug 2024 18:37:36 +0200 Subject: [PATCH 1/7] =?UTF-8?q?Adaptation=20=C3=A0=20la=20lib=20core=20rok?= =?UTF-8?q?4=202.0.0=20(non=20termin=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.tmp | 3 + LICENSE.txt | 517 +++++++++++++++++++++++++++++++ README.md | 21 +- config.h.in | 3 - src/cache2work.cpp | 32 +- src/checkWork.cpp | 5 +- src/composeNtiff.cpp | 54 ++-- src/decimateNtiff.cpp | 178 +++++------ src/manageNodata.cpp | 45 ++- src/merge4tiff.cpp | 142 ++++----- src/mergeNtiff.cpp | 700 +++++++++++++++++++++--------------------- src/overlayNtiff.cpp | 73 ++--- src/pbf2cache.cpp | 14 +- src/work2cache.cpp | 136 +++----- 14 files changed, 1138 insertions(+), 785 deletions(-) create mode 100644 CHANGELOG.tmp create mode 100644 LICENSE.txt diff --git a/CHANGELOG.tmp b/CHANGELOG.tmp new file mode 100644 index 0000000..b3fec80 --- /dev/null +++ b/CHANGELOG.tmp @@ -0,0 +1,3 @@ +* Le format des canaux contient la taille en bits +* Passage en snake case +* Suppression de l'option crop dans work2cache \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..2bb09b4 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,517 @@ + +CeCILL-C FREE SOFTWARE LICENSE AGREEMENT + + + Notice + +This Agreement is a Free Software license agreement that is the result +of discussions between its authors in order to ensure compliance with +the two main principles guiding its drafting: + + * firstly, compliance with the principles governing the distribution + of Free Software: access to source code, broad rights granted to + users, + * secondly, the election of a governing law, French law, with which + it is conformant, both as regards the law of torts and + intellectual property law, and the protection that it offers to + both authors and holders of the economic rights over software. + +The authors of the CeCILL-C (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) +license are: + +Commissariat à l'Energie Atomique - CEA, a public scientific, technical +and industrial research establishment, having its principal place of +business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France. + +Centre National de la Recherche Scientifique - CNRS, a public scientific +and technological establishment, having its principal place of business +at 3 rue Michel-Ange, 75794 Paris cedex 16, France. + +Institut National de Recherche en Informatique et en Automatique - +INRIA, a public scientific and technological establishment, having its +principal place of business at Domaine de Voluceau, Rocquencourt, BP +105, 78153 Le Chesnay cedex, France. + + + Preamble + +The purpose of this Free Software license agreement is to grant users +the right to modify and re-use the software governed by this license. + +The exercising of this right is conditional upon the obligation to make +available to the community the modifications made to the source code of +the software so as to contribute to its evolution. + +In consideration of access to the source code and the rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors only have limited liability. + +In this respect, the risks associated with loading, using, modifying +and/or developing or reproducing the software by the user are brought to +the user's attention, given its Free Software status, which may make it +complicated to use, with the result that its use is reserved for +developers and experienced professionals having in-depth computer +knowledge. Users are therefore encouraged to load and test the +suitability of the software as regards their requirements in conditions +enabling the security of their systems and/or data to be ensured and, +more generally, to use and operate it in the same conditions of +security. This Agreement may be freely reproduced and published, +provided it is not altered, and that no provisions are either added or +removed herefrom. + +This Agreement may apply to any or all software for which the holder of +the economic rights decides to submit the use thereof to its provisions. + + + Article 1 - DEFINITIONS + +For the purpose of this Agreement, when the following expressions +commence with a capital letter, they shall have the following meaning: + +Agreement: means this license agreement, and its possible subsequent +versions and annexes. + +Software: means the software in its Object Code and/or Source Code form +and, where applicable, its documentation, "as is" when the Licensee +accepts the Agreement. + +Initial Software: means the Software in its Source Code and possibly its +Object Code form and, where applicable, its documentation, "as is" when +it is first distributed under the terms and conditions of the Agreement. + +Modified Software: means the Software modified by at least one +Integrated Contribution. + +Source Code: means all the Software's instructions and program lines to +which access is required so as to modify the Software. + +Object Code: means the binary files originating from the compilation of +the Source Code. + +Holder: means the holder(s) of the economic rights over the Initial +Software. + +Licensee: means the Software user(s) having accepted the Agreement. + +Contributor: means a Licensee having made at least one Integrated +Contribution. + +Licensor: means the Holder, or any other individual or legal entity, who +distributes the Software under the Agreement. + +Integrated Contribution: means any or all modifications, corrections, +translations, adaptations and/or new functions integrated into the +Source Code by any or all Contributors. + +Related Module: means a set of sources files including their +documentation that, without modification to the Source Code, enables +supplementary functions or services in addition to those offered by the +Software. + +Derivative Software: means any combination of the Software, modified or +not, and of a Related Module. + +Parties: mean both the Licensee and the Licensor. + +These expressions may be used both in singular and plural form. + + + Article 2 - PURPOSE + +The purpose of the Agreement is the grant by the Licensor to the +Licensee of a non-exclusive, transferable and worldwide license for the +Software as set forth in Article 5 hereinafter for the whole term of the +protection granted by the rights over said Software. + + + Article 3 - ACCEPTANCE + +3.1 The Licensee shall be deemed as having accepted the terms and +conditions of this Agreement upon the occurrence of the first of the +following events: + + * (i) loading the Software by any or all means, notably, by + downloading from a remote server, or by loading from a physical + medium; + * (ii) the first time the Licensee exercises any of the rights + granted hereunder. + +3.2 One copy of the Agreement, containing a notice relating to the +characteristics of the Software, to the limited warranty, and to the +fact that its use is restricted to experienced users has been provided +to the Licensee prior to its acceptance as set forth in Article 3.1 +hereinabove, and the Licensee hereby acknowledges that it has read and +understood it. + + + Article 4 - EFFECTIVE DATE AND TERM + + + 4.1 EFFECTIVE DATE + +The Agreement shall become effective on the date when it is accepted by +the Licensee as set forth in Article 3.1. + + + 4.2 TERM + +The Agreement shall remain in force for the entire legal term of +protection of the economic rights over the Software. + + + Article 5 - SCOPE OF RIGHTS GRANTED + +The Licensor hereby grants to the Licensee, who accepts, the following +rights over the Software for any or all use, and for the term of the +Agreement, on the basis of the terms and conditions set forth hereinafter. + +Besides, if the Licensor owns or comes to own one or more patents +protecting all or part of the functions of the Software or of its +components, the Licensor undertakes not to enforce the rights granted by +these patents against successive Licensees using, exploiting or +modifying the Software. If these patents are transferred, the Licensor +undertakes to have the transferees subscribe to the obligations set +forth in this paragraph. + + + 5.1 RIGHT OF USE + +The Licensee is authorized to use the Software, without any limitation +as to its fields of application, with it being hereinafter specified +that this comprises: + + 1. permanent or temporary reproduction of all or part of the Software + by any or all means and in any or all form. + + 2. loading, displaying, running, or storing the Software on any or + all medium. + + 3. entitlement to observe, study or test its operation so as to + determine the ideas and principles behind any or all constituent + elements of said Software. This shall apply when the Licensee + carries out any or all loading, displaying, running, transmission + or storage operation as regards the Software, that it is entitled + to carry out hereunder. + + + 5.2 RIGHT OF MODIFICATION + +The right of modification includes the right to translate, adapt, +arrange, or make any or all modifications to the Software, and the right +to reproduce the resulting software. It includes, in particular, the +right to create a Derivative Software. + +The Licensee is authorized to make any or all modification to the +Software provided that it includes an explicit notice that it is the +author of said modification and indicates the date of the creation thereof. + + + 5.3 RIGHT OF DISTRIBUTION + +In particular, the right of distribution includes the right to publish, +transmit and communicate the Software to the general public on any or +all medium, and by any or all means, and the right to market, either in +consideration of a fee, or free of charge, one or more copies of the +Software by any means. + +The Licensee is further authorized to distribute copies of the modified +or unmodified Software to third parties according to the terms and +conditions set forth hereinafter. + + + 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION + +The Licensee is authorized to distribute true copies of the Software in +Source Code or Object Code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's + warranty and liability as set forth in Articles 8 and 9, + +and that, in the event that only the Object Code of the Software is +redistributed, the Licensee allows effective access to the full Source +Code of the Software at a minimum during the entire period of its +distribution of the Software, it being understood that the additional +cost of acquiring the Source Code shall not exceed the cost of +transferring the data. + + + 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE + +When the Licensee makes an Integrated Contribution to the Software, the +terms and conditions for the distribution of the resulting Modified +Software become subject to all the provisions of this Agreement. + +The Licensee is authorized to distribute the Modified Software, in +source code or object code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's + warranty and liability as set forth in Articles 8 and 9, + +and that, in the event that only the object code of the Modified +Software is redistributed, the Licensee allows effective access to the +full source code of the Modified Software at a minimum during the entire +period of its distribution of the Modified Software, it being understood +that the additional cost of acquiring the source code shall not exceed +the cost of transferring the data. + + + 5.3.3 DISTRIBUTION OF DERIVATIVE SOFTWARE + +When the Licensee creates Derivative Software, this Derivative Software +may be distributed under a license agreement other than this Agreement, +subject to compliance with the requirement to include a notice +concerning the rights over the Software as defined in Article 6.4. +In the event the creation of the Derivative Software required modification +of the Source Code, the Licensee undertakes that: + + 1. the resulting Modified Software will be governed by this Agreement, + 2. the Integrated Contributions in the resulting Modified Software + will be clearly identified and documented, + 3. the Licensee will allow effective access to the source code of the + Modified Software, at a minimum during the entire period of + distribution of the Derivative Software, such that such + modifications may be carried over in a subsequent version of the + Software; it being understood that the additional cost of + purchasing the source code of the Modified Software shall not + exceed the cost of transferring the data. + + + 5.3.4 COMPATIBILITY WITH THE CeCILL LICENSE + +When a Modified Software contains an Integrated Contribution subject to +the CeCILL license agreement, or when a Derivative Software contains a +Related Module subject to the CeCILL license agreement, the provisions +set forth in the third item of Article 6.4 are optional. + + + Article 6 - INTELLECTUAL PROPERTY + + + 6.1 OVER THE INITIAL SOFTWARE + +The Holder owns the economic rights over the Initial Software. Any or +all use of the Initial Software is subject to compliance with the terms +and conditions under which the Holder has elected to distribute its work +and no one shall be entitled to modify the terms and conditions for the +distribution of said Initial Software. + +The Holder undertakes that the Initial Software will remain ruled at +least by this Agreement, for the duration set forth in Article 4.2. + + + 6.2 OVER THE INTEGRATED CONTRIBUTIONS + +The Licensee who develops an Integrated Contribution is the owner of the +intellectual property rights over this Contribution as defined by +applicable law. + + + 6.3 OVER THE RELATED MODULES + +The Licensee who develops a Related Module is the owner of the +intellectual property rights over this Related Module as defined by +applicable law and is free to choose the type of agreement that shall +govern its distribution under the conditions defined in Article 5.3.3. + + + 6.4 NOTICE OF RIGHTS + +The Licensee expressly undertakes: + + 1. not to remove, or modify, in any manner, the intellectual property + notices attached to the Software; + + 2. to reproduce said notices, in an identical manner, in the copies + of the Software modified or not; + + 3. to ensure that use of the Software, its intellectual property + notices and the fact that it is governed by the Agreement is + indicated in a text that is easily accessible, specifically from + the interface of any Derivative Software. + +The Licensee undertakes not to directly or indirectly infringe the +intellectual property rights of the Holder and/or Contributors on the +Software and to take, where applicable, vis-à-vis its staff, any and all +measures required to ensure respect of said intellectual property rights +of the Holder and/or Contributors. + + + Article 7 - RELATED SERVICES + +7.1 Under no circumstances shall the Agreement oblige the Licensor to +provide technical assistance or maintenance services for the Software. + +However, the Licensor is entitled to offer this type of services. The +terms and conditions of such technical assistance, and/or such +maintenance, shall be set forth in a separate instrument. Only the +Licensor offering said maintenance and/or technical assistance services +shall incur liability therefor. + +7.2 Similarly, any Licensor is entitled to offer to its licensees, under +its sole responsibility, a warranty, that shall only be binding upon +itself, for the redistribution of the Software and/or the Modified +Software, under terms and conditions that it is free to decide. Said +warranty, and the financial terms and conditions of its application, +shall be subject of a separate instrument executed between the Licensor +and the Licensee. + + + Article 8 - LIABILITY + +8.1 Subject to the provisions of Article 8.2, the Licensee shall be +entitled to claim compensation for any direct loss it may have suffered +from the Software as a result of a fault on the part of the relevant +Licensor, subject to providing evidence thereof. + +8.2 The Licensor's liability is limited to the commitments made under +this Agreement and shall not be incurred as a result of in particular: +(i) loss due the Licensee's total or partial failure to fulfill its +obligations, (ii) direct or consequential loss that is suffered by the +Licensee due to the use or performance of the Software, and (iii) more +generally, any consequential loss. In particular the Parties expressly +agree that any or all pecuniary or business loss (i.e. loss of data, +loss of profits, operating loss, loss of customers or orders, +opportunity cost, any disturbance to business activities) or any or all +legal proceedings instituted against the Licensee by a third party, +shall constitute consequential loss and shall not provide entitlement to +any or all compensation from the Licensor. + + + Article 9 - WARRANTY + +9.1 The Licensee acknowledges that the scientific and technical +state-of-the-art when the Software was distributed did not enable all +possible uses to be tested and verified, nor for the presence of +possible defects to be detected. In this respect, the Licensee's +attention has been drawn to the risks associated with loading, using, +modifying and/or developing and reproducing the Software which are +reserved for experienced users. + +The Licensee shall be responsible for verifying, by any or all means, +the suitability of the product for its requirements, its good working +order, and for ensuring that it shall not cause damage to either persons +or properties. + +9.2 The Licensor hereby represents, in good faith, that it is entitled +to grant all the rights over the Software (including in particular the +rights set forth in Article 5). + +9.3 The Licensee acknowledges that the Software is supplied "as is" by +the Licensor without any other express or tacit warranty, other than +that provided for in Article 9.2 and, in particular, without any warranty +as to its commercial value, its secured, safe, innovative or relevant +nature. + +Specifically, the Licensor does not warrant that the Software is free +from any error, that it will operate without interruption, that it will +be compatible with the Licensee's own equipment and software +configuration, nor that it will meet the Licensee's requirements. + +9.4 The Licensor does not either expressly or tacitly warrant that the +Software does not infringe any third party intellectual property right +relating to a patent, software or any other property right. Therefore, +the Licensor disclaims any and all liability towards the Licensee +arising out of any or all proceedings for infringement that may be +instituted in respect of the use, modification and redistribution of the +Software. Nevertheless, should such proceedings be instituted against +the Licensee, the Licensor shall provide it with technical and legal +assistance for its defense. Such technical and legal assistance shall be +decided on a case-by-case basis between the relevant Licensor and the +Licensee pursuant to a memorandum of understanding. The Licensor +disclaims any and all liability as regards the Licensee's use of the +name of the Software. No warranty is given as regards the existence of +prior rights over the name of the Software or as regards the existence +of a trademark. + + + Article 10 - TERMINATION + +10.1 In the event of a breach by the Licensee of its obligations +hereunder, the Licensor may automatically terminate this Agreement +thirty (30) days after notice has been sent to the Licensee and has +remained ineffective. + +10.2 A Licensee whose Agreement is terminated shall no longer be +authorized to use, modify or distribute the Software. However, any +licenses that it may have granted prior to termination of the Agreement +shall remain valid subject to their having been granted in compliance +with the terms and conditions hereof. + + + Article 11 - MISCELLANEOUS + + + 11.1 EXCUSABLE EVENTS + +Neither Party shall be liable for any or all delay, or failure to +perform the Agreement, that may be attributable to an event of force +majeure, an act of God or an outside cause, such as defective +functioning or interruptions of the electricity or telecommunications +networks, network paralysis following a virus attack, intervention by +government authorities, natural disasters, water damage, earthquakes, +fire, explosions, strikes and labor unrest, war, etc. + +11.2 Any failure by either Party, on one or more occasions, to invoke +one or more of the provisions hereof, shall under no circumstances be +interpreted as being a waiver by the interested Party of its right to +invoke said provision(s) subsequently. + +11.3 The Agreement cancels and replaces any or all previous agreements, +whether written or oral, between the Parties and having the same +purpose, and constitutes the entirety of the agreement between said +Parties concerning said purpose. No supplement or modification to the +terms and conditions hereof shall be effective as between the Parties +unless it is made in writing and signed by their duly authorized +representatives. + +11.4 In the event that one or more of the provisions hereof were to +conflict with a current or future applicable act or legislative text, +said act or legislative text shall prevail, and the Parties shall make +the necessary amendments so as to comply with said act or legislative +text. All other provisions shall remain effective. Similarly, invalidity +of a provision of the Agreement, for any reason whatsoever, shall not +cause the Agreement as a whole to be invalid. + + + 11.5 LANGUAGE + +The Agreement is drafted in both French and English and both versions +are deemed authentic. + + + Article 12 - NEW VERSIONS OF THE AGREEMENT + +12.1 Any person is authorized to duplicate and distribute copies of this +Agreement. + +12.2 So as to ensure coherence, the wording of this Agreement is +protected and may only be modified by the authors of the License, who +reserve the right to periodically publish updates or new versions of the +Agreement, each with a separate number. These subsequent versions may +address new issues encountered by Free Software. + +12.3 Any Software distributed under a given version of the Agreement may +only be subsequently distributed under the same version of the Agreement +or a subsequent version. + + + Article 13 - GOVERNING LAW AND JURISDICTION + +13.1 The Agreement is governed by French law. The Parties agree to +endeavor to seek an amicable solution to any disagreements or disputes +that may arise during the performance of the Agreement. + +13.2 Failing an amicable solution within two (2) months as from their +occurrence, and unless emergency proceedings are necessary, the +disagreements or disputes shall be referred to the Paris Courts having +jurisdiction, by the more diligent Party. + + +Version 1.0 dated 2006-09-05. diff --git a/README.md b/README.md index e7f551d..5478c71 100644 --- a/README.md +++ b/README.md @@ -145,8 +145,7 @@ Les informations sur les canaux (nombre, taille en bits et format) peuvent : * `-f ` : fichier de configuration contenant l'image en sortie et la liste des images en entrée, avec leur géoréférencement et les masques éventuels * `-c ` : compression des données dans l'image TIFF en sortie : jpg, jpg90, raw (défaut), zip, lzw, pkb * `-n ` : couleur de nodata, valeurs décimales pour chaque canal, séparées par des virgules (exemple : 255,255,255 pour du blanc sans transparence) -* `-a ` : format des canaux : float, uint -* `-b ` : nombre de bits pour un canal : 8, 32 +* `-a ` : format des canaux : float32, uint8 * `-s ` : nombre de canaux : 1, 2, 3, 4 * `-d` : activation des logs de niveau DEBUG @@ -232,8 +231,7 @@ image3 | image4 ``` * X = b : image de fond * `-mX ` : X = [1..4] ou b, masque associé à l'image en entrée -* `-a ` : format des canaux : float, uint -* `-b ` : nombre de bits pour un canal : 8, 32 +* `-a ` : format des canaux : float32, uint8 * `-s ` : nombre de canaux : 1, 2, 3, 4 * `-d` : activation des logs de niveau DEBUG @@ -257,7 +255,7 @@ Les informations sur les canaux (nombre, taille en bits et format) peuvent : #### Usage -`mergeNtiff -f [-r ] -c -i -n [-a -s -b ]` +`mergeNtiff -f [-r ] -c -i -n [-a -s ]` * `-f ` : fichier de configuration contenant l'image en sortie et la liste des images en entrée, avec leur géoréférencement et les masques éventuels * `-g` : la première image en entrée dans le fichier est une image de fond. Il ne faudra pas lui appliquer l'éventuel style fourni. @@ -266,8 +264,7 @@ Les informations sur les canaux (nombre, taille en bits et format) peuvent : * `-i ` : interpolation à utiliser pour les reprojections et le réechantillonnage : nn (plus proche voisin), linear, bicubic, lanzos * `-c ` : compression des données dans l'image TIFF en sortie : jpg, jpg90, raw (défaut), zip, lzw, pkb * `-n ` : couleur de nodata, valeurs décimales pour chaque canal, séparées par des virgules (exemple : 255,255,255 pour du blanc sans transparence). Si un style est fourni, cette valeur de nodata est celle dans les données source. Le nodata dans l'image en sortie est déduit du style (ou est égal à celui en entrée si le style ne modifie pas le format des données). -* `-a ` : format des canaux : float, uint -* `-b ` : nombre de bits pour un canal : 8, 32 +* `-a ` : format des canaux : float32, uint8 * `-s ` : nombre de canaux : 1, 2, 3, 4 * `-d` : activation des logs de niveau DEBUG @@ -297,7 +294,7 @@ L'image `/home/IGN/IMAGE.tif` sera écrite ainsi que son masque associé `/home/ #### Exemples * `mergeNtiff -f conf.txt -c zip -i bicubic -n 255,255,255` -* `mergeNtiff -f conf.txt -c zip -i nn -s 1 -b 32 -p gray -a float -n -99999` +* `mergeNtiff -f conf.txt -c zip -i nn -s 1 -p gray -a float32 -n -99999` ### OVERLAYNTIFF @@ -382,14 +379,12 @@ La taille de tuile précisée doit être cohérente avec la taille totale de la #### Usage -`work2cache -c -t [-a -s -b ] [-crop]` +`work2cache -c -t [-a -s ]` * `-c ` : compression des données dans l'image TIFF en sortie : jpg, jpg90, raw (défaut), zip, lzw, pkb, png * `-t ` : taille pixel d'une tuile, enlargeur et hauteur. Doit être un diviseur de la largeur et de la hauteur de l'image en entrée -* `-a ` : format des canaux : float, uint -* `-b ` : nombre de bits pour un canal : 8, 32 +* `-a ` : format des canaux : float32, uint8 * `-s ` : nombre de canaux : 1, 2, 3, 4 -* `-crop` : dans le cas d'une compression des données en JPEG, un bloc (16x16 pixels, base d'application de la compression) qui contient un pixel blanc est complètement rempli de blanc * `-d` : activation des logs de niveau DEBUG Les options a, b et s doivent être toutes fournies ou aucune. @@ -399,7 +394,7 @@ La compression PNG a la particularité de ne pas être un standard du TIFF. Une #### Exemples * Stockage fichier sans conversion : `work2cache input.tif -c png -t 256 256 output.tif` -* Stockage fichier avec conversion : `work2cache input.tif -c png -t 256 256 -a uint -b 8 -s 1 output.tif` +* Stockage fichier avec conversion : `work2cache input.tif -c png -t 256 256 -a uint8 -s 1 output.tif` * Stockage CEPH sans conversion : `work2cache input.tif -c png -t 256 256 ceph://PYRAMIDS/output.tif` * Stockage S3 sans conversion : `work2cache input.tif -c png -t 256 256 s3://PYRAMIDS/output.tif` * Stockage SWIFT sans conversion : `work2cache input.tif -c png -t 256 256 swift://PYRAMIDS/output.tif` diff --git a/config.h.in b/config.h.in index 9e58ed0..d4e8ebf 100644 --- a/config.h.in +++ b/config.h.in @@ -40,8 +40,5 @@ // Variable issues du cmake #cmakedefine VERSION "@VERSION@" -#cmakedefine OBJECT_ENABLED @OBJECT_ENABLED@ -#cmakedefine KDU_ENABLED @KDU_ENABLED@ -#cmakedefine KDU_THREADING @KDU_THREADING@ #endif diff --git a/src/cache2work.cpp b/src/cache2work.cpp index fceac79..ec01e48 100644 --- a/src/cache2work.cpp +++ b/src/cache2work.cpp @@ -47,27 +47,20 @@ #include #include #include - #include #include #include #include namespace logging = boost::log; namespace keywords = boost::log::keywords; - #include + #include #include #include -#include "config.h" #include - -#if OBJECT_ENABLED -#include -#include -#include -#endif +#include "config.h" /** \~french Message d'usage de la commande cache2work */ std::string help = std::string("\ncache2work version ") + std::string(VERSION) + "\n\n" @@ -111,7 +104,6 @@ void usage() { void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -134,7 +126,7 @@ int main ( int argc, char **argv ) char* input = 0, *output = 0; Compression::eCompression compression = Compression::NONE; - bool debugLogger=false; + bool debug_logger=false; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -154,7 +146,7 @@ int main ( int argc, char **argv ) exit ( 0 ); break; case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 'c': // compression if ( ++i == argc ) { @@ -188,7 +180,7 @@ int main ( int argc, char **argv ) } } - if (debugLogger) { + if (debug_logger) { // le niveau debug du logger est activé boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } @@ -206,7 +198,7 @@ int main ( int argc, char **argv ) Context* context; curl_global_init(CURL_GLOBAL_ALL); - BOOST_LOG_TRIVIAL(debug) << std::string("Input is on a " + ContextType::toString(type) + " storage in the tray ") + tray_name; + BOOST_LOG_TRIVIAL(debug) << std::string("Input is on a " + ContextType::to_string(type) + " storage in the tray ") + tray_name; context = StoragePool::get_context(type, tray_name); // Problème lors de l'ajout ou de la récupération de ce contexte de stockage @@ -214,17 +206,15 @@ int main ( int argc, char **argv ) error("Unable to connect context", -1); } - Rok4ImageFactory R4IF; - Rok4Image* rok4image = R4IF.createRok4ImageToRead(fo_name, BoundingBox(0.,0.,0.,0.), 0., 0., context); + Rok4Image* rok4image = Rok4Image::create_to_read(fo_name, BoundingBox(0.,0.,0.,0.), 0., 0., context); if (rok4image == NULL) { StoragePool::cleanStoragePool(); error (std::string("Cannot create ROK4 image to read ") + input, 1); } - FileImageFactory FIF; - FileImage* outputImage = FIF.createImageToWrite( - output, rok4image->getBbox(), rok4image->getResX(), rok4image->getResY(), rok4image->getWidth(), rok4image->getHeight(), - rok4image->getChannels(), rok4image->getSampleFormat(), rok4image->getBitsPerSample(), rok4image->getPhotometric(), compression + FileImage* outputImage = FileImage::create_to_write( + output, rok4image->get_bbox(), rok4image->get_resx(), rok4image->get_resy(), rok4image->get_width(), rok4image->get_height(), + rok4image->get_channels(), rok4image->get_sample_format(), rok4image->get_photometric(), compression ); if (outputImage == NULL) { @@ -234,7 +224,7 @@ int main ( int argc, char **argv ) } BOOST_LOG_TRIVIAL(debug) << "Write" ; - if (outputImage->writeImage(rok4image) < 0) { + if (outputImage->write_image(rok4image) < 0) { delete rok4image; delete outputImage; StoragePool::cleanStoragePool(); diff --git a/src/checkWork.cpp b/src/checkWork.cpp index 50ec8a6..e07476a 100644 --- a/src/checkWork.cpp +++ b/src/checkWork.cpp @@ -80,7 +80,6 @@ void usage() { void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -133,9 +132,7 @@ int main ( int argc, char **argv ) error ("Argument must specify one input file", -1); } - FileImageFactory FIF; - - FileImage* image = FIF.createImageToRead(input); + FileImage* image = FileImage::create_to_read(input); int ret; if (image == NULL) { BOOST_LOG_TRIVIAL(error) << "Image NOK"; diff --git a/src/composeNtiff.cpp b/src/composeNtiff.cpp index 9956255..4d50b4b 100644 --- a/src/composeNtiff.cpp +++ b/src/composeNtiff.cpp @@ -82,7 +82,7 @@ char* inputDir = 0; char* outputImage = 0; /** \~french Activation du niveau de log debug. Faux par défaut */ -bool debugLogger=false; +bool debug_logger=false; /** \~french Message d'usage de la commande pbf2cache */ std::string help = std::string("\ncomposeNtiff version ") + std::string(VERSION) + "\n\n" @@ -126,7 +126,6 @@ void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << message ; BOOST_LOG_TRIVIAL(error) << "Source directory : " << inputDir ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -137,7 +136,7 @@ void error ( std::string message, int errorCode ) { * \param[in] argv tableau des paramètres * \return code de retour, 0 si réussi, -1 sinon */ -int parseCommandLine ( int argc, char** argv ) { +int parse_command_line ( int argc, char** argv ) { for ( int i = 1; i < argc; i++ ) { if ( argv[i][0] == '-' ) { @@ -146,7 +145,7 @@ int parseCommandLine ( int argc, char** argv ) { usage(); exit ( 0 ); case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 's': // Input directory if ( i++ >= argc ) { @@ -229,7 +228,7 @@ int parseCommandLine ( int argc, char** argv ) { * \param[out] ppCompoundIn ensemble des images en entrée * \return code de retour, 0 si réussi, -1 sinon */ -int loadImages ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { +int load_images ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { std::vector< std::string > imagesNames; @@ -242,13 +241,10 @@ int loadImages ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { for ( int i = 0; i < heightwiseImage; i++ ) for ( int j = 0; j < widthwiseImage; j++ ) imagesIn[i][j] = NULL; int width, height; - int samplesperpixel, bitspersample; - SampleFormat::eSampleFormat sampleformat; + int samplesperpixel; + SampleFormat::eSampleFormat sample_format; Photometric::ePhotometric photometric; - FileImageFactory FIF; - - /********* Parcours du dossier ************/ // Ouverture et test du répertoire source @@ -296,7 +292,7 @@ int loadImages ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { memset(filename, 0, 256); memcpy(filename, str.c_str(), str.length()); - FileImage* pImage = FIF.createImageToRead (filename, BoundingBox(0,0,0,0), -1., -1. ); + FileImage* pImage = FileImage::create_to_read (filename, BoundingBox(0,0,0,0), -1., -1. ); if ( pImage == NULL ) { BOOST_LOG_TRIVIAL(error) << "Cannot create a FileImage from the file " << filename ; return -1; @@ -304,20 +300,18 @@ int loadImages ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { if ( i == 0 && j == 0 ) { // C'est notre première image en entrée, on mémorise les caractéristiques - bitspersample = pImage->getBitsPerSample(); - sampleformat = pImage->getSampleFormat(); - photometric = pImage->getPhotometric(); - samplesperpixel = pImage->getChannels(); - width = pImage->getWidth(); - height = pImage->getHeight(); + sample_format = pImage->get_sample_format(); + photometric = pImage->get_photometric(); + samplesperpixel = pImage->get_channels(); + width = pImage->get_width(); + height = pImage->get_height(); } else { // Toutes les images en entrée doivent avoir certaines caractéristiques en commun - if ( bitspersample != pImage->getBitsPerSample() || - sampleformat != pImage->getSampleFormat() || - photometric != pImage->getPhotometric() || - samplesperpixel != pImage->getChannels() || - width != pImage->getWidth() || - height != pImage->getHeight() ) + if ( sample_format != pImage->get_sample_format() || + photometric != pImage->get_photometric() || + samplesperpixel != pImage->get_channels() || + width != pImage->get_width() || + height != pImage->get_height() ) { delete pImage; for ( int ii = 0; ii < heightwiseImage; ii++ ) for ( int jj = 0; jj < widthwiseImage; jj++ ) delete imagesIn[ii][jj]; @@ -326,7 +320,7 @@ int loadImages ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { } } - pImage->setBbox(BoundingBox(j * width, (heightwiseImage - i - 1) * height, (j+1) * width, (heightwiseImage - i) * height)); + pImage->set_bbox(BoundingBox(j * width, (heightwiseImage - i - 1) * height, (j+1) * width, (heightwiseImage - i) * height)); imagesIn[i][j] = pImage; @@ -335,9 +329,9 @@ int loadImages ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { *ppCompoundIn = new CompoundImage(imagesIn); // Création de l'image de sortie - *ppImageOut = FIF.createImageToWrite ( + *ppImageOut = FileImage::create_to_write ( outputImage, BoundingBox(0., 0., 0., 0.), -1., -1., width*widthwiseImage, height*heightwiseImage, samplesperpixel, - sampleformat, bitspersample, photometric,compression + sample_format, photometric,compression ); if ( *ppImageOut == NULL ) { @@ -375,18 +369,18 @@ int main ( int argc, char **argv ) { ); // Lecture des parametres de la ligne de commande - if ( parseCommandLine ( argc,argv ) < 0 ) { + if ( parse_command_line ( argc,argv ) < 0 ) { error ( "Cannot parse command line",-1 ); } // On sait maintenant si on doit activer le niveau de log DEBUG - if (debugLogger) { + if (debug_logger) { boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } BOOST_LOG_TRIVIAL(debug) << "Load" ; // Chargement des images - if ( loadImages ( &pImageOut, &pCompoundIn ) < 0 ) { + if ( load_images ( &pImageOut, &pCompoundIn ) < 0 ) { if ( pCompoundIn ) { delete pCompoundIn; } @@ -398,7 +392,7 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Save image" ; // Enregistrement de l'image fusionnée - if ( pImageOut->writeImage ( pCompoundIn ) < 0 ) { + if ( pImageOut->write_image ( pCompoundIn ) < 0 ) { error ( "Cannot write the compound image",-1 ); } diff --git a/src/decimateNtiff.cpp b/src/decimateNtiff.cpp index a503cf0..6ed9edf 100644 --- a/src/decimateNtiff.cpp +++ b/src/decimateNtiff.cpp @@ -80,18 +80,16 @@ namespace keywords = boost::log::keywords; // Paramètres de la ligne de commande déclarés en global /** \~french Chemin du fichier de configuration des images */ -char imageListFilename[256]; +char configuration_file[256]; /** \~french Valeur de nodata sour forme de chaîne de caractère (passée en paramètre de la commande) */ char strnodata[256]; -/** \~french A-t-on précisé le format en sortie, c'est à dire les 3 informations samplesperpixel, bitspersample et sampleformat */ -bool outputProvided = false; +/** \~french A-t-on précisé le format en sortie, c'est à dire les 3 informations samplesperpixel et sample_format */ +bool output_format_provided = false; /** \~french Nombre de canaux par pixel, pour l'image en sortie */ uint16_t samplesperpixel = 0; -/** \~french Nombre de bits occupé par un canal, pour l'image en sortie */ -uint16_t bitspersample = 0; /** \~french Format du canal (entier, flottant, signé ou non...), pour l'image en sortie */ -SampleFormat::eSampleFormat sampleformat = SampleFormat::UNKNOWN; +SampleFormat::eSampleFormat sample_format = SampleFormat::UNKNOWN; /** \~french Photométrie (rgb, gray), déduit du nombre de canaux */ Photometric::ePhotometric photometric; @@ -100,7 +98,7 @@ Photometric::ePhotometric photometric; Compression::eCompression compression; /** \~french Activation du niveau de log debug. Faux par défaut */ -bool debugLogger=false; +bool debug_logger=false; /** \~french Message d'usage de la commande decimateNtiff */ @@ -123,12 +121,11 @@ std::string help = std::string("\ndecimateNtiff version ") + std::string(VERSION " -n nodata value, one integer per sample, seperated with comma. Examples\n" " -99999 for DTM\n" " 255,255,255 for orthophotography\n" - " -a sample format : (float or uint)\n" - " -b bits per sample : (8 or 32)\n" + " -a sample format : (float32 or uint8)\n" " -s samples per pixel : (1, 2, 3 or 4)\n" " -d debug logger activation\n\n" - "If bitspersample, sampleformat or samplesperpixel are not provided, those 3 informations are read from the image sources (all have to own the same). If 3 are provided, conversion may be done.\n\n"; + "If sample_format or samplesperpixel are not provided, those informations are read from the image sources (all have to own the same). If all are provided, conversion may be done.\n\n"; /** * \~french @@ -147,9 +144,8 @@ void usage() { */ void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << message ; - BOOST_LOG_TRIVIAL(error) << "Configuration file : " << imageListFilename ; + BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_file ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -160,7 +156,7 @@ void error ( std::string message, int errorCode ) { * \param[in] argv tableau des paramètres * \return code de retour, 0 si réussi, -1 sinon */ -int parseCommandLine ( int argc, char** argv ) { +int parse_command_line ( int argc, char** argv ) { for ( int i = 1; i < argc; i++ ) { if ( argv[i][0] == '-' ) { @@ -169,14 +165,14 @@ int parseCommandLine ( int argc, char** argv ) { usage(); exit ( 0 ); case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 'f': // fichier de liste des images source if ( i++ >= argc ) { BOOST_LOG_TRIVIAL(error) << "Error in option -f" ; return -1; } - strcpy ( imageListFilename,argv[i] ); + strcpy ( configuration_file,argv[i] ); break; case 'n': // nodata if ( i++ >= argc ) { @@ -218,25 +214,13 @@ int parseCommandLine ( int argc, char** argv ) { return -1; } break; - case 'b': // bitspersample - if ( i++ >= argc ) { - BOOST_LOG_TRIVIAL(error) << "Error in option -b" ; - return -1; - } - if ( strncmp ( argv[i], "8",1 ) == 0 ) bitspersample = 8 ; - else if ( strncmp ( argv[i], "32",2 ) == 0 ) bitspersample = 32 ; - else { - BOOST_LOG_TRIVIAL(error) << "Unknown value for option -b : " << argv[i] ; - return -1; - } - break; - case 'a': // sampleformat + case 'a': // sample_format if ( i++ >= argc ) { BOOST_LOG_TRIVIAL(error) << "Error in option -a" ; return -1; } - if ( strncmp ( argv[i],"uint",4 ) == 0 ) sampleformat = SampleFormat::UINT ; - else if ( strncmp ( argv[i],"float",5 ) == 0 ) sampleformat = SampleFormat::FLOAT; + if ( strncmp ( argv[i],"uint8",5 ) == 0 ) sample_format = SampleFormat::UINT8 ; + else if ( strncmp ( argv[i],"float32",7 ) == 0 ) sample_format = SampleFormat::FLOAT32; else { BOOST_LOG_TRIVIAL(error) << "Unknown value for option -a : " << argv[i] ; return -1; @@ -251,7 +235,7 @@ int parseCommandLine ( int argc, char** argv ) { } } - BOOST_LOG_TRIVIAL(debug) << "decimateNtiff -f " << imageListFilename ; + BOOST_LOG_TRIVIAL(debug) << "decimateNtiff -f " << configuration_file ; return 0; } @@ -267,7 +251,7 @@ int parseCommandLine ( int argc, char** argv ) { * \param[in,out] resys Résolution en y des images * \return true en cas de succès, false si échec */ -bool loadConfiguration ( +bool load_configuration ( std::vector* masks, std::vector* paths, std::vector >* bboxes, @@ -277,9 +261,9 @@ bool loadConfiguration ( std::ifstream file; - file.open ( imageListFilename ); + file.open ( configuration_file ); if ( ! file.is_open() ) { - BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << imageListFilename ; + BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << configuration_file ; return false; } @@ -294,7 +278,7 @@ bool loadConfiguration ( char type[3]; BoundingBox bb(0.,0.,0.,0.); double resx, resy; - bool isMask; + bool is_mask; file.getline(line, 2*IMAGE_MAX_FILENAME_LENGTH); BOOST_LOG_TRIVIAL(debug) << line; @@ -304,11 +288,11 @@ bool loadConfiguration ( int nb = std::sscanf ( line,"%s %s %lf %lf %lf %lf %lf %lf", type, tmpPath, &bb.xmin, &bb.ymax, &bb.xmax, &bb.ymin, &resx, &resy ); if ( nb == 8 && memcmp ( type,"IMG",3 ) == 0) { // On lit la ligne d'une image - isMask = false; + is_mask = false; } else if ( nb == 2 && memcmp ( type,"MSK",3 ) == 0) { // On lit la ligne d'un masque - isMask = true; + is_mask = true; if (masks->size() == 0 || masks->back()) { // La première ligne ne peut être un masque et on ne peut pas avoir deux masques à la suite @@ -328,7 +312,7 @@ bool loadConfiguration ( strcpy ( path,tmpPath ); // On ajoute tout ça dans les vecteurs - masks->push_back(isMask); + masks->push_back(is_mask); paths->push_back(path); bboxes->push_back(bb); resxs->push_back(resx); @@ -341,7 +325,7 @@ bool loadConfiguration ( file.close(); return true; } else { - BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << imageListFilename; + BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << configuration_file; file.close(); return false; } @@ -353,13 +337,13 @@ bool loadConfiguration ( * \brief Charge les images en entrée et en sortie depuis le fichier de configuration * \details On va récupérer toutes les informations de toutes les images et masques présents dans le fichier de configuration et créer les objets FileImage correspondant. Toutes les images ici manipulées sont de vraies images (physiques) dans ce sens où elles sont des fichiers soit lus, soit qui seront écrits. * - * Le chemin vers le fichier de configuration est stocké dans la variables globale imageListFilename et outImagesRoot va être concaténer au chemin vers les fichiers de sortie. + * Le chemin vers le fichier de configuration est stocké dans la variables globale configuration_file et images_root va être concaténer au chemin vers les fichiers de sortie. * \param[out] ppImageOut image résultante de l'outil * \param[out] ppMaskOut masque résultat de l'outil, si demandé * \param[out] pImagesIn ensemble des images en entrée * \return code de retour, 0 si réussi, -1 sinon */ -int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vector* pImagesIn ) { +int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vector* pImagesIn ) { std::vector masks; std::vector paths; @@ -367,14 +351,14 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vector resxs; std::vector resys; - if (! loadConfiguration(&masks, &paths, &bboxes, &resxs, &resys) ) { - BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << imageListFilename ; + if (! load_configuration(&masks, &paths, &bboxes, &resxs, &resys) ) { + BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << configuration_file ; return -1; } // On doit avoir au moins deux lignes, trois si on a un masque de sortie if (masks.size() < 2 || (masks.size() == 2 && masks.back()) ) { - BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << imageListFilename ; + BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << configuration_file ; return -1; } @@ -386,7 +370,6 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorsetMask ( pMask ) ) { + if ( ! pImage->set_mask ( pMask ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the input FileImage" ; return -1; } @@ -431,45 +414,37 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorpush_back ( pImage ); /* On vérifie que le format des canaux est le même pour toutes les images en entrée : - * - sampleformat - * - bitspersample + * - sample_format * - samplesperpixel */ - if (! outputProvided && nbImgsIn == 1) { + if (! output_format_provided && nbImgsIn == 1) { /* On n'a pas précisé de format en sortie, on va donc utiliser celui des entrées * On veut donc avoir le même format pour toutes les entrées * On lit la première image en entrée, qui sert de référence * L'image en sortie sera à ce format */ - bitspersample = pImage->getBitsPerSample(); - samplesperpixel = pImage->getChannels(); - sampleformat = pImage->getSampleFormat(); - } else if (! outputProvided) { + samplesperpixel = pImage->get_channels(); + sample_format = pImage->get_sample_format(); + } else if (! output_format_provided) { // On doit avoir le même format pour tout le monde - if (bitspersample != pImage->getBitsPerSample()) { - BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same" ; - BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same number of bits per sample" ; - BOOST_LOG_TRIVIAL(error) << bitspersample << " != " << pImage->getBitsPerSample() ; - return -1; - } - if (samplesperpixel != pImage->getChannels()) { + if (samplesperpixel != pImage->get_channels()) { BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same" ; BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same number of samples per pixel" ; - BOOST_LOG_TRIVIAL(error) << samplesperpixel << " != " << pImage->getChannels() ; + BOOST_LOG_TRIVIAL(error) << samplesperpixel << " != " << pImage->get_channels() ; return -1; } - if (sampleformat != pImage->getSampleFormat()) { + if (sample_format != pImage->get_sample_format()) { BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same" ; BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same sample format" ; - BOOST_LOG_TRIVIAL(error) << sampleformat << " != " << pImage->getSampleFormat() ; + BOOST_LOG_TRIVIAL(error) << sample_format << " != " << pImage->get_sample_format() ; return -1; } } } if ( pImagesIn->size() == 0 ) { - BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << imageListFilename << "' : pas de données en entrée." ; + BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << configuration_file << "' : pas de données en entrée." ; return -1; } else { BOOST_LOG_TRIVIAL(debug) << nbImgsIn << " image(s) en entrée" ; @@ -489,9 +464,9 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorprint(); + if (debug_logger) ( *ppImageOut )->print(); return 0; } -int addConverters(std::vector ImageIn) { - if (! outputProvided) { +int add_converters(std::vector ImageIn) { + if (! output_format_provided) { // On n'a pas précisé de format en sortie, donc toutes les images doivent avoir le même // Et la sortie a aussi ce format, donc pas besoin de convertisseur @@ -531,13 +506,13 @@ int addConverters(std::vector ImageIn) { for ( std::vector::iterator itImg = ImageIn.begin(); itImg < ImageIn.end(); itImg++ ) { - if ( ! ( *itImg )->addConverter ( sampleformat, bitspersample, samplesperpixel ) ) { + if ( ! ( *itImg )->add_converter ( sample_format, samplesperpixel ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add converter for an input image"; ( *itImg )->print(); return -1; } - if (debugLogger) ( *itImg )->print(); + if (debug_logger) ( *itImg )->print(); } return 0; @@ -557,7 +532,7 @@ int addConverters(std::vector ImageIn) { * \param[out] pTabImageIn images en entrée, triées en paquets compatibles * \return code de retour, 0 si réussi, -1 sinon */ -int sortImages ( std::vector ImagesIn, std::vector >* pTabImageIn ) { +int sort_images ( std::vector ImagesIn, std::vector >* pTabImageIn ) { std::vector vTmpImg; std::vector::iterator itiniImg = ImagesIn.begin(); @@ -566,7 +541,7 @@ int sortImages ( std::vector ImagesIn, std::vector::iterator itImg = ImagesIn.begin(); itImg < ImagesIn.end()-1; itImg++ ) { - if ( ! ( *itImg )->isCompatibleWith ( * ( itImg+1 ) ) ) { + if ( ! ( *itImg )->compatible ( * ( itImg+1 ) ) ) { // two following images are not compatible, we split images' vector vTmpImg.assign ( itiniImg,itImg+1 ); itiniImg = itImg+1; @@ -606,20 +581,17 @@ int sortImages ( std::vector ImagesIn, std::vector >& TabImagesIn, // Entrée ExtendedCompoundImage** ppECIout, // Résultat du merge int* nodata ) { - ExtendedCompoundImageFactory ECIF ; - DecimatedImageFactory DIF ; std::vector pOverlayedImages; - // ************* Le fond (éventuel) if ( TabImagesIn.size() == 2) { BOOST_LOG_TRIVIAL(debug) << "We have a background"; - if ( ! TabImagesIn.at(0).at(0)->isCompatibleWith ( pImageOut ) ) { + if ( ! TabImagesIn.at(0).at(0)->compatible ( pImageOut ) ) { BOOST_LOG_TRIVIAL(error) << "Background image have to be consistent with the output image" ; TabImagesIn.at(0).at(0)->print(); BOOST_LOG_TRIVIAL(error) << "not consistent with"; @@ -632,13 +604,13 @@ int mergeTabImages ( FileImage* pImageOut, // Sortie // ************* Les images à décimer // L'image - ExtendedCompoundImage* pECI = ECIF.createExtendedCompoundImage ( TabImagesIn.at(TabImagesIn.size() - 1), nodata, 0 ); + ExtendedCompoundImage* pECI = ExtendedCompoundImage::create ( TabImagesIn.at(TabImagesIn.size() - 1), nodata, 0 ); if ( pECI == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible d'assembler les images en entrée" ; return -1; } - DecimatedImage* pDII = DIF.createDecimatedImage(pECI, pImageOut->getBbox(), pImageOut->getResX(), pImageOut->getResY(), nodata); + DecimatedImage* pDII = DecimatedImage::create(pECI, pImageOut->get_bbox(), pImageOut->get_resx(), pImageOut->get_resy(), nodata); if ( pDII == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible de créer la DecimatedImage (image)" ; return -1; @@ -646,31 +618,31 @@ int mergeTabImages ( FileImage* pImageOut, // Sortie // Le masque ExtendedCompoundMask* pECMI = new ExtendedCompoundMask ( pECI ); - if ( ! pECI->setMask ( pECMI ) ) { + if ( ! pECI->set_mask ( pECMI ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the compound image " ; return -1; } int nodata_mask[1] = {0}; - DecimatedImage* pDIM = DIF.createDecimatedImage(pECMI, pImageOut->getBbox(), pImageOut->getResX(), pImageOut->getResY(), nodata_mask); + DecimatedImage* pDIM = DecimatedImage::create(pECMI, pImageOut->get_bbox(), pImageOut->get_resx(), pImageOut->get_resy(), nodata_mask); if ( pDIM == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible de créer la DecimatedImage (mask)" ; return -1; } - if ( ! pDII->setMask ( pDIM ) ) { + if ( ! pDII->set_mask ( pDIM ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the DecimatedImage" ; return -1; } - if (debugLogger) pECI->print(); - if (debugLogger) pDII->print(); + if (debug_logger) pECI->print(); + if (debug_logger) pDII->print(); pOverlayedImages.push_back(pDII); // Assemblage des paquets et decoupage aux dimensions de l image de sortie - *ppECIout = ECIF.createExtendedCompoundImage ( - pImageOut->getWidth(), pImageOut->getHeight(), pImageOut->getChannels(), pImageOut->getBbox(), + *ppECIout = ExtendedCompoundImage::create ( + pImageOut->get_width(), pImageOut->get_height(), pImageOut->get_channels(), pImageOut->get_bbox(), pOverlayedImages, nodata, 0 ); @@ -682,7 +654,7 @@ int mergeTabImages ( FileImage* pImageOut, // Sortie // Masque ExtendedCompoundMask* pECMIout = new ExtendedCompoundMask ( *ppECIout ); - if ( ! ( *ppECIout )->setMask ( pECMIout ) ) { + if ( ! ( *ppECIout )->set_mask ( pECMIout ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the main Extended Compound Image" ; return -1; } @@ -720,35 +692,35 @@ int main ( int argc, char **argv ) { ); // Lecture des parametres de la ligne de commande - if ( parseCommandLine ( argc, argv ) < 0 ) { + if ( parse_command_line ( argc, argv ) < 0 ) { error ( "Echec lecture ligne de commande",-1 ); } // On sait maintenant si on doit activer le niveau de log DEBUG - if (debugLogger) { + if (debug_logger) { boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } // On regarde si on a tout précisé en sortie, pour voir si des conversions sont possibles - if (sampleformat != SampleFormat::UNKNOWN && bitspersample != 0 && samplesperpixel !=0) { - outputProvided = true; + if (sample_format != SampleFormat::UNKNOWN && samplesperpixel != 0) { + output_format_provided = true; } BOOST_LOG_TRIVIAL(debug) << "Load" ; // Chargement des images - if ( loadImages ( &pImageOut, &pMaskOut, &ImagesIn ) < 0 ) { + if ( load_images ( &pImageOut, &pMaskOut, &ImagesIn ) < 0 ) { error ( "Echec chargement des images",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Add converters" ; // Ajout des modules de conversion aux images en entrée - if ( addConverters ( ImagesIn ) < 0 ) { + if ( add_converters ( ImagesIn ) < 0 ) { error ( "Echec ajout des convertisseurs", -1 ); } // Conversion string->int[] du paramètre nodata BOOST_LOG_TRIVIAL(debug) << "Nodata interpretation" ; - int spp = ImagesIn.at(0)->getChannels(); + int spp = ImagesIn.at(0)->get_channels(); int nodata[spp]; char* charValue = strtok ( strnodata,"," ); @@ -766,26 +738,26 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Sort" ; // Tri des images - if ( sortImages ( ImagesIn, &TabImagesIn ) < 0 ) { + if ( sort_images ( ImagesIn, &TabImagesIn ) < 0 ) { error ( "Echec tri des images",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Merge" ; // Fusion des paquets d images - if ( mergeTabImages ( pImageOut, TabImagesIn, &pECI, nodata ) < 0 ) { + if ( merge_images ( pImageOut, TabImagesIn, &pECI, nodata ) < 0 ) { error ( "Echec fusion des paquets d images",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Save image" ; // Enregistrement de l'image fusionnée - if ( pImageOut->writeImage ( pECI ) < 0 ) { + if ( pImageOut->write_image ( pECI ) < 0 ) { error ( "Echec enregistrement de l image finale",-1 ); } if ( pMaskOut != NULL ) { BOOST_LOG_TRIVIAL(debug) << "Save mask" ; // Enregistrement du masque fusionné, si demandé - if ( pMaskOut->writeImage ( pECI->Image::getMask() ) < 0 ) { + if ( pMaskOut->write_image ( pECI->Image::get_mask() ) < 0 ) { error ( "Echec enregistrement du masque final",-1 ); } } diff --git a/src/manageNodata.cpp b/src/manageNodata.cpp index 58f50a0..94bcc19 100644 --- a/src/manageNodata.cpp +++ b/src/manageNodata.cpp @@ -130,7 +130,6 @@ void usage() { void error ( std::string message, int errorCode = -1 ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -159,11 +158,11 @@ int main ( int argc, char* argv[] ) { char* strNewData = 0; int channels = 0; - uint16_t bitspersample = 0, sampleformat = 0; + SampleFormat::eSampleFormat sample_format = SampleFormat::UNKNOWN; - bool touchEdges = false; + bool touch_edges = false; int tolerance = 0; - bool debugLogger=false; + bool debug_logger=false; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -182,12 +181,12 @@ int main ( int argc, char* argv[] ) { } if ( !strcmp ( argv[i],"-d" ) ) { // debug logs - debugLogger = true; + debug_logger = true; break; } if ( !strcmp ( argv[i],"-touch-edges" ) ) { - touchEdges = true; + touch_edges = true; continue; } else if ( !strcmp ( argv[i],"-tolerance" ) ) { @@ -214,11 +213,9 @@ int main ( int argc, char* argv[] ) { } else if ( !strcmp ( argv[i],"-format" ) ) { if ( i++ >= argc ) error ( "Error with option -format",-1 ); if ( strncmp ( argv[i], "uint8", 5 ) == 0 ) { - bitspersample = 8; - sampleformat = SampleFormat::UINT; + sample_format = SampleFormat::UINT8; } else if ( strncmp ( argv[i], "float32", 7 ) == 0 ) { - bitspersample = 32; - sampleformat = SampleFormat::FLOAT; + sample_format = SampleFormat::FLOAT32; } else error ( "Unknown value for option -format : " + string ( argv[i] ), -1 ); continue; @@ -243,7 +240,7 @@ int main ( int argc, char* argv[] ) { } } - if (debugLogger) { + if (debug_logger) { // le niveau debug du logger est activé boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } @@ -261,7 +258,7 @@ int main ( int argc, char* argv[] ) { } if ( ! channels ) error ( "Missing number of samples per pixel",-1 ); - if ( ! bitspersample ) error ( "Missing sample format",-1 ); + if ( sample_format == SampleFormat::UNKNOWN ) error ( "Missing sample format",-1 ); if ( ! strTargetValue ) error ( "How to identify the nodata in the input image ? Provide a target color (-target)",-1 ); @@ -269,7 +266,7 @@ int main ( int argc, char* argv[] ) { if ( ! strNewNodata && ! strNewData && ! outputMask ) error ( "What have we to do with the target color ? Precise a new nodata or data color, or a mask to write",-1 ); - int* targetValue = new int[channels]; + int* target_value = new int[channels]; int* newNodata = new int[channels]; int* newData = new int[channels]; @@ -281,13 +278,13 @@ int main ( int argc, char* argv[] ) { if ( charValue == NULL ) { error ( "Error with option -target : integer values seperated by comma",-1 ); } - targetValue[0] = atoi ( charValue ); + target_value[0] = atoi ( charValue ); for ( int i = 1; i < channels; i++ ) { charValue = strtok ( NULL, "," ); if ( charValue == NULL ) { error ( "Error with option -oldValue : integer values seperated by comma",-1 ); } - targetValue[i] = atoi ( charValue ); + target_value[i] = atoi ( charValue ); } // New nodata @@ -306,7 +303,7 @@ int main ( int argc, char* argv[] ) { } } else { // On ne précise pas de nouvelle couleur de non-donnée, elle est la même que la couleur cible. - memcpy ( newNodata, targetValue, channels*sizeof ( int ) ); + memcpy ( newNodata, target_value, channels*sizeof ( int ) ); } // New data @@ -325,21 +322,21 @@ int main ( int argc, char* argv[] ) { } } else { // Pas de nouvelle couleur pour la donnée : elle a la valeur de la couleur cible - memcpy ( newData, targetValue, channels*sizeof ( int ) ); + memcpy ( newData, target_value, channels*sizeof ( int ) ); } /******************* APPEL A LA CLASSE TIFFNODATAMANAGER *******************/ - if ( bitspersample == 32 && sampleformat == SampleFormat::FLOAT ) { + if ( sample_format == SampleFormat::FLOAT32 ) { BOOST_LOG_TRIVIAL(debug) << "Target color treatment (uint8)" ; - TiffNodataManager TNM ( channels, targetValue, touchEdges, newData, newNodata, tolerance ); - if ( ! TNM.treatNodata ( inputImage, outputImage, outputMask ) ) { + TiffNodataManager TNM ( channels, target_value, touch_edges, newData, newNodata, tolerance ); + if ( ! TNM.process_nodata ( inputImage, outputImage, outputMask ) ) { error ( "Error : unable to treat nodata for this 32-bit float image : " + string ( inputImage ), -1 ); } - } else if ( bitspersample == 8 && sampleformat == SampleFormat::UINT ) { + } else if ( sample_format == SampleFormat::UINT8 ) { BOOST_LOG_TRIVIAL(debug) << "Target color treatment (float)" ; - TiffNodataManager TNM ( channels, targetValue, touchEdges, newData, newNodata, tolerance ); - if ( ! TNM.treatNodata ( inputImage, outputImage, outputMask ) ) { + TiffNodataManager TNM ( channels, target_value, touch_edges, newData, newNodata, tolerance ); + if ( ! TNM.process_nodata ( inputImage, outputImage, outputMask ) ) { error ( "Error : unable to treat nodata for this 8-bit integer float image : " + string ( inputImage ), -1 ); } } @@ -347,7 +344,7 @@ int main ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(debug) << "Clean" ; ProjPool::cleanProjPool(); proj_cleanup(); - delete[] targetValue; + delete[] target_value; if (overwrite) delete[] outputImage; delete[] newData; delete[] newNodata; diff --git a/src/merge4tiff.cpp b/src/merge4tiff.cpp index d17127a..c3cf630 100644 --- a/src/merge4tiff.cpp +++ b/src/merge4tiff.cpp @@ -92,12 +92,10 @@ uint32_t height; /** \~french Compression de l'image de sortie */ Compression::eCompression compression = Compression::NONE; -/** \~french A-t-on précisé le format en sortie, c'est à dire les 3 informations samplesperpixel, bitspersample et sampleformat */ -bool outputProvided = false; +/** \~french A-t-on précisé le format en sortie, c'est à dire les 3 informations samplesperpixel et sampleformat */ +bool output_format_provided = false; /** \~french Nombre de canaux par pixel, pour l'image en sortie */ uint16_t samplesperpixel = 0; -/** \~french Nombre de bits occupé par un canal, pour l'image en sortie */ -uint16_t bitspersample = 0; /** \~french Format du canal (entier, flottant, signé ou non...), pour l'image en sortie */ SampleFormat::eSampleFormat sampleformat = SampleFormat::UNKNOWN; @@ -105,7 +103,7 @@ SampleFormat::eSampleFormat sampleformat = SampleFormat::UNKNOWN; Photometric::ePhotometric photometric; /** \~french Activation du niveau de log debug. Faux par défaut */ -bool debugLogger=false; +bool debug_logger=false; /** \~french Message d'usage de la commande merge4tiff */ std::string help = std::string("\ncache2work version ") + std::string(VERSION) + "\n\n" @@ -141,11 +139,10 @@ std::string help = std::string("\ncache2work version ") + std::string(VERSION) + " -mX input associated masks (optionnal)\n" " X = [1..4] or X = b\n" " -a sample format : (float or uint)\n" - " -b bits per sample : (8 or 32)\n" " -s samples per pixel : (1, 2, 3 or 4)\n" " -d debug logger activation\n\n" - "If bitspersample, sampleformat or samplesperpixel are not provided, those 3 informations are read from the image sources (all have to own the same). If 3 are provided, conversion may be done.\n\n" + "If sampleformat or samplesperpixel are not provided, those informations are read from the image sources (all have to own the same). If all are provided, conversion may be done.\n\n" "Examples\n" " - without mask, with background image\n" @@ -172,7 +169,6 @@ void usage() { void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -183,7 +179,7 @@ void error ( std::string message, int errorCode ) { * \param[in] argv tableau des paramètres * \return code de retour, 0 si réussi, -1 sinon */ -int parseCommandLine ( int argc, char* argv[] ) { +int parse_command_line ( int argc, char* argv[] ) { // Initialisation gammaM4t = 1.; strnodata = 0; @@ -204,7 +200,7 @@ int parseCommandLine ( int argc, char* argv[] ) { usage(); exit ( 0 ); case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 'g': // gamma if ( ++i == argc ) { @@ -316,25 +312,13 @@ int parseCommandLine ( int argc, char* argv[] ) { return -1; } break; - case 'b': // bitspersample - if ( i++ >= argc ) { - BOOST_LOG_TRIVIAL(error) << "Error in option -b" ; - return -1; - } - if ( strncmp ( argv[i], "8",1 ) == 0 ) bitspersample = 8 ; - else if ( strncmp ( argv[i], "32",2 ) == 0 ) bitspersample = 32 ; - else { - BOOST_LOG_TRIVIAL(error) << "Unknown value for option -b : " << argv[i] ; - return -1; - } - break; case 'a': // sampleformat if ( i++ >= argc ) { BOOST_LOG_TRIVIAL(error) << "Error in option -a" ; return -1; } - if ( strncmp ( argv[i],"uint",4 ) == 0 ) sampleformat = SampleFormat::UINT ; - else if ( strncmp ( argv[i],"float",5 ) == 0 ) sampleformat = SampleFormat::FLOAT; + if ( strncmp ( argv[i],"uint8",5 ) == 0 ) sampleformat = SampleFormat::UINT8 ; + else if ( strncmp ( argv[i],"float32",7 ) == 0 ) sampleformat = SampleFormat::FLOAT32; else { BOOST_LOG_TRIVIAL(error) << "Unknown value for option -a : " << argv[i] ; return -1; @@ -376,22 +360,21 @@ int parseCommandLine ( int argc, char* argv[] ) { int checkComponents ( FileImage* image, FileImage* mask) { if ( width == 0 ) { // read the parameters of the first input file - width = image->getWidth(); - height = image->getHeight(); + width = image->get_width(); + height = image->get_height(); if ( width%2 || height%2 ) { BOOST_LOG_TRIVIAL(error) << "Sorry : only even dimensions for input images are supported" ; return -1; } - if (! outputProvided) { + if (! output_format_provided) { // On n'a pas précisé de format de sortie // Toutes les images en entrée doivent avoir le même format // La sortie aura ce format - bitspersample = image->getBitsPerSample(); - photometric = image->getPhotometric(); - sampleformat = image->getSampleFormat(); - samplesperpixel = image->getChannels(); + photometric = image->get_photometric(); + sampleformat = image->get_sample_format(); + samplesperpixel = image->get_channels(); } else { // La photométrie est déduite du nombre de canaux if (samplesperpixel == 1) { @@ -403,46 +386,44 @@ int checkComponents ( FileImage* image, FileImage* mask) { } } - if ( ! (( bitspersample == 32 && sampleformat == SampleFormat::FLOAT ) || ( bitspersample == 8 && sampleformat == SampleFormat::UINT )) ) { - BOOST_LOG_TRIVIAL(error) << "Unknown sample type (sample format + bits per sample)" ; + if ( sampleformat == SampleFormat::UNKNOWN ) { + BOOST_LOG_TRIVIAL(error) << "Unknown sample format" ; return -1; } } else { - if ( image->getWidth() != width || image->getHeight() != height) { - BOOST_LOG_TRIVIAL(error) << "Error : all input image must have the same dimensions (width, height) : " << image->getFilename(); + if ( image->get_width() != width || image->get_height() != height) { + BOOST_LOG_TRIVIAL(error) << "Error : all input image must have the same dimensions (width, height) : " << image->get_filename(); return -1; } - if (! outputProvided) { - if ( image->getBitsPerSample() != bitspersample || image->getSampleFormat() != sampleformat || - image->getPhotometric() != photometric || image->getChannels() != samplesperpixel - ) { - BOOST_LOG_TRIVIAL(error) << "Error : output format is not provided, so all input image must have the same format (bits per sample, channels, etc...) : " << image->getFilename(); + if (! output_format_provided) { + if (image->get_sample_format() != sampleformat || image->get_photometric() != photometric || image->get_channels() != samplesperpixel) { + BOOST_LOG_TRIVIAL(error) << "Error : output format is not provided, so all input image must have the same format (sample format, channels, etc...) : " << image->get_filename(); return -1; } } } if (mask != NULL) { - if ( ! ( mask->getWidth() == width && mask->getHeight() == height && mask->getBitsPerSample() == 8 && - mask->getSampleFormat() == SampleFormat::UINT && mask->getPhotometric() == Photometric::GRAY && mask->getChannels() == 1 ) ) { + if ( ! ( mask->get_width() == width && mask->get_height() == height && mask->get_sample_format() == SampleFormat::UINT8 && + mask->get_photometric() == Photometric::GRAY && mask->get_channels() == 1 ) ) { - BOOST_LOG_TRIVIAL(error) << "Error : all input masks must have the same parameters (width, height, etc...) : " << mask->getFilename(); + BOOST_LOG_TRIVIAL(error) << "Error : all input masks must have the same parameters (width, height, etc...) : " << mask->get_filename(); return -1; } - if ( ! image->setMask(mask) ) { - BOOST_LOG_TRIVIAL(error) << "Cannot add associated mask to the input FileImage " << image->getFilename() ; + if ( ! image->set_mask(mask) ) { + BOOST_LOG_TRIVIAL(error) << "Cannot add associated mask to the input FileImage " << image->get_filename() ; return -1; } } - if (outputProvided) { - bool ok = image->addConverter ( sampleformat, bitspersample, samplesperpixel ); + if (output_format_provided) { + bool ok = image->add_converter ( sampleformat, samplesperpixel ); if (! ok ) { - BOOST_LOG_TRIVIAL(error) << "Cannot add converter to the input FileImage " << image->getFilename() ; + BOOST_LOG_TRIVIAL(error) << "Cannot add converter to the input FileImage " << image->get_filename() ; return -1; } } @@ -461,7 +442,6 @@ int checkComponents ( FileImage* image, FileImage* mask) { */ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, FileImage*& OUTPUTM) { width = 0; - FileImageFactory FIF; for ( int i = 0; i < 4; i++ ) { BOOST_LOG_TRIVIAL(debug) << "Place " << i ; @@ -473,7 +453,7 @@ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, } // Image en entrée - FileImage* inputi = FIF.createImageToRead(inputImages[i]); + FileImage* inputi = FileImage::create_to_read(inputImages[i]); if ( inputi == NULL ) { BOOST_LOG_TRIVIAL(error) << "Unable to open input image: " + std::string ( inputImages[i] ) ; return -1; @@ -483,7 +463,7 @@ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, // Eventuelle masque associé FileImage* inputm = NULL; if ( inputMasks[i] != 0 ) { - inputm = FIF.createImageToRead(inputMasks[i]); + inputm = FileImage::create_to_read(inputMasks[i]); if ( inputm == NULL ) { BOOST_LOG_TRIVIAL(error) << "Unable to open input mask: " << std::string ( inputMasks[i] ) ; return -1; @@ -507,7 +487,7 @@ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, backgroundImage=0; if ( backgroundImage ) { - BGI = FIF.createImageToRead(backgroundImage); + BGI = FileImage::create_to_read(backgroundImage); if ( BGI == NULL ) { BOOST_LOG_TRIVIAL(error) << "Unable to open background image: " + std::string ( backgroundImage ) ; return -1; @@ -516,7 +496,7 @@ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, FileImage* BGM = NULL; if ( backgroundMask ) { - BGM = FIF.createImageToRead(backgroundMask); + BGM = FileImage::create_to_read(backgroundMask); if ( BGM == NULL ) { BOOST_LOG_TRIVIAL(error) << "Unable to open background mask: " + std::string ( backgroundMask ) ; return -1; @@ -535,22 +515,22 @@ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, OUTPUTI = NULL; OUTPUTM = NULL; - OUTPUTI = FIF.createImageToWrite(outputImage, BoundingBox(0,0,0,0), -1, -1, width, height, - samplesperpixel, sampleformat, bitspersample, photometric, compression); + OUTPUTI = FileImage::create_to_write(outputImage, BoundingBox(0,0,0,0), -1, -1, width, height, + samplesperpixel, sampleformat, photometric, compression); if ( OUTPUTI == NULL ) { BOOST_LOG_TRIVIAL(error) << "Unable to open output image: " + std::string ( outputImage ) ; return -1; } if ( outputMask ) { - OUTPUTM = FIF.createImageToWrite(outputMask, BoundingBox(0,0,0,0), -1, -1, width, height, - 1, SampleFormat::UINT, 8, Photometric::MASK, Compression::DEFLATE); + OUTPUTM = FileImage::create_to_write(outputMask, BoundingBox(0,0,0,0), -1, -1, width, height, + 1, SampleFormat::UINT8, Photometric::MASK, Compression::DEFLATE); if ( OUTPUTM == NULL ) { BOOST_LOG_TRIVIAL(error) << "Unable to open output mask: " + std::string ( outputMask ) ; return -1; } - OUTPUTI->setMask(OUTPUTM); + OUTPUTI->set_mask(OUTPUTM); } return 0; @@ -570,10 +550,10 @@ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, */ template int fillBgLine ( FileImage* BGI, T* image, uint8_t* mask, int line, T* nodata ) { - if ( BGI->getline( image, line ) == 0 ) return 1; + if ( BGI->get_line( image, line ) == 0 ) return 1; - if ( BGI->getMask() != NULL ) { - if ( BGI->getMask()->getline( mask, line ) == 0 ) return 1; + if ( BGI->get_mask() != NULL ) { + if ( BGI->get_mask()->get_line( mask, line ) == 0 ) return 1; for ( int w = 0; w < width; w++ ) { if ( mask[w] == 0 ) { memcpy ( image + w*samplesperpixel, nodata,samplesperpixel*sizeof ( T ) ); @@ -645,12 +625,12 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma if ( left == right ) { // On n'a pas d'image en entrée pour cette ligne, on stocke le fond et on passe à la suivante - if ( OUTPUTI->writeLine( line_bgI, line ) == -1 ) { + if ( OUTPUTI->write_line( line_bgI, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write image's line " << line ; return -1; } if ( OUTPUTM ) - if ( OUTPUTM->writeLine( line_bgM, line ) == -1 ) { + if ( OUTPUTM->write_line( line_bgM, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write mask's line " << line ; return -1; } @@ -668,21 +648,21 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma // ----------------- les images ----------------- // ------ et les éventuels masques -------------- if ( INPUTI[y][0] ) { - if ( INPUTI[y][0]->getline( line_1I, 2*h ) == 0 ) { + if ( INPUTI[y][0]->get_line( line_1I, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][0]->getline( line_2I, 2*h+1 ) == 0 ) { + if ( INPUTI[y][0]->get_line( line_2I, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][0]->getMask() ) { - if ( INPUTI[y][0]->getMask()->getline( line_1M, 2*h ) == 0 ) { + if ( INPUTI[y][0]->get_mask() ) { + if ( INPUTI[y][0]->get_mask()->get_line( line_1M, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][0]->getMask()->getline( line_2M, 2*h+1 ) == 0 ) { + if ( INPUTI[y][0]->get_mask()->get_line( line_2M, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } @@ -691,21 +671,21 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma if ( INPUTI[y][1] ) { - if ( INPUTI[y][1]->getline( line_1I + nbsamples, 2*h ) == 0 ) { + if ( INPUTI[y][1]->get_line( line_1I + nbsamples, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][1]->getline( line_2I + nbsamples, 2*h+1 ) == 0 ) { + if ( INPUTI[y][1]->get_line( line_2I + nbsamples, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][1]->getMask() ) { - if ( INPUTI[y][1]->getMask()->getline( line_1M + width, 2*h ) == 0 ) { + if ( INPUTI[y][1]->get_mask() ) { + if ( INPUTI[y][1]->get_mask()->get_line( line_1M + width, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][1]->getMask()->getline( line_2M + width, 2*h+1 ) == 0 ) { + if ( INPUTI[y][1]->get_mask()->get_line( line_2M + width, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } @@ -750,12 +730,12 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma } } - if ( OUTPUTI->writeLine( line_outI, line ) == -1 ) { + if ( OUTPUTI->write_line( line_outI, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write image" ; return -1; } if ( OUTPUTM ) - if ( OUTPUTM->writeLine( line_outM, line ) == -1 ) { + if ( OUTPUTM->write_line( line_outM, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write mask" ; return -1; } @@ -796,18 +776,18 @@ int main ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(debug) << "Parse" ; // Lecture des parametres de la ligne de commande - if ( parseCommandLine ( argc, argv ) < 0 ) { + if ( parse_command_line ( argc, argv ) < 0 ) { error ( "Echec lecture ligne de commande",-1 ); } // On sait maintenant si on doit activer le niveau de log DEBUG - if (debugLogger) { + if (debug_logger) { boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } // On regarde si on a tout précisé en sortie, pour voir si des conversions sont possibles - if (sampleformat != SampleFormat::UNKNOWN && bitspersample != 0 && samplesperpixel !=0) { - outputProvided = true; + if (sampleformat != SampleFormat::UNKNOWN && samplesperpixel != 0) { + output_format_provided = true; } BOOST_LOG_TRIVIAL(debug) << "Check images" ; @@ -841,14 +821,14 @@ int main ( int argc, char* argv[] ) { } // Cas MNT - if ( bitspersample == 32 && sampleformat == SampleFormat::FLOAT ) { + if ( sampleformat == SampleFormat::FLOAT32 ) { BOOST_LOG_TRIVIAL(debug) << "Merge images (float)" ; float nodata[samplesperpixel]; for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( float ) nodataInt[i]; if ( merge ( BGI, INPUTI, OUTPUTI, OUTPUTM, nodata ) < 0 ) error ( "Unable to merge float images",-1 ); } // Cas images - else if ( bitspersample == 8 && sampleformat == SampleFormat::UINT ) { + else if ( sampleformat == SampleFormat::UINT8 ) { BOOST_LOG_TRIVIAL(debug) << "Merge images (uint8_t)" ; uint8_t nodata[samplesperpixel]; for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( uint8_t ) nodataInt[i]; diff --git a/src/mergeNtiff.cpp b/src/mergeNtiff.cpp index 1872665..afe5be8 100644 --- a/src/mergeNtiff.cpp +++ b/src/mergeNtiff.cpp @@ -84,27 +84,27 @@ namespace keywords = boost::log::keywords; #include "config.h" #include -#include +#include #include #include #include // Paramètres de la ligne de commande déclarés en global /** \~french Chemin du fichier de configuration des images */ -char imageListFilename[256]; +char configuration_file[256]; /** \~french Racine pour les images de sortie */ -char outImagesRoot[256]; +char images_root[256]; /** \~french Valeur de nodata sous forme de chaîne de caractère (passée en paramètre de la commande) */ char strnodata[256]; int* nodata; +/** \~french A-t-on précisé une valeur de nodata */ +bool nodata_provided = false; -/** \~french A-t-on précisé le format en sortie, c'est à dire les 3 informations samplesperpixel, bitspersample et sampleformat */ -bool outputProvided = false; +/** \~french A-t-on précisé le format en sortie, c'est à dire les 3 informations samplesperpixel et sampleformat */ +bool output_format_provided = false; /** \~french Nombre de canaux par pixel, pour l'image en sortie */ uint16_t samplesperpixel = 0; -/** \~french Nombre de bits occupé par un canal, pour l'image en sortie */ -uint16_t bitspersample = 0; /** \~french Format du canal (entier, flottant, signé ou non...), pour l'image en sortie */ SampleFormat::eSampleFormat sampleformat = SampleFormat::UNKNOWN; @@ -117,18 +117,16 @@ Compression::eCompression compression = Compression::NONE; Interpolation::KernelType interpolation = Interpolation::CUBIC; /** \~french A-t-on précisé une image de fond */ -bool backgroundProvided = false; +bool background_provided = false; /** \~french A-t-on précisé un style */ -bool styleProvided = false; +bool style_provided = false; /** \~french Chemin du fichier de style à appliquer */ -char styleFilename[256]; +char style_file[256]; /** \~french Objet style à appliquer */ Style* style; -/** \~french Valeur de nodata après application du style */ -int* styleNodata = NULL; /** \~french Activation du niveau de log debug. Faux par défaut */ -bool debugLogger = false; +bool debug_logger = false; /** \~french Message d'usage de la commande mergeNtiff */ std::string help = std::string("\nmergeNtiff version ") + std::string(VERSION) + @@ -154,22 +152,21 @@ std::string help = std::string("\nmergeNtiff version ") + std::string(VERSION) + " linear\n" " bicubic\n" " lanczos lanczos 3\n" - " -n nodata value, one interger per sample, seperated with comma. If a style is provided, this value is the nodata in source data. Examples\n" + " -n nodata value, one interger per sample, seperated with comma. If a style is provided, nodata values will be read from style. Examples\n" " -99999 for DTM\n" " 255,255,255 for orthophotography\n" " -p style file\n" " -a sample format : (float or uint)\n" - " -b bits per sample : (8 or 32)\n" " -s samples per pixel : (1, 2, 3 or 4)\n" " -d debug logger activation\n\n" - "If bitspersample, sampleformat or samplesperpixel are not provided, those 3 informations are read from the image sources (all have to own the same). If 3 are provided, conversion may be done.\n\n" + "If sampleformat or samplesperpixel are not provided, those informations are read from the image sources (all have to own the same). If all are provided, conversion may be done.\n\n" "Examples\n" " - for orthophotography\n" " mergeNtiff -f conf.txt -c zip -i bicubic -n 255,255,255\n" " - for DTM\n" - " mergeNtiff -f conf.txt -c zip -i nn -s 1 -b 32 -p gray -a float -n -99999\n\n"; + " mergeNtiff -f conf.txt -c zip -i nn -s 1 -p gray -a float32 -n -99999\n\n"; /** * \~french @@ -188,9 +185,8 @@ void usage() { */ void error(std::string message, int errorCode) { BOOST_LOG_TRIVIAL(error) << message; - BOOST_LOG_TRIVIAL(error) << "Configuration file : " << imageListFilename; + BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_file; usage(); - sleep(1); exit(errorCode); } @@ -201,7 +197,7 @@ void error(std::string message, int errorCode) { * \param[in] argv tableau des paramètres * \return code de retour, 0 si réussi, -1 sinon */ -int parseCommandLine(int argc, char** argv) { +int parse_command_line(int argc, char** argv) { for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { @@ -209,24 +205,24 @@ int parseCommandLine(int argc, char** argv) { usage(); exit(0); case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 'g': // background - backgroundProvided = true; + background_provided = true; break; case 'f': // fichier de liste des images source if (i++ >= argc) { BOOST_LOG_TRIVIAL(error) << "Error in option -f"; return -1; } - strcpy(imageListFilename, argv[i]); + strcpy(configuration_file, argv[i]); break; case 'r': // racine pour le fichier de configuration if (i++ >= argc) { BOOST_LOG_TRIVIAL(error) << "Error in option -r"; return -1; } - strcpy(outImagesRoot, argv[i]); + strcpy(images_root, argv[i]); break; case 'i': // interpolation if (i++ >= argc) { @@ -252,6 +248,7 @@ int parseCommandLine(int argc, char** argv) { return -1; } strcpy(strnodata, argv[i]); + nodata_provided = true; break; case 'c': // compression if (i++ >= argc) { @@ -281,8 +278,8 @@ int parseCommandLine(int argc, char** argv) { BOOST_LOG_TRIVIAL(error) << "Error in option -p"; return -1; } - strcpy(styleFilename, argv[i]); - styleProvided = true; + strcpy(style_file, argv[i]); + style_provided = true; break; /****************** OPTIONNEL, POUR FORCER DES CONVERSIONS **********************/ @@ -304,29 +301,15 @@ int parseCommandLine(int argc, char** argv) { return -1; } break; - case 'b': // bitspersample - if (i++ >= argc) { - BOOST_LOG_TRIVIAL(error) << "Error in option -b"; - return -1; - } - if (strncmp(argv[i], "8", 1) == 0) - bitspersample = 8; - else if (strncmp(argv[i], "32", 2) == 0) - bitspersample = 32; - else { - BOOST_LOG_TRIVIAL(error) << "Unknown value for option -b : " << argv[i]; - return -1; - } - break; case 'a': // sampleformat if (i++ >= argc) { BOOST_LOG_TRIVIAL(error) << "Error in option -a"; return -1; } - if (strncmp(argv[i], "uint", 4) == 0) - sampleformat = SampleFormat::UINT; - else if (strncmp(argv[i], "float", 5) == 0) - sampleformat = SampleFormat::FLOAT; + if (strncmp(argv[i], "uint8", 5) == 0) + sampleformat = SampleFormat::UINT8; + else if (strncmp(argv[i], "float32", 7) == 0) + sampleformat = SampleFormat::FLOAT32; else { BOOST_LOG_TRIVIAL(error) << "Unknown value for option -a : " << argv[i]; return -1; @@ -341,7 +324,7 @@ int parseCommandLine(int argc, char** argv) { } } - BOOST_LOG_TRIVIAL(debug) << "mergeNtiff -f " << imageListFilename; + BOOST_LOG_TRIVIAL(debug) << "mergeNtiff -f " << configuration_file; return 0; } @@ -361,7 +344,7 @@ int parseCommandLine(int argc, char** argv) { * \param[in,out] resys Résolution en y des images * \return true en cas de succès, false si échec */ -bool loadConfiguration( +bool load_configuration( std::vector* masks, std::vector* paths, std::vector* srss, @@ -369,11 +352,11 @@ bool loadConfiguration( std::vector* resxs, std::vector* resys) { std::ifstream file; - int rootLength = strlen(outImagesRoot); + int rootLength = strlen(images_root); - file.open(imageListFilename); + file.open(configuration_file); if (!file.is_open()) { - BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << imageListFilename; + BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << configuration_file; return false; } @@ -389,7 +372,7 @@ bool loadConfiguration( std::string crs; BoundingBox bb(0., 0., 0., 0.); double resx, resy; - bool isMask; + bool is_mask; file.getline(line, 2 * IMAGE_MAX_FILENAME_LENGTH); if (strlen(line) == 0) { @@ -399,10 +382,10 @@ bool loadConfiguration( if (nb == 9 && memcmp(type, "IMG", 3) == 0) { // On lit la ligne d'une image crs.assign(tmpCRS); - isMask = false; + is_mask = false; } else if (nb == 2 && memcmp(type, "MSK", 3) == 0) { // On lit la ligne d'un masque - isMask = true; + is_mask = true; if (masks->size() == 0 || masks->back()) { // La première ligne ne peut être un masque et on ne peut pas avoir deux masques à la suite @@ -420,14 +403,14 @@ bool loadConfiguration( memset(path, 0, IMAGE_MAX_FILENAME_LENGTH); if (!strncmp(tmpPath, "?", 1)) { - strcpy(path, outImagesRoot); + strcpy(path, images_root); strcpy(&(path[rootLength]), &(tmpPath[1])); } else { strcpy(path, tmpPath); } // On ajoute tout ça dans les vecteurs - masks->push_back(isMask); + masks->push_back(is_mask); paths->push_back(path); srss->push_back(crs); bboxes->push_back(bb); @@ -440,7 +423,7 @@ bool loadConfiguration( file.close(); return true; } else { - BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << imageListFilename; + BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << configuration_file; file.close(); return false; } @@ -451,13 +434,13 @@ bool loadConfiguration( * \brief Charge les images en entrée et en sortie depuis le fichier de configuration * \details On va récupérer toutes les informations de toutes les images et masques présents dans le fichier de configuration et créer les objets FileImage correspondant. Toutes les images ici manipulées sont de vraies images (physiques) dans ce sens où elles sont des fichiers soit lus, soit qui seront écrits. * - * Le chemin vers le fichier de configuration est stocké dans la variables globale imageListFilename et outImagesRoot va être concaténer au chemin vers les fichiers de sortie. - * \param[out] ppImageOut image résultante de l'outil - * \param[out] ppMaskOut masque résultat de l'outil, si demandé - * \param[out] pImageIn ensemble des images en entrée + * Le chemin vers le fichier de configuration est stocké dans la variables globale configuration_file et images_root va être concaténer au chemin vers les fichiers de sortie. + * \param[out] output_image image résultante de l'outil + * \param[out] output_mask masque résultat de l'outil, si demandé + * \param[out] sorted_input_images ensemble des images en entrée * \return code de retour, 0 si réussi, -1 sinon */ -int loadImages(FileImage** ppImageOut, FileImage** ppMaskOut, std::vector* pImageIn) { +int load_images(FileImage** output_image, FileImage** output_mask, std::vector* input_images) { std::vector masks; std::vector paths; std::vector srss; @@ -465,70 +448,69 @@ int loadImages(FileImage** ppImageOut, FileImage** ppMaskOut, std::vector resxs; std::vector resys; - if (!loadConfiguration(&masks, &paths, &srss, &bboxes, &resxs, &resys)) { - BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << imageListFilename; + if (! load_configuration(&masks, &paths, &srss, &bboxes, &resxs, &resys)) { + BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << configuration_file; return -1; } // On doit avoir au moins deux lignes, trois si on a un masque de sortie if (masks.size() < 2 || (masks.size() == 2 && masks.back())) { - BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << imageListFilename; + BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << configuration_file; return -1; } // On va charger les images en entrée en premier pour avoir certaines informations - int firstInput = 1; + int first_input = 1; if (masks.at(1)) { // La deuxième ligne est le masque de sortie - firstInput = 2; + first_input = 2; } /****************** LES ENTRÉES : CRÉATION ******************/ - FileImageFactory factory; - int nbImgsIn = 0; + int input_count = 0; - for (int i = firstInput; i < masks.size(); i++) { - nbImgsIn++; - BOOST_LOG_TRIVIAL(debug) << "Input " << nbImgsIn; + for (int i = first_input; i < masks.size(); i++) { + input_count++; + BOOST_LOG_TRIVIAL(debug) << "Input " << input_count; if (resxs.at(i) == 0. || resys.at(i) == 0.) { - BOOST_LOG_TRIVIAL(error) << "Source image " << nbImgsIn << " is not valid (resolutions)"; + BOOST_LOG_TRIVIAL(error) << "Source image " << input_count << " is not valid (resolutions)"; return -1; } CRS *crs = new CRS(srss.at(i)); - if (!crs->isDefine()) { + if (! crs->is_define()) { BOOST_LOG_TRIVIAL(error) << "Input CRS unknown: " << srss.at(i); return -1; } else { - BOOST_LOG_TRIVIAL(debug) << crs->getProjCode(); - bboxes.at(i).crs = crs->getRequestCode(); + BOOST_LOG_TRIVIAL(debug) << crs->get_proj_code(); + bboxes.at(i).crs = crs->get_request_code(); } - if (!bboxes.at(i).isInAreaOfCRS(crs)) { + if (! bboxes.at(i).isInAreaOfCRS(crs)) { BOOST_LOG_TRIVIAL(debug) << "Warning : the input image's (" << paths.at(i) << ") bbox is not included in the srs (" << srss.at(i) << ") definition extent"; - BOOST_LOG_TRIVIAL(debug) << bboxes.at(i).toString() << " not included in " << crs->getNativeCrsDefinitionArea().toString(); + BOOST_LOG_TRIVIAL(debug) << bboxes.at(i).to_string() << " not included in " << crs->get_native_crs_definition_area().to_string(); } - FileImage* pImage = factory.createImageToRead(paths.at(i), bboxes.at(i), resxs.at(i), resys.at(i)); - if (pImage == NULL) { + FileImage* input_image = FileImage::create_to_read(paths.at(i), bboxes.at(i), resxs.at(i), resys.at(i)); + if (input_image == NULL) { BOOST_LOG_TRIVIAL(error) << "Impossible de creer une image a partir de " << paths.at(i); return -1; } - pImage->setCRS(crs); + input_image->set_crs(crs); free(paths.at(i)); if (i + 1 < masks.size() && masks.at(i + 1)) { - FileImage* pMask = factory.createImageToRead(paths.at(i + 1), bboxes.at(i), resxs.at(i), resys.at(i)); - if (pMask == NULL) { + FileImage* input_mask = FileImage::create_to_read(paths.at(i + 1), bboxes.at(i), resxs.at(i), resys.at(i)); + if (input_mask == NULL) { BOOST_LOG_TRIVIAL(error) << "Impossible de creer un masque a partir de " << paths.at(i); return -1; } - pMask->setCRS(crs); + input_mask->set_crs(crs); - if (!pImage->setMask(pMask)) { + if (!input_image->set_mask(input_mask)) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the input FileImage"; return -1; } @@ -537,55 +519,48 @@ int loadImages(FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorpush_back(pImage); + input_images->push_back(input_image); /* On vérifie que le format des canaux est le même pour toutes les images en entrée : * - sampleformat - * - bitspersample * - samplesperpixel */ - if (! outputProvided && nbImgsIn == 1) { + if (! output_format_provided && input_count == 1) { /* On n'a pas précisé de format en sortie, on va donc utiliser celui des entrées * On veut donc avoir le même format pour toutes les entrées * On lit la première image en entrée, qui sert de référence * L'image en sortie sera à ce format */ - bitspersample = pImage->getBitsPerSample(); - samplesperpixel = pImage->getChannels(); - sampleformat = pImage->getSampleFormat(); - } else if (!outputProvided) { + samplesperpixel = input_image->get_channels(); + sampleformat = input_image->get_sample_format(); + } else if (!output_format_provided) { // On doit avoir le même format pour tout le monde - if (bitspersample != pImage->getBitsPerSample()) { + if (samplesperpixel != input_image->get_channels()) { BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same"; - BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same number of bits per sample"; - BOOST_LOG_TRIVIAL(error) << bitspersample << " != " << pImage->getBitsPerSample(); + BOOST_LOG_TRIVIAL(error) << "The first image and the " << input_count << " one don't have the same number of samples per pixel"; + BOOST_LOG_TRIVIAL(error) << samplesperpixel << " != " << input_image->get_channels(); } - if (samplesperpixel != pImage->getChannels()) { + if (sampleformat != input_image->get_sample_format()) { BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same"; - BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same number of samples per pixel"; - BOOST_LOG_TRIVIAL(error) << samplesperpixel << " != " << pImage->getChannels(); - } - if (sampleformat != pImage->getSampleFormat()) { - BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same"; - BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same sample format"; - BOOST_LOG_TRIVIAL(error) << sampleformat << " != " << pImage->getSampleFormat(); + BOOST_LOG_TRIVIAL(error) << "The first image and the " << input_count << " one don't have the same sample format"; + BOOST_LOG_TRIVIAL(error) << sampleformat << " != " << input_image->get_sample_format(); } } } - if (pImageIn->size() == 0) { - BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << imageListFilename << "' : pas de données en entrée."; + if (input_images->size() == 0) { + BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << configuration_file << "' : pas de données en entrée."; return -1; } else { - BOOST_LOG_TRIVIAL(debug) << nbImgsIn << " image(s) en entrée"; + BOOST_LOG_TRIVIAL(debug) << input_count << " image(s) en entrée"; } /********************** LE STYLE : CRÉATION *************************/ - if (styleProvided) { + if (style_provided) { BOOST_LOG_TRIVIAL(debug) << "Load style"; - style = new Style(styleFilename, false); + style = new Style(style_file); if ( ! style->isOk() ) { BOOST_LOG_TRIVIAL(error) << style->getErrorMessage(); BOOST_LOG_TRIVIAL(error) << "Cannot load style"; @@ -598,9 +573,8 @@ int loadImages(FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorgetBitsPerSample(bitspersample); - samplesperpixel = style->getChannels(samplesperpixel); - sampleformat = style->getSampleFormat(sampleformat); + samplesperpixel = style->get_channels(samplesperpixel); + sampleformat = style->get_sample_format(sampleformat); } /********************** LA SORTIE : CRÉATION *************************/ @@ -613,8 +587,8 @@ int loadImages(FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorisDefine()) { + CRS *output_crs = new CRS(srss.at(0)); + if (! output_crs->is_define()) { BOOST_LOG_TRIVIAL(error) << "Output CRS unknown: " << srss.at(0); return -1; } @@ -623,55 +597,55 @@ int loadImages(FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorsetCRS(outCrs); + (*output_image)->set_crs(output_crs); free(paths.at(0)); - if (firstInput == 2) { - *ppMaskOut = factory.createImageToWrite( + if (first_input == 2) { + *output_mask = FileImage::create_to_write( paths.at(1), bboxes.at(0), resxs.at(0), resys.at(0), width, height, - 1, SampleFormat::UINT, 8, Photometric::MASK, Compression::DEFLATE); + 1, SampleFormat::UINT8, Photometric::MASK, Compression::DEFLATE); - if (*ppMaskOut == NULL) { + if (*output_mask == NULL) { BOOST_LOG_TRIVIAL(error) << "Impossible de creer le masque " << paths.at(1); return -1; } - (*ppMaskOut)->setCRS(outCrs); + (*output_mask)->set_crs(output_crs); free(paths.at(1)); } - delete outCrs; + delete output_crs; - if (debugLogger) (*ppImageOut)->print(); + if (debug_logger) (*output_image)->print(); return 0; } -int addConverters(std::vector ImageIn) { - if (! outputProvided) { +int add_converters(std::vector input_images) { + if (! output_format_provided) { // On n'a pas précisé de format en sortie, donc toutes les images doivent avoir le même // Et la sortie a aussi ce format, donc pas besoin de convertisseur return 0; } - for (std::vector::iterator itImg = ImageIn.begin(); itImg < ImageIn.end(); itImg++) { - if (!(*itImg)->addConverter(sampleformat, bitspersample, samplesperpixel)) { + for (std::vector::iterator input_images_iterator = input_images.begin(); input_images_iterator < input_images.end(); input_images_iterator++) { + if (!(*input_images_iterator)->add_converter(sampleformat, samplesperpixel)) { BOOST_LOG_TRIVIAL(error) << "Cannot add converter for an input image"; - (*itImg)->print(); + (*input_images_iterator)->print(); return -1; } - if (debugLogger) (*itImg)->print(); + if (debug_logger) (*input_images_iterator)->print(); } return 0; @@ -689,30 +663,30 @@ int addConverters(std::vector ImageIn) { * * \~ \image html mergeNtiff_package.png \~french * - * \param[in] ImageIn images en entrée - * \param[out] pTabImageIn images en entrée, triées en paquets compatibles + * \param[in] input_images images en entrée + * \param[out] sorted_input_images images en entrée, triées en paquets compatibles * \return code de retour, 0 si réussi, -1 sinon */ -int sortImages(std::vector ImageIn, std::vector >* pTabImageIn) { - std::vector vTmpImg; - std::vector::iterator itiniImg = ImageIn.begin(); +int sort_images(std::vector input_images, std::vector >* sorted_input_images) { + std::vector tmp; + std::vector::iterator current_input_images_iterator = input_images.begin(); /* we create consistent images' vectors (X/Y resolution and X/Y phases) * Masks are moved in parallel with images */ - for (std::vector::iterator itImg = ImageIn.begin(); itImg < ImageIn.end() - 1; itImg++) { - if (!(*itImg)->isCompatibleWith(*(itImg + 1))) { + for (std::vector::iterator input_images_iterator = input_images.begin(); input_images_iterator < input_images.end() - 1; input_images_iterator++) { + if (!(*input_images_iterator)->compatible(*(input_images_iterator + 1))) { // two following images are not compatible, we split images' vector - vTmpImg.assign(itiniImg, itImg + 1); - itiniImg = itImg + 1; - pTabImageIn->push_back(vTmpImg); + tmp.assign(current_input_images_iterator, input_images_iterator + 1); + current_input_images_iterator = input_images_iterator + 1; + sorted_input_images->push_back(tmp); } } - // we don't forget to store last images in pTabImageIn + // we don't forget to store last images in sorted_input_images // images - vTmpImg.assign(itiniImg, ImageIn.end()); - pTabImageIn->push_back(vTmpImg); + tmp.assign(current_input_images_iterator, input_images.end()); + sorted_input_images->push_back(tmp); return 0; } @@ -721,29 +695,29 @@ int sortImages(std::vector ImageIn, std::vector * \~french * \brief Réechantillonne un paquet d'images compatibles * \details On crée l'objet ResampledImage correspondant au réechantillonnage du paquet d'images, afin de le rendre compatible avec l'image de sortie. On veut que l'emprise de l'image réechantillonnée ne dépasse ni de l'image de sortie, ni des images en entrée (sans prendre en compte les miroirs, données virtuelles). - * \param[in] pImageOut image résultante de l'outil - * \param[in] pECI paquet d'images compatibles, à réechantillonner - * \param[in] ppRImage image réechantillonnée + * \param[in] output_image image résultante de l'outil + * \param[in] input_images paquet d'images compatibles, à réechantillonner + * \param[in] resampled_image image réechantillonnée * \return VRAI si succès, FAUX sinon */ -bool resampleImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, ResampledImage** ppRImage) { - double resx_dst = pImageOut->getResX(), resy_dst = pImageOut->getResY(); +bool resample_images(FileImage* output_image, ExtendedCompoundImage* input_images, ResampledImage** resampled_image) { + double resx_dst = output_image->get_resx(), resy_dst = output_image->get_resy(); - const Kernel& K = Kernel::getInstance(interpolation); + const Kernel& kernel = Kernel::getInstance(interpolation); // Ajout des miroirs // Valeurs utilisées pour déterminer la taille des miroirs en pixel (taille optimale en fonction du noyau utilisé) - int mirrorSizeX = ceil(K.size(resx_dst / pECI->getResX())) + 1; - int mirrorSizeY = ceil(K.size(resy_dst / pECI->getResY())) + 1; + int mirror_size_x = ceil(kernel.size(resx_dst / input_images->get_resx())) + 1; + int mirror_size_y = ceil(kernel.size(resy_dst / input_images->get_resy())) + 1; - int mirrorSize = std::max(mirrorSizeX, mirrorSizeY); + int mirror_size = std::max(mirror_size_x, mirror_size_y); - BOOST_LOG_TRIVIAL(debug) << "\t Mirror's size : " << mirrorSize; + BOOST_LOG_TRIVIAL(debug) << "\t Mirror's size : " << mirror_size; // On mémorise la bbox d'origine, sans les miroirs - BoundingBox realBbox = pECI->getBbox(); + BoundingBox real_bbox = input_images->get_bbox(); - if (! pECI->addMirrors(mirrorSize)) { + if (! input_images->add_mirrors(mirror_size)) { BOOST_LOG_TRIVIAL(error) << "Unable to add mirrors"; return false; } @@ -751,10 +725,10 @@ bool resampleImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, Resampled /* L'image reechantillonnee est limitee a l'intersection entre l'image de sortie et les images sources * (sans compter les miroirs) */ - double xmin_dst = std::max(realBbox.xmin, pImageOut->getXmin()); - double xmax_dst = std::min(realBbox.xmax, pImageOut->getXmax()); - double ymin_dst = std::max(realBbox.ymin, pImageOut->getYmin()); - double ymax_dst = std::min(realBbox.ymax, pImageOut->getYmax()); + double xmin_dst = std::max(real_bbox.xmin, output_image->get_xmin()); + double xmax_dst = std::min(real_bbox.xmax, output_image->get_xmax()); + double ymin_dst = std::max(real_bbox.ymin, output_image->get_ymin()); + double ymax_dst = std::min(real_bbox.ymax, output_image->get_ymax()); BoundingBox bbox_dst(xmin_dst, ymin_dst, xmax_dst, ymax_dst); @@ -762,7 +736,7 @@ bool resampleImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, Resampled * avec l'image de sortie. Il faut donc modifier la bounding box afin qu'elle remplisse les conditions de compatibilité * (phases égales en x et en y). */ - bbox_dst.phase(pImageOut->getBbox(), pImageOut->getResX(), pImageOut->getResY()); + bbox_dst.phase(output_image->get_bbox(), output_image->get_resx(), output_image->get_resy()); // Dimension de l'image reechantillonnee int width_dst = int((bbox_dst.xmax - bbox_dst.xmin) / resx_dst + 0.5); @@ -774,38 +748,38 @@ bool resampleImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, Resampled } // On réechantillonne le masque : TOUJOURS EN PPV, sans utilisation de masque pour l'interpolation - ResampledImage* pRMask = new ResampledImage(pECI->Image::getMask(), width_dst, height_dst, resx_dst, resy_dst, bbox_dst, + ResampledImage* resampled_mask = new ResampledImage(input_images->Image::get_mask(), width_dst, height_dst, resx_dst, resy_dst, bbox_dst, Interpolation::NEAREST_NEIGHBOUR, false); // Reechantillonnage - Image* pInput = pECI; - if (styleProvided) { - Image* pStyled = NULL; + Image* input_to_resample = input_images; + if (style_provided) { + Image* styled_image = NULL; - if (style->isEstompage()) { - pStyled = new EstompageImage (pECI, style->getEstompage()); + if (style->estompage_defined()) { + styled_image = new EstompageImage (input_images, style->get_estompage()); } - else if (style->isPente()) { - pStyled = new PenteImage (pECI, style->getPente()); + else if (style->pente_defined()) { + styled_image = new PenteImage (input_images, style->get_pente()); } - else if (style->isAspect()) { - pStyled = new AspectImage (pECI, style->getAspect()) ; + else if (style->aspect_defined()) { + styled_image = new AspectImage (input_images, style->get_aspect()) ; } - if ( pInput->getChannels() == 1 && ! ( style->getPalette()->getColoursMap()->empty() ) ) { - if (pStyled != NULL) { - pInput = new StyledImage ( pStyled, samplesperpixel , style->getPalette() ); + if ( input_to_resample->get_channels() == 1 && ! ( style->get_palette()->is_empty() ) ) { + if (styled_image != NULL) { + input_to_resample = new PaletteImage ( styled_image , style->get_palette() ); } else { - pInput = new StyledImage ( pECI, samplesperpixel , style->getPalette() ); + input_to_resample = new PaletteImage ( input_images , style->get_palette() ); } } else { - pInput = pStyled; + input_to_resample = styled_image; } } - *ppRImage = new ResampledImage(pInput, width_dst, height_dst, resx_dst, resy_dst, bbox_dst, interpolation, pECI->useMasks()); + *resampled_image = new ResampledImage(input_to_resample, width_dst, height_dst, resx_dst, resy_dst, bbox_dst, interpolation, input_images->use_masks()); - if (!(*ppRImage)->setMask(pRMask)) { + if (!(*resampled_image)->set_mask(resampled_mask)) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the ResampledImage"; return false; } @@ -822,53 +796,53 @@ bool resampleImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, Resampled * * L'image reprojetée peut être nulle, dans le cas où l'image source ne recouvrait pas suffisemment l'image de sortie pour permettre le calcul d'une image (une dimensions de l'image reprojetée aurait été nulle). * - * \param[in] pImageOut image résultante de l'outil - * \param[in] pECI paquet d'images compatibles, à reprojeter - * \param[in] ppRImage image reprojetée + * \param[in] output_image image résultante de l'outil + * \param[in] input_images paquet d'images compatibles, à reprojeter + * \param[in] reprojected_image image reprojetée * \return VRAI si succès, FAUX sinon */ -bool reprojectImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, ReprojectedImage** ppRImage) { +bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_images, ReprojectedImage** reprojected_image) { // Calcul des paramètres de reprojection - double resx_dst = pImageOut->getResX(), resy_dst = pImageOut->getResY(); - double resx_src = pECI->getResX(), resy_src = pECI->getResY(); + double resx_dst = output_image->get_resx(), resy_dst = output_image->get_resy(); + double resx_src = input_images->get_resx(), resy_src = input_images->get_resy(); - const Kernel& K = Kernel::getInstance(interpolation); + const Kernel& kernel = Kernel::getInstance(interpolation); /******** Conversion de la bbox source dans le srs de sortie ********/ /******************* et calcul des ratios des résolutions ***********/ - BoundingBox tmp_bbox = pECI->getBbox().cropToAreaOfCRS(pECI->getCRS()); + BoundingBox tmp_bbox = input_images->get_bbox().cropToAreaOfCRS(input_images->get_crs()); - int cropWidth = ceil((tmp_bbox.xmax - tmp_bbox.xmin) / resx_src); - int cropHeight = ceil((tmp_bbox.ymax - tmp_bbox.ymin) / resy_src); + int crop_width = ceil((tmp_bbox.xmax - tmp_bbox.xmin) / resx_src); + int crop_height = ceil((tmp_bbox.ymax - tmp_bbox.ymin) / resy_src); - if (!tmp_bbox.reproject(pECI->getCRS(), pImageOut->getCRS())) { + if (!tmp_bbox.reproject(input_images->get_crs(), output_image->get_crs())) { BOOST_LOG_TRIVIAL(error) << "Erreur reprojection bbox src -> dst"; return false; } /* On valcule les résolutions de l'image source "équivalente" dans le SRS de destination, pour pouvoir calculer le ratio * des résolutions pour la taille des miroirs */ - double resx_calc = (tmp_bbox.xmax - tmp_bbox.xmin) / double(cropWidth); - double resy_calc = (tmp_bbox.ymax - tmp_bbox.ymin) / double(cropHeight); + double resx_calc = (tmp_bbox.xmax - tmp_bbox.xmin) / double(crop_width); + double resy_calc = (tmp_bbox.ymax - tmp_bbox.ymin) / double(crop_height); /******************** Image reprojetée : dimensions *****************/ /* On fait particulièrement attention à ne considérer que la partie valide de la bbox finale * c'est à dire la partie incluse dans l'espace de définition du SRS * On va donc la "croper" */ - BoundingBox croped_output_bbox = pImageOut->getBbox().cropToAreaOfCRS(pImageOut->getCRS()); + BoundingBox croped_output_bbox = output_image->get_bbox().cropToAreaOfCRS(output_image->get_crs()); BoundingBox bbox_dst = croped_output_bbox.getIntersection(tmp_bbox); - BOOST_LOG_TRIVIAL(debug) << " BBOX dst (srs destination) : " << bbox_dst.toString(); + BOOST_LOG_TRIVIAL(debug) << " BBOX dst (srs destination) : " << bbox_dst.to_string(); /* Nous avons maintenant les limites de l'image reprojetée. N'oublions pas que celle ci doit être compatible * avec l'image de sortie. Il faut donc modifier la bounding box afin qu'elle remplisse les conditions de compatibilité * (phases égales en x et en y). */ - bbox_dst.phase(pImageOut->getBbox(), pImageOut->getResX(), pImageOut->getResY()); + bbox_dst.phase(output_image->get_bbox(), output_image->get_resx(), output_image->get_resy()); // Dimension de l'image reechantillonnee BOOST_LOG_TRIVIAL(debug) << " Calculated destination width (float) : " << (bbox_dst.xmax - bbox_dst.xmin) / resx_dst; @@ -876,105 +850,109 @@ bool reprojectImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, Reprojec int width_dst = int((bbox_dst.xmax - bbox_dst.xmin) / resx_dst + 0.5); int height_dst = int((bbox_dst.ymax - bbox_dst.ymin) / resy_dst + 0.5); - if (width_dst <= 0 || height_dst <= 0) - { + if (width_dst <= 0 || height_dst <= 0) { BOOST_LOG_TRIVIAL(warning) << "A ReprojectedImage's dimension would have been null"; return true; } tmp_bbox = bbox_dst; - if (!tmp_bbox.reproject(pImageOut->getCRS(), pECI->getCRS())) { + if (! tmp_bbox.reproject(output_image->get_crs(), input_images->get_crs())) { BOOST_LOG_TRIVIAL(error) << "Erreur reprojection bbox dst en crs src"; return false; } - BOOST_LOG_TRIVIAL(debug) << " BBOX dst (srs source) : " << tmp_bbox.toString(); - BOOST_LOG_TRIVIAL(debug) << " BBOX source : " << pECI->getBbox().toString(); + BOOST_LOG_TRIVIAL(debug) << " BBOX dst (srs source) : " << tmp_bbox.to_string(); + BOOST_LOG_TRIVIAL(debug) << " BBOX source : " << input_images->get_bbox().to_string(); /************************ Ajout des miroirs *************************/ - double ratioX = resx_dst / resx_calc; - double ratioY = resy_dst / resy_calc; + double ratio_x = resx_dst / resx_calc; + double ratio_y = resy_dst / resy_calc; // Ajout des miroirs - int mirrorSizeX = ceil(K.size(ratioX)) + 1; - int mirrorSizeY = ceil(K.size(ratioY)) + 1; + int mirror_size_x = ceil(kernel.size(ratio_x)) + 1; + int mirror_size_y = ceil(kernel.size(ratio_y)) + 1; - int mirrorSize = 2 * std::max(mirrorSizeX, mirrorSizeY); + int mirror_size = 2 * std::max(mirror_size_x, mirror_size_y); - BOOST_LOG_TRIVIAL(debug) << " Mirror's size : " << mirrorSize; + BOOST_LOG_TRIVIAL(debug) << " Mirror's size : " << mirror_size; - if (!pECI->addMirrors(mirrorSize)) { + if (! input_images->add_mirrors(mirror_size)) { BOOST_LOG_TRIVIAL(error) << "Unable to add mirrors"; return false; } - BOOST_LOG_TRIVIAL(debug) << " BBOX source avec miroir : " << pECI->getBbox().toString(); + BOOST_LOG_TRIVIAL(debug) << " BBOX source avec miroir : " << input_images->get_bbox().to_string(); /********************** Image source agrandie ***********************/ /* L'image à reprojeter n'est pas intégralement contenue dans l'image source. Cela va poser des problèmes lors de l'interpolation : * ReprojectedImage va vouloir accéder à des coordonnées pixel négatives -> segmentation fault. * Pour éviter cela, on va agrandir artificiellemnt l'étendue de l'image source (avec du nodata) */ - if (!pECI->extendBbox(tmp_bbox, mirrorSize + 1)) { + if (! input_images->extend_bbox(tmp_bbox, mirror_size + 1)) { BOOST_LOG_TRIVIAL(error) << "Unable to extend the source image extent for the reprojection"; return false; } - BOOST_LOG_TRIVIAL(debug) << " BBOX source agrandie : " << pECI->getBbox().toString(); + BOOST_LOG_TRIVIAL(debug) << " BBOX source agrandie : " << input_images->get_bbox().to_string(); /********************** Grille de reprojection **********************/ Grid* grid = new Grid(width_dst, height_dst, bbox_dst); - if (!(grid->reproject(pImageOut->getCRS(), pECI->getCRS()))) { + if (!(grid->reproject(output_image->get_crs(), input_images->get_crs()))) { BOOST_LOG_TRIVIAL(error) << "Bbox image invalide"; return false; } - grid->affine_transform(1. / resx_src, -pECI->getBbox().xmin / resx_src - 0.5, - -1. / resy_src, pECI->getBbox().ymax / resy_src - 0.5); + grid->affine_transform(1. / resx_src, -input_images->get_bbox().xmin / resx_src - 0.5, + -1. / resy_src, input_images->get_bbox().ymax / resy_src - 0.5); /********************** Application du style **********************/ - Image* pInput = pECI; - if (styleProvided) { - Image* pStyled = NULL; + Image* input_to_reproject = input_images; + if (style_provided) { + Image* styled_image = NULL; - if (style->isEstompage()) { - pStyled = new EstompageImage (pECI, style->getEstompage()); + if (style->estompage_defined()) { + styled_image = new EstompageImage (input_images, style->get_estompage()); } - else if (style->isPente()) { - pStyled = new PenteImage (pECI, style->getPente()); + else if (style->pente_defined()) { + BOOST_LOG_TRIVIAL(debug) << "--------------- On ajoute la pente"; + styled_image = new PenteImage (input_images, style->get_pente()); } - else if (style->isAspect()) { - pStyled = new AspectImage (pECI, style->getAspect()) ; + else if (style->aspect_defined()) { + styled_image = new AspectImage (input_images, style->get_aspect()) ; } - if ( pInput->getChannels() == 1 && ! ( style->getPalette()->getColoursMap()->empty() ) ) { - if (pStyled != NULL) { - pInput = new StyledImage ( pStyled, samplesperpixel , style->getPalette() ); + if ( input_to_reproject->get_channels() == 1 && ! ( style->get_palette()->is_empty() ) ) { + if (styled_image != NULL) { + BOOST_LOG_TRIVIAL(debug) << "--------------- On ajoute la palette sur la pente"; + input_to_reproject = new PaletteImage ( styled_image , style->get_palette() ); } else { - pInput = new StyledImage ( pECI, samplesperpixel , style->getPalette() ); + input_to_reproject = new PaletteImage ( input_images , style->get_palette() ); } } else { - pInput = pStyled; + input_to_reproject = styled_image; } } + input_to_reproject->set_crs(input_images->get_crs()); + input_to_reproject->print(); + /*************************** Image reprojetée ***********************/ // On reprojete le masque : TOUJOURS EN PPV, sans utilisation de masque pour l'interpolation - ReprojectedImage* pRMask = new ReprojectedImage(pECI->Image::getMask(), bbox_dst, resx_dst, resy_dst, grid, + ReprojectedImage* reprojected_mask = new ReprojectedImage(input_images->Image::get_mask(), bbox_dst, resx_dst, resy_dst, grid, Interpolation::NEAREST_NEIGHBOUR, false); - pRMask->setCRS(pImageOut->getCRS()); + reprojected_mask->set_crs(output_image->get_crs()); // Reprojection de l'image - *ppRImage = new ReprojectedImage(pInput, bbox_dst, resx_dst, resy_dst, grid, interpolation, pECI->useMasks()); - (*ppRImage)->setCRS(pImageOut->getCRS()); + *reprojected_image = new ReprojectedImage(input_to_reproject, bbox_dst, resx_dst, resy_dst, grid, interpolation, input_images->use_masks()); + (*reprojected_image)->set_crs(output_image->get_crs()); - if (!(*ppRImage)->setMask(pRMask)) { + if (!(*reprojected_image)->set_mask(reprojected_mask)) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the ReprojectedImage"; return false; } @@ -998,134 +976,139 @@ bool reprojectImages(FileImage* pImageOut, ExtendedCompoundImage* pECI, Reprojec * \~ \image html mergeNtiff_decoupe.png \~french * * Les masques sont gérés en toile de fond, en étant attachés à chacune des images manipulées. - * \param[in] pImageOut image de sortie - * \param[in] TabImageIn paquets d'images en entrée - * \param[out] ppECIout paquet d'images superposable avec l'image de sortie - * \param[in] nodata valeur de non-donnée + * \param[in] output_image image de sortie + * \param[in] input_images paquets d'images en entrée + * \param[out] merged_image paquet d'images superposable avec l'image de sortie * \return 0 en cas de succès, -1 en cas d'erreur */ -int mergeTabImages(FileImage *pImageOut, // Sortie - std::vector> &TabImageIn, // Entrée - ExtendedCompoundImage **ppECIout) // Résultat du merge +int merge_images(FileImage *output_image, // Sortie + std::vector> &sorted_input_images, // Entrée + ExtendedCompoundImage **merged_image) // Résultat du merge { - ExtendedCompoundImageFactory ECIF; - std::vector pOverlayedImages; + std::vector stackable_images; + + // Les données en entrée sont remplies : + // - Avec le nodata fourni si pas de style + // - Avec le nodata attendu en entrée du style fourni + int* nd = nodata; + if (style_provided) { + nd = style->get_input_nodata_value(); + } - for (unsigned int i = 0; i < TabImageIn.size(); i++) { - BOOST_LOG_TRIVIAL(debug) << "Pack " << i << " : " << TabImageIn.at(i).size() << " image(s)"; + for (unsigned int i = 0; i < sorted_input_images.size(); i++) { + BOOST_LOG_TRIVIAL(debug) << "Pack " << i << " : " << sorted_input_images.at(i).size() << " image(s)"; // Mise en superposition du paquet d'images en 2 etapes // Etape 1 : Creation d'une image composite (avec potentiellement une seule image) - ExtendedCompoundImage* pECI = ECIF.createExtendedCompoundImage(TabImageIn.at(i), nodata, 0); - if (pECI == NULL) { + ExtendedCompoundImage* stackable_image = ExtendedCompoundImage::create(sorted_input_images.at(i), nd, 0); + if (stackable_image == NULL) { BOOST_LOG_TRIVIAL(error) << "Impossible d'assembler les images"; return -1; } - pECI->setCRS(TabImageIn.at(i).at(0)->getCRS()); + stackable_image->set_crs(sorted_input_images.at(i).at(0)->get_crs()); - ExtendedCompoundMask* pECMI = new ExtendedCompoundMask(pECI); + ExtendedCompoundMask* stackable_mask = new ExtendedCompoundMask(stackable_image); - pECMI->setCRS(TabImageIn.at(i).at(0)->getCRS()); - if (! pECI->setMask(pECMI)) { + stackable_mask->set_crs(sorted_input_images.at(i).at(0)->get_crs()); + if (! stackable_image->set_mask(stackable_mask)) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the Image's pack " << i; return -1; } - if (pImageOut->isCompatibleWith(pECI)) { + if (output_image->compatible(stackable_image)) { BOOST_LOG_TRIVIAL(debug) << "\t is compatible"; /* les images sources et finale ont la meme resolution et la meme phase * on aura donc pas besoin de reechantillonnage.*/ - if (styleProvided && ! (i == 0 && backgroundProvided)) { + if (style_provided && ! (i == 0 && background_provided)) { // Un style est fourni et nous ne sommes pas dans le cas de la première entrée qui est une image de fond - Image* pStyled = NULL; + Image* styled_image = NULL; - if (style->isEstompage()) { - pStyled = new EstompageImage (pECI, style->getEstompage()); + if (style->estompage_defined()) { + styled_image = new EstompageImage (stackable_image, style->get_estompage()); } - else if (style->isPente()) { - pStyled = new PenteImage (pECI, style->getPente()); + else if (style->pente_defined()) { + styled_image = new PenteImage (stackable_image, style->get_pente()); } - else if (style->isAspect()) { - pStyled = new AspectImage (pECI, style->getAspect()) ; + else if (style->aspect_defined()) { + styled_image = new AspectImage (stackable_image, style->get_aspect()) ; } - if ( pECI->getChannels() == 1 && ! ( style->getPalette()->getColoursMap()->empty() ) ) { - if (pStyled != NULL) { - pOverlayedImages.push_back(new StyledImage ( pStyled, samplesperpixel , style->getPalette() )); + if ( stackable_image->get_channels() == 1 && ! ( style->get_palette()->is_empty() ) ) { + if (styled_image != NULL) { + stackable_images.push_back(new PaletteImage ( styled_image , style->get_palette() )); } else { - pOverlayedImages.push_back(new StyledImage ( pECI, samplesperpixel , style->getPalette() )); + stackable_images.push_back(new PaletteImage ( stackable_image , style->get_palette() )); } } else { - pOverlayedImages.push_back(pStyled); + stackable_images.push_back(styled_image); } } else { - pOverlayedImages.push_back(pECI); + stackable_images.push_back(stackable_image); } - } else if (pECI->getCRS()->cmpRequestCode(pImageOut->getCRS()->getRequestCode())) { + } else if (stackable_image->get_crs()->cmp_request_code(output_image->get_crs()->get_request_code())) { BOOST_LOG_TRIVIAL(debug) << "\t need a resampling"; - ResampledImage* pResampledImage = NULL; + ResampledImage* resampled_image = NULL; - if (!resampleImages(pImageOut, pECI, &pResampledImage)) { + if (!resample_images(output_image, stackable_image, &resampled_image)) { BOOST_LOG_TRIVIAL(error) << "Cannot resample images' pack"; return -1; } - if (pResampledImage == NULL) { + if (resampled_image == NULL) { BOOST_LOG_TRIVIAL(warning) << "No resampled image to add"; } else { - pOverlayedImages.push_back(pResampledImage); + stackable_images.push_back(resampled_image); } } else { BOOST_LOG_TRIVIAL(debug) << "\t need a reprojection"; - ReprojectedImage* pReprojectedImage = NULL; + ReprojectedImage* reprojected_image = NULL; - if (!reprojectImages(pImageOut, pECI, &pReprojectedImage)) { + if (!reproject_images(output_image, stackable_image, &reprojected_image)) { BOOST_LOG_TRIVIAL(error) << "Cannot reproject images' pack"; return -1; } - if (pReprojectedImage == NULL) { + if (reprojected_image == NULL) { BOOST_LOG_TRIVIAL(warning) << "No reprojected image to add"; } else { - pOverlayedImages.push_back(pReprojectedImage); + stackable_images.push_back(reprojected_image); } } } - int* outputNodata; - if (! styleProvided || style->getNodata(&styleNodata) == 0) { - // Si il n'y a pas de style ou que le style ne modifie pas les canaux (getNodata = 0), on met le même nodata que pour les entrées - // (potentiellement converties à la volée) - BOOST_LOG_TRIVIAL(debug) << "Input nodata = output nodata"; - outputNodata = nodata; - } else { - outputNodata = styleNodata; + + // Les données en sortie sont remplies : + // - Avec le nodata fourni si pas de style + // - Avec le nodata de sortie du style fourni + nd = nodata; + if (style_provided) { + nd = style->get_output_nodata_value(); } - for (int i = 0; i < pImageOut->getChannels(); i++) { - BOOST_LOG_TRIVIAL(debug) << "output nodata [" << i << "] = " << outputNodata[i]; + for (int i = 0; i < output_image->get_channels(); i++) { + BOOST_LOG_TRIVIAL(debug) << "output nodata [" << i << "] = " << nd[i]; } // Assemblage des paquets et decoupage aux dimensions de l image de sortie - *ppECIout = ECIF.createExtendedCompoundImage( - pImageOut->getWidth(), pImageOut->getHeight(), pImageOut->getChannels(), pImageOut->getBbox(), - pOverlayedImages, outputNodata, 0); + *merged_image = ExtendedCompoundImage::create( + output_image->get_width(), output_image->get_height(), output_image->get_channels(), output_image->get_bbox(), + stackable_images, nd, 0); - if (*ppECIout == NULL) { - for (int i = 0; i < pOverlayedImages.size(); i++) delete pOverlayedImages.at(i); + if (*merged_image == NULL) { + for (int i = 0; i < stackable_images.size(); i++) delete stackable_images.at(i); BOOST_LOG_TRIVIAL(error) << "Cannot create final compounded image."; return -1; } // Masque - ExtendedCompoundMask* pECMIout = new ExtendedCompoundMask(*ppECIout); + ExtendedCompoundMask* merged_mask = new ExtendedCompoundMask(*merged_image); - if (!(*ppECIout)->setMask(pECMIout)) { + if (!(*merged_image)->set_mask(merged_mask)) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the main Extended Compound Image"; return -1; } @@ -1146,11 +1129,11 @@ int mergeTabImages(FileImage *pImageOut, // Sortie * \return 0 if success, -1 otherwise */ int main(int argc, char** argv) { - FileImage* pImageOut = NULL; - FileImage* pMaskOut = NULL; - std::vector ImageIn; - std::vector > TabImageIn; - ExtendedCompoundImage* pECI = NULL; + FileImage* output_image = NULL; + FileImage* output_mask = NULL; + std::vector input_images; + std::vector > sorted_input_images; + ExtendedCompoundImage* merged_image = NULL; /* Initialisation des Loggers */ boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info); @@ -1158,32 +1141,37 @@ int main(int argc, char** argv) { boost::log::register_simple_formatter_factory("Severity"); logging::add_console_log( std::cout, - keywords::format = "%Severity%\t%Message%"); + keywords::format = "%Severity%\t%Message%" + ); // Lecture des parametres de la ligne de commande - if (parseCommandLine(argc, argv) < 0) { + if (parse_command_line(argc, argv) < 0) { error("Echec lecture ligne de commande", -1); } // On sait maintenant si on doit activer le niveau de log DEBUG - if (debugLogger) { + if (debug_logger) { boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::debug); } // On regarde si on a tout précisé en sortie, pour voir si des conversions sont possibles - if (sampleformat != SampleFormat::UNKNOWN && bitspersample != 0 && samplesperpixel != 0) { - outputProvided = true; + if (sampleformat != SampleFormat::UNKNOWN && samplesperpixel != 0) { + output_format_provided = true; } - if (outputProvided && styleProvided) { + if (output_format_provided && style_provided) { error("Impossible d'appliquer un style et une conversion à la volée", -1); } + if (! style_provided && ! nodata_provided) { + error("Préciser une valeur de nodata est obligatoire sans style", -1); + } + BOOST_LOG_TRIVIAL(debug) << "Load"; // Chargement des images - if (loadImages(&pImageOut, &pMaskOut, &ImageIn) < 0) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; + if (load_images(&output_image, &output_mask, &input_images) < 0) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; ProjPool::cleanProjPool(); proj_cleanup(); error("Echec chargement des images", -1); @@ -1191,57 +1179,54 @@ int main(int argc, char** argv) { BOOST_LOG_TRIVIAL(debug) << "Add converters"; // Ajout des modules de conversion aux images en entrée - if (addConverters(ImageIn) < 0) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; + if (add_converters(input_images) < 0) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; ProjPool::cleanProjPool(); proj_cleanup(); error("Echec ajout des convertisseurs", -1); } - // Maintenant que l'on a la valeur de samplesperpixel, on peut lire le nodata + // Maintenant que l'on a la valeur de samplesperpixel, on peut lire le nodata fourni // Conversion string->int[] du paramètre nodata - BOOST_LOG_TRIVIAL(debug) << "Nodata interpretation"; - int nodataElements = samplesperpixel; - if (styleProvided) { - // Si un style est fourni, la valeur de nodata fournie est celle des données en entrée, et non de la sortie - // Le nodata de la sortie est déduit du style - nodataElements = ImageIn.at(0)->getChannels(); - } - nodata = new int[nodataElements]; + if (nodata_provided) { + BOOST_LOG_TRIVIAL(debug) << "Nodata interpretation"; + + nodata = new int[samplesperpixel]; - char* charValue = strtok(strnodata, ","); - if (charValue == NULL) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; - ProjPool::cleanProjPool(); - proj_cleanup(); - error("Error with option -n : a value for nodata is missing", -1); - } - nodata[0] = atoi(charValue); - - for (int i = 1; i < nodataElements; i++) { - charValue = strtok(NULL, ","); - if (charValue == NULL) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; + char* char_iterator = strtok(strnodata, ","); + if (char_iterator == NULL) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; ProjPool::cleanProjPool(); proj_cleanup(); - error("Error with option -n : one value per sample, separate with comma", -1); + error("Error with option -n : a value for nodata is missing", -1); + } + nodata[0] = atoi(char_iterator); + + for (int i = 1; i < samplesperpixel; i++) { + char_iterator = strtok(NULL, ","); + if (char_iterator == NULL) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; + ProjPool::cleanProjPool(); + proj_cleanup(); + error("Error with option -n : one value per sample, separate with comma", -1); + } + nodata[i] = atoi(char_iterator); } - nodata[i] = atoi(charValue); } BOOST_LOG_TRIVIAL(debug) << "Sort"; // Tri des images - if (sortImages(ImageIn, &TabImageIn) < 0) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; + if (sort_images(input_images, &sorted_input_images) < 0) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; delete[] nodata; ProjPool::cleanProjPool(); proj_cleanup(); @@ -1250,10 +1235,10 @@ int main(int argc, char** argv) { BOOST_LOG_TRIVIAL(debug) << "Merge"; // Fusion des paquets d images - if (mergeTabImages(pImageOut, TabImageIn, &pECI) < 0) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; + if (merge_images(output_image, sorted_input_images, &merged_image) < 0) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; delete[] nodata; ProjPool::cleanProjPool(); proj_cleanup(); @@ -1262,23 +1247,23 @@ int main(int argc, char** argv) { BOOST_LOG_TRIVIAL(debug) << "Save image"; // Enregistrement de l'image fusionnée - if (pImageOut->writeImage(pECI) < 0) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; + if (output_image->write_image(merged_image) < 0) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; delete[] nodata; ProjPool::cleanProjPool(); proj_cleanup(); error("Echec enregistrement de l image finale", -1); } - if (pMaskOut != NULL) { + if (output_mask != NULL) { BOOST_LOG_TRIVIAL(debug) << "Save mask"; // Enregistrement du masque fusionné, si demandé - if (pMaskOut->writeImage(pECI->Image::getMask()) < 0) { - if (pECI) delete pECI; - if (pImageOut) delete pImageOut; - if (pMaskOut) delete pMaskOut; + if (output_mask->write_image(merged_image->Image::get_mask()) < 0) { + if (merged_image) delete merged_image; + if (output_image) delete output_image; + if (output_mask) delete output_mask; delete[] nodata; ProjPool::cleanProjPool(); proj_cleanup(); @@ -1288,16 +1273,15 @@ int main(int argc, char** argv) { BOOST_LOG_TRIVIAL(debug) << "Clean"; // Nettoyage - if (styleProvided) { - if (! style->isIdentity()) { - delete[] styleNodata; - } + if (style_provided) { delete style; } - delete[] nodata; - delete pECI; - delete pImageOut; - delete pMaskOut; + if (nodata_provided) { + delete[] nodata; + } + delete merged_image; + delete output_image; + delete output_mask; ProjPool::cleanProjPool(); proj_cleanup(); StoragePool::cleanStoragePool(); diff --git a/src/overlayNtiff.cpp b/src/overlayNtiff.cpp index 0a2c0da..44b912b 100644 --- a/src/overlayNtiff.cpp +++ b/src/overlayNtiff.cpp @@ -68,11 +68,9 @@ namespace keywords = boost::log::keywords; #include /** \~french Chemin du fichier de configuration des images */ -char imageListFilename[256]; +char configuration_file[256]; /** \~french Nombre de canaux par pixel de l'image en sortie */ uint16_t samplesperpixel = 0; -/** \~french Nombre de bits occupé par un canal */ -uint16_t bitspersample; /** \~french Format du canal (entier, flottant, signé ou non...), dans les images en entrée et celle en sortie */ SampleFormat::eSampleFormat sampleformat; /** \~french Photométrie (rgb, gray), pour les images en sortie */ @@ -88,7 +86,7 @@ int* transparent; int* background; /** \~french Activation du niveau de log debug. Faux par défaut */ -bool debugLogger=false; +bool debug_logger=false; /** \~french Message d'usage de la commande overlayNtiff */ @@ -144,9 +142,8 @@ void usage() { */ void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << message ; - BOOST_LOG_TRIVIAL(error) << "Configuration file : " << imageListFilename ; + BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_file ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -157,7 +154,7 @@ void error ( std::string message, int errorCode ) { * \param[in] argv tableau des paramètres * \return code de retour, 0 si réussi, -1 sinon */ -int parseCommandLine ( int argc, char** argv ) { +int parse_command_line ( int argc, char** argv ) { char strTransparent[256]; memset ( strTransparent, 0, 256 ); @@ -171,21 +168,21 @@ int parseCommandLine ( int argc, char** argv ) { usage(); exit ( 0 ); case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 'f': // Images' list file if ( i++ >= argc ) { BOOST_LOG_TRIVIAL(error) << "Error with images' list file (option -f)" ; return -1; } - strcpy ( imageListFilename,argv[i] ); + strcpy ( configuration_file,argv[i] ); break; case 'm': // image merge method if ( i++ >= argc ) { BOOST_LOG_TRIVIAL(error) << "Error with merge method (option -m)" ; return -1; } - mergeMethod = Merge::fromString ( argv[i] ); + mergeMethod = Merge::from_string ( argv[i] ); if ( mergeMethod == Merge::UNKNOWN ) { BOOST_LOG_TRIVIAL(error) << "Unknown value for merge method (option -m) : " << argv[i] ; return -1; @@ -262,7 +259,7 @@ int parseCommandLine ( int argc, char** argv ) { } // Image list file control - if ( strlen ( imageListFilename ) == 0 ) { + if ( strlen ( configuration_file ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "We need to have one images' list (text file, option -f)" ; return -1; } @@ -343,7 +340,7 @@ int readFileLine ( std::ifstream& file, char* imageFileName, bool* hasMask, char BOOST_LOG_TRIVIAL(debug) << "Configuration file end reached" ; return -1; } - std::getline ( file,str ); + std::getline ( file, str ); } if ( std::sscanf ( str.c_str(),"%s %s", imageFileName, maskFileName ) == 2 ) { @@ -365,7 +362,7 @@ int readFileLine ( std::ifstream& file, char* imageFileName, bool* hasMask, char * \param[out] pImageIn ensemble des images en entrée * \return code de retour, 0 si réussi, -1 sinon */ -int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppMergeIn ) { +int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppMergeIn ) { char inputImagePath[IMAGE_MAX_FILENAME_LENGTH]; char inputMaskPath[IMAGE_MAX_FILENAME_LENGTH]; @@ -378,21 +375,19 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppM int width, height; bool hasMask, hasOutMask; - FileImageFactory FIF; - MergeImageFactory MIF; // Ouverture du fichier texte listant les images std::ifstream file; - file.open ( imageListFilename ); + file.open ( configuration_file ); if ( !file ) { - BOOST_LOG_TRIVIAL(error) << "Cannot open the file " << imageListFilename ; + BOOST_LOG_TRIVIAL(error) << "Cannot open the file " << configuration_file ; return -1; } // Lecture de l'image de sortie if ( readFileLine ( file,outputImagePath,&hasOutMask,outputMaskPath ) ) { - BOOST_LOG_TRIVIAL(error) << "Cannot read output image in the file : " << imageListFilename ; + BOOST_LOG_TRIVIAL(error) << "Cannot read output image in the file : " << configuration_file ; return -1; } @@ -402,7 +397,7 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppM int inputNb = 0; int out = 0; while ( ( out = readFileLine ( file,inputImagePath,&hasMask,inputMaskPath ) ) == 0 ) { - FileImage* pImage = FIF.createImageToRead ( inputImagePath ); + FileImage* pImage = FileImage::create_to_read ( inputImagePath ); if ( pImage == NULL ) { BOOST_LOG_TRIVIAL(error) << "Cannot create a FileImage from the file " << inputImagePath ; return -1; @@ -410,16 +405,12 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppM if ( inputNb == 0 ) { // C'est notre première image en entrée, on mémorise les caractéristiques) - bitspersample = pImage->getBitsPerSample(); - sampleformat = pImage->getSampleFormat(); - width = pImage->getWidth(); - height = pImage->getHeight(); + sampleformat = pImage->get_sample_format(); + width = pImage->get_width(); + height = pImage->get_height(); } else { // Toutes les images en entrée doivent avoir certaines caractéristiques en commun - if ( bitspersample != pImage->getBitsPerSample() || - sampleformat != pImage->getSampleFormat() || - width != pImage->getWidth() || height != pImage->getHeight() ) { - + if (sampleformat != pImage->get_sample_format() || width != pImage->get_width() || height != pImage->get_height() ) { BOOST_LOG_TRIVIAL(error) << "All input images must have same dimension and sample type" ; return -1; } @@ -430,13 +421,13 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppM * - même dimensions que l'image * - 1 seul canal (entier) */ - FileImage* pMask = FIF.createImageToRead ( inputMaskPath ); + FileImage* pMask = FileImage::create_to_read ( inputMaskPath ); if ( pMask == NULL ) { BOOST_LOG_TRIVIAL(error) << "Cannot create a FileImage (mask) from the file " << inputMaskPath ; return -1; } - if ( ! pImage->setMask ( pMask ) ) { + if ( ! pImage->set_mask ( pMask ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask " << inputMaskPath ; return -1; } @@ -447,7 +438,7 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppM } if ( out != -1 ) { - BOOST_LOG_TRIVIAL(error) << "Failure reading the file " << imageListFilename ; + BOOST_LOG_TRIVIAL(error) << "Failure reading the file " << configuration_file ; return -1; } @@ -456,19 +447,19 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppM // On crée notre MergeImage, qui s'occupera des calculs de fusion des pixels - *ppMergeIn = MIF.createMergeImage ( ImageIn, samplesperpixel, background, transparent, mergeMethod ); + *ppMergeIn = MergeImage::create ( ImageIn, samplesperpixel, background, transparent, mergeMethod ); // Le masque fusionné est ajouté MergeMask* pMM = new MergeMask ( *ppMergeIn ); - if ( ! ( *ppMergeIn )->setMask ( pMM ) ) { + if ( ! ( *ppMergeIn )->set_mask ( pMM ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the merged image" ; return -1; } // Création des sorties - *ppImageOut = FIF.createImageToWrite ( outputImagePath, fakeBbox, -1., -1., width, height, samplesperpixel, - sampleformat, bitspersample, photometric,compression ); + *ppImageOut = FileImage::create_to_write ( outputImagePath, fakeBbox, -1., -1., width, height, samplesperpixel, + sampleformat, photometric,compression ); if ( *ppImageOut == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible de creer l'image " << outputImagePath ; @@ -476,8 +467,8 @@ int loadImages ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppM } if ( hasOutMask ) { - *ppMaskOut = FIF.createImageToWrite ( outputMaskPath, fakeBbox, -1., -1., width, height, 1, - SampleFormat::UINT, 8, Photometric::MASK, Compression::DEFLATE ); + *ppMaskOut = FileImage::create_to_write ( outputMaskPath, fakeBbox, -1., -1., width, height, 1, + SampleFormat::UINT8, Photometric::MASK, Compression::DEFLATE ); if ( *ppMaskOut == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible de creer le masque " << outputMaskPath ; @@ -517,31 +508,31 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Read parameters" ; // Lecture des parametres de la ligne de commande - if ( parseCommandLine ( argc,argv ) < 0 ) { + if ( parse_command_line ( argc,argv ) < 0 ) { error ( "Cannot parse command line",-1 ); } // On sait maintenant si on doit activer le niveau de log DEBUG - if (debugLogger) { + if (debug_logger) { boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } BOOST_LOG_TRIVIAL(debug) << "Load" ; // Chargement des images - if ( loadImages ( &pImageOut,&pMaskOut,&pMergeIn ) < 0 ) { + if ( load_images ( &pImageOut,&pMaskOut,&pMergeIn ) < 0 ) { error ( "Cannot load images from the configuration file",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Save image" ; // Enregistrement de l'image fusionnée - if ( pImageOut->writeImage ( pMergeIn ) < 0 ) { + if ( pImageOut->write_image ( pMergeIn ) < 0 ) { error ( "Cannot write the merged image",-1 ); } // Enregistrement du masque fusionné, si demandé if ( pMaskOut != NULL) { BOOST_LOG_TRIVIAL(debug) << "Save mask" ; - if ( pMaskOut->writeImage ( pMergeIn->Image::getMask() ) < 0 ) { + if ( pMaskOut->write_image ( pMergeIn->Image::get_mask() ) < 0 ) { error ( "Cannot write the merged mask",-1 ); } } diff --git a/src/pbf2cache.cpp b/src/pbf2cache.cpp index ab733d2..fff9052 100644 --- a/src/pbf2cache.cpp +++ b/src/pbf2cache.cpp @@ -94,7 +94,6 @@ void usage() { void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - sleep ( 1 ); exit ( errorCode ); } @@ -117,7 +116,7 @@ int main ( int argc, char **argv ) { int ulCol = -1; int ulRow = -1; - bool debugLogger=false; + bool debug_logger=false; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -144,7 +143,7 @@ int main ( int argc, char **argv ) { usage(); exit ( 0 ); case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 'r': // root directory if ( i++ >= argc ) { @@ -168,7 +167,7 @@ int main ( int argc, char **argv ) { } } - if (debugLogger) { + if (debug_logger) { // le niveau debug du logger est activé boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } @@ -193,17 +192,16 @@ int main ( int argc, char **argv ) { Context* context; curl_global_init(CURL_GLOBAL_ALL); - BOOST_LOG_TRIVIAL(debug) << std::string("Output is on a " + ContextType::toString(type) + " storage in the tray ") + tray_name; + BOOST_LOG_TRIVIAL(debug) << std::string("Output is on a " + ContextType::to_string(type) + " storage in the tray ") + tray_name; context = StoragePool::get_context(type, tray_name); - Rok4ImageFactory R4IF; - Rok4Image* rok4Image = R4IF.createRok4ImageToWrite( fo_name, tilePerWidth, tilePerHeight, context ); + Rok4Image* rok4Image = Rok4Image::create_to_write( fo_name, tilePerWidth, tilePerHeight, context ); if (rok4Image == NULL) { error("Cannot create the ROK4 image to write", -1); } - if (debugLogger) { + if (debug_logger) { rok4Image->print(); } diff --git a/src/work2cache.cpp b/src/work2cache.cpp index b26c397..7552bc1 100644 --- a/src/work2cache.cpp +++ b/src/work2cache.cpp @@ -63,21 +63,14 @@ namespace keywords = boost::log::keywords; #include #include #include -#include #include "config.h" - -/** \~french Presque blanc, en RGBA. Utilisé pour supprimer le blanc pur des données quand l'option "crop" est active */ -int fastWhite[4] = {254,254,254,255}; -/** \~french Blanc, en RGBA. Utilisé pour supprimer le blanc pur des données quand l'option "crop" est active */ -int white[4] = {255,255,255,255}; - /** \~french Message d'usage de la commande work2cache */ std::string help = std::string("\nwork2cache version ") + std::string(VERSION) + "\n\n" "Make image tiled and compressed, in TIFF format, respecting ROK4 specifications.\n\n" - "Usage: work2cache -c -t [-crop]\n\n" + "Usage: work2cache -c -t \n\n" "Parameters:\n" " -c output compression :\n" @@ -90,13 +83,11 @@ std::string help = std::string("\nwork2cache version ") + std::string(VERSION) + " zip Deflate encoding\n" " png Non-official TIFF compression, each tile is an independant PNG image (with PNG header)\n" " -t tile size : widthwise and heightwise. Have to be a divisor of the global image's size\n" - " -crop : blocks (used by JPEG compression) wich contain a white pixel are filled with white\n" " -a sample format : (float or uint)\n" - " -b bits per sample : (8 or 32)\n" " -s samples per pixel : (1, 2, 3 or 4)\n" " -d : debug logger activation\n\n" - "If bitspersample, sampleformat or samplesperpixel are not provided, those 3 informations are read from the image sources (all have to own the same). If 3 are provided, conversion may be done.\n\n" + "If sampleformat or samplesperpixel are not provided, those informations are read from the image sources (all have to own the same). If all are provided, conversion may be done.\n\n" "Output file / object format : [ceph|s3|swift]://tray_name/object_name or [file|ceph|s3|swift]://file_name or file_name\n\n" @@ -124,20 +115,19 @@ void usage() { void error ( std::string message, int errorCode ) { BOOST_LOG_TRIVIAL(error) << ( message ); usage(); - sleep ( 1 ); exit ( errorCode ); } /** ** \~french * \brief Fonction principale de l'outil work2cache - * \details Tout est contenu dans cette fonction. Le "cropage" se fait grâce à la classe TiffNodataManager, et le tuilage / compression est géré Rok4Image + * \details Tout est contenu dans cette fonction. Le tuilage / compression est géré Rok4Image * \param[in] argc nombre de paramètres * \param[in] argv tableau des paramètres * \return code de retour, 0 en cas de succès, -1 sinon ** \~english * \brief Main function for tool work2cache - * \details All instructions are in this function. the crop is handled by the class TiffNodataManager and Rok4Image make image tiled and compressed. + * \details All instructions are in this function. Rok4Image make image tiled and compressed. * \param[in] argc parameters number * \param[in] argv parameters array * \return return code, 0 if success, -1 otherwise @@ -145,25 +135,16 @@ void error ( std::string message, int errorCode ) { int main ( int argc, char **argv ) { char* input = 0, *output = 0; - int tileWidth = 256, tileHeight = 256; + int tile_width = 256, tile_height = 256; Compression::eCompression compression = Compression::NONE; - bool outputProvided = false; + bool output_format_provided = false; uint16_t samplesperpixel = 0; - uint16_t bitspersample = 0; SampleFormat::eSampleFormat sampleformat = SampleFormat::UNKNOWN; Photometric::ePhotometric photometric; - bool crop = false; - bool debugLogger=false; - -#if OBJECT_ENABLED - char *pool = 0, *container = 0, *bucket = 0; - bool onCeph = false; - bool onSwift = false; - bool onS3 = false; -#endif + bool debug_logger=false; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -176,10 +157,6 @@ int main ( int argc, char **argv ) { // Récupération des paramètres for ( int i = 1; i < argc; i++ ) { - if ( !strcmp ( argv[i],"-crop" ) ) { - crop = true; - continue; - } if ( argv[i][0] == '-' ) { switch ( argv[i][1] ) { @@ -187,7 +164,7 @@ int main ( int argc, char **argv ) { usage(); exit ( 0 ); case 'd': // debug logs - debugLogger = true; + debug_logger = true; break; case 'c': // compression if ( ++i == argc ) { error ( "Error in -c option", -1 ); } @@ -206,13 +183,13 @@ int main ( int argc, char **argv ) { } else if ( strncmp ( argv[i], "pkb",3 ) == 0 ) { compression = Compression::PACKBITS; } else { - error ( "Unknown compression : " + string(argv[i]), -1 ); + error ( "Unknown compression : " + std::string(argv[i]), -1 ); } break; case 't': if ( i+2 >= argc ) { error("Error in -t option", -1 ); } - tileWidth = atoi ( argv[++i] ); - tileHeight = atoi ( argv[++i] ); + tile_width = atoi ( argv[++i] ); + tile_height = atoi ( argv[++i] ); break; /****************** OPTIONNEL, POUR FORCER DES CONVERSIONS **********************/ @@ -225,33 +202,23 @@ int main ( int argc, char **argv ) { else if ( strncmp ( argv[i], "3",1 ) == 0 ) samplesperpixel = 3 ; else if ( strncmp ( argv[i], "4",1 ) == 0 ) samplesperpixel = 4 ; else { - error ( "Unknown value for option -s : " + string(argv[i]), -1 ); - } - break; - case 'b': // bitspersample - if ( i++ >= argc ) { - error ( "Error in option -b", -1 ); - } - if ( strncmp ( argv[i], "8",1 ) == 0 ) bitspersample = 8 ; - else if ( strncmp ( argv[i], "32",2 ) == 0 ) bitspersample = 32 ; - else { - error ( "Unknown value for option -b : " + string(argv[i]), -1 ); + error ( "Unknown value for option -s : " + std::string(argv[i]), -1 ); } break; case 'a': // sampleformat if ( i++ >= argc ) { error ( "Error in option -a", -1 ); } - if ( strncmp ( argv[i],"uint",4 ) == 0 ) sampleformat = SampleFormat::UINT ; - else if ( strncmp ( argv[i],"float",5 ) == 0 ) sampleformat = SampleFormat::FLOAT; + if ( strncmp ( argv[i],"uint8",5 ) == 0 ) sampleformat = SampleFormat::UINT8 ; + else if ( strncmp ( argv[i],"float32",7 ) == 0 ) sampleformat = SampleFormat::FLOAT32; else { - error ( "Unknown value for option -a : " + string(argv[i]), -1 ); + error ( "Unknown value for option -a : " + std::string(argv[i]), -1 ); } break; /*******************************************************************************/ default: - error ( "Unknown option : " + string(argv[i]) ,-1 ); + error ( "Unknown option : " + std::string(argv[i]) ,-1 ); } } else { if ( input == 0 ) input = argv[i]; @@ -260,7 +227,7 @@ int main ( int argc, char **argv ) { } } - if (debugLogger) { + if (debug_logger) { // le niveau debug du logger est activé boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } @@ -278,45 +245,18 @@ int main ( int argc, char **argv ) { Context* context; curl_global_init(CURL_GLOBAL_ALL); - BOOST_LOG_TRIVIAL(debug) << std::string("Output is on a " + ContextType::toString(type) + " storage in the tray ") + tray_name; + BOOST_LOG_TRIVIAL(debug) << std::string("Output is on a " + ContextType::to_string(type) + " storage in the tray ") + tray_name; context = StoragePool::get_context(type, tray_name); - FileImageFactory FIF; - - if (crop && compression != Compression::JPEG) { - BOOST_LOG_TRIVIAL(warning) << ("Crop option is reserved for JPEG compression"); - crop = false; - } - - // For jpeg compression with crop option, we have to remove white pixel, to avoid empty bloc in data - if ( crop ) { - BOOST_LOG_TRIVIAL(debug) << ( "Open image to read" ); - // On récupère les informations nécessaires pour appeler le nodata manager - FileImage* tmpSourceImage = FIF.createImageToRead(input); - int spp = tmpSourceImage->getChannels(); - int bps = tmpSourceImage->getBitsPerSample(); - SampleFormat::eSampleFormat sf = tmpSourceImage->getSampleFormat(); - delete tmpSourceImage; - - if ( bps == 8 && sf == SampleFormat::UINT ) { - TiffNodataManager TNM ( spp, white, true, fastWhite,white ); - if ( ! TNM.treatNodata ( input,input ) ) { - error ( "Unable to treat white pixels in this image : " + string(input), -1 ); - } - } else { - BOOST_LOG_TRIVIAL(warning) << "Crop option ignored (only for 8-bit integer images) for the image : " << input; - } - } - BOOST_LOG_TRIVIAL(debug) << ( "Open image to read" ); - FileImage* sourceImage = FIF.createImageToRead(input); - if (sourceImage == NULL) { + FileImage* source_image = FileImage::create_to_read(input); + if (source_image == NULL) { error("Cannot read the source image", -1); } // On regarde si on a tout précisé en sortie, pour voir si des conversions sont demandées et possibles - if (sampleformat != SampleFormat::UNKNOWN && bitspersample != 0 && samplesperpixel !=0) { - outputProvided = true; + if (sampleformat != SampleFormat::UNKNOWN && samplesperpixel !=0) { + output_format_provided = true; // La photométrie est déduite du nombre de canaux if (samplesperpixel == 1) { photometric = Photometric::GRAY; @@ -326,42 +266,40 @@ int main ( int argc, char **argv ) { photometric = Photometric::RGB; } - if (! sourceImage->addConverter ( sampleformat, bitspersample, samplesperpixel ) ) { - error ( "Cannot add converter to the input FileImage " + string(input), -1 ); + if (! source_image->add_converter ( sampleformat, samplesperpixel ) ) { + error ( "Cannot add converter to the input FileImage " + std::string(input), -1 ); } } else { // On n'a pas précisé de format de sortie // La sortie aura ce format - bitspersample = sourceImage->getBitsPerSample(); - photometric = sourceImage->getPhotometric(); - sampleformat = sourceImage->getSampleFormat(); - samplesperpixel = sourceImage->getChannels(); + photometric = source_image->get_photometric(); + sampleformat = source_image->get_sample_format(); + samplesperpixel = source_image->get_channels(); } - if (debugLogger) { - sourceImage->print(); + if (debug_logger) { + source_image->print(); } - Rok4ImageFactory R4IF; - Rok4Image* rok4Image = R4IF.createRok4ImageToWrite( - fo_name, BoundingBox(0.,0.,0.,0.), -1, -1, sourceImage->getWidth(), sourceImage->getHeight(), samplesperpixel, - sampleformat, bitspersample, photometric, compression, - tileWidth, tileHeight, context + Rok4Image* rok4Image = Rok4Image::create_to_write( + fo_name, BoundingBox(0.,0.,0.,0.), -1, -1, source_image->get_width(), source_image->get_height(), samplesperpixel, + sampleformat, photometric, compression, + tile_width, tile_height, context ); if (rok4Image == NULL) { error("Cannot create the ROK4 image to write", -1); } - rok4Image->setExtraSample(sourceImage->getExtraSample()); + rok4Image->set_extra_sample(source_image->get_extra_sample()); - if (debugLogger) { + if (debug_logger) { rok4Image->print(); } BOOST_LOG_TRIVIAL(debug) << ( "Write" ); - if (rok4Image->writeImage(sourceImage, crop) < 0) { + if (rok4Image->write_image(source_image) < 0) { error("Cannot write ROK4 image", -1); } @@ -372,7 +310,7 @@ int main ( int argc, char **argv ) { CurlPool::cleanCurlPool(); curl_global_cleanup(); StoragePool::cleanStoragePool(); - delete sourceImage; + delete source_image; delete rok4Image; return 0; From 57ad3ee882609b9e2332a5eedef78dca1039d8d5 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Fri, 9 Aug 2024 11:19:12 +0200 Subject: [PATCH 2/7] Passage en snake case (fin) --- src/cache2work.cpp | 42 ++--- src/checkWork.cpp | 6 +- src/composeNtiff.cpp | 120 +++++++------- src/decimateNtiff.cpp | 232 +++++++++++++-------------- src/manageNodata.cpp | 114 +++++++------- src/merge4tiff.cpp | 357 +++++++++++++++++++++--------------------- src/mergeNtiff.cpp | 99 ++++++------ src/overlayNtiff.cpp | 194 +++++++++++------------ src/pbf2cache.cpp | 48 +++--- src/work2cache.cpp | 38 ++--- 10 files changed, 626 insertions(+), 624 deletions(-) diff --git a/src/cache2work.cpp b/src/cache2work.cpp index ec01e48..77fb2cd 100644 --- a/src/cache2work.cpp +++ b/src/cache2work.cpp @@ -99,12 +99,12 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -206,40 +206,40 @@ int main ( int argc, char **argv ) error("Unable to connect context", -1); } - Rok4Image* rok4image = Rok4Image::create_to_read(fo_name, BoundingBox(0.,0.,0.,0.), 0., 0., context); - if (rok4image == NULL) { - StoragePool::cleanStoragePool(); + Rok4Image* rok4_image = Rok4Image::create_to_read(fo_name, BoundingBox(0.,0.,0.,0.), 0., 0., context); + if (rok4_image == NULL) { + StoragePool::clean_storages(); error (std::string("Cannot create ROK4 image to read ") + input, 1); } - FileImage* outputImage = FileImage::create_to_write( - output, rok4image->get_bbox(), rok4image->get_resx(), rok4image->get_resy(), rok4image->get_width(), rok4image->get_height(), - rok4image->get_channels(), rok4image->get_sample_format(), rok4image->get_photometric(), compression + FileImage* output_image = FileImage::create_to_write( + output, rok4_image->get_bbox(), rok4_image->get_resx(), rok4_image->get_resy(), rok4_image->get_width(), rok4_image->get_height(), + rok4_image->get_channels(), rok4_image->get_sample_format(), rok4_image->get_photometric(), compression ); - if (outputImage == NULL) { - delete rok4image; - StoragePool::cleanStoragePool(); + if (output_image == NULL) { + delete rok4_image; + StoragePool::clean_storages(); error (std::string("Cannot create image to write ") + output, -1); } BOOST_LOG_TRIVIAL(debug) << "Write" ; - if (outputImage->write_image(rok4image) < 0) { - delete rok4image; - delete outputImage; - StoragePool::cleanStoragePool(); + if (output_image->write_image(rok4_image) < 0) { + delete rok4_image; + delete output_image; + StoragePool::clean_storages(); error("Cannot write image", -1); } BOOST_LOG_TRIVIAL(debug) << "Clean" ; - delete rok4image; - delete outputImage; - ProjPool::cleanProjPool(); + delete rok4_image; + delete output_image; + ProjPool::clean_projs(); proj_cleanup(); - CurlPool::cleanCurlPool(); + CurlPool::clean_curls(); curl_global_cleanup(); - StoragePool::cleanStoragePool(); + StoragePool::clean_storages(); return 0; } diff --git a/src/checkWork.cpp b/src/checkWork.cpp index e07476a..dab2c0e 100644 --- a/src/checkWork.cpp +++ b/src/checkWork.cpp @@ -75,12 +75,12 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** diff --git a/src/composeNtiff.cpp b/src/composeNtiff.cpp index 4d50b4b..2d316a0 100644 --- a/src/composeNtiff.cpp +++ b/src/composeNtiff.cpp @@ -68,18 +68,18 @@ namespace keywords = boost::log::keywords; #include "config.h" /** \~french Nombre d'images dans le sens de la largeur */ -int widthwiseImage = 0; +int images_widthwise = 0; /** \~french Nombre d'images dans le sens de la hauteur */ -int heightwiseImage = 0; +int images_heightwise = 0; /** \~french Compression de l'image de sortie */ Compression::eCompression compression = Compression::NONE; /** \~french Dossier des images sources */ -char* inputDir = 0; +char* input_directory_path = 0; /** \~french Chemin de l'image en sortie */ -char* outputImage = 0; +char* output_image_path = 0; /** \~french Activation du niveau de log debug. Faux par défaut */ bool debug_logger=false; @@ -120,13 +120,13 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; - BOOST_LOG_TRIVIAL(error) << "Source directory : " << inputDir ; + BOOST_LOG_TRIVIAL(error) << "Source directory : " << input_directory_path ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -152,7 +152,7 @@ int parse_command_line ( int argc, char** argv ) { BOOST_LOG_TRIVIAL(error) << "Error id -s option" ; return -1; } - inputDir = argv[i]; + input_directory_path = argv[i]; break; case 'c': // compression if ( ++i == argc ) { @@ -181,15 +181,15 @@ int parse_command_line ( int argc, char** argv ) { BOOST_LOG_TRIVIAL(error) << "Error in -g option" ; return -1; } - widthwiseImage = atoi ( argv[++i] ); - heightwiseImage = atoi ( argv[++i] ); + images_widthwise = atoi ( argv[++i] ); + images_heightwise = atoi ( argv[++i] ); break; default: BOOST_LOG_TRIVIAL(error) << "Unknown option : " << argv[i] ; return -1; } } else { - if ( outputImage == 0 ) outputImage = argv[i]; + if ( output_image_path == 0 ) output_image_path = argv[i]; else { BOOST_LOG_TRIVIAL(error) << "Argument must specify just ONE output file" ; return -1; @@ -198,19 +198,19 @@ int parse_command_line ( int argc, char** argv ) { } // Input directory control - if ( inputDir == 0 ) { + if ( input_directory_path == 0 ) { BOOST_LOG_TRIVIAL(error) << "We need to have a source images' directory (option -s)" ; return -1; } // Output file control - if ( outputImage == 0 ) { + if ( output_image_path == 0 ) { BOOST_LOG_TRIVIAL(error) << "We need to have an output file" ; return -1; } // Geometry control - if ( widthwiseImage == 0 || heightwiseImage == 0) { + if ( images_widthwise == 0 || images_heightwise == 0) { BOOST_LOG_TRIVIAL(error) << "We need to know composition geometry (option -g)" ; return -1; } @@ -224,21 +224,21 @@ int parse_command_line ( int argc, char** argv ) { * \brief Charge les images contenues dans le dossier en entrée et l'image de sortie * \details Toutes les images doivent avoir les mêmes caractéristiques, dimensions et type des canaux. Les images en entrée seront gérée par un objet de la classe #CompoundImage, et l'image en sortie sera une image TIFF. * - * \param[out] ppImageOut image résultante de l'outil - * \param[out] ppCompoundIn ensemble des images en entrée + * \param[out] output_image image résultante de l'outil + * \param[out] compound_image ensemble des images en entrée * \return code de retour, 0 si réussi, -1 sinon */ -int load_images ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { +int load_images ( FileImage** output_image, CompoundImage** compound_image ) { - std::vector< std::string > imagesNames; + std::vector< std::string > images_filenames; - std::vector< std::vector > imagesIn; + std::vector< std::vector > input_images; - // Dimensionnement de imagesIn - imagesIn.resize(heightwiseImage); - for (int row = 0; row < heightwiseImage; row++) - imagesIn.at(row).resize(widthwiseImage); - for ( int i = 0; i < heightwiseImage; i++ ) for ( int j = 0; j < widthwiseImage; j++ ) imagesIn[i][j] = NULL; + // Dimensionnement de input_images + input_images.resize(images_heightwise); + for (int row = 0; row < images_heightwise; row++) + input_images.at(row).resize(images_widthwise); + for ( int i = 0; i < images_heightwise; i++ ) for ( int j = 0; j < images_widthwise; j++ ) input_images[i][j] = NULL; int width, height; int samplesperpixel; @@ -248,46 +248,46 @@ int load_images ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { /********* Parcours du dossier ************/ // Ouverture et test du répertoire source - DIR * rep = opendir(inputDir); + DIR * input_directory = opendir(input_directory_path); - if (rep == NULL) { - BOOST_LOG_TRIVIAL(error) << "Cannot open input directory : " << inputDir; + if (input_directory == NULL) { + BOOST_LOG_TRIVIAL(error) << "Cannot open input directory : " << input_directory_path; return -1; } struct dirent * ent; // On récupère tous les fichiers, puis on les trie - while ((ent = readdir(rep)) != NULL) { + while ((ent = readdir(input_directory)) != NULL) { if (ent->d_name[0] == '.') continue; - imagesNames.push_back(std::string(ent->d_name)); + images_filenames.push_back(std::string(ent->d_name)); } - closedir(rep); + closedir(input_directory); - BOOST_LOG_TRIVIAL(debug) << imagesNames.size() << " files in the provided directory"; - if (imagesNames.size() > widthwiseImage*heightwiseImage) { + BOOST_LOG_TRIVIAL(debug) << images_filenames.size() << " files in the provided directory"; + if (images_filenames.size() > images_widthwise*images_heightwise) { BOOST_LOG_TRIVIAL(warning) << "We have too much images in the input directory (regarding to the provided geometry)."; - BOOST_LOG_TRIVIAL(warning) << "Only " << widthwiseImage*heightwiseImage << " first images will be used"; + BOOST_LOG_TRIVIAL(warning) << "Only " << images_widthwise*images_heightwise << " first images will be used"; } - if (imagesNames.size() < widthwiseImage*heightwiseImage) { - BOOST_LOG_TRIVIAL(error) << "Not enough images, we need " << widthwiseImage*heightwiseImage << ", and we find " << imagesNames.size(); + if (images_filenames.size() < images_widthwise*images_heightwise) { + BOOST_LOG_TRIVIAL(error) << "Not enough images, we need " << images_widthwise*images_heightwise << ", and we find " << images_filenames.size(); return -1; } - std::sort(imagesNames.begin(), imagesNames.end()); + std::sort(images_filenames.begin(), images_filenames.end()); /********* Chargement des images ************/ /* On doit connaître les dimensions des images en entrée pour pouvoir créer les images de sortie * Lecture et création des images sources */ - for (int k = 0; k < widthwiseImage*heightwiseImage; k++) { + for (int k = 0; k < images_widthwise*images_heightwise; k++) { - int i = k/widthwiseImage; - int j = k%widthwiseImage; + int i = k/images_widthwise; + int j = k%images_widthwise; - std::string str = inputDir + imagesNames.at(k); + std::string str = input_directory_path + images_filenames.at(k); char filename[256]; memset(filename, 0, 256); memcpy(filename, str.c_str(), str.length()); @@ -314,28 +314,28 @@ int load_images ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { height != pImage->get_height() ) { delete pImage; - for ( int ii = 0; ii < heightwiseImage; ii++ ) for ( int jj = 0; jj < widthwiseImage; jj++ ) delete imagesIn[ii][jj]; + for ( int ii = 0; ii < images_heightwise; ii++ ) for ( int jj = 0; jj < images_widthwise; jj++ ) delete input_images[ii][jj]; BOOST_LOG_TRIVIAL(error) << "All input images must have same dimensions and sample type : error for image " << filename ; return -1; } } - pImage->set_bbox(BoundingBox(j * width, (heightwiseImage - i - 1) * height, (j+1) * width, (heightwiseImage - i) * height)); + pImage->set_bbox(BoundingBox(j * width, (images_heightwise - i - 1) * height, (j+1) * width, (images_heightwise - i) * height)); - imagesIn[i][j] = pImage; + input_images[i][j] = pImage; } - *ppCompoundIn = new CompoundImage(imagesIn); + *compound_image = new CompoundImage(input_images); // Création de l'image de sortie - *ppImageOut = FileImage::create_to_write ( - outputImage, BoundingBox(0., 0., 0., 0.), -1., -1., width*widthwiseImage, height*heightwiseImage, samplesperpixel, + *output_image = FileImage::create_to_write ( + output_image_path, BoundingBox(0., 0., 0., 0.), -1., -1., width*images_widthwise, height*images_heightwise, samplesperpixel, sample_format, photometric,compression ); - if ( *ppImageOut == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Impossible de creer l'image de sortie " << outputImage ; + if ( *output_image == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Impossible de creer l'image de sortie " << output_image_path ; return -1; } @@ -356,8 +356,8 @@ int load_images ( FileImage** ppImageOut, CompoundImage** ppCompoundIn ) { */ int main ( int argc, char **argv ) { - FileImage* pImageOut = NULL; - CompoundImage* pCompoundIn = NULL; + FileImage* output_image = NULL; + CompoundImage* compound_image = NULL; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -380,26 +380,26 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Load" ; // Chargement des images - if ( load_images ( &pImageOut, &pCompoundIn ) < 0 ) { - if ( pCompoundIn ) { - delete pCompoundIn; + if ( load_images ( &output_image, &compound_image ) < 0 ) { + if ( compound_image ) { + delete compound_image; } - if ( pImageOut ) { - delete pImageOut; + if ( output_image ) { + delete output_image; } error ( "Cannot load images from the input directory",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Save image" ; // Enregistrement de l'image fusionnée - if ( pImageOut->write_image ( pCompoundIn ) < 0 ) { + if ( output_image->write_image ( compound_image ) < 0 ) { error ( "Cannot write the compound image",-1 ); } - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); - delete pCompoundIn; - delete pImageOut; + delete compound_image; + delete output_image; return 0; } diff --git a/src/decimateNtiff.cpp b/src/decimateNtiff.cpp index 6ed9edf..56ff8a1 100644 --- a/src/decimateNtiff.cpp +++ b/src/decimateNtiff.cpp @@ -80,7 +80,7 @@ namespace keywords = boost::log::keywords; // Paramètres de la ligne de commande déclarés en global /** \~french Chemin du fichier de configuration des images */ -char configuration_file[256]; +char configuration_path[256]; /** \~french Valeur de nodata sour forme de chaîne de caractère (passée en paramètre de la commande) */ char strnodata[256]; @@ -140,13 +140,13 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; - BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_file ; + BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_path ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -172,7 +172,7 @@ int parse_command_line ( int argc, char** argv ) { BOOST_LOG_TRIVIAL(error) << "Error in option -f" ; return -1; } - strcpy ( configuration_file,argv[i] ); + strcpy ( configuration_path,argv[i] ); break; case 'n': // nodata if ( i++ >= argc ) { @@ -235,7 +235,7 @@ int parse_command_line ( int argc, char** argv ) { } } - BOOST_LOG_TRIVIAL(debug) << "decimateNtiff -f " << configuration_file ; + BOOST_LOG_TRIVIAL(debug) << "decimateNtiff -f " << configuration_path ; return 0; } @@ -261,9 +261,9 @@ bool load_configuration ( std::ifstream file; - file.open ( configuration_file ); + file.open ( configuration_path ); if ( ! file.is_open() ) { - BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << configuration_file ; + BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << configuration_path ; return false; } @@ -325,7 +325,7 @@ bool load_configuration ( file.close(); return true; } else { - BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << configuration_file; + BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << configuration_path; file.close(); return false; } @@ -337,13 +337,13 @@ bool load_configuration ( * \brief Charge les images en entrée et en sortie depuis le fichier de configuration * \details On va récupérer toutes les informations de toutes les images et masques présents dans le fichier de configuration et créer les objets FileImage correspondant. Toutes les images ici manipulées sont de vraies images (physiques) dans ce sens où elles sont des fichiers soit lus, soit qui seront écrits. * - * Le chemin vers le fichier de configuration est stocké dans la variables globale configuration_file et images_root va être concaténer au chemin vers les fichiers de sortie. - * \param[out] ppImageOut image résultante de l'outil - * \param[out] ppMaskOut masque résultat de l'outil, si demandé - * \param[out] pImagesIn ensemble des images en entrée + * Le chemin vers le fichier de configuration est stocké dans la variables globale configuration_path et images_root va être concaténer au chemin vers les fichiers de sortie. + * \param[out] output_image image résultante de l'outil + * \param[out] output_mask masque résultat de l'outil, si demandé + * \param[out] input_images ensemble des images en entrée * \return code de retour, 0 si réussi, -1 sinon */ -int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vector* pImagesIn ) { +int load_images ( FileImage** output_image, FileImage** output_mask, std::vector* input_images ) { std::vector masks; std::vector paths; @@ -352,43 +352,43 @@ int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vector resys; if (! load_configuration(&masks, &paths, &bboxes, &resxs, &resys) ) { - BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << configuration_file ; + BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << configuration_path ; return -1; } // On doit avoir au moins deux lignes, trois si on a un masque de sortie if (masks.size() < 2 || (masks.size() == 2 && masks.back()) ) { - BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << configuration_file ; + BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << configuration_path ; return -1; } // On va charger les images en entrée en premier pour avoir certaines informations - int firstInput = 1; + int first_input = 1; if (masks.at(1)) { // La deuxième ligne est le masque de sortie - firstInput = 2; + first_input = 2; } /****************** LES ENTRÉES : CRÉATION ******************/ - int nbImgsIn = 0; + int input_count = 0; for ( int i = 0; i < paths.size(); i++ ) { BOOST_LOG_TRIVIAL(debug) << "paths[" << i << "] = " << paths.at(i); } - for ( int i = firstInput; i < masks.size(); i++ ) { + for ( int i = first_input; i < masks.size(); i++ ) { BOOST_LOG_TRIVIAL(debug) << "image " << paths.at(i); - nbImgsIn++; - BOOST_LOG_TRIVIAL(debug) << "Input " << nbImgsIn; + input_count++; + BOOST_LOG_TRIVIAL(debug) << "Input " << input_count; if ( resxs.at(i) == 0. || resys.at(i) == 0.) { - BOOST_LOG_TRIVIAL(error) << "Source image " << nbImgsIn << " is not valid (resolutions)" ; + BOOST_LOG_TRIVIAL(error) << "Source image " << input_count << " is not valid (resolutions)" ; return -1; } - FileImage* pImage = FileImage::create_to_read ( paths.at(i), bboxes.at(i), resxs.at(i), resys.at(i) ); - if ( pImage == NULL ) { + FileImage* input_image = FileImage::create_to_read ( paths.at(i), bboxes.at(i), resxs.at(i), resys.at(i) ); + if ( input_image == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible de creer une image a partir de " << paths.at(i) ; return -1; } @@ -397,13 +397,13 @@ int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorset_mask ( pMask ) ) { + if ( ! input_image->set_mask ( input_mask ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the input FileImage" ; return -1; } @@ -411,43 +411,43 @@ int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorpush_back ( pImage ); + input_images->push_back ( input_image ); /* On vérifie que le format des canaux est le même pour toutes les images en entrée : * - sample_format * - samplesperpixel */ - if (! output_format_provided && nbImgsIn == 1) { + if (! output_format_provided && input_count == 1) { /* On n'a pas précisé de format en sortie, on va donc utiliser celui des entrées * On veut donc avoir le même format pour toutes les entrées * On lit la première image en entrée, qui sert de référence * L'image en sortie sera à ce format */ - samplesperpixel = pImage->get_channels(); - sample_format = pImage->get_sample_format(); + samplesperpixel = input_image->get_channels(); + sample_format = input_image->get_sample_format(); } else if (! output_format_provided) { // On doit avoir le même format pour tout le monde - if (samplesperpixel != pImage->get_channels()) { + if (samplesperpixel != input_image->get_channels()) { BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same" ; - BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same number of samples per pixel" ; - BOOST_LOG_TRIVIAL(error) << samplesperpixel << " != " << pImage->get_channels() ; + BOOST_LOG_TRIVIAL(error) << "The first image and the " << input_count << " one don't have the same number of samples per pixel" ; + BOOST_LOG_TRIVIAL(error) << samplesperpixel << " != " << input_image->get_channels() ; return -1; } - if (sample_format != pImage->get_sample_format()) { + if (sample_format != input_image->get_sample_format()) { BOOST_LOG_TRIVIAL(error) << "We don't provided output format, so all inputs have to own the same" ; - BOOST_LOG_TRIVIAL(error) << "The first image and the " << nbImgsIn << " one don't have the same sample format" ; - BOOST_LOG_TRIVIAL(error) << sample_format << " != " << pImage->get_sample_format() ; + BOOST_LOG_TRIVIAL(error) << "The first image and the " << input_count << " one don't have the same sample format" ; + BOOST_LOG_TRIVIAL(error) << sample_format << " != " << input_image->get_sample_format() ; return -1; } } } - if ( pImagesIn->size() == 0 ) { - BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << configuration_file << "' : pas de données en entrée." ; + if ( input_images->size() == 0 ) { + BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << configuration_path << "' : pas de données en entrée." ; return -1; } else { - BOOST_LOG_TRIVIAL(debug) << nbImgsIn << " image(s) en entrée" ; + BOOST_LOG_TRIVIAL(debug) << input_count << " image(s) en entrée" ; } /********************** LA SORTIE : CRÉATION *************************/ @@ -464,26 +464,26 @@ int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, std::vectorprint(); + if (debug_logger) ( *output_image )->print(); return 0; } -int add_converters(std::vector ImageIn) { +int add_converters(std::vector input_images) { if (! output_format_provided) { // On n'a pas précisé de format en sortie, donc toutes les images doivent avoir le même // Et la sortie a aussi ce format, donc pas besoin de convertisseur @@ -504,15 +504,15 @@ int add_converters(std::vector ImageIn) { return 0; } - for ( std::vector::iterator itImg = ImageIn.begin(); itImg < ImageIn.end(); itImg++ ) { + for ( std::vector::iterator input_images_iterator = input_images.begin(); input_images_iterator < input_images.end(); input_images_iterator++ ) { - if ( ! ( *itImg )->add_converter ( sample_format, samplesperpixel ) ) { + if ( ! ( *input_images_iterator )->add_converter ( sample_format, samplesperpixel ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add converter for an input image"; - ( *itImg )->print(); + ( *input_images_iterator )->print(); return -1; } - if (debug_logger) ( *itImg )->print(); + if (debug_logger) ( *input_images_iterator )->print(); } return 0; @@ -528,39 +528,39 @@ int add_converters(std::vector ImageIn) { * * On doit donc avoir à la fin soit un paquet, soit deux avec une seule image dans le premier (le fond) * - * \param[in] ImagesIn images en entrée - * \param[out] pTabImageIn images en entrée, triées en paquets compatibles + * \param[in] input_images images en entrée + * \param[out] sorted_input_images images en entrée, triées en paquets compatibles * \return code de retour, 0 si réussi, -1 sinon */ -int sort_images ( std::vector ImagesIn, std::vector >* pTabImageIn ) { - std::vector vTmpImg; - std::vector::iterator itiniImg = ImagesIn.begin(); +int sort_images ( std::vector input_images, std::vector >* sorted_input_images ) { + std::vector current_pack; + std::vector::iterator current_input_images_iterator = input_images.begin(); /* we create consistent images' vectors (X/Y resolution and X/Y phases) * Masks are moved in parallel with images */ - for ( std::vector::iterator itImg = ImagesIn.begin(); itImg < ImagesIn.end()-1; itImg++ ) { + for ( std::vector::iterator input_images_iterator = input_images.begin(); input_images_iterator < input_images.end()-1; input_images_iterator++ ) { - if ( ! ( *itImg )->compatible ( * ( itImg+1 ) ) ) { + if ( ! ( *input_images_iterator )->compatible ( * ( input_images_iterator+1 ) ) ) { // two following images are not compatible, we split images' vector - vTmpImg.assign ( itiniImg,itImg+1 ); - itiniImg = itImg+1; - pTabImageIn->push_back ( vTmpImg ); + current_pack.assign ( current_input_images_iterator,input_images_iterator+1 ); + current_input_images_iterator = input_images_iterator+1; + sorted_input_images->push_back ( current_pack ); } } - // we don't forget to store last images in pTabImageIn + // we don't forget to store last images in sorted_input_images // images - vTmpImg.assign ( itiniImg,ImagesIn.end() ); - pTabImageIn->push_back ( vTmpImg ); + current_pack.assign ( current_input_images_iterator,input_images.end() ); + sorted_input_images->push_back ( current_pack ); - if (! (pTabImageIn->size() == 1 || pTabImageIn->size() == 2) ) { + if (! (sorted_input_images->size() == 1 || sorted_input_images->size() == 2) ) { BOOST_LOG_TRIVIAL(error) << "Input images have to constitute 1 or 2 (the background) consistent images' pack"; return -1; } - if (pTabImageIn->size() == 2) { - if (pTabImageIn->at(0).size() != 1) { + if (sorted_input_images->size() == 2) { + if (sorted_input_images->at(0).size() != 1) { BOOST_LOG_TRIVIAL(error) << "If a background image is present, no another consistent image with it (one image pack)"; return -1; } @@ -575,86 +575,86 @@ int sort_images ( std::vector ImagesIn, std::vector >& TabImagesIn, // Entrée - ExtendedCompoundImage** ppECIout, // Résultat du merge +int merge_images ( FileImage* output_image, // Sortie + std::vector >& sorted_input_images, // Entrée + ExtendedCompoundImage** merged_image, // Résultat du merge int* nodata ) { - std::vector pOverlayedImages; + std::vector stackable_images; // ************* Le fond (éventuel) - if ( TabImagesIn.size() == 2) { + if ( sorted_input_images.size() == 2) { BOOST_LOG_TRIVIAL(debug) << "We have a background"; - if ( ! TabImagesIn.at(0).at(0)->compatible ( pImageOut ) ) { + if ( ! sorted_input_images.at(0).at(0)->compatible ( output_image ) ) { BOOST_LOG_TRIVIAL(error) << "Background image have to be consistent with the output image" ; - TabImagesIn.at(0).at(0)->print(); + sorted_input_images.at(0).at(0)->print(); BOOST_LOG_TRIVIAL(error) << "not consistent with"; - pImageOut->print(); + output_image->print(); return -1; } - pOverlayedImages.push_back ( TabImagesIn.at(0).at(0) ); + stackable_images.push_back ( sorted_input_images.at(0).at(0) ); } // ************* Les images à décimer // L'image - ExtendedCompoundImage* pECI = ExtendedCompoundImage::create ( TabImagesIn.at(TabImagesIn.size() - 1), nodata, 0 ); - if ( pECI == NULL ) { + ExtendedCompoundImage* image_to_decimate = ExtendedCompoundImage::create ( sorted_input_images.at(sorted_input_images.size() - 1), nodata, 0 ); + if ( image_to_decimate == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible d'assembler les images en entrée" ; return -1; } - DecimatedImage* pDII = DecimatedImage::create(pECI, pImageOut->get_bbox(), pImageOut->get_resx(), pImageOut->get_resy(), nodata); - if ( pDII == NULL ) { + DecimatedImage* decimated_image = DecimatedImage::create(image_to_decimate, output_image->get_bbox(), output_image->get_resx(), output_image->get_resy(), nodata); + if ( decimated_image == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible de créer la DecimatedImage (image)" ; return -1; } // Le masque - ExtendedCompoundMask* pECMI = new ExtendedCompoundMask ( pECI ); - if ( ! pECI->set_mask ( pECMI ) ) { + ExtendedCompoundMask* make_to_decimate = new ExtendedCompoundMask ( image_to_decimate ); + if ( ! image_to_decimate->set_mask ( make_to_decimate ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the compound image " ; return -1; } int nodata_mask[1] = {0}; - DecimatedImage* pDIM = DecimatedImage::create(pECMI, pImageOut->get_bbox(), pImageOut->get_resx(), pImageOut->get_resy(), nodata_mask); - if ( pDIM == NULL ) { + DecimatedImage* decimated_mask = DecimatedImage::create(make_to_decimate, output_image->get_bbox(), output_image->get_resx(), output_image->get_resy(), nodata_mask); + if ( decimated_mask == NULL ) { BOOST_LOG_TRIVIAL(error) << "Impossible de créer la DecimatedImage (mask)" ; return -1; } - if ( ! pDII->set_mask ( pDIM ) ) { + if ( ! decimated_image->set_mask ( decimated_mask ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the DecimatedImage" ; return -1; } - if (debug_logger) pECI->print(); - if (debug_logger) pDII->print(); + if (debug_logger) image_to_decimate->print(); + if (debug_logger) decimated_image->print(); - pOverlayedImages.push_back(pDII); + stackable_images.push_back(decimated_image); // Assemblage des paquets et decoupage aux dimensions de l image de sortie - *ppECIout = ExtendedCompoundImage::create ( - pImageOut->get_width(), pImageOut->get_height(), pImageOut->get_channels(), pImageOut->get_bbox(), - pOverlayedImages, nodata, 0 + *merged_image = ExtendedCompoundImage::create ( + output_image->get_width(), output_image->get_height(), output_image->get_channels(), output_image->get_bbox(), + stackable_images, nodata, 0 ); - if ( *ppECIout == NULL ) { + if ( *merged_image == NULL ) { BOOST_LOG_TRIVIAL(error) << "Cannot create final compounded image." ; return -1; } // Masque - ExtendedCompoundMask* pECMIout = new ExtendedCompoundMask ( *ppECIout ); + ExtendedCompoundMask* merged_mask = new ExtendedCompoundMask ( *merged_image ); - if ( ! ( *ppECIout )->set_mask ( pECMIout ) ) { + if ( ! ( *merged_image )->set_mask ( merged_mask ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the main Extended Compound Image" ; return -1; } @@ -676,11 +676,11 @@ int merge_images ( FileImage* pImageOut, // Sortie */ int main ( int argc, char **argv ) { - FileImage* pImageOut ; - FileImage* pMaskOut = NULL; - std::vector ImagesIn; - std::vector > TabImagesIn; - ExtendedCompoundImage* pECI; + FileImage* output_image ; + FileImage* output_mask = NULL; + std::vector input_images; + std::vector > sorted_input_images; + ExtendedCompoundImage* merged_image; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -708,19 +708,19 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Load" ; // Chargement des images - if ( load_images ( &pImageOut, &pMaskOut, &ImagesIn ) < 0 ) { + if ( load_images ( &output_image, &output_mask, &input_images ) < 0 ) { error ( "Echec chargement des images",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Add converters" ; // Ajout des modules de conversion aux images en entrée - if ( add_converters ( ImagesIn ) < 0 ) { + if ( add_converters ( input_images ) < 0 ) { error ( "Echec ajout des convertisseurs", -1 ); } // Conversion string->int[] du paramètre nodata BOOST_LOG_TRIVIAL(debug) << "Nodata interpretation" ; - int spp = ImagesIn.at(0)->get_channels(); + int spp = input_images.at(0)->get_channels(); int nodata[spp]; char* charValue = strtok ( strnodata,"," ); @@ -738,38 +738,38 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Sort" ; // Tri des images - if ( sort_images ( ImagesIn, &TabImagesIn ) < 0 ) { + if ( sort_images ( input_images, &sorted_input_images ) < 0 ) { error ( "Echec tri des images",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Merge" ; // Fusion des paquets d images - if ( merge_images ( pImageOut, TabImagesIn, &pECI, nodata ) < 0 ) { + if ( merge_images ( output_image, sorted_input_images, &merged_image, nodata ) < 0 ) { error ( "Echec fusion des paquets d images",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Save image" ; // Enregistrement de l'image fusionnée - if ( pImageOut->write_image ( pECI ) < 0 ) { + if ( output_image->write_image ( merged_image ) < 0 ) { error ( "Echec enregistrement de l image finale",-1 ); } - if ( pMaskOut != NULL ) { + if ( output_mask != NULL ) { BOOST_LOG_TRIVIAL(debug) << "Save mask" ; // Enregistrement du masque fusionné, si demandé - if ( pMaskOut->write_image ( pECI->Image::get_mask() ) < 0 ) { + if ( output_mask->write_image ( merged_image->Image::get_mask() ) < 0 ) { error ( "Echec enregistrement du masque final",-1 ); } } BOOST_LOG_TRIVIAL(debug) << "Clean" ; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); - delete pECI; - delete pImageOut; - delete pMaskOut; + delete merged_image; + delete output_image; + delete output_mask; return 0; } diff --git a/src/manageNodata.cpp b/src/manageNodata.cpp index 94bcc19..1e5a7d1 100644 --- a/src/manageNodata.cpp +++ b/src/manageNodata.cpp @@ -125,12 +125,12 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour, -1 par défaut + * \param[in] error_code code de retour, -1 par défaut */ -void error ( std::string message, int errorCode = -1 ) { +void error ( std::string message, int error_code = -1 ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -148,14 +148,14 @@ void error ( std::string message, int errorCode = -1 ) { * \return return code, 0 if success, -1 otherwise */ int main ( int argc, char* argv[] ) { - char* inputImage = 0; - char* outputImage = 0; + char* input_image_path = 0; + char* output_image_path = 0; - char* outputMask = 0; + char* output_mask_path = 0; - char* strTargetValue = 0; - char* strNewNodata = 0; - char* strNewData = 0; + char* target_value_string = 0; + char* new_nodata_value_string = 0; + char* new_data_value_string = 0; int channels = 0; SampleFormat::eSampleFormat sample_format = SampleFormat::UNKNOWN; @@ -197,17 +197,17 @@ int main ( int argc, char* argv[] ) { } else if ( !strcmp ( argv[i],"-target" ) ) { if ( i++ >= argc ) error ( "Error with option -target",-1 ); - strTargetValue = argv[i]; + target_value_string = argv[i]; continue; } else if ( !strcmp ( argv[i],"-nodata" ) ) { if ( i++ >= argc ) error ( "Error with option -nodata",-1 ); - strNewNodata = argv[i]; + new_nodata_value_string = argv[i]; continue; } else if ( !strcmp ( argv[i],"-data" ) ) { if ( i++ >= argc ) error ( "Error with option -data",-1 ); - strNewData = argv[i]; + new_data_value_string = argv[i]; continue; } else if ( !strcmp ( argv[i],"-format" ) ) { @@ -226,14 +226,14 @@ int main ( int argc, char* argv[] ) { } else if ( !strcmp ( argv[i],"-mask-out" ) ) { if ( i++ >= argc ) error ( "Error with option -mask-out",-1 ); - outputMask = argv[i]; + output_mask_path = argv[i]; continue; - } else if ( !inputImage ) { - inputImage = argv[i]; + } else if ( !input_image_path ) { + input_image_path = argv[i]; - } else if ( !outputImage ) { - outputImage = argv[i]; + } else if ( !output_image_path ) { + output_image_path = argv[i]; } else { error ( "Error : unknown option : " + string ( argv[i] ),-1 ); @@ -247,107 +247,107 @@ int main ( int argc, char* argv[] ) { /***************** VERIFICATION DES PARAMETRES FOURNIS *********************/ - if ( ! inputImage ) error ( "Missing input file",-1 ); + if ( ! input_image_path ) error ( "Missing input file",-1 ); bool overwrite = false; - if ( ! outputImage ) { + if ( ! output_image_path ) { BOOST_LOG_TRIVIAL(info) << "If the input image have to be modify, it will be overwrite" ; - outputImage = new char[sizeof ( inputImage ) +1]; + output_image_path = new char[sizeof ( input_image_path ) +1]; overwrite = true; - memcpy ( outputImage, inputImage, sizeof ( inputImage ) ); + memcpy ( output_image_path, input_image_path, sizeof ( input_image_path ) ); } if ( ! channels ) error ( "Missing number of samples per pixel",-1 ); if ( sample_format == SampleFormat::UNKNOWN ) error ( "Missing sample format",-1 ); - if ( ! strTargetValue ) + if ( ! target_value_string ) error ( "How to identify the nodata in the input image ? Provide a target color (-target)",-1 ); - if ( ! strNewNodata && ! strNewData && ! outputMask ) + if ( ! new_nodata_value_string && ! new_data_value_string && ! output_mask_path ) error ( "What have we to do with the target color ? Precise a new nodata or data color, or a mask to write",-1 ); int* target_value = new int[channels]; - int* newNodata = new int[channels]; - int* newData = new int[channels]; + int* new_nodata_value = new int[channels]; + int* new_data_value = new int[channels]; /***************** INTERPRETATION DES COULEURS FOURNIES ********************/ BOOST_LOG_TRIVIAL(debug) << "Color interpretation" ; // Target value - char* charValue = strtok ( strTargetValue,"," ); - if ( charValue == NULL ) { + char* char_iterator = strtok ( target_value_string,"," ); + if ( char_iterator == NULL ) { error ( "Error with option -target : integer values seperated by comma",-1 ); } - target_value[0] = atoi ( charValue ); + target_value[0] = atoi ( char_iterator ); for ( int i = 1; i < channels; i++ ) { - charValue = strtok ( NULL, "," ); - if ( charValue == NULL ) { + char_iterator = strtok ( NULL, "," ); + if ( char_iterator == NULL ) { error ( "Error with option -oldValue : integer values seperated by comma",-1 ); } - target_value[i] = atoi ( charValue ); + target_value[i] = atoi ( char_iterator ); } // New nodata - if ( strNewNodata ) { - charValue = strtok ( strNewNodata,"," ); - if ( charValue == NULL ) { + if ( new_nodata_value ) { + char_iterator = strtok ( new_nodata_value_string,"," ); + if ( char_iterator == NULL ) { error ( "Error with option -nodata : integer values seperated by comma",-1 ); } - newNodata[0] = atoi ( charValue ); + new_nodata_value[0] = atoi ( char_iterator ); for ( int i = 1; i < channels; i++ ) { - charValue = strtok ( NULL, "," ); - if ( charValue == NULL ) { + char_iterator = strtok ( NULL, "," ); + if ( char_iterator == NULL ) { error ( "Error with option -nodata : integer values seperated by comma",-1 ); } - newNodata[i] = atoi ( charValue ); + new_nodata_value[i] = atoi ( char_iterator ); } } else { // On ne précise pas de nouvelle couleur de non-donnée, elle est la même que la couleur cible. - memcpy ( newNodata, target_value, channels*sizeof ( int ) ); + memcpy ( new_nodata_value, target_value, channels*sizeof ( int ) ); } // New data - if ( strNewData ) { - charValue = strtok ( strNewData,"," ); - if ( charValue == NULL ) { + if ( new_data_value_string ) { + char_iterator = strtok ( new_data_value_string,"," ); + if ( char_iterator == NULL ) { error ( "Error with option -data : integer values seperated by comma",-1 ); } - newData[0] = atoi ( charValue ); + new_data_value[0] = atoi ( char_iterator ); for ( int i = 1; i < channels; i++ ) { - charValue = strtok ( NULL, "," ); - if ( charValue == NULL ) { + char_iterator = strtok ( NULL, "," ); + if ( char_iterator == NULL ) { error ( "Error with option -data : integer values seperated by comma",-1 ); } - newData[i] = atoi ( charValue ); + new_data_value[i] = atoi ( char_iterator ); } } else { // Pas de nouvelle couleur pour la donnée : elle a la valeur de la couleur cible - memcpy ( newData, target_value, channels*sizeof ( int ) ); + memcpy ( new_data_value, target_value, channels*sizeof ( int ) ); } /******************* APPEL A LA CLASSE TIFFNODATAMANAGER *******************/ if ( sample_format == SampleFormat::FLOAT32 ) { BOOST_LOG_TRIVIAL(debug) << "Target color treatment (uint8)" ; - TiffNodataManager TNM ( channels, target_value, touch_edges, newData, newNodata, tolerance ); - if ( ! TNM.process_nodata ( inputImage, outputImage, outputMask ) ) { - error ( "Error : unable to treat nodata for this 32-bit float image : " + string ( inputImage ), -1 ); + TiffNodataManager TNM ( channels, target_value, touch_edges, new_data_value, new_nodata_value, tolerance ); + if ( ! TNM.process_nodata ( input_image_path, output_image_path, output_mask_path ) ) { + error ( "Error : unable to treat nodata for this 32-bit float image : " + string ( input_image_path ), -1 ); } } else if ( sample_format == SampleFormat::UINT8 ) { BOOST_LOG_TRIVIAL(debug) << "Target color treatment (float)" ; - TiffNodataManager TNM ( channels, target_value, touch_edges, newData, newNodata, tolerance ); - if ( ! TNM.process_nodata ( inputImage, outputImage, outputMask ) ) { - error ( "Error : unable to treat nodata for this 8-bit integer float image : " + string ( inputImage ), -1 ); + TiffNodataManager TNM ( channels, target_value, touch_edges, new_data_value, new_nodata_value, tolerance ); + if ( ! TNM.process_nodata ( input_image_path, output_image_path, output_mask_path ) ) { + error ( "Error : unable to treat nodata for this 8-bit integer float image : " + string ( input_image_path ), -1 ); } } BOOST_LOG_TRIVIAL(debug) << "Clean" ; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); delete[] target_value; - if (overwrite) delete[] outputImage; - delete[] newData; - delete[] newNodata; + if (overwrite) delete[] output_image_path; + delete[] new_data_value; + delete[] new_nodata_value; return 0; } diff --git a/src/merge4tiff.cpp b/src/merge4tiff.cpp index c3cf630..a831e30 100644 --- a/src/merge4tiff.cpp +++ b/src/merge4tiff.cpp @@ -70,21 +70,21 @@ char* strnodata; /* Chemins des images en entrée et en sortie */ /** \~french Chemin de l'image de fond */ -char* backgroundImage; +char* background_image_path; /** \~french Chemin du masque associé à l'image de fond */ -char* backgroundMask; +char* background_mask_path; /** \~french Chemins des images en entrée */ -char* inputImages[4]; +char* input_images_paths[4]; /** \~french Chemins des masques associés aux images en entrée */ -char* inputMasks[4]; +char* input_masks_paths[4]; /** \~french Chemin de l'image en sortie */ -char* outputImage; +char* output_image_path; /** \~french Chemin du masque associé à l'image en sortie */ -char* outputMask; +char* output_mask_path; /* Caractéristiques des images en entrée et en sortie */ /** \~french Valeur de gamma, pour foncer ou éclaircir des images en entier */ -double gammaM4t; +double local_gamma; /** \~french Largeur des images */ uint32_t width; /** \~french Hauteur des images */ @@ -146,7 +146,7 @@ std::string help = std::string("\ncache2work version ") + std::string(VERSION) + "Examples\n" " - without mask, with background image\n" - " merge4tiff -g 1 -n 255,255,255 -c zip -ib backgroundImage.tif -i1 image1.tif -i3 image3.tif -io imageOut.tif\n\n" + " merge4tiff -g 1 -n 255,255,255 -c zip -ib background_image_path.tif -i1 image1.tif -i3 image3.tif -io imageOut.tif\n\n" " - with mask, without background image\n" " merge4tiff -g 1 -n 255,255,255 -c zip -i1 image1.tif -m1 mask1.tif -i3 image3.tif -m3 mask3.tif -mo maskOut.tif -io imageOut.tif\n"; @@ -164,12 +164,12 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -181,17 +181,17 @@ void error ( std::string message, int errorCode ) { */ int parse_command_line ( int argc, char* argv[] ) { // Initialisation - gammaM4t = 1.; + local_gamma = 1.; strnodata = 0; compression = Compression::NONE; - backgroundImage = 0; - backgroundMask = 0; + background_image_path = 0; + background_mask_path = 0; for ( int i=0; i<4; i++ ) { - inputImages[i] = 0; - inputMasks[i] = 0; + input_images_paths[i] = 0; + input_masks_paths[i] = 0; } - outputImage = 0; - outputMask = 0; + output_image_path = 0; + output_mask_path = 0; for ( int i = 1; i < argc; i++ ) { if ( argv[i][0] == '-' ) { @@ -207,8 +207,8 @@ int parse_command_line ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(error) << "Error in option -g" ; return -1; } - gammaM4t = atof ( argv[i] ); - if ( gammaM4t <= 0. ) { + local_gamma = atof ( argv[i] ); + if ( local_gamma <= 0. ) { BOOST_LOG_TRIVIAL(error) << "Unvalid parameter in -g argument, have to be positive" ; return -1; } @@ -245,22 +245,22 @@ int parse_command_line ( int argc, char* argv[] ) { } switch ( argv[i-1][2] ) { case '1': - inputImages[0] = argv[i]; + input_images_paths[0] = argv[i]; break; case '2': - inputImages[1] = argv[i]; + input_images_paths[1] = argv[i]; break; case '3': - inputImages[2] = argv[i]; + input_images_paths[2] = argv[i]; break; case '4': - inputImages[3] = argv[i]; + input_images_paths[3] = argv[i]; break; case 'b': - backgroundImage = argv[i]; + background_image_path = argv[i]; break; case 'o': - outputImage = argv[i]; + output_image_path = argv[i]; break; default: BOOST_LOG_TRIVIAL(error) << "Unknown image's indice : -m" << argv[i-1][2] ; @@ -274,22 +274,22 @@ int parse_command_line ( int argc, char* argv[] ) { } switch ( argv[i-1][2] ) { case '1': - inputMasks[0] = argv[i]; + input_masks_paths[0] = argv[i]; break; case '2': - inputMasks[1] = argv[i]; + input_masks_paths[1] = argv[i]; break; case '3': - inputMasks[2] = argv[i]; + input_masks_paths[2] = argv[i]; break; case '4': - inputMasks[3] = argv[i]; + input_masks_paths[3] = argv[i]; break; case 'b': - backgroundMask = argv[i]; + background_mask_path = argv[i]; break; case 'o': - outputMask = argv[i]; + output_mask_path = argv[i]; break; default: BOOST_LOG_TRIVIAL(error) << "Unknown mask's indice : -m" << argv[i-1][2] ; @@ -341,7 +341,7 @@ int parse_command_line ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(error) << "Missing nodata value" ; return -1; } - if ( outputImage == 0 ) { + if ( output_image_path == 0 ) { BOOST_LOG_TRIVIAL(error) << "Missing output file" ; return -1; } @@ -357,7 +357,7 @@ int parse_command_line ( int argc, char* argv[] ) { * \param[in] mask précise éventuellement un masque de donnée * \return code de retour, 0 si réussi, -1 sinon */ -int checkComponents ( FileImage* image, FileImage* mask) { +int check_components ( FileImage* image, FileImage* mask) { if ( width == 0 ) { // read the parameters of the first input file width = image->get_width(); @@ -435,102 +435,102 @@ int checkComponents ( FileImage* image, FileImage* mask) { * \~french * \brief Contrôle l'ensemble des images et masques, en entrée et sortie * \details Crée les objets TIFF, contrôle la cohérence des caractéristiques des images en entrée, ouvre les flux de lecture et écriture. Les éventuels masques associés sont ajoutés aux objets FileImage. - * \param[in] INPUTI images en entrée - * \param[in] BGI image de fond en entrée - * \param[in] OUTPUTI image en sortie + * \param[in] input_images images en entrée + * \param[in] background_image image de fond en entrée + * \param[in] output_image image en sortie * \return code de retour, 0 si réussi, -1 sinon */ -int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, FileImage*& OUTPUTM) { +int check_images ( FileImage* input_images[2][2], FileImage*& background_image, FileImage*& output_image, FileImage*& output_mask) { width = 0; for ( int i = 0; i < 4; i++ ) { BOOST_LOG_TRIVIAL(debug) << "Place " << i ; // Initialisation - if ( inputImages[i] == 0 ) { + if ( input_images_paths[i] == 0 ) { BOOST_LOG_TRIVIAL(debug) << "No image" ; - INPUTI[i/2][i%2] = NULL; + input_images[i/2][i%2] = NULL; continue; } // Image en entrée - FileImage* inputi = FileImage::create_to_read(inputImages[i]); + FileImage* inputi = FileImage::create_to_read(input_images_paths[i]); if ( inputi == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Unable to open input image: " + std::string ( inputImages[i] ) ; + BOOST_LOG_TRIVIAL(error) << "Unable to open input image: " + std::string ( input_images_paths[i] ) ; return -1; } - INPUTI[i/2][i%2] = inputi; + input_images[i/2][i%2] = inputi; // Eventuelle masque associé - FileImage* inputm = NULL; - if ( inputMasks[i] != 0 ) { - inputm = FileImage::create_to_read(inputMasks[i]); - if ( inputm == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Unable to open input mask: " << std::string ( inputMasks[i] ) ; + FileImage* input_mask = NULL; + if ( input_masks_paths[i] != 0 ) { + input_mask = FileImage::create_to_read(input_masks_paths[i]); + if ( input_mask == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Unable to open input mask: " << std::string ( input_masks_paths[i] ) ; return -1; } } // Controle des composantes des images/masques et association BOOST_LOG_TRIVIAL(debug) << "Check" ; - if ( checkComponents ( inputi, inputm ) < 0 ) { - BOOST_LOG_TRIVIAL(error) << "Unvalid components for the image " << std::string ( inputImages[i] ) << " (or its mask)" ; + if ( check_components ( inputi, input_mask ) < 0 ) { + BOOST_LOG_TRIVIAL(error) << "Unvalid components for the image " << std::string ( input_images_paths[i] ) << " (or its mask)" ; return -1; } } - BGI = NULL; + background_image = NULL; // Si on a quatre image et pas de masque (images considérées comme pleines), le fond est inutile - if ( inputImages[0] && inputImages[1] && inputImages[2] && inputImages[3] && - ! inputMasks[0] && ! inputMasks[1] && ! inputMasks[2] && ! inputMasks[3] ) + if ( input_images_paths[0] && input_images_paths[1] && input_images_paths[2] && input_images_paths[3] && + ! input_masks_paths[0] && ! input_masks_paths[1] && ! input_masks_paths[2] && ! input_masks_paths[3] ) - backgroundImage=0; + background_image_path=0; - if ( backgroundImage ) { - BGI = FileImage::create_to_read(backgroundImage); - if ( BGI == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Unable to open background image: " + std::string ( backgroundImage ) ; + if ( background_image_path ) { + background_image = FileImage::create_to_read(background_image_path); + if ( background_image == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Unable to open background image: " + std::string ( background_image_path ) ; return -1; } - FileImage* BGM = NULL; + FileImage* background_mask = NULL; - if ( backgroundMask ) { - BGM = FileImage::create_to_read(backgroundMask); - if ( BGM == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Unable to open background mask: " + std::string ( backgroundMask ) ; + if ( background_mask_path ) { + background_mask = FileImage::create_to_read(background_mask_path); + if ( background_mask == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Unable to open background mask: " + std::string ( background_mask_path ) ; return -1; } } // Controle des composantes des images/masques - if ( checkComponents ( BGI, BGM ) < 0 ) { - BOOST_LOG_TRIVIAL(error) << "Unvalid components for the background image " << std::string ( backgroundImage ) << " (or its mask)" ; + if ( check_components ( background_image, background_mask ) < 0 ) { + BOOST_LOG_TRIVIAL(error) << "Unvalid components for the background image " << std::string ( background_image_path ) << " (or its mask)" ; return -1; } } /********************** EN SORTIE ***********************/ - OUTPUTI = NULL; - OUTPUTM = NULL; + output_image = NULL; + output_mask = NULL; - OUTPUTI = FileImage::create_to_write(outputImage, BoundingBox(0,0,0,0), -1, -1, width, height, + output_image = FileImage::create_to_write(output_image_path, BoundingBox(0,0,0,0), -1, -1, width, height, samplesperpixel, sampleformat, photometric, compression); - if ( OUTPUTI == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Unable to open output image: " + std::string ( outputImage ) ; + if ( output_image == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Unable to open output image: " + std::string ( output_image_path ) ; return -1; } - if ( outputMask ) { - OUTPUTM = FileImage::create_to_write(outputMask, BoundingBox(0,0,0,0), -1, -1, width, height, + if ( output_mask_path ) { + output_mask = FileImage::create_to_write(output_mask_path, BoundingBox(0,0,0,0), -1, -1, width, height, 1, SampleFormat::UINT8, Photometric::MASK, Compression::DEFLATE); - if ( OUTPUTM == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Unable to open output mask: " + std::string ( outputMask ) ; + if ( output_mask == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Unable to open output mask: " + std::string ( output_mask_path ) ; return -1; } - OUTPUTI->set_mask(OUTPUTM); + output_image->set_mask(output_mask); } return 0; @@ -541,26 +541,26 @@ int checkImages ( FileImage* INPUTI[2][2], FileImage*& BGI, FileImage*& OUTPUTI, * \~french * \brief Remplit un buffer à partir d'une ligne d'une image et d'un potentiel masque associé * \details les pixels qui ne contiennent pas de donnée sont remplis avec la valeur de nodata - * \param[in] BGI image de fond à lire - * \param[out] image ligne de l'image en sortie - * \param[out] mask ligne du masque en sortie + * \param[in] background_image image de fond à lire + * \param[out] image_line ligne de l'image en sortie + * \param[out] mask_line ligne du masque en sortie * \param[in] line indice de la ligne source dans l'image (et son masque) * \param[in] nodata valeur de nodata * \return code de retour, 0 si réussi, -1 sinon */ template -int fillBgLine ( FileImage* BGI, T* image, uint8_t* mask, int line, T* nodata ) { - if ( BGI->get_line( image, line ) == 0 ) return 1; +int fill_background_line ( FileImage* background_image, T* image_line, uint8_t* mask_line, int line, T* nodata ) { + if ( background_image->get_line( image_line, line ) == 0 ) return 1; - if ( BGI->get_mask() != NULL ) { - if ( BGI->get_mask()->get_line( mask, line ) == 0 ) return 1; + if ( background_image->get_mask() != NULL ) { + if ( background_image->get_mask()->get_line( mask_line, line ) == 0 ) return 1; for ( int w = 0; w < width; w++ ) { - if ( mask[w] == 0 ) { - memcpy ( image + w*samplesperpixel, nodata,samplesperpixel*sizeof ( T ) ); + if ( mask_line[w] == 0 ) { + memcpy ( image_line + w*samplesperpixel, nodata,samplesperpixel*sizeof ( T ) ); } } } else { - memset ( mask,255,width ); + memset ( mask_line,255,width ); } return 0; @@ -570,67 +570,67 @@ int fillBgLine ( FileImage* BGI, T* image, uint8_t* mask, int line, T* nodata ) * \~french * \brief Fusionne les 4 images en entrée et le masque de fond dans l'image de sortie * \details Dans le cas entier, lors de la moyenne des 4 pixels, on utilise une valeur de gamma qui éclaircit (si supérieure à 1.0) ou fonce (si inférieure à 1.0) le résultat. Si gamma vaut 1, le résultat est une moyenne classique. Les masques sont déjà associé aux objets FileImage, sauf pour l'image de sortie. - * \param[in] BGI image de fond en entrée - * \param[in] INPUTI images en entrée - * \param[in] OUTPUTI image en sortie - * \param[in] OUTPUTI éventuel masque en sortie + * \param[in] background_image image de fond en entrée + * \param[in] input_images images en entrée + * \param[in] output_image image en sortie + * \param[in] output_image éventuel masque en sortie * \return code de retour, 0 si réussi, -1 sinon */ template -int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileImage* OUTPUTM, T* nodata ) { +int merge ( FileImage* background_image, FileImage* input_images[2][2], FileImage* output_image, FileImage* output_mask, T* nodata ) { - uint8 MERGE[1024]; - for ( int i = 0; i <= 1020; i++ ) MERGE[i] = 255 - ( uint8 ) round ( pow ( double ( 1020 - i ) /1020., gammaM4t ) * 255. ); + uint8 merge_weights[1024]; + for ( int i = 0; i <= 1020; i++ ) merge_weights[i] = 255 - ( uint8 ) round ( pow ( double ( 1020 - i ) /1020., local_gamma ) * 255. ); - int nbsamples = width * samplesperpixel; + int samples_count = width * samplesperpixel; int left,right; - T line_bgI[nbsamples]; - uint8_t line_bgM[width]; + T background_image_line[samples_count]; + uint8_t background_mask_line[width]; - int nbData; - float pix[samplesperpixel]; + int data_count; + float pixel[samplesperpixel]; - T line_1I[2*nbsamples]; - uint8_t line_1M[2*width]; + T input_images_line_1[2*samples_count]; + uint8_t input_masks_line_1[2*width]; - T line_2I[2*nbsamples]; - uint8_t line_2M[2*width]; + T input_images_line_2[2*samples_count]; + uint8_t input_masks_line_2[2*width]; - T line_outI[nbsamples]; - uint8_t line_outM[width]; + T output_image_line[samples_count]; + uint8_t output_mask_line[width]; // ----------- initialisation du fond ----------- - for ( int i = 0; i < nbsamples ; i++ ) - line_bgI[i] = nodata[i%samplesperpixel]; + for ( int i = 0; i < samples_count ; i++ ) + background_image_line[i] = nodata[i%samplesperpixel]; - memset ( line_bgM,0,width ); + memset ( background_mask_line,0,width ); for ( int y = 0; y < 2; y++ ) { - if ( INPUTI[y][0] ) left = 0; + if ( input_images[y][0] ) left = 0; else left = width; - if ( INPUTI[y][1] ) right = 2*width; + if ( input_images[y][1] ) right = 2*width; else right = width; - for ( uint32 h = 0; h < height/2; h++ ) { + for ( uint32 h = 0; h < height / 2; h++ ) { - int line = y*height/2 + h; + int line = y * height / 2 + h; // ------------------- le fond ------------------ - if ( BGI ) - if ( fillBgLine ( BGI, line_bgI, line_bgM, line, nodata ) ) { + if ( background_image ) + if ( fill_background_line ( background_image, background_image_line, background_mask_line, line, nodata ) ) { BOOST_LOG_TRIVIAL(error) << "Unable to read background line" ; return -1; } if ( left == right ) { // On n'a pas d'image en entrée pour cette ligne, on stocke le fond et on passe à la suivante - if ( OUTPUTI->write_line( line_bgI, line ) == -1 ) { + if ( output_image->write_line( background_image_line, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write image's line " << line ; return -1; } - if ( OUTPUTM ) - if ( OUTPUTM->write_line( line_bgM, line ) == -1 ) { + if ( output_mask ) + if ( output_mask->write_line( background_mask_line, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write mask's line " << line ; return -1; } @@ -639,30 +639,30 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma } // -- initialisation de la sortie avec le fond -- - memcpy ( line_outI,line_bgI,nbsamples*sizeof ( T ) ); - memcpy ( line_outM,line_bgM,width ); + memcpy ( output_image_line,background_image_line,samples_count*sizeof ( T ) ); + memcpy ( output_mask_line,background_mask_line,width ); - memset ( line_1M,255,2*width ); - memset ( line_2M,255,2*width ); + memset ( input_masks_line_1,255,2*width ); + memset ( input_masks_line_2,255,2*width ); // ----------------- les images ----------------- // ------ et les éventuels masques -------------- - if ( INPUTI[y][0] ) { - if ( INPUTI[y][0]->get_line( line_1I, 2*h ) == 0 ) { + if ( input_images[y][0] ) { + if ( input_images[y][0]->get_line( input_images_line_1, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][0]->get_line( line_2I, 2*h+1 ) == 0 ) { + if ( input_images[y][0]->get_line( input_images_line_2, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][0]->get_mask() ) { - if ( INPUTI[y][0]->get_mask()->get_line( line_1M, 2*h ) == 0 ) { + if ( input_images[y][0]->get_mask() ) { + if ( input_images[y][0]->get_mask()->get_line( input_masks_line_1, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][0]->get_mask()->get_line( line_2M, 2*h+1 ) == 0 ) { + if ( input_images[y][0]->get_mask()->get_line( input_masks_line_2, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } @@ -670,22 +670,22 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma } - if ( INPUTI[y][1] ) { - if ( INPUTI[y][1]->get_line( line_1I + nbsamples, 2*h ) == 0 ) { + if ( input_images[y][1] ) { + if ( input_images[y][1]->get_line( input_images_line_1 + samples_count, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][1]->get_line( line_2I + nbsamples, 2*h+1 ) == 0 ) { + if ( input_images[y][1]->get_line( input_images_line_2 + samples_count, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][1]->get_mask() ) { - if ( INPUTI[y][1]->get_mask()->get_line( line_1M + width, 2*h ) == 0 ) { + if ( input_images[y][1]->get_mask() ) { + if ( input_images[y][1]->get_mask()->get_line( input_masks_line_1 + width, 2*h ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } - if ( INPUTI[y][1]->get_mask()->get_line( line_2M + width, 2*h+1 ) == 0 ) { + if ( input_images[y][1]->get_mask()->get_line( input_masks_line_2 + width, 2*h+1 ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "Unable to read data line" ; return -1; } @@ -693,52 +693,53 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma } // ----------------- la moyenne ---------------- - for ( int pixIn = left, sampleIn = left * samplesperpixel; pixIn < right; - pixIn += 2, sampleIn += 2*samplesperpixel ) { + for ( int input_pixel = left, input_sample = left * samplesperpixel; input_pixel < right; + input_pixel += 2, input_sample += 2*samplesperpixel ) { - memset ( pix,0,samplesperpixel*sizeof ( float ) ); - nbData = 0; + memset ( pixel,0,samplesperpixel*sizeof ( float ) ); + data_count = 0; - if ( line_1M[pixIn] ) { - nbData++; - for ( int c = 0; c < samplesperpixel; c++ ) pix[c] += line_1I[sampleIn+c]; + if ( input_masks_line_1[input_pixel] ) { + data_count++; + for ( int c = 0; c < samplesperpixel; c++ ) pixel[c] += input_images_line_1[input_sample+c]; } - if ( line_1M[pixIn+1] ) { - nbData++; - for ( int c = 0; c < samplesperpixel; c++ ) pix[c] += line_1I[sampleIn+samplesperpixel+c]; + if ( input_masks_line_1[input_pixel+1] ) { + data_count++; + for ( int c = 0; c < samplesperpixel; c++ ) pixel[c] += input_images_line_1[input_sample+samplesperpixel+c]; } - if ( line_2M[pixIn] ) { - nbData++; - for ( int c = 0; c < samplesperpixel; c++ ) pix[c] += line_2I[sampleIn+c]; + if ( input_masks_line_2[input_pixel] ) { + data_count++; + for ( int c = 0; c < samplesperpixel; c++ ) pixel[c] += input_images_line_2[input_sample+c]; } - if ( line_2M[pixIn+1] ) { - nbData++; - for ( int c = 0; c < samplesperpixel; c++ ) pix[c] += line_2I[sampleIn+samplesperpixel+c]; + if ( input_masks_line_2[input_pixel+1] ) { + data_count++; + for ( int c = 0; c < samplesperpixel; c++ ) pixel[c] += input_images_line_2[input_sample+samplesperpixel+c]; } - if ( nbData > 1 ) { - line_outM[pixIn/2] = 255; + if ( data_count > 1 ) { + output_mask_line[input_pixel/2] = 255; if ( sizeof ( T ) == 1 ) { // Cas entier : utilisation d'un gamma - for ( int c = 0; c < samplesperpixel; c++ ) line_outI[sampleIn/2+c] = MERGE[ ( int ) pix[c]*4/nbData]; + for ( int c = 0; c < samplesperpixel; c++ ) output_image_line[input_sample/2+c] = merge_weights[ ( int ) pixel[c]*4/data_count]; } else if ( sizeof ( T ) == 4 ) { - for ( int c = 0; c < samplesperpixel; c++ ) line_outI[sampleIn/2+c] = pix[c]/ ( float ) nbData; + for ( int c = 0; c < samplesperpixel; c++ ) output_image_line[input_sample/2+c] = pixel[c]/ ( float ) data_count; } } } - if ( OUTPUTI->write_line( line_outI, line ) == -1 ) { + if ( output_image->write_line( output_image_line, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write image" ; return -1; } - if ( OUTPUTM ) - if ( OUTPUTM->write_line( line_outM, line ) == -1 ) { + if ( output_mask ) { + if ( output_mask->write_line( output_mask_line, line ) == -1 ) { BOOST_LOG_TRIVIAL(error) << "Unable to write mask" ; return -1; } + } } } @@ -759,11 +760,11 @@ int merge ( FileImage* BGI, FileImage* INPUTI[2][2], FileImage* OUTPUTI, FileIma * \return 0 if success, -1 otherwise */ int main ( int argc, char* argv[] ) { - FileImage* INPUTI[2][2]; - for ( int i = 0; i < 2; i++ ) for ( int j = 0; j < 2; j++ ) INPUTI[i][j] = NULL; - FileImage* BGI = NULL; - FileImage* OUTPUTI = NULL; - FileImage* OUTPUTM = NULL; + FileImage* input_images[2][2]; + for ( int i = 0; i < 2; i++ ) for ( int j = 0; j < 2; j++ ) input_images[i][j] = NULL; + FileImage* background_image = NULL; + FileImage* output_image = NULL; + FileImage* output_mask = NULL; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -792,12 +793,12 @@ int main ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(debug) << "Check images" ; // Controle des images - if ( checkImages ( INPUTI, BGI, OUTPUTI, OUTPUTM ) < 0 ) { - if ( BGI ) delete BGI; + if ( check_images ( input_images, background_image, output_image, output_mask ) < 0 ) { + if ( background_image ) delete background_image; for ( int i = 0; i < 2; i++ ) for ( int j = 0; j < 2; j++ ) { - if ( INPUTI[i][j] ) { - delete INPUTI[i][j] ; + if ( input_images[i][j] ) { + delete input_images[i][j] ; } } error ( "Echec controle des images",-1 ); @@ -805,34 +806,34 @@ int main ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(debug) << "Nodata interpretation" ; // Conversion string->int[] du paramètre nodata - int nodataInt[samplesperpixel]; + int nodata[samplesperpixel]; - char* charValue = strtok ( strnodata,"," ); - if ( charValue == NULL ) { + char* char_iterator = strtok ( strnodata,"," ); + if ( char_iterator == NULL ) { error ( "Error with option -n : a value for nodata is missing",-1 ); } - nodataInt[0] = atoi ( charValue ); + nodata[0] = atoi ( char_iterator ); for ( int i = 1; i < samplesperpixel; i++ ) { - charValue = strtok ( NULL, "," ); - if ( charValue == NULL ) { + char_iterator = strtok ( NULL, "," ); + if ( char_iterator == NULL ) { error ( "Error with option -n : a value for nodata is missing",-1 ); } - nodataInt[i] = atoi ( charValue ); + nodata[i] = atoi ( char_iterator ); } // Cas MNT if ( sampleformat == SampleFormat::FLOAT32 ) { BOOST_LOG_TRIVIAL(debug) << "Merge images (float)" ; float nodata[samplesperpixel]; - for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( float ) nodataInt[i]; - if ( merge ( BGI, INPUTI, OUTPUTI, OUTPUTM, nodata ) < 0 ) error ( "Unable to merge float images",-1 ); + for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( float ) nodata[i]; + if ( merge ( background_image, input_images, output_image, output_mask, nodata ) < 0 ) error ( "Unable to merge float images",-1 ); } // Cas images else if ( sampleformat == SampleFormat::UINT8 ) { BOOST_LOG_TRIVIAL(debug) << "Merge images (uint8_t)" ; uint8_t nodata[samplesperpixel]; - for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( uint8_t ) nodataInt[i]; - if ( merge ( BGI, INPUTI, OUTPUTI, OUTPUTM, nodata ) < 0 ) error ( "Unable to merge integer images",-1 ); + for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( uint8_t ) nodata[i]; + if ( merge ( background_image, input_images, output_image, output_mask, nodata ) < 0 ) error ( "Unable to merge integer images",-1 ); } else { error ( "Unhandled sample's format",-1 ); } @@ -840,15 +841,15 @@ int main ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(debug) << "Clean" ; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); - if ( BGI ) delete BGI; + if ( background_image ) delete background_image; for ( int i = 0; i < 2; i++ ) for ( int j = 0; j < 2; j++ ) { - if ( INPUTI[i][j] ) delete INPUTI[i][j] ; + if ( input_images[i][j] ) delete input_images[i][j] ; } - delete OUTPUTI; + delete output_image; } diff --git a/src/mergeNtiff.cpp b/src/mergeNtiff.cpp index afe5be8..2ce21a9 100644 --- a/src/mergeNtiff.cpp +++ b/src/mergeNtiff.cpp @@ -91,7 +91,7 @@ namespace keywords = boost::log::keywords; // Paramètres de la ligne de commande déclarés en global /** \~french Chemin du fichier de configuration des images */ -char configuration_file[256]; +char configuration_path[256]; /** \~french Racine pour les images de sortie */ char images_root[256]; @@ -181,13 +181,13 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error(std::string message, int errorCode) { +void error(std::string message, int error_code) { BOOST_LOG_TRIVIAL(error) << message; - BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_file; + BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_path; usage(); - exit(errorCode); + exit(error_code); } /** @@ -215,7 +215,7 @@ int parse_command_line(int argc, char** argv) { BOOST_LOG_TRIVIAL(error) << "Error in option -f"; return -1; } - strcpy(configuration_file, argv[i]); + strcpy(configuration_path, argv[i]); break; case 'r': // racine pour le fichier de configuration if (i++ >= argc) { @@ -324,7 +324,7 @@ int parse_command_line(int argc, char** argv) { } } - BOOST_LOG_TRIVIAL(debug) << "mergeNtiff -f " << configuration_file; + BOOST_LOG_TRIVIAL(debug) << "mergeNtiff -f " << configuration_path; return 0; } @@ -354,9 +354,9 @@ bool load_configuration( std::ifstream file; int rootLength = strlen(images_root); - file.open(configuration_file); + file.open(configuration_path); if (!file.is_open()) { - BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << configuration_file; + BOOST_LOG_TRIVIAL(error) << "Impossible d'ouvrir le fichier " << configuration_path; return false; } @@ -423,7 +423,7 @@ bool load_configuration( file.close(); return true; } else { - BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << configuration_file; + BOOST_LOG_TRIVIAL(error) << "Failure reading the configuration file " << configuration_path; file.close(); return false; } @@ -434,7 +434,7 @@ bool load_configuration( * \brief Charge les images en entrée et en sortie depuis le fichier de configuration * \details On va récupérer toutes les informations de toutes les images et masques présents dans le fichier de configuration et créer les objets FileImage correspondant. Toutes les images ici manipulées sont de vraies images (physiques) dans ce sens où elles sont des fichiers soit lus, soit qui seront écrits. * - * Le chemin vers le fichier de configuration est stocké dans la variables globale configuration_file et images_root va être concaténer au chemin vers les fichiers de sortie. + * Le chemin vers le fichier de configuration est stocké dans la variables globale configuration_path et images_root va être concaténer au chemin vers les fichiers de sortie. * \param[out] output_image image résultante de l'outil * \param[out] output_mask masque résultat de l'outil, si demandé * \param[out] sorted_input_images ensemble des images en entrée @@ -449,13 +449,13 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vector resys; if (! load_configuration(&masks, &paths, &srss, &bboxes, &resxs, &resys)) { - BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << configuration_file; + BOOST_LOG_TRIVIAL(error) << "Cannot load configuration file " << configuration_path; return -1; } // On doit avoir au moins deux lignes, trois si on a un masque de sortie if (masks.size() < 2 || (masks.size() == 2 && masks.back())) { - BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << configuration_file; + BOOST_LOG_TRIVIAL(error) << "We have no input images in configuration file " << configuration_path; return -1; } @@ -479,7 +479,7 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectoris_define()) { BOOST_LOG_TRIVIAL(error) << "Input CRS unknown: " << srss.at(i); @@ -489,7 +489,7 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectorget_request_code(); } - if (! bboxes.at(i).isInAreaOfCRS(crs)) { + if (! bboxes.at(i).is_in_crs_area(crs)) { BOOST_LOG_TRIVIAL(debug) << "Warning : the input image's (" << paths.at(i) << ") bbox is not included in the srs (" << srss.at(i) << ") definition extent"; BOOST_LOG_TRIVIAL(debug) << bboxes.at(i).to_string() << " not included in " << crs->get_native_crs_definition_area().to_string(); } @@ -505,7 +505,7 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectorset_crs(crs); @@ -550,7 +550,7 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectorsize() == 0) { - BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << configuration_file << "' : pas de données en entrée."; + BOOST_LOG_TRIVIAL(error) << "Erreur lecture du fichier de parametres '" << configuration_path << "' : pas de données en entrée."; return -1; } else { BOOST_LOG_TRIVIAL(debug) << input_count << " image(s) en entrée"; @@ -561,13 +561,13 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectorisOk() ) { - BOOST_LOG_TRIVIAL(error) << style->getErrorMessage(); + if ( ! style->is_ok() ) { + BOOST_LOG_TRIVIAL(error) << style->get_error_message(); BOOST_LOG_TRIVIAL(error) << "Cannot load style"; return -1; } - if ( ! style->youCan(samplesperpixel) ) { + if ( ! style->handle(samplesperpixel) ) { BOOST_LOG_TRIVIAL(error) << "Cannot apply this style for this channels number"; return -1; } @@ -668,7 +668,7 @@ int add_converters(std::vector input_images) { * \return code de retour, 0 si réussi, -1 sinon */ int sort_images(std::vector input_images, std::vector >* sorted_input_images) { - std::vector tmp; + std::vector current_pack; std::vector::iterator current_input_images_iterator = input_images.begin(); /* we create consistent images' vectors (X/Y resolution and X/Y phases) @@ -677,16 +677,16 @@ int sort_images(std::vector input_images, std::vector::iterator input_images_iterator = input_images.begin(); input_images_iterator < input_images.end() - 1; input_images_iterator++) { if (!(*input_images_iterator)->compatible(*(input_images_iterator + 1))) { // two following images are not compatible, we split images' vector - tmp.assign(current_input_images_iterator, input_images_iterator + 1); + current_pack.assign(current_input_images_iterator, input_images_iterator + 1); current_input_images_iterator = input_images_iterator + 1; - sorted_input_images->push_back(tmp); + sorted_input_images->push_back(current_pack); } } // we don't forget to store last images in sorted_input_images // images - tmp.assign(current_input_images_iterator, input_images.end()); - sorted_input_images->push_back(tmp); + current_pack.assign(current_input_images_iterator, input_images.end()); + sorted_input_images->push_back(current_pack); return 0; } @@ -703,7 +703,7 @@ int sort_images(std::vector input_images, std::vectorget_resx(), resy_dst = output_image->get_resy(); - const Kernel& kernel = Kernel::getInstance(interpolation); + const Kernel& kernel = Kernel::get_instance(interpolation); // Ajout des miroirs // Valeurs utilisées pour déterminer la taille des miroirs en pixel (taille optimale en fonction du noyau utilisé) @@ -807,12 +807,12 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag double resx_dst = output_image->get_resx(), resy_dst = output_image->get_resy(); double resx_src = input_images->get_resx(), resy_src = input_images->get_resy(); - const Kernel& kernel = Kernel::getInstance(interpolation); + const Kernel& kernel = Kernel::get_instance(interpolation); /******** Conversion de la bbox source dans le srs de sortie ********/ /******************* et calcul des ratios des résolutions ***********/ - BoundingBox tmp_bbox = input_images->get_bbox().cropToAreaOfCRS(input_images->get_crs()); + BoundingBox tmp_bbox = input_images->get_bbox().crop_to_crs_area(input_images->get_crs()); int crop_width = ceil((tmp_bbox.xmax - tmp_bbox.xmin) / resx_src); int crop_height = ceil((tmp_bbox.ymax - tmp_bbox.ymin) / resy_src); @@ -822,7 +822,7 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag return false; } - /* On valcule les résolutions de l'image source "équivalente" dans le SRS de destination, pour pouvoir calculer le ratio + /* On calcule les résolutions de l'image source "équivalente" dans le SRS de destination, pour pouvoir calculer le ratio * des résolutions pour la taille des miroirs */ double resx_calc = (tmp_bbox.xmax - tmp_bbox.xmin) / double(crop_width); double resy_calc = (tmp_bbox.ymax - tmp_bbox.ymin) / double(crop_height); @@ -832,9 +832,9 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag /* On fait particulièrement attention à ne considérer que la partie valide de la bbox finale * c'est à dire la partie incluse dans l'espace de définition du SRS * On va donc la "croper" */ - BoundingBox croped_output_bbox = output_image->get_bbox().cropToAreaOfCRS(output_image->get_crs()); + BoundingBox croped_output_bbox = output_image->get_bbox().crop_to_crs_area(output_image->get_crs()); - BoundingBox bbox_dst = croped_output_bbox.getIntersection(tmp_bbox); + BoundingBox bbox_dst = croped_output_bbox.get_intersection(tmp_bbox); BOOST_LOG_TRIVIAL(debug) << " BBOX dst (srs destination) : " << bbox_dst.to_string(); @@ -918,7 +918,6 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag styled_image = new EstompageImage (input_images, style->get_estompage()); } else if (style->pente_defined()) { - BOOST_LOG_TRIVIAL(debug) << "--------------- On ajoute la pente"; styled_image = new PenteImage (input_images, style->get_pente()); } else if (style->aspect_defined()) { @@ -927,7 +926,6 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag if ( input_to_reproject->get_channels() == 1 && ! ( style->get_palette()->is_empty() ) ) { if (styled_image != NULL) { - BOOST_LOG_TRIVIAL(debug) << "--------------- On ajoute la palette sur la pente"; input_to_reproject = new PaletteImage ( styled_image , style->get_palette() ); } else { input_to_reproject = new PaletteImage ( input_images , style->get_palette() ); @@ -935,16 +933,17 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag } else { input_to_reproject = styled_image; } - } - input_to_reproject->set_crs(input_images->get_crs()); - input_to_reproject->print(); + input_to_reproject->set_crs(input_images->get_crs()); + } /*************************** Image reprojetée ***********************/ // On reprojete le masque : TOUJOURS EN PPV, sans utilisation de masque pour l'interpolation - ReprojectedImage* reprojected_mask = new ReprojectedImage(input_images->Image::get_mask(), bbox_dst, resx_dst, resy_dst, grid, - Interpolation::NEAREST_NEIGHBOUR, false); + ReprojectedImage* reprojected_mask = new ReprojectedImage( + input_images->Image::get_mask(), bbox_dst, resx_dst, resy_dst, grid, + Interpolation::NEAREST_NEIGHBOUR, false + ); reprojected_mask->set_crs(output_image->get_crs()); // Reprojection de l'image @@ -952,6 +951,8 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag *reprojected_image = new ReprojectedImage(input_to_reproject, bbox_dst, resx_dst, resy_dst, grid, interpolation, input_images->use_masks()); (*reprojected_image)->set_crs(output_image->get_crs()); + (*reprojected_image)->print(); + if (!(*reprojected_image)->set_mask(reprojected_mask)) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the ReprojectedImage"; return false; @@ -1172,7 +1173,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Echec chargement des images", -1); } @@ -1183,7 +1184,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Echec ajout des convertisseurs", -1); } @@ -1201,7 +1202,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Error with option -n : a value for nodata is missing", -1); } @@ -1213,7 +1214,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Error with option -n : one value per sample, separate with comma", -1); } @@ -1228,7 +1229,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Echec tri des images", -1); } @@ -1240,7 +1241,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Echec fusion des paquets d images", -1); } @@ -1252,7 +1253,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Echec enregistrement de l image finale", -1); } @@ -1265,7 +1266,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); error("Echec enregistrement du masque final", -1); } @@ -1282,10 +1283,10 @@ int main(int argc, char** argv) { delete merged_image; delete output_image; delete output_mask; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); - StoragePool::cleanStoragePool(); - CurlPool::cleanCurlPool(); + StoragePool::clean_storages(); + CurlPool::clean_curls(); curl_global_cleanup(); return 0; diff --git a/src/overlayNtiff.cpp b/src/overlayNtiff.cpp index 44b912b..9768e6e 100644 --- a/src/overlayNtiff.cpp +++ b/src/overlayNtiff.cpp @@ -68,7 +68,7 @@ namespace keywords = boost::log::keywords; #include /** \~french Chemin du fichier de configuration des images */ -char configuration_file[256]; +char configuration_path[256]; /** \~french Nombre de canaux par pixel de l'image en sortie */ uint16_t samplesperpixel = 0; /** \~french Format du canal (entier, flottant, signé ou non...), dans les images en entrée et celle en sortie */ @@ -78,7 +78,7 @@ Photometric::ePhotometric photometric = Photometric::RGB; /** \~french Compression de l'image de sortie */ Compression::eCompression compression = Compression::NONE; /** \~french Mode de fusion des images */ -Merge::eMergeType mergeMethod = Merge::UNKNOWN; +Merge::eMergeType merge_method = Merge::UNKNOWN; /** \~french Couleur à considérer comme transparent dans le images en entrée. Vrai couleur (sur 3 canaux). Peut ne pas être définie */ int* transparent; @@ -138,13 +138,13 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; - BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_file ; + BOOST_LOG_TRIVIAL(error) << "Configuration file : " << configuration_path ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -156,10 +156,10 @@ void error ( std::string message, int errorCode ) { */ int parse_command_line ( int argc, char** argv ) { - char strTransparent[256]; - memset ( strTransparent, 0, 256 ); - char strBg[256]; - memset ( strBg, 0, 256 ); + char transparent_string[256]; + memset ( transparent_string, 0, 256 ); + char background_string[256]; + memset ( background_string, 0, 256 ); for ( int i = 1; i < argc; i++ ) { if ( argv[i][0] == '-' ) { @@ -175,15 +175,15 @@ int parse_command_line ( int argc, char** argv ) { BOOST_LOG_TRIVIAL(error) << "Error with images' list file (option -f)" ; return -1; } - strcpy ( configuration_file,argv[i] ); + strcpy ( configuration_path,argv[i] ); break; case 'm': // image merge method if ( i++ >= argc ) { BOOST_LOG_TRIVIAL(error) << "Error with merge method (option -m)" ; return -1; } - mergeMethod = Merge::from_string ( argv[i] ); - if ( mergeMethod == Merge::UNKNOWN ) { + merge_method = Merge::from_string ( argv[i] ); + if ( merge_method == Merge::UNKNOWN ) { BOOST_LOG_TRIVIAL(error) << "Unknown value for merge method (option -m) : " << argv[i] ; return -1; } @@ -236,14 +236,14 @@ int parse_command_line ( int argc, char** argv ) { BOOST_LOG_TRIVIAL(error) << "Error with transparent color (option -t)" ; return -1; } - strcpy ( strTransparent,argv[i] ); + strcpy ( transparent_string,argv[i] ); break; case 'b': // background color if ( i++ >= argc ) { BOOST_LOG_TRIVIAL(error) << "Error with background color (option -b)" ; return -1; } - strcpy ( strBg,argv[i] ); + strcpy ( background_string,argv[i] ); break; default: BOOST_LOG_TRIVIAL(error) << "Unknown option : -" << argv[i][1] ; @@ -253,13 +253,13 @@ int parse_command_line ( int argc, char** argv ) { } // Merge method control - if ( mergeMethod == Merge::UNKNOWN ) { + if ( merge_method == Merge::UNKNOWN ) { BOOST_LOG_TRIVIAL(error) << "We need to know the merge method (option -m)" ; return -1; } // Image list file control - if ( strlen ( configuration_file ) == 0 ) { + if ( strlen ( configuration_path ) == 0 ) { BOOST_LOG_TRIVIAL(error) << "We need to have one images' list (text file, option -f)" ; return -1; } @@ -270,47 +270,47 @@ int parse_command_line ( int argc, char** argv ) { return -1; } - if (mergeMethod == Merge::ALPHATOP && strlen ( strTransparent ) != 0 ) { + if (merge_method == Merge::ALPHATOP && strlen ( transparent_string ) != 0 ) { transparent = new int[3]; // Transparent interpretation - char* charValue = strtok ( strTransparent,"," ); - if ( charValue == NULL ) { + char* char_iterator = strtok ( transparent_string,"," ); + if ( char_iterator == NULL ) { BOOST_LOG_TRIVIAL(error) << "Error with option -t : 3 integers values separated by comma" ; return -1; } - int value = atoi ( charValue ); + int value = atoi ( char_iterator ); transparent[0] = value; for ( int i = 1; i < 3; i++ ) { - charValue = strtok ( NULL, "," ); - if ( charValue == NULL ) { + char_iterator = strtok ( NULL, "," ); + if ( char_iterator == NULL ) { BOOST_LOG_TRIVIAL(error) << "Error with option -t : 3 integers values separated by comma" ; return -1; } - value = atoi ( charValue ); + value = atoi ( char_iterator ); transparent[i] = value; } } - if ( strlen ( strBg ) != 0 ) { + if ( strlen ( background_string ) != 0 ) { background = new int[samplesperpixel]; // Background interpretation - char* charValue = strtok ( strBg,"," ); - if ( charValue == NULL ) { + char* char_iterator = strtok ( background_string,"," ); + if ( char_iterator == NULL ) { BOOST_LOG_TRIVIAL(error) << "Error with option -b : one integer value per final sample separated by comma" ; return -1; } - int value = atoi ( charValue ); + int value = atoi ( char_iterator ); background[0] = value; for ( int i = 1; i < samplesperpixel; i++ ) { - charValue = strtok ( NULL, "," ); - if ( charValue == NULL ) { + char_iterator = strtok ( NULL, "," ); + if ( char_iterator == NULL ) { BOOST_LOG_TRIVIAL(error) << "Error with option -b : one integer value per final sample separated by comma" ; return -1; } - value = atoi ( charValue ); + value = atoi ( char_iterator ); background[i] = value; } @@ -326,27 +326,27 @@ int parse_command_line ( int argc, char** argv ) { * \~french * \brief Lit une ligne du fichier de configuration * \details Une ligne contient le chemin vers une image, potentiellement suivi du chemin vers le masque associé. - * \param[in,out] file flux de lecture vers le fichier de configuration - * \param[out] imageFileName chemin de l'image lu dans le fichier de configuration - * \param[out] hasMask précise si l'image possède un masque - * \param[out] maskFileName chemin du masque lu dans le fichier de configuration + * \param[in,out] configuration_file flux de lecture vers le fichier de configuration + * \param[out] image_path chemin de l'image lu dans le fichier de configuration + * \param[out] has_mask précise si l'image possède un masque + * \param[out] mask_path chemin du masque lu dans le fichier de configuration * \return code de retour, 0 en cas de succès, -1 si la fin du fichier est atteinte, 1 en cas d'erreur */ -int readFileLine ( std::ifstream& file, char* imageFileName, bool* hasMask, char* maskFileName ) { +int read_configuration_line ( std::ifstream& configuration_file, char* image_path, bool* has_mask, char* mask_path ) { std::string str; while ( str.empty() ) { - if ( file.eof() ) { + if ( configuration_file.eof() ) { BOOST_LOG_TRIVIAL(debug) << "Configuration file end reached" ; return -1; } - std::getline ( file, str ); + std::getline ( configuration_file, str ); } - if ( std::sscanf ( str.c_str(),"%s %s", imageFileName, maskFileName ) == 2 ) { - *hasMask = true; + if ( std::sscanf ( str.c_str(),"%s %s", image_path, mask_path ) == 2 ) { + *has_mask = true; } else { - *hasMask = false; + *has_mask = false; } return 0; @@ -357,121 +357,121 @@ int readFileLine ( std::ifstream& file, char* imageFileName, bool* hasMask, char * \brief Charge les images en entrée et en sortie depuis le fichier de configuration * \details On va récupérer toutes les informations de toutes les images et masques présents dans le fichier de configuration et créer les objets LibtiffImage correspondant. Toutes les images ici manipulées sont de vraies images (physiques) dans ce sens où elles sont des fichiers soit lus, soit qui seront écrits. * - * \param[out] ppImageOut image résultante de l'outil - * \param[out] ppMaskOut masque résultat de l'outil, si demandé + * \param[out] output_image image résultante de l'outil + * \param[out] output_mask masque résultat de l'outil, si demandé * \param[out] pImageIn ensemble des images en entrée * \return code de retour, 0 si réussi, -1 sinon */ -int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** ppMergeIn ) { - char inputImagePath[IMAGE_MAX_FILENAME_LENGTH]; - char inputMaskPath[IMAGE_MAX_FILENAME_LENGTH]; +int load_images ( FileImage** output_image, FileImage** output_mask, MergeImage** merged_image ) { + char input_image_path[IMAGE_MAX_FILENAME_LENGTH]; + char input_mask_path[IMAGE_MAX_FILENAME_LENGTH]; - char outputImagePath[IMAGE_MAX_FILENAME_LENGTH]; - char outputMaskPath[IMAGE_MAX_FILENAME_LENGTH]; + char output_image_path[IMAGE_MAX_FILENAME_LENGTH]; + char output_mask_path[IMAGE_MAX_FILENAME_LENGTH]; - std::vector ImageIn; - BoundingBox fakeBbox ( 0.,0.,0.,0. ); + std::vector input_images; + BoundingBox empty_bbox ( 0.,0.,0.,0. ); int width, height; - bool hasMask, hasOutMask; + bool has_input_mask, has_output_mask; // Ouverture du fichier texte listant les images - std::ifstream file; + std::ifstream configuration_file; - file.open ( configuration_file ); - if ( !file ) { - BOOST_LOG_TRIVIAL(error) << "Cannot open the file " << configuration_file ; + configuration_file.open ( configuration_path ); + if ( ! configuration_file ) { + BOOST_LOG_TRIVIAL(error) << "Cannot open the file " << configuration_path ; return -1; } // Lecture de l'image de sortie - if ( readFileLine ( file,outputImagePath,&hasOutMask,outputMaskPath ) ) { - BOOST_LOG_TRIVIAL(error) << "Cannot read output image in the file : " << configuration_file ; + if ( read_configuration_line ( configuration_file,output_image_path,&has_output_mask,output_mask_path ) ) { + BOOST_LOG_TRIVIAL(error) << "Cannot read output image in the file : " << configuration_path ; return -1; } // On doit connaître les dimensions des images en entrée pour pouvoir créer les images de sortie // Lecture et création des images sources - int inputNb = 0; + int input_count = 0; int out = 0; - while ( ( out = readFileLine ( file,inputImagePath,&hasMask,inputMaskPath ) ) == 0 ) { - FileImage* pImage = FileImage::create_to_read ( inputImagePath ); - if ( pImage == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Cannot create a FileImage from the file " << inputImagePath ; + while ( ( out = read_configuration_line ( configuration_file,input_image_path,&has_input_mask,input_mask_path ) ) == 0 ) { + FileImage* input_image = FileImage::create_to_read ( input_image_path ); + if ( input_image == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Cannot create a FileImage from the file " << input_image_path ; return -1; } - if ( inputNb == 0 ) { + if ( input_count == 0 ) { // C'est notre première image en entrée, on mémorise les caractéristiques) - sampleformat = pImage->get_sample_format(); - width = pImage->get_width(); - height = pImage->get_height(); + sampleformat = input_image->get_sample_format(); + width = input_image->get_width(); + height = input_image->get_height(); } else { // Toutes les images en entrée doivent avoir certaines caractéristiques en commun - if (sampleformat != pImage->get_sample_format() || width != pImage->get_width() || height != pImage->get_height() ) { + if (sampleformat != input_image->get_sample_format() || width != input_image->get_width() || height != input_image->get_height() ) { BOOST_LOG_TRIVIAL(error) << "All input images must have same dimension and sample type" ; return -1; } } - if ( hasMask ) { + if ( has_input_mask ) { /* On a un masque associé, on en fait une image à lire et on vérifie qu'elle est cohérentes : * - même dimensions que l'image * - 1 seul canal (entier) */ - FileImage* pMask = FileImage::create_to_read ( inputMaskPath ); + FileImage* pMask = FileImage::create_to_read ( input_mask_path ); if ( pMask == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Cannot create a FileImage (mask) from the file " << inputMaskPath ; + BOOST_LOG_TRIVIAL(error) << "Cannot create a FileImage (mask) from the file " << input_mask_path ; return -1; } - if ( ! pImage->set_mask ( pMask ) ) { - BOOST_LOG_TRIVIAL(error) << "Cannot add mask " << inputMaskPath ; + if ( ! input_image->set_mask ( pMask ) ) { + BOOST_LOG_TRIVIAL(error) << "Cannot add mask " << input_mask_path ; return -1; } } - ImageIn.push_back ( pImage ); - inputNb++; + input_images.push_back ( input_image ); + input_count++; } if ( out != -1 ) { - BOOST_LOG_TRIVIAL(error) << "Failure reading the file " << configuration_file ; + BOOST_LOG_TRIVIAL(error) << "Failure reading the file " << configuration_path ; return -1; } // Fermeture du fichier - file.close(); + configuration_file.close(); // On crée notre MergeImage, qui s'occupera des calculs de fusion des pixels - *ppMergeIn = MergeImage::create ( ImageIn, samplesperpixel, background, transparent, mergeMethod ); + *merged_image = MergeImage::create ( input_images, samplesperpixel, background, transparent, merge_method ); // Le masque fusionné est ajouté - MergeMask* pMM = new MergeMask ( *ppMergeIn ); + MergeMask* merged_mask = new MergeMask ( *merged_image ); - if ( ! ( *ppMergeIn )->set_mask ( pMM ) ) { + if ( ! ( *merged_image )->set_mask ( merged_mask ) ) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the merged image" ; return -1; } // Création des sorties - *ppImageOut = FileImage::create_to_write ( outputImagePath, fakeBbox, -1., -1., width, height, samplesperpixel, + *output_image = FileImage::create_to_write ( output_image_path, empty_bbox, -1., -1., width, height, samplesperpixel, sampleformat, photometric,compression ); - if ( *ppImageOut == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Impossible de creer l'image " << outputImagePath ; + if ( *output_image == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Impossible de creer l'image " << output_image_path ; return -1; } - if ( hasOutMask ) { - *ppMaskOut = FileImage::create_to_write ( outputMaskPath, fakeBbox, -1., -1., width, height, 1, + if ( has_output_mask ) { + *output_mask = FileImage::create_to_write ( output_mask_path, empty_bbox, -1., -1., width, height, 1, SampleFormat::UINT8, Photometric::MASK, Compression::DEFLATE ); - if ( *ppMaskOut == NULL ) { - BOOST_LOG_TRIVIAL(error) << "Impossible de creer le masque " << outputMaskPath ; + if ( *output_mask == NULL ) { + BOOST_LOG_TRIVIAL(error) << "Impossible de creer le masque " << output_mask_path ; return -1; } } @@ -493,9 +493,9 @@ int load_images ( FileImage** ppImageOut, FileImage** ppMaskOut, MergeImage** pp */ int main ( int argc, char **argv ) { - FileImage* pImageOut ; - FileImage* pMaskOut = NULL; - MergeImage* pMergeIn; + FileImage* output_image ; + FileImage* output_mask = NULL; + MergeImage* merged_image; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -519,29 +519,29 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Load" ; // Chargement des images - if ( load_images ( &pImageOut,&pMaskOut,&pMergeIn ) < 0 ) { + if ( load_images ( &output_image,&output_mask,&merged_image ) < 0 ) { error ( "Cannot load images from the configuration file",-1 ); } BOOST_LOG_TRIVIAL(debug) << "Save image" ; // Enregistrement de l'image fusionnée - if ( pImageOut->write_image ( pMergeIn ) < 0 ) { + if ( output_image->write_image ( merged_image ) < 0 ) { error ( "Cannot write the merged image",-1 ); } // Enregistrement du masque fusionné, si demandé - if ( pMaskOut != NULL) { + if ( output_mask != NULL) { BOOST_LOG_TRIVIAL(debug) << "Save mask" ; - if ( pMaskOut->write_image ( pMergeIn->Image::get_mask() ) < 0 ) { + if ( output_mask->write_image ( merged_image->Image::get_mask() ) < 0 ) { error ( "Cannot write the merged mask",-1 ); } } - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); - delete pMergeIn; - delete pImageOut; - delete pMaskOut; + delete merged_image; + delete output_image; + delete output_mask; delete [] background; if ( transparent != NULL ) { diff --git a/src/pbf2cache.cpp b/src/pbf2cache.cpp index fff9052..0bc78ae 100644 --- a/src/pbf2cache.cpp +++ b/src/pbf2cache.cpp @@ -89,12 +89,12 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -111,12 +111,12 @@ void error ( std::string message, int errorCode ) { */ int main ( int argc, char **argv ) { - char* output = 0, *rootDirectory = 0; - int tilePerWidth = 16, tilePerHeight = 16; - int ulCol = -1; - int ulRow = -1; + char* output = 0, *root_directory = 0; + int tiles_per_width = 16, tiles_per_height = 16; + int upper_left_column = -1; + int upper_left_row = -1; - bool debug_logger=false; + bool debug_logger = false; /* Initialisation des Loggers */ boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::info ); @@ -132,8 +132,8 @@ int main ( int argc, char **argv ) { if ( !strcmp ( argv[i],"-ultile" ) ) { if ( i+2 >= argc ) { error("Error in -ultile option", -1 ); } - ulCol = atoi ( argv[++i] ); - ulRow = atoi ( argv[++i] ); + upper_left_column = atoi ( argv[++i] ); + upper_left_row = atoi ( argv[++i] ); continue; } @@ -150,12 +150,12 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(error) << "Error in option -r" ; return -1; } - rootDirectory = argv[i]; + root_directory = argv[i]; break; case 't': if ( i+2 >= argc ) { error("Error in -t option", -1 ); } - tilePerWidth = atoi ( argv[++i] ); - tilePerHeight = atoi ( argv[++i] ); + tiles_per_width = atoi ( argv[++i] ); + tiles_per_height = atoi ( argv[++i] ); break; default: @@ -172,14 +172,14 @@ int main ( int argc, char **argv ) { boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } - if ( rootDirectory == 0 || output == 0 ) { + if ( root_directory == 0 || output == 0 ) { error ("Argument must specify one output file/object and one root directory", -1); } BOOST_LOG_TRIVIAL(debug) << "Output : " << output; - BOOST_LOG_TRIVIAL(debug) << "PBF root directory : " << rootDirectory; + BOOST_LOG_TRIVIAL(debug) << "PBF root directory : " << root_directory; - if ( ulRow == -1 || ulCol == -1 ) { + if ( upper_left_row == -1 || upper_left_column == -1 ) { error ("Upper left tile indices have to be provided (with option -ultile)", -1); } @@ -195,30 +195,30 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << std::string("Output is on a " + ContextType::to_string(type) + " storage in the tray ") + tray_name; context = StoragePool::get_context(type, tray_name); - Rok4Image* rok4Image = Rok4Image::create_to_write( fo_name, tilePerWidth, tilePerHeight, context ); + Rok4Image* rok4_image = Rok4Image::create_to_write( fo_name, tiles_per_width, tiles_per_height, context ); - if (rok4Image == NULL) { + if (rok4_image == NULL) { error("Cannot create the ROK4 image to write", -1); } if (debug_logger) { - rok4Image->print(); + rok4_image->print(); } BOOST_LOG_TRIVIAL(debug) << "Write" ; - if (rok4Image->writePbfTiles(ulCol, ulRow, rootDirectory) < 0) { + if (rok4_image->writePbfTiles(upper_left_column, upper_left_row, root_directory) < 0) { error("Cannot write ROK4 image from PBF tiles", -1); } BOOST_LOG_TRIVIAL(debug) << "Clean" ; - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); - CurlPool::cleanCurlPool(); + CurlPool::clean_curls(); curl_global_cleanup(); - StoragePool::cleanStoragePool(); - delete rok4Image; + StoragePool::clean_storages(); + delete rok4_image; return 0; } diff --git a/src/work2cache.cpp b/src/work2cache.cpp index 7552bc1..a75cba2 100644 --- a/src/work2cache.cpp +++ b/src/work2cache.cpp @@ -110,12 +110,12 @@ void usage() { * \~french * \brief Affiche un message d'erreur, l'utilisation de la commande et sort en erreur * \param[in] message message d'erreur - * \param[in] errorCode code de retour + * \param[in] error_code code de retour */ -void error ( std::string message, int errorCode ) { +void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << ( message ); usage(); - exit ( errorCode ); + exit ( error_code ); } /** @@ -134,7 +134,7 @@ void error ( std::string message, int errorCode ) { */ int main ( int argc, char **argv ) { - char* input = 0, *output = 0; + char* input_path = 0, *output_path = 0; int tile_width = 256, tile_height = 256; Compression::eCompression compression = Compression::NONE; @@ -221,8 +221,8 @@ int main ( int argc, char **argv ) { error ( "Unknown option : " + std::string(argv[i]) ,-1 ); } } else { - if ( input == 0 ) input = argv[i]; - else if ( output == 0 ) output = argv[i]; + if ( input_path == 0 ) input_path = argv[i]; + else if ( output_path == 0 ) output_path = argv[i]; else { error ( "Argument must specify ONE input file and ONE output file/object", 2 ); } } } @@ -232,12 +232,12 @@ int main ( int argc, char **argv ) { boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::debug ); } - if ( input == 0 || output == 0 ) { + if ( input_path == 0 || output_path == 0 ) { error ("Argument must specify one input file and one output file/object", -1); } ContextType::eContextType type; - std::string fo_name = std::string(output); + std::string fo_name = std::string(output_path); std::string tray_name; ContextType::split_path(fo_name, type, fo_name, tray_name); @@ -249,7 +249,7 @@ int main ( int argc, char **argv ) { context = StoragePool::get_context(type, tray_name); BOOST_LOG_TRIVIAL(debug) << ( "Open image to read" ); - FileImage* source_image = FileImage::create_to_read(input); + FileImage* source_image = FileImage::create_to_read(input_path); if (source_image == NULL) { error("Cannot read the source image", -1); } @@ -267,7 +267,7 @@ int main ( int argc, char **argv ) { } if (! source_image->add_converter ( sampleformat, samplesperpixel ) ) { - error ( "Cannot add converter to the input FileImage " + std::string(input), -1 ); + error ( "Cannot add converter to the input FileImage " + std::string(input_path), -1 ); } } else { // On n'a pas précisé de format de sortie @@ -281,37 +281,37 @@ int main ( int argc, char **argv ) { source_image->print(); } - Rok4Image* rok4Image = Rok4Image::create_to_write( + Rok4Image* rok4_image = Rok4Image::create_to_write( fo_name, BoundingBox(0.,0.,0.,0.), -1, -1, source_image->get_width(), source_image->get_height(), samplesperpixel, sampleformat, photometric, compression, tile_width, tile_height, context ); - if (rok4Image == NULL) { + if (rok4_image == NULL) { error("Cannot create the ROK4 image to write", -1); } - rok4Image->set_extra_sample(source_image->get_extra_sample()); + rok4_image->set_extra_sample(source_image->get_extra_sample()); if (debug_logger) { - rok4Image->print(); + rok4_image->print(); } BOOST_LOG_TRIVIAL(debug) << ( "Write" ); - if (rok4Image->write_image(source_image) < 0) { + if (rok4_image->write_image(source_image) < 0) { error("Cannot write ROK4 image", -1); } BOOST_LOG_TRIVIAL(debug) << ( "Clean" ); - ProjPool::cleanProjPool(); + ProjPool::clean_projs(); proj_cleanup(); - CurlPool::cleanCurlPool(); + CurlPool::clean_curls(); curl_global_cleanup(); - StoragePool::cleanStoragePool(); + StoragePool::clean_storages(); delete source_image; - delete rok4Image; + delete rok4_image; return 0; } From 0b092fafa683a6b3a3d0b45af65b5e1f9c30ea4f Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Thu, 22 Aug 2024 17:19:44 +0200 Subject: [PATCH 3/7] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20la=20documentat?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/merge4tiff.cpp | 2 +- src/mergeNtiff.cpp | 2 +- src/work2cache.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/merge4tiff.cpp b/src/merge4tiff.cpp index a831e30..fdc2019 100644 --- a/src/merge4tiff.cpp +++ b/src/merge4tiff.cpp @@ -138,7 +138,7 @@ std::string help = std::string("\ncache2work version ") + std::string(VERSION) + " X = b background image\n" " -mX input associated masks (optionnal)\n" " X = [1..4] or X = b\n" - " -a sample format : (float or uint)\n" + " -a sample format : (float32 or uint8)\n" " -s samples per pixel : (1, 2, 3 or 4)\n" " -d debug logger activation\n\n" diff --git a/src/mergeNtiff.cpp b/src/mergeNtiff.cpp index 2ce21a9..ba156bf 100644 --- a/src/mergeNtiff.cpp +++ b/src/mergeNtiff.cpp @@ -156,7 +156,7 @@ std::string help = std::string("\nmergeNtiff version ") + std::string(VERSION) + " -99999 for DTM\n" " 255,255,255 for orthophotography\n" " -p style file\n" - " -a sample format : (float or uint)\n" + " -a sample format : (float32 or uint8)\n" " -s samples per pixel : (1, 2, 3 or 4)\n" " -d debug logger activation\n\n" diff --git a/src/work2cache.cpp b/src/work2cache.cpp index a75cba2..0e28ef7 100644 --- a/src/work2cache.cpp +++ b/src/work2cache.cpp @@ -83,7 +83,7 @@ std::string help = std::string("\nwork2cache version ") + std::string(VERSION) + " zip Deflate encoding\n" " png Non-official TIFF compression, each tile is an independant PNG image (with PNG header)\n" " -t tile size : widthwise and heightwise. Have to be a divisor of the global image's size\n" - " -a sample format : (float or uint)\n" + " -a sample format : (float32 or uint8)\n" " -s samples per pixel : (1, 2, 3 or 4)\n" " -d : debug logger activation\n\n" From f7f4b354ca6890fa38e2bff85d3573bb23fa42bb Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Wed, 28 Aug 2024 15:55:22 +0200 Subject: [PATCH 4/7] Utilisation de l'annuaire de CRS --- src/cache2work.cpp | 1 + src/composeNtiff.cpp | 1 + src/decimateNtiff.cpp | 1 + src/manageNodata.cpp | 2 ++ src/merge4tiff.cpp | 37 ++++++++++++++++++------------------- src/mergeNtiff.cpp | 18 +++++++++++------- src/overlayNtiff.cpp | 1 + src/pbf2cache.cpp | 1 + src/work2cache.cpp | 1 + 9 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/cache2work.cpp b/src/cache2work.cpp index 77fb2cd..562fc2c 100644 --- a/src/cache2work.cpp +++ b/src/cache2work.cpp @@ -235,6 +235,7 @@ int main ( int argc, char **argv ) delete rok4_image; delete output_image; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); CurlPool::clean_curls(); diff --git a/src/composeNtiff.cpp b/src/composeNtiff.cpp index 2d316a0..defa2ac 100644 --- a/src/composeNtiff.cpp +++ b/src/composeNtiff.cpp @@ -396,6 +396,7 @@ int main ( int argc, char **argv ) { error ( "Cannot write the compound image",-1 ); } + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); delete compound_image; diff --git a/src/decimateNtiff.cpp b/src/decimateNtiff.cpp index 56ff8a1..59191f6 100644 --- a/src/decimateNtiff.cpp +++ b/src/decimateNtiff.cpp @@ -764,6 +764,7 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Clean" ; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); diff --git a/src/manageNodata.cpp b/src/manageNodata.cpp index 1e5a7d1..becacfe 100644 --- a/src/manageNodata.cpp +++ b/src/manageNodata.cpp @@ -342,6 +342,8 @@ int main ( int argc, char* argv[] ) { } BOOST_LOG_TRIVIAL(debug) << "Clean" ; + + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); delete[] target_value; diff --git a/src/merge4tiff.cpp b/src/merge4tiff.cpp index fdc2019..136b6f5 100644 --- a/src/merge4tiff.cpp +++ b/src/merge4tiff.cpp @@ -44,11 +44,8 @@ */ #include -#include -#include -#include -#include +#include #include #include #include @@ -62,6 +59,12 @@ namespace keywords = boost::log::keywords; #include #include #include + +#include +#include +#include +#include + #include "config.h" /* Valeurs de nodata */ @@ -806,34 +809,29 @@ int main ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(debug) << "Nodata interpretation" ; // Conversion string->int[] du paramètre nodata - int nodata[samplesperpixel]; + int int_nodata[samplesperpixel]; - char* char_iterator = strtok ( strnodata,"," ); - if ( char_iterator == NULL ) { - error ( "Error with option -n : a value for nodata is missing",-1 ); - } - nodata[0] = atoi ( char_iterator ); - for ( int i = 1; i < samplesperpixel; i++ ) { - char_iterator = strtok ( NULL, "," ); - if ( char_iterator == NULL ) { - error ( "Error with option -n : a value for nodata is missing",-1 ); - } - nodata[i] = atoi ( char_iterator ); + std::vector vector_nodata; + boost::split(vector_nodata, strnodata, boost::is_any_of(",")); + if (vector_nodata.size() != samplesperpixel) error ( "Error with option -n : a value for nodata is missing",-1 ); + + for ( int i = 0; i < samplesperpixel; i++ ) { + int_nodata[i] = atoi ( vector_nodata.at(i).c_str() ); } // Cas MNT if ( sampleformat == SampleFormat::FLOAT32 ) { BOOST_LOG_TRIVIAL(debug) << "Merge images (float)" ; float nodata[samplesperpixel]; - for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( float ) nodata[i]; + for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( float ) int_nodata[i]; if ( merge ( background_image, input_images, output_image, output_mask, nodata ) < 0 ) error ( "Unable to merge float images",-1 ); } // Cas images else if ( sampleformat == SampleFormat::UINT8 ) { BOOST_LOG_TRIVIAL(debug) << "Merge images (uint8_t)" ; uint8_t nodata[samplesperpixel]; - for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( uint8_t ) nodata[i]; - if ( merge ( background_image, input_images, output_image, output_mask, nodata ) < 0 ) error ( "Unable to merge integer images",-1 ); + for ( int i = 0; i < samplesperpixel; i++ ) nodata[i] = ( uint8_t ) int_nodata[i]; + if ( merge ( background_image, input_images, output_image, output_mask, nodata ) < 0 ) error ( "Unable to merge integer images",-1 ); } else { error ( "Unhandled sample's format",-1 ); } @@ -841,6 +839,7 @@ int main ( int argc, char* argv[] ) { BOOST_LOG_TRIVIAL(debug) << "Clean" ; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); diff --git a/src/mergeNtiff.cpp b/src/mergeNtiff.cpp index ba156bf..84324b0 100644 --- a/src/mergeNtiff.cpp +++ b/src/mergeNtiff.cpp @@ -479,7 +479,7 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectoris_define()) { BOOST_LOG_TRIVIAL(error) << "Input CRS unknown: " << srss.at(i); @@ -517,7 +517,6 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectorpush_back(input_image); @@ -587,7 +586,7 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectoris_define()) { BOOST_LOG_TRIVIAL(error) << "Output CRS unknown: " << srss.at(0); return -1; @@ -623,8 +622,6 @@ int load_images(FileImage** output_image, FileImage** output_mask, std::vectorprint(); return 0; @@ -951,8 +948,6 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag *reprojected_image = new ReprojectedImage(input_to_reproject, bbox_dst, resx_dst, resy_dst, grid, interpolation, input_images->use_masks()); (*reprojected_image)->set_crs(output_image->get_crs()); - (*reprojected_image)->print(); - if (!(*reprojected_image)->set_mask(reprojected_mask)) { BOOST_LOG_TRIVIAL(error) << "Cannot add mask to the ReprojectedImage"; return false; @@ -1173,6 +1168,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Echec chargement des images", -1); @@ -1184,6 +1180,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Echec ajout des convertisseurs", -1); @@ -1202,6 +1199,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Error with option -n : a value for nodata is missing", -1); @@ -1214,6 +1212,7 @@ int main(int argc, char** argv) { if (merged_image) delete merged_image; if (output_image) delete output_image; if (output_mask) delete output_mask; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Error with option -n : one value per sample, separate with comma", -1); @@ -1229,6 +1228,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Echec tri des images", -1); @@ -1241,6 +1241,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Echec fusion des paquets d images", -1); @@ -1253,6 +1254,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Echec enregistrement de l image finale", -1); @@ -1266,6 +1268,7 @@ int main(int argc, char** argv) { if (output_image) delete output_image; if (output_mask) delete output_mask; delete[] nodata; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); error("Echec enregistrement du masque final", -1); @@ -1283,6 +1286,7 @@ int main(int argc, char** argv) { delete merged_image; delete output_image; delete output_mask; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); StoragePool::clean_storages(); diff --git a/src/overlayNtiff.cpp b/src/overlayNtiff.cpp index 9768e6e..cbbb73a 100644 --- a/src/overlayNtiff.cpp +++ b/src/overlayNtiff.cpp @@ -537,6 +537,7 @@ int main ( int argc, char **argv ) { } } + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); delete merged_image; diff --git a/src/pbf2cache.cpp b/src/pbf2cache.cpp index 0bc78ae..6359860 100644 --- a/src/pbf2cache.cpp +++ b/src/pbf2cache.cpp @@ -213,6 +213,7 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << "Clean" ; + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); CurlPool::clean_curls(); diff --git a/src/work2cache.cpp b/src/work2cache.cpp index 0e28ef7..09de411 100644 --- a/src/work2cache.cpp +++ b/src/work2cache.cpp @@ -305,6 +305,7 @@ int main ( int argc, char **argv ) { BOOST_LOG_TRIVIAL(debug) << ( "Clean" ); + CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); CurlPool::clean_curls(); From 0c21ab8812db078b9425e05762df5061162551ee Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Mon, 19 May 2025 18:08:05 +0200 Subject: [PATCH 5/7] =?UTF-8?q?`mergeNtiff`=20:=20Correction=20de=20l'util?= =?UTF-8?q?isation=20de=20style=20identit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/labeler.yml | 28 +++++++++++++++++++-------- .github/workflows/pr-auto-labeler.yml | 13 +++++-------- README.md | 2 +- src/composeNtiff.cpp | 1 - src/manageNodata.cpp | 2 +- src/merge4tiff.cpp | 2 +- src/mergeNtiff.cpp | 16 +++++++++------ 7 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index dd91ab3..6a2014d 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,19 +1,31 @@ ci-cd: - - .github/**/* +- changed-files: + - any-glob-to-any-file: + - .github/** dependencies: - - cmake/**/* +- changed-files: + - any-glob-to-any-file: + - cmake/** documentation: - - docs/**/* +- changed-files: + - any-glob-to-any-file: + - docs/** enhancement: - - src/**/* +- changed-files: + - any-glob-to-any-file: + - src/** quality: - - tests/**/* +- changed-files: + - any-glob-to-any-file: + - tests/** tooling: - - CMakeLists.txt - - config.h.in - - '**/CMakeLists.txt' +- changed-files: + - any-glob-to-any-file: + - CMakeLists.txt + - config.h.in + - '**/CMakeLists.txt' diff --git a/.github/workflows/pr-auto-labeler.yml b/.github/workflows/pr-auto-labeler.yml index cc5272e..ec24fd0 100644 --- a/.github/workflows/pr-auto-labeler.yml +++ b/.github/workflows/pr-auto-labeler.yml @@ -2,14 +2,11 @@ name: "🏷 PR Labeler" on: - pull_request -permissions: - contents: read - pull-requests: write - jobs: - triage: + labeler: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/labeler@v5 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" + - uses: actions/labeler@v5 \ No newline at end of file diff --git a/README.md b/README.md index 5478c71..c37aa73 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Outils de génération de dalles raster et vecteur -![ROK4 Logo](https://rok4.github.io/assets/images/rok4.png) +![ROK4 Logo](https://rok4.github.io/assets/images/rok4-256.png) Ces outils permettent le calcul des dalles de données composant les pyramides exploitées par le [serveur](https://github.com/rok4/server) et s'appuient essentiellement sur la [librairie C++ du projet](https://github.com/rok4/core-cpp) diff --git a/src/composeNtiff.cpp b/src/composeNtiff.cpp index defa2ac..0641921 100644 --- a/src/composeNtiff.cpp +++ b/src/composeNtiff.cpp @@ -124,7 +124,6 @@ void usage() { */ void error ( std::string message, int error_code ) { BOOST_LOG_TRIVIAL(error) << message ; - BOOST_LOG_TRIVIAL(error) << "Source directory : " << input_directory_path ; usage(); exit ( error_code ); } diff --git a/src/manageNodata.cpp b/src/manageNodata.cpp index becacfe..173d66a 100644 --- a/src/manageNodata.cpp +++ b/src/manageNodata.cpp @@ -288,7 +288,7 @@ int main ( int argc, char* argv[] ) { } // New nodata - if ( new_nodata_value ) { + if ( new_nodata_value_string ) { char_iterator = strtok ( new_nodata_value_string,"," ); if ( char_iterator == NULL ) { error ( "Error with option -nodata : integer values seperated by comma",-1 ); diff --git a/src/merge4tiff.cpp b/src/merge4tiff.cpp index 136b6f5..0530768 100644 --- a/src/merge4tiff.cpp +++ b/src/merge4tiff.cpp @@ -109,7 +109,7 @@ Photometric::ePhotometric photometric; bool debug_logger=false; /** \~french Message d'usage de la commande merge4tiff */ -std::string help = std::string("\ncache2work version ") + std::string(VERSION) + "\n\n" +std::string help = std::string("\nmerge4tiff version ") + std::string(VERSION) + "\n\n" "Four images subsampling, formed a square, might use a background and data masks\n\n" diff --git a/src/mergeNtiff.cpp b/src/mergeNtiff.cpp index 84324b0..84323fb 100644 --- a/src/mergeNtiff.cpp +++ b/src/mergeNtiff.cpp @@ -770,7 +770,9 @@ bool resample_images(FileImage* output_image, ExtendedCompoundImage* input_image input_to_resample = new PaletteImage ( input_images , style->get_palette() ); } } else { - input_to_resample = styled_image; + if (styled_image != NULL) { + input_to_resample = styled_image; + } } } @@ -928,7 +930,9 @@ bool reproject_images(FileImage* output_image, ExtendedCompoundImage* input_imag input_to_reproject = new PaletteImage ( input_images , style->get_palette() ); } } else { - input_to_reproject = styled_image; + if (styled_image != NULL) { + input_to_reproject = styled_image; + } } input_to_reproject->set_crs(input_images->get_crs()); @@ -988,7 +992,7 @@ int merge_images(FileImage *output_image, // Sortie // - Avec le nodata attendu en entrée du style fourni int* nd = nodata; if (style_provided) { - nd = style->get_input_nodata_value(); + nd = style->get_input_nodata_value(nd); } for (unsigned int i = 0; i < sorted_input_images.size(); i++) { @@ -1015,7 +1019,7 @@ int merge_images(FileImage *output_image, // Sortie if (output_image->compatible(stackable_image)) { BOOST_LOG_TRIVIAL(debug) << "\t is compatible"; /* les images sources et finale ont la meme resolution et la meme phase - * on aura donc pas besoin de reechantillonnage.*/ + * on n'aura donc pas besoin de reechantillonnage.*/ if (style_provided && ! (i == 0 && background_provided)) { // Un style est fourni et nous ne sommes pas dans le cas de la première entrée qui est une image de fond Image* styled_image = NULL; @@ -1083,7 +1087,7 @@ int merge_images(FileImage *output_image, // Sortie // - Avec le nodata de sortie du style fourni nd = nodata; if (style_provided) { - nd = style->get_output_nodata_value(); + nd = style->get_output_nodata_value(nd); } for (int i = 0; i < output_image->get_channels(); i++) { @@ -1215,7 +1219,7 @@ int main(int argc, char** argv) { CrsBook::clean_crss(); ProjPool::clean_projs(); proj_cleanup(); - error("Error with option -n : one value per sample, separate with comma", -1); + error("Error with option -n : one value per sample(" + std::to_string(samplesperpixel) + "), separate with comma", -1); } nodata[i] = atoi(char_iterator); } From 9d87dcb570351efd5e9fcd1d21ce7b0de4832090 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Fri, 13 Jun 2025 12:32:33 +0200 Subject: [PATCH 6/7] Suppression du changelog temporaire --- CHANGELOG.tmp | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 CHANGELOG.tmp diff --git a/CHANGELOG.tmp b/CHANGELOG.tmp deleted file mode 100644 index b3fec80..0000000 --- a/CHANGELOG.tmp +++ /dev/null @@ -1,3 +0,0 @@ -* Le format des canaux contient la taille en bits -* Passage en snake case -* Suppression de l'option crop dans work2cache \ No newline at end of file From 5daeb4b9131b5503fd10bced2a2022350dd4e291 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Fri, 13 Jun 2025 12:39:33 +0200 Subject: [PATCH 7/7] =?UTF-8?q?Compl=C3=A9tion=20du=20changelog=20pour=20l?= =?UTF-8?q?a=20release=205.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-and-release.yaml | 5 ++--- CHANGELOG.md | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index 1f4892b..2d36166 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -39,7 +39,6 @@ jobs: fail-fast: true matrix: include: - - os: ubuntu-20.04 - os: ubuntu-22.04 runs-on: ${{ matrix.os }} @@ -76,7 +75,7 @@ jobs: release-tag: ${{ github.ref_name }} - name: Build documentation - if: "matrix.os == 'ubuntu-20.04'" + if: "matrix.os == 'ubuntu-22.04'" run: | cd build make doc @@ -105,7 +104,7 @@ jobs: run: pip install -r docs/requirements.txt - name: Publish documentation - if: "matrix.os == 'ubuntu-20.04'" + if: "matrix.os == 'ubuntu-22.04'" run: | git config user.name github-actions git config user.email github-actions@github.com diff --git a/CHANGELOG.md b/CHANGELOG.md index 38ba5d7..5a0100d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +## 5.0.0 + +### [Changed] + +* Le format des canaux contient la taille en bits +* Passage en snake case + +### [Fixed] + +* Correction de l'utilisation d'un style "identité" + +### [Removed] + +* Suppression de l'option crop dans work2cache + ## 4.2.0 ### [Added]