~ubuntu-branches/ubuntu/utopic/libopenraw/utopic

« back to all changes in this revision

Viewing changes to demo/ppmload.c

  • Committer: Package Import Robot
  • Author(s): David Paleino
  • Date: 2012-03-10 08:57:09 UTC
  • mto: (7.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20120310085709-zuimi0xsth01nfkc
Tags: upstream-0.0.9
ImportĀ upstreamĀ versionĀ 0.0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libopenraw - ppmload.c
 
3
 *
 
4
 * Copyright (C) 2007, 2010 Hubert Figuiere
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
19
 */
 
20
 
 
21
 
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
 
 
26
#include <libopenraw/libopenraw.h>
 
27
 
 
28
int
 
29
main(int argc, char **argv)
 
30
{
 
31
        const char *filename;
 
32
 
 
33
        if(argc < 2) {
 
34
                return 1;
 
35
        }
 
36
 
 
37
        filename = argv[1];
 
38
 
 
39
        or_debug_set_level(DEBUG2);
 
40
 
 
41
        if(filename && *filename) {
 
42
                ORRawFileRef raw_file = or_rawfile_new(filename, OR_RAWFILE_TYPE_UNKNOWN);
 
43
                
 
44
                if(raw_file) {
 
45
                    or_error err;
 
46
                    ORBitmapDataRef bitmapdata = or_bitmapdata_new();
 
47
                    err = or_rawfile_get_rendered_image(raw_file, bitmapdata, 0);
 
48
                    if(err == OR_ERROR_NONE) {
 
49
                        uint32_t x, y;
 
50
                        FILE * f;
 
51
                        size_t size, written_size;
 
52
                        
 
53
                or_bitmapdata_dimensions(bitmapdata, &x, &y);
 
54
                printf(" --- dimensions x = %d, y = %d\n", x, y);
 
55
                f = fopen("image.ppm", "wb");
 
56
                fprintf(f, "P6\n");
 
57
                fprintf(f, "%d %d\n", x - 2, y);
 
58
                fprintf(f, "255\n");
 
59
                
 
60
                size = or_bitmapdata_data_size(bitmapdata);
 
61
                printf(" --- size = %ld\n", (long)size);
 
62
                written_size = fwrite(or_bitmapdata_data(bitmapdata), 1, size, f);
 
63
                if(written_size != size) {
 
64
                        printf("short read\n");
 
65
                }
 
66
                                fclose(f);
 
67
                    }
 
68
                        or_bitmapdata_release(bitmapdata);
 
69
                    or_rawfile_release(raw_file);
 
70
                }
 
71
        }
 
72
        else {
 
73
                printf("No input file name\n");
 
74
        }
 
75
 
 
76
        return 0;
 
77
}