Changeset 1426 for trunk


Ignore:
Timestamp:
07/31/19 15:51:04 (5 years ago)
Author:
bln4
Message:

Implemented surrogates for images. When you add an encryption label to a picture, the default is a on-the-fly generated image of noise. This generated image has the same size specifications as the primary image.

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

Legend:

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

    r1097 r1426  
    147147        }
    148148       
     149        public static Image getNoise() {
     150                return _manager.getNoise();
     151        }
     152       
    149153        /** Convenience access to ImageManager.getImage(URL). */
    150154        public static Image getImage(URL url)
  • trunk/src/org/expeditee/gio/ImageManager.java

    r1097 r1426  
    55import java.net.HttpURLConnection;
    66import java.net.URL;
     7import java.util.Random;
    78
    89import org.expeditee.core.Colour;
     
    7576        public abstract Image getImage(String filename);
    7677       
     78        /** Gets an image that is just noise */
     79        public Image getNoise() {
     80                int width = 100;
     81                int height = 100;
     82                int[] pixelData = new int[width * height];
     83                Random rand = new Random();
     84               
     85                for (int i = 0; i < pixelData.length; i++) {
     86                        int alpha = rand.nextInt(256) << 24;
     87                        int red = rand.nextInt(256) << 16;
     88                        int green = rand.nextInt(256) << 8;
     89                        int blue = rand.nextInt(256);
     90                        pixelData[i] = alpha | red | green | blue;
     91                }
     92               
     93                return createImage(width, height, pixelData);
     94        }
     95       
    7796        /** Gets image data from a HTTP connection. */
    7897        public abstract Image getImage(HttpURLConnection connection) throws IOException;
     
    125144       
    126145        /** Writes the image data to disk. Format should be png, bmp, etc. */
    127         public abstract boolean writeImageToDisk(Image image, String format, File file) throws IOException;
    128        
     146        public abstract boolean writeImageToDisk(Image image, String format, File file) throws IOException;     
    129147}
  • trunk/src/org/expeditee/gui/Frame.java

    r1425 r1426  
    2626import java.util.HashMap;
    2727import java.util.HashSet;
     28import java.util.Iterator;
    2829import java.util.LinkedHashSet;
    2930import java.util.LinkedList;
     
    28232824                        if (i.isVisible()) {
    28242825                                _interactableItems.add(i);
     2826                        } else {
     2827                                Collection<? extends XRayable> enclosures = i.getEnclosures();
     2828                                if (enclosures != null && !enclosures.isEmpty()) {
     2829                                        Iterator<? extends XRayable> iterator = enclosures.iterator();
     2830                                        while (iterator.hasNext()) {
     2831                                                _interactableItems.add(iterator.next());
     2832                                        }
     2833                                }
    28252834                        }
    28262835                }
  • trunk/src/org/expeditee/items/Item.java

    r1422 r1426  
    40524052                if (copy.isAnnotation()) {
    40534053                        if (ItemUtils.startsWithTag(copy, ItemUtils.TAG_IMAGE, true)) {
    4054                                 copy.setText(ItemUtils.GetTag(ItemUtils.TAG_IMAGE) + ": redacted.png");
     4054                                String text = copy.getText();
     4055                                String size = "";
     4056                               
     4057                                // remove @i tag
     4058                                text = text.replaceFirst("@i:", "");
     4059                                text = text.replaceAll("\n", "");
     4060                                text = text.trim();
     4061
     4062                                int dotPos = text.indexOf('.');
     4063                                if (dotPos >= 0) {
     4064                                        int endOfFileNamePos = text.indexOf(' ', dotPos);
     4065                                        if (endOfFileNamePos >= 0) {
     4066                                                size = text.substring(endOfFileNamePos).trim();
     4067                                        }
     4068                                }
     4069                               
     4070                                String copyText = ItemUtils.GetTag(ItemUtils.TAG_IMAGE) + ": " + Picture.REDACTED_IMAGE_NAME + " " + size;
     4071                                copy.setText(copyText.trim());
    40554072                                copy.setVisible(true);
    40564073                        }
  • trunk/src/org/expeditee/items/ItemUtils.java

    r1415 r1426  
    400400                        }
    401401                        fileName = path;
    402 
    403                         // try images subdirectory
    404                         File file = null;
    405 
    406                         for (String dir : FolderSettings.ImageDirs.getAbsoluteDirs()) {
    407                                 file = new File(dir + path);
    408                                 if (file.exists() && !file.isDirectory()) {
    409                                         break;
    410                                 }
    411                         }
    412 
    413                         if (file == null || !file.exists() || file.isDirectory()) {
     402                       
     403                        if (!fileName.equals(Picture.REDACTED_IMAGE_NAME)) {
     404                                // try images subdirectory
     405                                File file = null;
     406
     407                                for (String dir : FolderSettings.ImageDirs.getAbsoluteDirs()) {
     408                                        file = new File(dir + path);
     409                                        if (file.exists() && !file.isDirectory()) {
     410                                                break;
     411                                        }
     412                                }
     413
     414                                if (file == null || !file.exists() || file.isDirectory()) {
     415                                        file = new File(path);
     416                                }
     417
     418                                // try relative path
     419                                if (!file.exists() || file.isDirectory()) {
     420                                        URL picture = new Object().getClass().getResource(path);
     421
     422                                        // decode to remove %20 in windows folder names
     423                                        if (picture != null) {
     424                                                try {
     425                                                        path = URLDecoder.decode(picture.getFile(), "UTF-8");
     426                                                } catch (UnsupportedEncodingException e) {
     427                                                        // TODO Auto-generated catch block
     428                                                        e.printStackTrace();
     429                                                }
     430                                        }
     431
     432                                } else {
     433                                        path = file.getPath();
     434                                }
     435
     436                                // if the image isn't found by now, try remote servers
    414437                                file = new File(path);
    415                         }
    416 
    417                         // try relative path
    418                         if (!file.exists() || file.isDirectory()) {
    419                                 URL picture = new Object().getClass().getResource(path);
    420 
    421                                 // decode to remove %20 in windows folder names
    422                                 if (picture != null) {
    423                                         try {
    424                                                 path = URLDecoder.decode(picture.getFile(), "UTF-8");
    425                                         } catch (UnsupportedEncodingException e) {
    426                                                 // TODO Auto-generated catch block
    427                                                 e.printStackTrace();
    428                                         }
    429                                 }
    430 
    431                         } else {
    432                                 path = file.getPath();
    433                         }
    434 
    435                         // if the image isn't found by now, try remote servers
    436                         file = new File(path);
    437                         if (!file.exists() || file.isDirectory()) {
    438                         if(tryRemote && FrameShare.getInstance().loadImage(fileName, null)) {
    439                                 // call CreatePicture again, but with tryRemote set to false so we won't get into an infinite loop
    440                                 // if something goes wrong with finding the downloaded image
    441                                 return CreatePicture(source, false);
    442                         }
    443                                 return null;
    444                         }
    445 
     438                                if (!file.exists() || file.isDirectory()) {
     439                                if(tryRemote && FrameShare.getInstance().loadImage(fileName, null)) {
     440                                        // call CreatePicture again, but with tryRemote set to false so we won't get into an infinite loop
     441                                        // if something goes wrong with finding the downloaded image
     442                                        return CreatePicture(source, false);
     443                                }
     444                                        return null;
     445                                }
     446                        }
    446447                } catch (Exception e) {
    447448                        return null;
  • trunk/src/org/expeditee/items/Picture.java

    r1420 r1426  
    6262public class Picture extends XRayable {
    6363       
     64        public static final String REDACTED_IMAGE_NAME = "redacted.png";
     65       
    6466        private static final float CROPPING_COMPOSITE_ALPHA = 0.5f;
    6567
     
    146148                parseSize();
    147149        }
     150       
     151        public boolean isNoise() {
     152                return _fileName.equals(REDACTED_IMAGE_NAME);
     153        }
     154       
     155       
    148156
    149157        protected String getImageSize() {
     
    788796                }
    789797*/
    790                 _image = Image.getImage(_path);
     798               
     799                if (isNoise()) {
     800                        _image = Image.getNoise();
     801                } else {
     802                        _image = Image.getImage(_path);
     803                }
     804               
    791805                return true;
    792806        }
  • trunk/src/org/expeditee/items/XRayable.java

    r1423 r1426  
    4141       
    4242        @Override
     43        public Item getPrimary() {
     44                return _source.getPrimary();
     45        }
     46       
     47        @Override
     48        public boolean isSurrogate() {
     49                return _source.isSurrogate();
     50        }
     51       
     52        @Override
    4353        public void setEncryptionLabel(String label) {
    4454                _source.setEncryptionLabel(label);
Note: See TracChangeset for help on using the changeset viewer.