~ubuntu-branches/ubuntu/lucid/onscripter/lucid

« back to all changes in this revision

Viewing changes to sarconv.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2008-02-12 20:22:19 UTC
  • mfrom: (0.1.2 lenny) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080212202219-jx4xdi0izczp0pcy
Tags: 20080121-0ubuntu1
* Fake-sync onscripter 0.0.20080121-1 from Debian unstable (LP: #187890).
  Drop the leading zeroes from the version due to different versioning in
  Debian and Ubuntu.
* debian/control:
  + Modify Maintainer value to match DebianMaintainerField spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * 
3
3
 *  sarconv.cpp - Images in SAR archive are re-scaled to 320x240 size
4
4
 *
5
 
 *  Copyright (c) 2001-2004 Ogapee. All rights reserved.
 
5
 *  Copyright (c) 2001-2006 Ogapee. All rights reserved.
6
6
 *
7
7
 *  ogapee@aqua.dti2.ne.jp
8
8
 *
26
26
#include <string.h>
27
27
#include <sys/types.h>
28
28
#include <sys/stat.h>
29
 
#include <errno.h>
30
29
#include "SarReader.h"
31
30
 
32
 
extern int errno;
33
31
extern int scale_ratio_upper;
34
32
extern int scale_ratio_lower;
35
33
 
36
 
extern size_t rescaleJPEG( unsigned char *original_buffer, size_t length, unsigned char **rescaled_buffer );
37
 
extern size_t rescaleBMP( unsigned char *original_buffer, size_t length, unsigned char **rescaled_buffer );
 
34
extern size_t rescaleJPEG( unsigned char *original_buffer, size_t length, unsigned char **rescaled_buffer,
 
35
                           int quality );
 
36
extern size_t rescaleBMP( unsigned char *original_buffer, unsigned char **rescaled_buffer,
 
37
                          bool output_jpeg_flag, int quality );
38
38
 
39
39
#ifdef main
40
40
#undef main
41
41
#endif
42
42
 
 
43
void help()
 
44
{
 
45
    fprintf(stderr, "Usage: sarconv [-j] [-q quality] src_width dst_width src_archive_file dst_archive_file\n");
 
46
    fprintf(stderr, "           quality   ... 0 to 100\n");
 
47
    fprintf(stderr, "           src_width ... 640 or 800\n");
 
48
    fprintf(stderr, "           dst_width ... 176, 220, 320, 360, 384, 640, etc.\n");
 
49
    exit(-1);
 
50
}
 
51
 
43
52
int main( int argc, char **argv )
44
53
{
45
54
    SarReader cSR;
46
55
    unsigned long length, offset = 0, buffer_length = 0;
47
56
    unsigned char *buffer = NULL, *rescaled_buffer = NULL;
48
57
    unsigned int i, count;
 
58
    bool bmp2jpeg_flag = false;
 
59
    int quality = 75;
49
60
    FILE *fp;
50
61
 
51
 
    if ( argc == 4 ){
52
 
        int s = atoi( argv[1] );
53
 
        if      ( s == 640 ){ scale_ratio_upper = 1; scale_ratio_lower = 2; }
54
 
        else if ( s == 800 ){ scale_ratio_upper = 2; scale_ratio_lower = 5; }
55
 
        else argc = 1;
56
 
    }
57
 
    if ( argc != 4 ){
58
 
        fprintf( stderr, "Usage: sarconv 640 arc_file rescaled_arc_file\n");
59
 
        fprintf( stderr, "Usage: sarconv 800 arc_file rescaled_arc_file\n");
60
 
        exit(-1);
61
 
    }
 
62
    argc--; // skip command name
 
63
    argv++;
 
64
    while (argc > 4){
 
65
        if      ( !strcmp( argv[0], "-j" ) )    bmp2jpeg_flag = true;
 
66
        else if ( !strcmp( argv[0], "-q" ) ){
 
67
            argc--;
 
68
            argv++;
 
69
            quality = atoi(argv[0]);
 
70
        }
 
71
        argc--;
 
72
        argv++;
 
73
    }
 
74
    if (argc != 4) help();
62
75
 
 
76
    scale_ratio_lower = atoi(argv[0]); // src width
 
77
    if (scale_ratio_lower!=640 && scale_ratio_lower!=800) help();
 
78
    
 
79
    scale_ratio_upper = atoi(argv[1]); // dst width
 
80
    
63
81
    if ( (fp = fopen( argv[3], "wb" ) ) == NULL ){
64
82
        fprintf( stderr, "can't open file %s for writing.\n", argv[3] );
65
83
        exit(-1);
90
108
                fprintf( stderr, "file %s can't be retrieved %ld\n", sFI.name, length );
91
109
                continue;
92
110
            }
93
 
            sFI.length = rescaleJPEG( buffer, length, &rescaled_buffer );
 
111
            sFI.length = rescaleJPEG( buffer, length, &rescaled_buffer, quality );
94
112
            cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.length, true, rescaled_buffer );
95
113
        }
96
114
        else if ( strlen( sFI.name ) > 3 && !strcmp( sFI.name + strlen( sFI.name ) - 3, "BMP") ){
98
116
                fprintf( stderr, "file %s can't be retrieved %ld\n", sFI.name, length );
99
117
                continue;
100
118
            }
101
 
            sFI.length = rescaleBMP( buffer, length, &rescaled_buffer );
 
119
            sFI.length = rescaleBMP( buffer, &rescaled_buffer, bmp2jpeg_flag, quality );
102
120
            cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.length, true, rescaled_buffer );
103
121
        }
104
122
        else{
114
132
    if ( rescaled_buffer ) delete[] rescaled_buffer;
115
133
    if ( buffer ) delete[] buffer;
116
134
    
117
 
    exit(0);
 
135
    return 0;
118
136
}