~ubuntu-branches/ubuntu/trusty/vips/trusty

« back to all changes in this revision

Viewing changes to libvips/foreign/csv.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2014-03-29 12:29:29 UTC
  • mfrom: (1.1.21) (30.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20140329122929-fvxnaann32ex0gzk
Tags: 7.38.5-2
Enable dh-autoreconf. (Closes: #742872)

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
        if( ch == '"' ) {
184
184
                (void) fgetc( fp );
185
185
                (void) skip_to_quote( fp );
186
 
                ch = fgetc( fp );
 
186
                (void) fgetc( fp );
187
187
        }
188
188
        else if( !sepmap[ch] && 
189
189
                fscanf( fp, "%lf", out ) != 1 ) {
196
196
 
197
197
                /* Step over the bad data to the next separator.
198
198
                 */
199
 
                ch = skip_to_sep( fp, sepmap );
 
199
                (void) skip_to_sep( fp, sepmap );
200
200
        }
201
201
 
202
202
        /* Don't need to check result, we have read a field successfully.
280
280
                fsetpos( fp, &pos );
281
281
        }
282
282
 
 
283
        vips_image_pipelinev( out, VIPS_DEMAND_STYLE_THINSTRIP, NULL );
283
284
        vips_image_init_fields( out,
284
285
                columns, lines, 1, 
285
286
                VIPS_FORMAT_DOUBLE, 
286
287
                VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, 1.0, 1.0 );
287
 
        vips_demand_hint( out, VIPS_DEMAND_STYLE_THINSTRIP, NULL );
288
288
 
289
289
        /* Just reading the header? We are done.
290
290
         */
663
663
}
664
664
 
665
665
VipsImage * 
666
 
vips__matrix_read( const char *filename )
 
666
vips__matrix_read_file( FILE *fp )
667
667
{
668
668
        char whitemap[256];
669
669
        int i;
670
670
        char *p;
671
 
        FILE *fp;
672
671
        int width;
673
672
        int height;
674
673
        double scale;
680
679
        for( p = WHITESPACE; *p; p++ )
681
680
                whitemap[(int) *p] = 1;
682
681
 
683
 
        if( !(fp = vips__file_open_read( filename, NULL, TRUE )) ) 
684
 
                return( NULL );
685
682
        if( vips__matrix_header( whitemap, fp,
686
 
                &width, &height, &scale, &offset ) ) {  
687
 
                fclose( fp );
 
683
                &width, &height, &scale, &offset ) )   
688
684
                return( NULL );
689
 
        }
690
685
 
691
686
        if( !(out = vips_image_new_matrix( width, height )) )
692
687
                return( NULL );
695
690
 
696
691
        if( vips__matrix_body( whitemap, out, fp ) ) {
697
692
                g_object_unref( out );
698
 
                fclose( fp );
699
693
                return( NULL );
700
694
        }
701
 
        fclose( fp );
702
695
 
703
696
        return( out ); 
704
697
}
705
698
 
 
699
VipsImage * 
 
700
vips__matrix_read( const char *filename )
 
701
{
 
702
        FILE *fp;
 
703
        VipsImage *out; 
 
704
 
 
705
        if( !(fp = vips__file_open_read( filename, NULL, TRUE )) ) 
 
706
                return( NULL );
 
707
        out = vips__matrix_read_file( fp ); 
 
708
        fclose( fp );
 
709
 
 
710
        return( out );
 
711
}
 
712
 
706
713
int
707
 
vips__matrix_write( VipsImage *in, const char *filename )
 
714
vips__matrix_write_file( VipsImage *in, FILE *fp )
708
715
{
709
716
        VipsImage *mask;
710
 
        FILE *fp;
711
717
        int x, y; 
712
718
 
713
719
        if( vips_check_matrix( "vips2mask", in, &mask ) )
714
720
                return( -1 );
715
721
 
716
 
        if( !(fp = vips__file_open_write( filename, TRUE )) ) {
717
 
                g_object_unref( mask ); 
718
 
                return( -1 );
719
 
        }
720
722
        fprintf( fp, "%d %d ", mask->Xsize, mask->Ysize ); 
721
723
        if( vips_image_get_typeof( mask, "scale" ) && 
722
724
                vips_image_get_typeof( mask, "offset" ) ) 
733
735
        }
734
736
 
735
737
        g_object_unref( mask ); 
 
738
 
 
739
        return( 0 );
 
740
}
 
741
 
 
742
int
 
743
vips__matrix_write( VipsImage *in, const char *filename )
 
744
{
 
745
        FILE *fp;
 
746
        int result;
 
747
 
 
748
        if( !(fp = vips__file_open_write( filename, TRUE )) ) 
 
749
                return( -1 );
 
750
        result = vips__matrix_write_file( in, fp );
736
751
        fclose( fp ); 
737
752
 
738
 
        return( 0 );
 
753
        return( result );
739
754
}
740
755
 
741
756
const char *vips__foreign_matrix_suffs[] = { ".mat", NULL };