~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/poppler/goo/JpegWriter.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// JpegWriter.cc
 
4
//
 
5
// This file is licensed under the GPLv2 or later
 
6
//
 
7
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
 
8
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
 
9
// Copyright (C) 2010 Harry Roberts <harry.roberts@midnight-labs.org>
 
10
//
 
11
//========================================================================
 
12
 
 
13
#include "JpegWriter.h"
 
14
 
 
15
#ifdef ENABLE_LIBJPEG
 
16
 
 
17
#include "poppler/Error.h"
 
18
 
 
19
void outputMessage(j_common_ptr cinfo)
 
20
{
 
21
        char buffer[JMSG_LENGTH_MAX];
 
22
 
 
23
        // Create the message
 
24
        (*cinfo->err->format_message) (cinfo, buffer);
 
25
 
 
26
        // Send it to poppler's error handler
 
27
        error(-1, "%s", buffer);
 
28
}
 
29
 
 
30
JpegWriter::JpegWriter(int q, bool p)
 
31
: progressive(p), quality(q)
 
32
{
 
33
}
 
34
 
 
35
JpegWriter::JpegWriter()
 
36
: progressive(false), quality(-1)
 
37
{
 
38
}
 
39
 
 
40
JpegWriter::~JpegWriter()
 
41
{
 
42
        // cleanup
 
43
        jpeg_destroy_compress(&cinfo);
 
44
}
 
45
 
 
46
bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
 
47
{
 
48
        // Setup error handler
 
49
        cinfo.err = jpeg_std_error(&jerr);
 
50
        jerr.output_message = &outputMessage;
 
51
 
 
52
        // Initialize libjpeg
 
53
        jpeg_create_compress(&cinfo);
 
54
        
 
55
        // Set destination file
 
56
        jpeg_stdio_dest(&cinfo, f);
 
57
        
 
58
        // Set libjpeg configuration
 
59
        cinfo.image_width = width;
 
60
        cinfo.image_height = height;
 
61
        cinfo.density_unit = 1; // dots per inch
 
62
        cinfo.X_density = hDPI;
 
63
        cinfo.Y_density = vDPI;
 
64
        cinfo.input_components = 3;     /* # of color components per pixel */
 
65
        cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
 
66
        jpeg_set_defaults(&cinfo);
 
67
        
 
68
        // Set quality
 
69
        if( quality >= 0 && quality <= 100 ) { 
 
70
                jpeg_set_quality(&cinfo, quality, true);
 
71
        }
 
72
        
 
73
        // Use progressive mode
 
74
        if( progressive) {
 
75
                jpeg_simple_progression(&cinfo);
 
76
        }
 
77
        
 
78
        // Get ready for data
 
79
        jpeg_start_compress(&cinfo, TRUE);
 
80
        
 
81
        return true;
 
82
}
 
83
 
 
84
bool JpegWriter::writePointers(unsigned char **rowPointers, int rowCount)
 
85
{
 
86
        // Write all rows to the file
 
87
        jpeg_write_scanlines(&cinfo, rowPointers, rowCount);
 
88
        
 
89
        return true;
 
90
}
 
91
 
 
92
bool JpegWriter::writeRow(unsigned char **row)
 
93
{
 
94
        // Write the row to the file
 
95
        jpeg_write_scanlines(&cinfo, row, 1);
 
96
        
 
97
        return true;
 
98
}
 
99
 
 
100
bool JpegWriter::close()
 
101
{
 
102
        jpeg_finish_compress(&cinfo);
 
103
        
 
104
        return true;
 
105
}
 
106
 
 
107
#endif