Changeset 1427 for trunk


Ignore:
Timestamp:
08/07/19 14:14:42 (5 years ago)
Author:
bln4
Message:

New piping and functionality implementation to support the encrypting of images.

Location:
trunk/src/org/expeditee
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/core/Image.java

    r1426 r1427  
    88
    99import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     10import org.expeditee.encryption.core.EncryptedImage;
    1011import org.expeditee.gio.ImageManager;
    1112
     
    2627
    2728        /** The ImageManager used to perform platform-specific image interactions. */
    28         private static ImageManager _manager = null;
     29        protected static ImageManager _manager = null;
    2930       
    3031        /** Sets the platform-specific ImageManager for all images. Can only be set once. */
     
    7273       
    7374        /** Private constructor as instantiation handled through Image.get(boolean). */
    74         private Image(boolean fromDisk)
    75         {
     75        protected Image(boolean fromDisk) {
    7676                // Assign the next available handle ID number
    7777                _handle = nextHandle;
     
    147147        }
    148148       
    149         public static Image getNoise() {
    150                 return _manager.getNoise();
    151         }
    152        
    153149        /** Convenience access to ImageManager.getImage(URL). */
    154150        public static Image getImage(URL url)
     
    158154
    159155        /** Convenience access to ImageManager.getImage(String). */
    160         public static Image getImage(String filename)
    161         {
    162                 return _manager.getImage(filename);
     156        public static Image getImage(String filename) {
     157                if (filename.endsWith(EncryptedImage.EXPEDITEE_ENCRYPTED_IMAGE_EXTENSION)) {
     158                        return EncryptedImage.getImage(filename);
     159                } else {
     160                        return _manager.getImage(filename);
     161                }
    163162        }
    164163
     
    168167                return _manager.getImage(connection);
    169168        }
    170 
     169       
    171170        /** Convenience access to ImageManager.releaseImage(Image). */
    172171        public void releaseImage()
  • trunk/src/org/expeditee/gio/ImageManager.java

    r1426 r1427  
    4040                return createImage(size.width, size.height, hintUseAcceleratedMemory);
    4141        }
    42        
    43         /**
    44          * Creates an image of the given width and height in either main or video RAM.
    45          *
    46          * @param hintUseAcceleratedMemory
    47          *                      True to use video RAM, false for main memory.
    48          */
    49         public abstract Image createImage(int width, int height, boolean hintUseAcceleratedMemory);
    5042
    5143        /** Creates an image in main memory with the given size. */
     
    5648
    5749        /** Creates an image in main memory with the given width and height. */
    58         public Image createImage(int width, int height)
    59         {
     50        public Image createImage(int width, int height) {
    6051                return createImage(width, height, false);
    6152        }
     53               
     54        /**
     55         * Creates an image of the given width and height in either main or video RAM.
     56         *
     57         * @param hintUseAcceleratedMemory
     58         *                      True to use video RAM, false for main memory.
     59         */
     60        public abstract Image createImage(int width, int height, boolean hintUseAcceleratedMemory);
    6261       
    6362        /** Creates an image from packed 32-bit ARGB data in an array. */
     
    6665        /** Creates an image of a PDF page. */
    6766        public abstract Image createImage(int width, int height, PDFPage page);
     67       
     68        /** Creates an image from the raw byte data read from a file.  Must be in a format recognised by the implementing Ecosystem. **/
     69        public abstract Image createImage(byte[] rawImageData);
    6870       
    6971        /** Creates a new image which is a cropped section of another image. */
     
    7577        /** Gets image data from a file. */
    7678        public abstract Image getImage(String filename);
     79       
     80        //public abstract Image getItem(byte[] imageData);
    7781       
    7882        /** Gets an image that is just noise */
  • trunk/src/org/expeditee/gio/javafx/JavaFXImageManager.java

    r1097 r1427  
    2020import javafx.scene.image.PixelFormat;
    2121import javafx.scene.image.WritableImage;
     22import sun.reflect.generics.reflectiveObjects.NotImplementedException;
    2223
    2324public class JavaFXImageManager extends ImageManager {
     
    9697                // Register the image
    9798                return register(writableImage, false);
     99        }
     100       
     101
     102        @Override
     103        public Image createImage(byte[] rawImageData) {
     104                throw new NotImplementedException();
    98105        }
    99106
  • trunk/src/org/expeditee/gio/swing/SwingImageManager.java

    r1097 r1427  
    117117        }
    118118       
     119        @Override
     120        public org.expeditee.core.Image createImage(byte[] rawImageData) {
     121                // Get the image from the given file
     122                java.awt.Image swingImage = Toolkit.getDefaultToolkit().createImage(rawImageData);
     123                if (swingImage == null) return null;
     124               
     125                // Register and return the handle
     126                return register(swingImage, true);
     127        }
     128       
    119129        /**
    120130         * Registers the given swing image with the Expeditee image system. Not available from the abstract interface.
  • trunk/src/org/expeditee/items/Item.java

    r1426 r1427  
    4747import org.expeditee.core.bounds.EllipticalBounds;
    4848import org.expeditee.core.bounds.PolygonBounds;
     49import org.expeditee.encryption.core.EncryptedImage;
    4950import org.expeditee.encryption.items.surrogates.EncryptionDetail;
    5051import org.expeditee.encryption.items.surrogates.EncryptionDetail.Type;
     
    40494050                }
    40504051               
     4052                //Setup surrogate items.
    40514053                Item copy = this.copy();
    40524054                if (copy.isAnnotation()) {
     
    40754077                        copy.setText("Encrypted");
    40764078                }
     4079               
     4080                // Encrypt XRayables representative files and update pointer.
     4081                Collection<? extends XRayable> xrayables = this.getEnclosures();
     4082                for (XRayable xray: xrayables) {
     4083                        if (xray instanceof Picture) {
     4084                                EncryptedImage.encryptImage((Picture) xray, labelResult.key);
     4085                                Text source = xray._source;
     4086                                String oldName = xray.getName();
     4087                                String newName = oldName.substring(0, oldName.lastIndexOf('.')) + EncryptedImage.EXPEDITEE_ENCRYPTED_IMAGE_EXTENSION;
     4088                                source.setText(source.getText().replace(oldName, newName));
     4089                        }
     4090                }
     4091               
    40774092                this.addToSurrogates(copy);
    40784093        }
  • trunk/src/org/expeditee/items/Picture.java

    r1426 r1427  
    3737import org.expeditee.core.bounds.AxisAlignedBoxBounds;
    3838import org.expeditee.core.bounds.PolygonBounds;
     39import org.expeditee.encryption.core.EncryptedImage;
     40import org.expeditee.encryption.items.surrogates.Label;
     41import org.expeditee.encryption.items.surrogates.Label.LabelResult;
    3942import org.expeditee.gio.EcosystemManager;
    4043import org.expeditee.gio.GraphicsManager;
     
    4245import org.expeditee.gui.FrameIO;
    4346import org.expeditee.gui.FrameUtils;
     47import org.expeditee.gui.MessageBay;
    4448
    4549/**
     
    6266public class Picture extends XRayable {
    6367       
    64         public static final String REDACTED_IMAGE_NAME = "redacted.png";
     68        public static final String REDACTED_IMAGE_NAME = "expeditee_noise.encrypted";
    6569       
    6670        private static final float CROPPING_COMPOSITE_ALPHA = 0.5f;
     
    775779        @Override
    776780        public boolean refresh() {
    777                 // ImageIcon is faster, but cannot handle some formats
    778                 // (notably.bmp) hence, we try this first, then if it fails we try
    779                 // ImageIO
    780                 /*
    781                 try {
    782                         _image = new ImageIcon(_path).getImage();
    783                 } catch (Exception e) {
    784                 }
    785 
    786                 // if ImageIcon failed to read the image
    787                 if (_image == null || _image.getWidth() <= 0) {
    788                         try {
    789                                 _image = ImageIO.read(new File(_path));
    790                         } catch (IOException e) {
    791                                 // e.printStackTrace();
    792                                 Logger.Log(e);
    793                                 _image = null;
    794                                 return false;
    795                         }
    796                 }
    797 */
    798                
    799781                if (isNoise()) {
    800                         _image = Image.getNoise();
     782                        _image = EncryptedImage.getNoise();
    801783                } else {
    802                         _image = Image.getImage(_path);
     784                        String encryptionLabel = _source.getEncryptionLabel();
     785                        if (encryptionLabel == null || encryptionLabel.isEmpty()) {
     786                                _image = Image.getImage(_path);
     787                        } else {
     788                                LabelResult result = Label.getLabel(encryptionLabel);
     789                                if (result == LabelResult.SuccessResolveLabelToKey) {
     790                                        _image = EncryptedImage.getImage(_path, result.key);
     791                                } else {
     792                                        MessageBay.displayMessage(result.toString());
     793                                        _image = EncryptedImage.getNoise();
     794                                }
     795                        }
    803796                }
    804797               
  • trunk/src/org/expeditee/items/XRayable.java

    r1426 r1427  
    2525import org.expeditee.core.Colour;
    2626import org.expeditee.core.Point;
     27import org.expeditee.encryption.core.EncryptedImage;
    2728import org.expeditee.encryption.items.surrogates.Label;
    2829import org.expeditee.gui.DisplayController;
    2930
    3031public abstract class XRayable extends Item {
    31        
    3232       
    3333        protected Text _source = null;
Note: See TracChangeset for help on using the changeset viewer.