[Castore-commits] ConverterPNG.java 1.3 1.4
Céline BENOIT
cbenoit at adullact1.hosting.cri74.org
Jeu 20 Avr 11:07:59 CEST 2006
Update of /cvsroot/castore/castore-core/src/java/fr/emn/castor/documents/metier/medias/images/conversion
In directory adullact1:/tmp/cvs-serv2711/src/java/fr/emn/castor/documents/metier/medias/images/conversion
Modified Files:
ConverterPNG.java
Log Message:
optimisation du code
Index: ConverterPNG.java
===================================================================
RCS file: /cvsroot/castore/castore-core/src/java/fr/emn/castor/documents/metier/medias/images/conversion/ConverterPNG.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ConverterPNG.java 31 Mar 2006 12:52:59 -0000 1.3
--- ConverterPNG.java 20 Apr 2006 09:07:57 -0000 1.4
***************
*** 54,65 ****
import javax.imageio.ImageIO;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
-
import fr.emn.castor.common.Constants;
- import fr.emn.castor.common.PropertiesHelper;
import fr.emn.castor.documents.DocumentsConstants;
import fr.emn.castor.documents.metier.docGenerique.conversion.AConverter;
- import fr.emn.castor.documents.metier.textes.retro.ConverterXML;
/**
--- 54,60 ----
***************
*** 74,111 ****
private static ConverterPNG instance = null;
- /** le logger.*/
- private static Log log = LogFactory.getLog(ConverterPNG.class);
-
- /** Type de compression PNG */
- public final static String IMAGE_TYPE_PNG = "PNG";
-
- /** largeur maximale acceptées */
- public final static int nouvWidth = 900;
-
/** Constructeur */
public ConverterPNG() {
super();
- // Formats acceptés : JPG, JPEG, JPE, PNG, GIF, TIF, TIFF, BMP
- //création de la Map contenant les extensions lisibles par OOo
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.jpg"), "JPG");
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.jpeg"), "JPG");
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.jpe"), "JPG");
-
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.gif"), "GIF");
-
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.png"), "PNG");
-
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.tif"), "TIFF");
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.tiff"), "TIFF");
-
- this.filesExtensionsAccepted.put(PropertiesHelper.getProperty(
- DocumentsConstants.EXTENSION, "ext.bmp"), "BMP");
}
--- 69,75 ----
***************
*** 128,149 ****
* @param compressionType String
*/
! public void convert(
! final String idDoc, final String format, final String fsUsed) {
String inputFormat;
// buffer
BufferedImage buf = null;
BufferedImage bufFinal = null;
! if (this.filesExtensionsAccepted.containsKey(format)) {
! inputFormat = this.filesExtensionsAccepted.get(format);
if (log.isDebugEnabled()) {
! log.debug("Conversion " + inputFormat + ", Extension : "
! + format);
}
! // on recupère le chemin du fichier source..
File sourceFile = new File(Constants.CASTOR_DOCUMENTS_PATH
! + Constants.FILE_SEPARATOR + "source" + format);
! // on Créé un fichier de destination.
File destFile = new File(Constants.CASTOR_DOCUMENTS_PATH
! + Constants.FILE_SEPARATOR + idDoc + ".png");
// récupération de l'image dans le buffer
try {
--- 92,116 ----
* @param compressionType String
*/
! public void convert(final String idDoc, final String extension) {
String inputFormat;
// buffer
BufferedImage buf = null;
BufferedImage bufFinal = null;
! if (this.fonds.isExtensionsPossibles(
! DocumentsConstants.EXTENSIONS_POSSIBLES_DOCIMAGE, extension)) {
! inputFormat = extension.replace(".", "").toUpperCase();
if (log.isDebugEnabled()) {
! log.debug("Conversion " + inputFormat
! + " en PNG, Extension : " + extension);
}
! // recupération le chemin du fichier source..
File sourceFile = new File(Constants.CASTOR_DOCUMENTS_PATH
! + Constants.FILE_SEPARATOR + idDoc
! + Constants.FILE_SEPARATOR + "source" + extension);
! // création du fichier de destination.
File destFile = new File(Constants.CASTOR_DOCUMENTS_PATH
! + Constants.FILE_SEPARATOR + idDoc
! + Constants.FILE_SEPARATOR + DocumentsConstants.DOCUMENT
! + ".png");
// récupération de l'image dans le buffer
try {
***************
*** 151,162 ****
} catch (IOException ex) {
if (log.isErrorEnabled()) {
! log
! .error("Conversion PNG : Erreur de lecture du document : "
! + idDoc);
}
this.fonds.setConvStatut(
idDoc, DocumentsConstants.CONVERSION_ERROR);
}
-
// contre la perte du fond transparent
GraphicsEnvironment ge = GraphicsEnvironment
--- 118,127 ----
} catch (IOException ex) {
if (log.isErrorEnabled()) {
! log.error("Erreur de lecture du document source : "
! + idDoc);
}
this.fonds.setConvStatut(
idDoc, DocumentsConstants.CONVERSION_ERROR);
}
// contre la perte du fond transparent
GraphicsEnvironment ge = GraphicsEnvironment
***************
*** 165,173 ****
GraphicsConfiguration gc = gd.getDefaultConfiguration();
// création du buffer final
! bufFinal = gc.createCompatibleImage(
! buf.getWidth(), buf.getHeight(), Transparency.TRANSLUCENT);
! // bufFinal = new BufferedImage(buf.getWidth() ,buf.getHeight(),BufferedImage.TYPE_INT_RGB);
!
! // récupérer l'objet Graphics
Graphics2D g = (Graphics2D) bufFinal.getGraphics();
g.setRenderingHint(
--- 130,136 ----
GraphicsConfiguration gc = gd.getDefaultConfiguration();
// création du buffer final
! bufFinal = gc.createCompatibleImage(buf.getWidth(), buf
! .getHeight(), Transparency.TRANSLUCENT);
! // récupération de l'objet Graphics
Graphics2D g = (Graphics2D) bufFinal.getGraphics();
g.setRenderingHint(
***************
*** 175,210 ****
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(buf, 0, 0, null);
! //libèration de l'objet Graphics
g.dispose();
-
// si taille image trop importante
int width = bufFinal.getWidth();
! //int height = bufFinal.getHeight() ;
!
! if (width > nouvWidth) {
// redimensionnement de l'image
! double scaleValue = (double) nouvWidth / (double) width;
! //bufFinal = scale(bufFinal, nouvWidth, nouvHeight) ;
bufFinal = scale(bufFinal, scaleValue);
}
!
! // Ecriture du fichier destination
try {
! ImageIO.write(bufFinal, IMAGE_TYPE_PNG, destFile);
} catch (IOException e) {
if (log.isErrorEnabled()) {
! log
! .error("Conversion PNG : Erreur d'écriture du document : "
! + idDoc);
}
this.fonds.setConvStatut(
idDoc, DocumentsConstants.CONVERSION_ERROR);
}
} else {
if (log.isErrorEnabled()) {
! log.error("Format non supporté :" + format);
}
! this.fonds
! .setConvStatut(idDoc, DocumentsConstants.CONVERSION_ERROR);
}
}
--- 138,170 ----
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(buf, 0, 0, null);
! //libération de l'objet Graphics
g.dispose();
// si taille image trop importante
int width = bufFinal.getWidth();
! if (width > DocumentsConstants.NEWS_WIDTH) {
// redimensionnement de l'image
! double scaleValue = (double) DocumentsConstants.NEWS_WIDTH
! / (double) width;
bufFinal = scale(bufFinal, scaleValue);
}
! // écriture du fichier destination
try {
! /** Format unique de stockage des images sous Castore -> Type de compression PNG */
! ImageIO.write(bufFinal, DocumentsConstants.PNG, destFile);
} catch (IOException e) {
if (log.isErrorEnabled()) {
! log.error("Erreur d'écriture du document : " + idDoc);
}
this.fonds.setConvStatut(
idDoc, DocumentsConstants.CONVERSION_ERROR);
}
+ this.fonds.setConvStatut(
+ idDoc, DocumentsConstants.CONVERSION_ENDED);
} else {
if (log.isErrorEnabled()) {
! log.error("Format non supporté :" + extension);
}
! this.fonds.setConvStatut(
! idDoc, DocumentsConstants.CONVERSION_ERROR);
}
}
***************
*** 216,220 ****
* @return une image réduite ou agrandie
*/
! public static BufferedImage scale(BufferedImage bi, double scaleValue) {
// coefficient >1 : correspond à un agrandissement
// coefficient <1 : correspond à une réduction.
--- 176,180 ----
* @return une image réduite ou agrandie
*/
! private static BufferedImage scale(BufferedImage bi, double scaleValue) {
// coefficient >1 : correspond à un agrandissement
// coefficient <1 : correspond à une réduction.
***************
*** 229,235 ****
}
- public boolean cleanConv(final String idDoc, final boolean cleanPic) {
- return true;
- }
-
}
--- 189,191 ----
Plus d'informations sur la liste de diffusion Castore-commits