We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › ")" inserted to complete Arguments
Page Index Toggle Pages: 1
")" inserted to complete Arguments (Read 1586 times)
")" inserted to complete Arguments
Oct 8th, 2008, 11:10am
 
Warning: Here, there be noobs.

So, I'm in way over my head with the EXIF library at http://www.drewnoakes.com/code/exif/

I'm trying to pull the thumbnails embedded in the EXIFs of my JPEGs. Ideally, I would be loading them straight from the file, but I've settled on writing them directly to a tiny temporary BMP, which I can reload, because the smattering of examples I can find do just that, and no more.

I'm pretty sure I need to do this:
Code:
ExifDirectory directory = (ExifDirectory)metadata.getDirectory(ExifDirectory.class); 



But every time it reaches that line, it dies and says:
Invalid type: 70
Syntax error: ")" inserted to complete Arguments

I have no idea what that means. Other people have apparently run this line successfully... it seems to have the correct number of parenthesis everywhere... it gives the same error if I just plop "ExifDirectory.class" on a line all by itself.

In case it's relevent, here's the whole shebang. It's pointless, uncommented, and verbose at the moment, because I'm still at the 'cobbling things together' stage.

Code:
String[] picFiles = new String[0];
Metadata[] picData = new Metadata[0];

File picFolder = processing.app.Base.selectFolder("Pick a folder:",new File((String)""),new Frame(""));

String[] allFiles = processing.app.Base.listFiles(picFolder,false);

for (int x = 0; x < allFiles.length; x++){
if((allFiles[x].substring(allFiles[x].length()-4,allFiles[x].length())).equals(".JPG")){
picFiles = append(picFiles,allFiles[x]);
println(picFiles[picFiles.length-1]);
}
}

for (int x = 0; x < picFiles.length; x++){
try{
picData = (Metadata[])append(picData,JpegMetadataReader.readMetadata(new File(picFiles[x])));
println(str(picData.length));}
catch(com.drew.imaging.jpeg.JpegProcessingException message){println("Something bad has happened.");}
}

for (int x = 0; x < picData.length; x++){
try{
ExifDirectory directory = (ExifDirectory)picData[x].getDirectory(ExifDirectory.class);
directory.writeThumbnail("../../pics/1/thumb.bmp");
}catch(Exception message){println("Something bad has happened.");}
}

Re: ")" inserted to complete Arguments
Reply #1 - Oct 8th, 2008, 4:01pm
 
put all that inside a "void setup()" block, and you should be fine. the problem is that the preprocessor (which isn't terribly smart) is seeing "class" mentioned, so it thinks you're trying to define a class.

if that still doesn't fix it, you can add wrap the code with a class declaration: "public class yoursketchname extends PApplet" (which is what it thinks you're doing anyway). though keep in mind that you'll need to make sure you keep the actual sketch name identical to the class name.

also /do not/ use anything from processing.app.* in a sketch--it won't be available on export. read revisions.txt, there are selectInput(), selectOutput(), and selectFolder() methods for selecting files and folders. there are folder listing examples elsewhere on the board, or if you need the recursive thing from Base.listFiles(), i recommend that you copy the code out of the p5 source and past it into your sketch.
Re: ")" inserted to complete Arguments
Reply #2 - Oct 9th, 2008, 6:09am
 
Neither tweak worked.

I got as far as thinking, "maybe it thinks I'm trying to make a class or something...", but never reached the potential-solution stage.

I thought the Reference: Extended page was the extend of standard processing. All I could find there about files and directories was... nothing... except how to load a file that already lives in the data folder, and I think the first relevant result from the Search box was something crazy and non-processing-Java filled from the Hacks page. These "revisions" you speak of sound like a beautiful wonderland that I should look into..
Re: ")" inserted to complete Arguments
Reply #3 - Dec 30th, 2008, 10:22pm
 
You might try casting ExifDirectory as an Object:

ExifDirectory directory = (ExifDirectory)metadata.getDirectory(
((Object)ExifDirectory).getClass()
);

This worked when I got the same message.

A bit late, I bet, but I hope it helps someone (I haven't found another solution).
Re: ")" inserted to complete Arguments
Reply #4 - Aug 29th, 2009, 6:18pm
 
I really hope someone can help me with this.  I've tried the above instructions, and have made a simple test sketch (below).  When I try to run the sketch, processing says: Cannot find anything named "ExifDirectory"

  • I tried fully qualifying the name of the offending class: com.drew.metadata.exif.ExitDirectory, but that doesn't seem to solve the problem.
  • I have the Exif library (metadata-extractor-2.3.1.jar) in a code subfolder of my sketch
  • I am running Processing 1.06


  • Code:
    import com.drew.*;

    public class try_exif extends PApplet
    {

     File jpegFile;
     Metadata testMetaData;

     void setup()
     {

       jpegFile = new File (this.sketchPath + jpegFile.separator + "IMG_2025.jpg");


       try {
         testMetaData = JpegMetadataReader.readMetadata (jpegFile);
       }
       catch (JpegProcessingException message)
       {
         println ("error");
       }

       Directory exifDirectory = testMetaData.getDirectory(((Object)ExifDirectory).getClass());
     }

     void loop ()
     {
     }

    }
    Re: ")" inserted to complete Arguments
    Reply #5 - Aug 30th, 2009, 1:12am
     
    Let see.
    You mention a com.drew.metadata.exif.ExitDirectory class, but you import com.drew.*, which is not enough. * doesn't mean "all classes below this package and sub-packages", but only "all classes below this package only", ie. com.drew.Foo, com.drew.Bar and nothing else.
    Also I am not sure how you test this, but in general, in the PDE, you don't create a class extending a PApplet. People do that when coding in Eclipse.
    And last, loop() is the old name for draw(), so perhaps the sample you took is obsolete.
    Re: ")" inserted to complete Arguments
    Reply #6 - Aug 30th, 2009, 12:34pm
     
    Phil,

    Thanks for the suggestions.  As you surmised, I didn't know how imports work in Java.

    So, I replaced what I had there before with
    Code:
    import com.drew.*;
    import com.drew.metadata.*;
    import com.drew.metadata.exif.*;


    As far as I can tell from the documentation at Code:
    drewnoakes.com/code/exif/javadoc/ 
    
    
    , the ExifDirectory class is located inside com.drew.metadata.exif

    I also commented out the
    Code:
    public class try_exit extends PApplet 
    
    

    stuff which was suggested in an earlier response to this topic.

    I renamed "loop ()" to "draw()" (I also program Arduinos, so I mix things up from time to time).

    Unfortunately, I'm still getting the same error.
    Re: ")" inserted to complete Arguments
    Reply #7 - Aug 30th, 2009, 11:17pm
     
    I just noted a typo in my message... which is a copy/paste of your: ExitDirectory. Check if it is not in your code too... Smiley

    Ah, no, it is not in your sample. Oh, wait, the (Object)ExifDirectory cast doesn't seem right! You cannot cast a class name, only an object (an instance of class).

    I have no time right now, but I find this library interesting, I will try it and report here.
    Re: ")" inserted to complete Arguments
    Reply #8 - Aug 31st, 2009, 4:44am
     
    Got it to work. As fry pointed out, the pre-processor doesn't appreciate the Foo.class syntax...
    I chose the easy solution, to put this syntax out of the pre-processor sight! For this, I wrap my functions in a class and put them in a .java file.
    Here is my current code. I am trying to see if I can get the thumbnail data directly in a PImage...
    ExifReader.pde Code:
    import com.drew.imaging.*;
    import com.drew.imaging.jpeg.*;
    import com.drew.metadata.*;
    import com.drew.metadata.exif.*;
    import com.drew.metadata.iptc.*;
    import com.drew.metadata.jpeg.*;

    void setup()
    {
    size(800, 800);
    background(0);

    String pictureFolder = selectFolder("Image Folder");

    if (pictureFolder == null)
    {
    println("Canceled");
    return;
    }
    File pictFolder = new File(pictureFolder);
    File[] pictureFiles = pictFolder.listFiles(
    new FilenameFilter()
    {
    boolean accept(File dir, String name)
    {
    String fn = name.toLowerCase();
    // Exif is only in these files, no?
    return fn.endsWith(".jpg") || fn.endsWith(".jpeg");
    }
    }
    );
    int x = 10, y = 10;
    int maxHeight = 0;
    for (int fi = 0; fi < pictureFiles.length; fi++)
    {
    File pf = null;
    Metadata metadata = null;
    try
    {
    pf = pictureFiles[fi];
    println("\n" + pf);
    metadata = JpegMetadataReader.readMetadata(pf);
    }
    catch (JpegProcessingException ex)
    {
    println("Ouch! " + pf.getName());
    }
    if (metadata != null)
    {
    ExifProcessing.ShowInformation(metadata);
    ExifProcessing.WriteThumbnail(metadata, pf);
    }
    }
    exit();
    }

    ExifProcessing.java Code:
    import java.util.*;
    import java.io.*;

    import java.awt.image.BufferedImage;

    import com.drew.imaging.*;
    import com.drew.imaging.jpeg.*;
    import com.drew.metadata.*;
    import com.drew.metadata.exif.*;
    import com.drew.metadata.iptc.*;
    import com.drew.metadata.jpeg.*;

    class ExifProcessing
    {
    static void ShowInformation(Metadata metadata)
    {
    Iterator directories = metadata.getDirectoryIterator();
    while (directories.hasNext())
    {
    Directory directory = (Directory) directories.next();
    // iterate through tags and print to System.out
    Iterator tags = directory.getTagIterator();
    while (tags.hasNext())
    {
    Tag tag = (Tag) tags.next();
    // use Tag.toString()
    System.out.println(tag);
    }
    }
    }

    static void WriteThumbnail(Metadata metadata, File pictureFile)
    {
    ExifDirectory dir = (ExifDirectory) metadata.getDirectory(ExifDirectory.class);
    if (!dir.containsThumbnail())
    {
    System.out.println("No thumbnail");
    return;
    }
    String fileName = pictureFile.getName();
    File file = new File(pictureFile.getParentFile().getPath(),
    fileName.replaceAll("\\.jpe?g$", ".thumb.jpg"));
    try
    {
    dir.writeThumbnail(file.getAbsolutePath());
    System.out.println("Thumbnail written: " + file.getAbsolutePath());
    }
    catch (MetadataException me)
    {
    System.out.println(me);
    }
    catch (IOException ioe)
    {
    System.out.println(ioe);
    }
    }
    }
    Re: ")" inserted to complete Arguments
    Reply #9 - Aug 31st, 2009, 7:29am
     
    Got the thumbnail display without disk writing working, at least for the Jpeg images I have. Later I will try against the library's collection.
    Changes:
    Code:
    // (end of setup())
    if (metadata != null)
    {
    BufferedImage bi = ExifProcessing.GetThumbnail(metadata);
    if (bi == null)
    continue; // No thumbnail
    println("\n" + pf);
    // println(bi);
    PImage pi = GetPImage(bi);
    println("Thumb: " + pi.width + "x" + pi.height);
    if (x + pi.width > width)
    {
    x = 10;
    y += maxHeight + 10;
    maxHeight = 0;
    }
    image(pi, x, y);
    x += pi.width + 10;
    if (pi.height > maxHeight)
    {
    maxHeight = pi.height;
    }
    }
    }
    // exit();
    }

    Code:
    // Added to ExifProcessing
    // Most of the code there comes from unfinished (commented out) work in ExifDirectory.java
    static BufferedImage GetThumbnail(Metadata metadata)
    {
    BufferedImage bi = null;
    ExifDirectory dir = (ExifDirectory) metadata.getDirectory(ExifDirectory.class);
    if (!dir.containsThumbnail())
    {
    return null;
    }
    int compression = 0;
    try
    {
    compression = dir.getInt(ExifDirectory.TAG_COMPRESSION);
    }
    catch (MetadataException e)
    {
    System.out.println("Unable to determine thumbnail type " + e);
    return null;
    }
    byte[] thumbnailBytes = null;
    try
    {
    thumbnailBytes = dir.getThumbnailData();
    }
    catch (MetadataException me)
    {
    System.out.println(me);
    return null;
    }

    if (compression == ExifDirectory.COMPRESSION_JPEG)
    {
    // That's the case for all my current test images
    try
    {
    return ImageIO.read(new ByteArrayInputStream(thumbnailBytes));
    }
    catch (IOException ioe)
    {
    System.out.println(ioe);
    }
    }
    else
    {
    // uncompressed thumbnail (raw RGB data)
    if (!dir.containsTag(ExifDirectory.TAG_PHOTOMETRIC_INTERPRETATION))
    return null;

    int imageWidth = 0, imageHeight = 0;
    try
    {
    if (!dir.containsTag(ExifDirectory.TAG_THUMBNAIL_IMAGE_WIDTH))
    {
    System.out.println("No thumbnail size");
    return null;
    }
    imageWidth = dir.getInt(ExifDirectory.TAG_THUMBNAIL_IMAGE_WIDTH);
    imageHeight = dir.getInt(ExifDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT);
    }
    catch (MetadataException e)
    {
    System.out.println("Cannot get thumbnail dimensions: " + e);
    return null;
    }

    try
    {
    // If the image is RGB format, then convert it to a bitmap
    int photometricInterpretation = dir.getInt(ExifDirectory.TAG_PHOTOMETRIC_INTERPRETATION);
    if (photometricInterpretation == ExifDirectory.PHOTOMETRIC_INTERPRETATION_RGB)
    {
    // RGB
    BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
    //? image.setRGB(0, 0, imageWidth, imageHeight, thumbnailBytes, 0, imageWidth);
    return image;
    }
    else if (photometricInterpretation == ExifDirectory.PHOTOMETRIC_INTERPRETATION_YCBCR)
    {
    // YCbCr
    //~ ColorSpace cs = ColorSpace.getInstance(ColorSpace.TYPE_YCbCr); // Wrong, I think...
    // TODO
    System.out.println("Unhandled YCbCr thumbnail");
    return null;
    }
    else if (photometricInterpretation == ExifDirectory.PHOTOMETRIC_INTERPRETATION_MONOCHROME)
    {
    // Monochrome
    //~ ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    // TODO
    System.out.println("Unhandled Monochrome thumbnail");
    return null;
    }
    }
    catch (Exception e)
    {
    System.out.println("Unable to extract thumbnail: " + e);
    return null;
    }
    }
    return bi;
    }
    Re: ")" inserted to complete Arguments
    Reply #10 - Aug 31st, 2009, 8:07am
     
    thank you PhiLo!  I am now unstuck.  

    Michael
    Page Index Toggle Pages: 1