make image/gif and image/png images be converted into PNG format. everything else...
authormh <mh>
Mon, 15 Apr 2002 23:20:50 +0000 (23:20 +0000)
committermh <mh>
Mon, 15 Apr 2002 23:20:50 +0000 (23:20 +0000)
dbscripts/populate_mediatyp.sql
source/mir/misc/WebdbImage.java
source/mircoders/entity/EntityImages.java
source/mircoders/media/MediaHandlerImages.java
source/mircoders/media/MediaHandlerImagesJpeg.java [new file with mode: 0755]
source/mircoders/media/MediaHandlerImagesPng.java [new file with mode: 0755]

index d540eab..ed843fe 100755 (executable)
@@ -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';
 
index 0513938..0b95da8 100755 (executable)
@@ -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();
index 977902e..c4635c9 100755 (executable)
@@ -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");
index 5f16abe..aa3fd0b 100755 (executable)
@@ -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 (executable)
index 0000000..e9ec0d3
--- /dev/null
@@ -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.
+ * <p>
+ *
+ * @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 (executable)
index 0000000..e1ac6d8
--- /dev/null
@@ -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.
+ * <p>
+ *
+ * @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;
+  }
+
+}