~ubuntu-branches/ubuntu/saucy/shotwell/saucy

« back to all changes in this revision

Viewing changes to src/Photo.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-04-04 19:11:05 UTC
  • mfrom: (1.2.19)
  • Revision ID: package-import@ubuntu.com-20130404191105-0mn24vyf1eqik51e
Tags: 0.14.1-0ubuntu1
New upstream bugfix version

Show diffs side-by-side

added added

removed removed

Lines of Context:
201
201
    // it hasn't been accessed in this many seconds, discard it to conserve memory.
202
202
    private const int PRECACHE_TIME_TO_LIVE = 180;
203
203
    
 
204
    // Minimum raw embedded preview size we're willing to accept; any smaller than this, and 
 
205
    // it's probably intended primarily for use only as a thumbnail and won't look good on the
 
206
    // PhotoPage.
 
207
    private const int MIN_EMBEDDED_SIZE = 1024;
 
208
    
204
209
    public enum Exception {
205
210
        NONE            = 0,
206
211
        ORIENTATION     = 1 << 0,
552
557
            case RawDeveloper.EMBEDDED:
553
558
                try {
554
559
                    PhotoMetadata meta = get_master_metadata();
555
 
                    if (meta.get_preview_count() > 0)
 
560
                    uint num_previews = meta.get_preview_count();
 
561
                    
 
562
                    if (num_previews > 0) {
 
563
                        PhotoPreview? prev = meta.get_preview(num_previews - 1);
 
564
 
 
565
                        // Embedded preview could not be fetched?
 
566
                        if (prev == null)
 
567
                            return false;
 
568
                        
 
569
                        Dimensions dims = prev.get_pixel_dimensions();
 
570
                        
 
571
                        // Largest embedded preview was an unacceptable size?
 
572
                        int preview_major_axis = (dims.width > dims.height) ? dims.width : dims.height;
 
573
                        if (preview_major_axis < MIN_EMBEDDED_SIZE)
 
574
                            return false;
 
575
                        
 
576
                        // Preview was a supported size, use it.
556
577
                        return true;
 
578
                    }
 
579
                    
 
580
                    // Image has no embedded preview at all.
 
581
                    return false;
557
582
                } catch (Error e) {
558
583
                    debug("Error accessing embedded preview. Message: %s", e.message);
559
584
                }
735
760
        if (is_raw_developer_available(RawDeveloper.CAMERA) && (d == RawDeveloper.EMBEDDED))
736
761
            d = RawDeveloper.CAMERA;
737
762
            
 
763
        // If the embedded preview is too small to be used in the PhotoPage, don't
 
764
        // allow EMBEDDED to be chosen.
 
765
        if (!is_raw_developer_available(RawDeveloper.EMBEDDED))
 
766
            d = RawDeveloper.SHOTWELL;
 
767
            
738
768
        lock (developments) {
739
769
            RawDeveloper stale_raw_developer = row.developer;
740
770
            
3565
3595
            metadata.set_comment(get_comment());
3566
3596
            metadata.set_software(Resources.APP_TITLE, Resources.APP_VERSION);
3567
3597
            
3568
 
            // Also, becausee JPEGs can store their own orientation, we'll save
3569
 
            // the original dimensions directly and let the orientation field do
3570
 
            // the rotation there, too...
3571
 
            if (get_file_format() == PhotoFileFormat.JFIF) {
3572
 
                metadata.set_pixel_dimensions(get_dimensions(Exception.ORIENTATION));
3573
 
                metadata.set_orientation(get_orientation());
3574
 
            } else {
3575
 
                // Non-JPEG image - we'll need to save the rotated dimensions.
3576
 
                metadata.set_pixel_dimensions(Dimensions.for_pixbuf(pixbuf));
3577
 
                metadata.set_orientation(Orientation.TOP_LEFT);
3578
 
            }
3579
 
            
3580
3598
            if (get_exposure_time() != 0)
3581
3599
                metadata.set_exposure_date_time(new MetadataDateTime(get_exposure_time()));
3582
3600
            else
3594
3612
            metadata.clear();
3595
3613
        }
3596
3614
        
 
3615
        // Even if we were told to trash camera-identifying data, we need
 
3616
        // to make sure the orientation propagates. Also, because JPEGs
 
3617
        // can store their own orientation, we'll save the original dimensions
 
3618
        // directly and let the orientation field do the rotation there.
 
3619
        if (get_file_format() == PhotoFileFormat.JFIF) {
 
3620
            metadata.set_pixel_dimensions(get_dimensions(Exception.ORIENTATION));
 
3621
            metadata.set_orientation(get_orientation());
 
3622
        } else {
 
3623
            // Non-JPEG image - we'll need to save the rotated dimensions.
 
3624
            metadata.set_pixel_dimensions(Dimensions.for_pixbuf(pixbuf));
 
3625
            metadata.set_orientation(Orientation.TOP_LEFT);
 
3626
        }
 
3627
        
3597
3628
        export_format.create_metadata_writer(dest_file.get_path()).write_metadata(metadata);
3598
3629
    }
3599
3630