From 2e2fce97b8753a913e305c2d031c1105740195f7 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 15 Apr 2002 23:20:50 +0000 Subject: [PATCH] make image/gif and image/png images be converted into PNG format. everything else remains Jpeg format. this makes MediaHandlerImages abstract. media_type table has to be updated. --- dbscripts/populate_mediatyp.sql | 5 ++-- source/mir/misc/WebdbImage.java | 19 +++++++----- source/mircoders/entity/EntityImages.java | 4 +-- source/mircoders/media/MediaHandlerImages.java | 10 +++++-- source/mircoders/media/MediaHandlerImagesJpeg.java | 34 ++++++++++++++++++++++ source/mircoders/media/MediaHandlerImagesPng.java | 34 ++++++++++++++++++++++ 6 files changed, 91 insertions(+), 15 deletions(-) create mode 100755 source/mircoders/media/MediaHandlerImagesJpeg.java create mode 100755 source/mircoders/media/MediaHandlerImagesPng.java diff --git a/dbscripts/populate_mediatyp.sql b/dbscripts/populate_mediatyp.sql index d540eab3..ed843fea 100755 --- a/dbscripts/populate_mediatyp.sql +++ b/dbscripts/populate_mediatyp.sql @@ -23,12 +23,13 @@ INSERT INTO "media_type" VALUES (8,'mov','video/quicktime','Video','Video',NULL) INSERT INTO "media_type" VALUES (7,'mpg','video/mpeg','Video','Video',NULL); INSERT INTO "media_type" VALUES (9,'avi','video/x-msvideo','Video','Video',NULL); INSERT INTO "media_type" VALUES (6,'pdf','application/pdf','Generic','Other',NULL); -INSERT INTO "media_type" VALUES (15,'png','- deprecated -','Images','Images',NULL); +INSERT INTO "media_type" VALUES (15,'png','image/png','ImagesPng','Images',NULL); INSERT INTO "media_type" VALUES (3,'jpg','- deprecated -','Images','Images',NULL); -INSERT INTO "media_type" VALUES (5,'jpg','image/*','Images','Images',NULL); +INSERT INTO "media_type" VALUES (5,'jpg','image/*','ImagesJpeg','Images',NULL); INSERT INTO "media_type" VALUES (16,'asf','video/x-ms-asf','Video','Video',NULL); INSERT INTO "media_type" VALUES (17,'rm','application/vnd.rn-realmedia','RealVideo','Video',NULL); INSERT INTO "media_type" VALUES (18,'mp3','audio/mpeg','Mp3','Audio',NULL); +INSERT INTO "media_type" VALUES (19,'png','image/gif','ImagesPng','Images',NULL); -- Enable triggers UPDATE pg_class SET reltriggers = (SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid) WHERE relname = 'media_type'; diff --git a/source/mir/misc/WebdbImage.java b/source/mir/misc/WebdbImage.java index 05139386..0b95da82 100755 --- a/source/mir/misc/WebdbImage.java +++ b/source/mir/misc/WebdbImage.java @@ -30,33 +30,38 @@ public class WebdbImage // internal representation of the image private PlanarImage planarImage; + // type of the image + private String _type; + // constructor - public WebdbImage(byte[] image) + public WebdbImage(byte[] image, String type) throws IOException { planarImage = JAI.create("stream",new ByteArraySeekableStream(image)); + _type = type; scaleImage(); } - public WebdbImage(byte[] image, int iconMax) + public WebdbImage(byte[] image, String type, int iconMax) throws IOException { maxIconSize=iconMax; planarImage = JAI.create("stream",new ByteArraySeekableStream(image)); + _type = type; scaleImage(); } - public WebdbImage(byte[] image, int iconMax, int imageMax) + public WebdbImage(byte[] image, String type, int iconMax, int imageMax) throws IOException { maxIconSize=iconMax; maxImageSize=imageMax; planarImage = JAI.create("stream",new ByteArraySeekableStream(image)); + _type = type; scaleImage(); } - // acc3ssor-methods public int getIconWidth() throws IOException { if (iconData==null) scaleIcon(); @@ -79,8 +84,7 @@ public class WebdbImage public byte[] getImage() { if (imageData==null) { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - // @todo the choice of PNG or JPEG should be made configurable - JAI.create("encode", planarImage, outStream, "JPEG", null); + JAI.create("encode", planarImage, outStream, _type, null); imageData = outStream.toByteArray(); } return imageData; @@ -136,8 +140,7 @@ public class WebdbImage params.setParameter("interpolation",new InterpolationBilinear()); PlanarImage temp = JAI.create("scale", params); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - // @todo the choice of PNG or JPEG should be made configurable - JAI.create("encode", temp, outStream, "JPEG", null); + JAI.create("encode", temp, outStream, _type, null); iconData = outStream.toByteArray(); iconWidth=temp.getWidth(); iconHeight=temp.getHeight(); diff --git a/source/mircoders/entity/EntityImages.java b/source/mircoders/entity/EntityImages.java index 977902ea..c4635c9e 100755 --- a/source/mircoders/entity/EntityImages.java +++ b/source/mircoders/entity/EntityImages.java @@ -89,7 +89,7 @@ public class EntityImages extends EntityUploadedMedia return img_data; } - public void setImage(byte[] uploadData) + public void setImage(byte[] uploadData, String type) throws StorageObjectException { if (uploadData!=null) { @@ -97,7 +97,7 @@ public class EntityImages extends EntityUploadedMedia try { theLog.printDebugInfo("settimage :: making internal representation of image"); - WebdbImage webdbImage= new WebdbImage(uploadData); + WebdbImage webdbImage= new WebdbImage(uploadData, type); theLog.printDebugInfo("settimage :: made internal representation of image"); byte[] imageData = webdbImage.getImage(); theLog.printDebugInfo("settimage :: getImage"); diff --git a/source/mircoders/media/MediaHandlerImages.java b/source/mircoders/media/MediaHandlerImages.java index 5f16abec..aa3fd0b2 100755 --- a/source/mircoders/media/MediaHandlerImages.java +++ b/source/mircoders/media/MediaHandlerImages.java @@ -32,10 +32,14 @@ import mircoders.entity.EntityImages; */ -public class MediaHandlerImages implements MirMedia +public abstract class MediaHandlerImages implements MirMedia { - private static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+ + static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home")+ "log/media.log"); + static final String PNG = "PNG"; + static final String JPEG = "JPEG"; + + abstract String getType(); public byte[] get(Entity ent, Entity mediaTypeEnt) throws MirMediaException @@ -56,7 +60,7 @@ public class MediaHandlerImages implements MirMedia throws MirMediaException { try { - ((EntityImages)ent).setImage(uploadData); + ((EntityImages)ent).setImage(uploadData, getType()); } catch ( StorageObjectException e) { theLog.printError("MediaHandlerImages.set: "+e.toString()); throw new MirMediaException(e.toString()); diff --git a/source/mircoders/media/MediaHandlerImagesJpeg.java b/source/mircoders/media/MediaHandlerImagesJpeg.java new file mode 100755 index 00000000..e9ec0d3a --- /dev/null +++ b/source/mircoders/media/MediaHandlerImagesJpeg.java @@ -0,0 +1,34 @@ + +package mircoders.media; + +//import java.lang.*; +//import java.io.*; +//import java.util.*; +//import java.lang.reflect.*; + +//import freemarker.template.SimpleList; + +import mir.media.*; +//import mir.misc.*; + +/** + * This class handles saving, fetching creating representations + * for all JPeg images. The image content is stored in the DB. The content is + * written out to a file at the ProducerImages level. + * It implements the MirMedia interface. + *

+ * + * @see mir.media.MirMedia + * @see mircoders.media.MediaHandlerImages + * @author mh + * @version 24.09.2001 + */ + + +public class MediaHandlerImagesJpeg extends MediaHandlerImages implements MirMedia +{ + public String getType() { + return JPEG; + } + +} diff --git a/source/mircoders/media/MediaHandlerImagesPng.java b/source/mircoders/media/MediaHandlerImagesPng.java new file mode 100755 index 00000000..e1ac6d8a --- /dev/null +++ b/source/mircoders/media/MediaHandlerImagesPng.java @@ -0,0 +1,34 @@ + +package mircoders.media; + +//import java.lang.*; +//import java.io.*; +//import java.util.*; +//import java.lang.reflect.*; + +//import freemarker.template.SimpleList; + +import mir.media.*; +//import mir.misc.*; + +/** + * This class handles saving, fetching creating representations + * for all png images. The image content is stored in the DB. The content is + * written out to a file at the ProducerImages level. + * It implements the MirMedia interface. + *

+ * + * @see mir.media.MirMedia + * @see mircoders.media.MediaHandlerImages + * @author mh + * @version 24.09.2001 + */ + + +public class MediaHandlerImagesPng extends MediaHandlerImages implements MirMedia +{ + public String getType() { + return PNG; + } + +} -- 2.11.0