~ubuntu-branches/ubuntu/trusty/compiz/trusty

« back to all changes in this revision

Viewing changes to plugins/imgjpeg/src/imgjpeg.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-08-22 06:58:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3352.
  • Revision ID: package-import@ubuntu.com-20130822065807-17nlzez0d30y09so
Tags: upstream-0.9.10+13.10.20130822
ImportĀ upstreamĀ versionĀ 0.9.10+13.10.20130822

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
           CompSize      &size,
32
32
           int           alpha)
33
33
{
34
 
    int  h, w;
35
 
    char *dest;
36
34
    int  height = size.height ();
37
 
    int  width = size.width ();
 
35
    int  width  = size.width ();
 
36
    char *dest  = (char *) malloc ((unsigned)(height * width * 4));
38
37
 
39
 
    dest = (char *) malloc ((unsigned)(height * width * 4));
40
38
    if (!dest)
41
39
        return false;
42
40
 
43
41
    data = dest;
 
42
    int pos;
44
43
 
45
 
    for (h = 0; h < height; h++)
46
 
        for (w = 0; w < width; w++)
 
44
    for (int h = 0; h < height; ++h)
 
45
    {
 
46
        for (int w = 0; w < width; ++w)
47
47
        {
48
 
            int pos = h * width + w;
 
48
            pos = h * width + w;
49
49
#if __BYTE_ORDER == __BIG_ENDIAN
50
50
            dest[(pos * 4) + 3] = source[(pos * 3) + 2];    /* blue */
51
51
            dest[(pos * 4) + 2] = source[(pos * 3) + 1];    /* green */
58
58
            dest[(pos * 4) + 3] = alpha;
59
59
#endif
60
60
        }
 
61
    }
61
62
 
62
63
    return true;
63
64
}
68
69
           CompSize      &size,
69
70
           int           stride)
70
71
{
71
 
    int     h, w;
72
72
    int     height = size.height ();
73
 
    int     width = size.width ();
74
 
    int     ps = stride / width;        /* pixel size */
 
73
    int     width  = size.width ();
75
74
    JSAMPLE *d;
76
75
 
77
76
    d = (JSAMPLE *) malloc ((unsigned)height * (unsigned)width * 3 *
81
80
 
82
81
    *dest = d;
83
82
 
84
 
    for (h = 0; h < height; h++)
85
 
        for (w = 0; w < width; w++)
 
83
    int ps = stride / width;    /* pixel size */
 
84
    int pos;
 
85
 
 
86
    for (int h = 0; h < height; ++h)
 
87
    {
 
88
        for (int w = 0; w < width; ++w)
86
89
        {
87
 
            int pos = h * width + w;
 
90
            pos = h * width + w;
88
91
#if __BYTE_ORDER == __BIG_ENDIAN
89
92
            d[(pos * 3) + 0] = source[(pos * ps) + 3];  /* red */
90
93
            d[(pos * 3) + 1] = source[(pos * ps) + 2];  /* green */
95
98
            d[(pos * 3) + 2] = source[(pos * ps) + 2];  /* blue */
96
99
#endif
97
100
        }
 
101
    }
98
102
 
99
103
    return true;
100
104
}
119
123
                      CompSize &size,
120
124
                      void     *&data)
121
125
{
 
126
    if (!file)
 
127
        return false;
 
128
 
122
129
    struct jpeg_decompress_struct cinfo;
123
130
    struct jpegErrorMgr           jerr;
124
 
    JSAMPLE                       *buf;
125
 
    JSAMPROW                      *rows;
126
 
    bool                          result;
127
 
 
128
 
    if (!file)
129
 
        return false;
130
131
 
131
132
    cinfo.err = jpeg_std_error (&jerr.pub);
132
133
    jerr.pub.error_exit = jpegErrorExit;
151
152
    size.setHeight ((int)cinfo.output_height);
152
153
    size.setWidth ((int)cinfo.output_width);
153
154
 
154
 
    buf = (JSAMPLE *) calloc (cinfo.output_height * cinfo.output_width *
155
 
                              (unsigned)cinfo.output_components,
156
 
                              sizeof (JSAMPLE));
 
155
    JSAMPLE *buf = (JSAMPLE *) calloc (cinfo.output_height * cinfo.output_width *
 
156
                                       (unsigned)cinfo.output_components,
 
157
                                       sizeof (JSAMPLE));
 
158
 
157
159
    if (!buf)
158
160
    {
159
161
        jpeg_finish_decompress (&cinfo);
161
163
        return false;
162
164
    }
163
165
 
164
 
    rows = (JSAMPROW *) malloc (cinfo.output_height * sizeof (JSAMPROW));
 
166
    JSAMPROW *rows = (JSAMPROW *) malloc (cinfo.output_height * sizeof (JSAMPROW));
 
167
 
165
168
    if (!rows)
166
169
    {
167
170
        free (buf);
170
173
        return false;
171
174
    }
172
175
 
173
 
    for (unsigned int i = 0; i < cinfo.output_height; i++)
 
176
    for (unsigned int i = 0; i < cinfo.output_height; ++i)
174
177
        rows[i] = &buf[i * cinfo.output_width *
175
 
                       (unsigned)cinfo.output_components];
 
178
                  (unsigned)cinfo.output_components];
176
179
 
177
180
    while (cinfo.output_scanline < cinfo.output_height)
178
181
        jpeg_read_scanlines (&cinfo, &rows[cinfo.output_scanline],
182
185
    jpeg_destroy_decompress (&cinfo);
183
186
 
184
187
    /* convert the rgb data into BGRA format */
185
 
    result = rgbToBGRA (buf, data, size, 255);
 
188
    bool result = rgbToBGRA (buf, data, size, 255);
186
189
 
187
190
    free (rows);
188
191
    free (buf);
 
192
 
189
193
    return result;
190
194
}
191
195
 
220
224
 
221
225
    while (cinfo.next_scanline < cinfo.image_height)
222
226
    {
223
 
        row_pointer[0] =
224
 
            &data[(cinfo.image_height - cinfo.next_scanline - 1) *
225
 
                  (unsigned) size.width () * 3];
 
227
        row_pointer[0] = &data[(cinfo.image_height - cinfo.next_scanline - 1) *
 
228
                         (unsigned) size.width () * 3];
 
229
 
226
230
        jpeg_write_scanlines (&cinfo, row_pointer, 1);
227
231
    }
228
232
 
250
254
JpegScreen::imageToFile (CompString &path,
251
255
                         CompString &format,
252
256
                         CompSize   &size,
253
 
                         int       stride,
254
 
                         void      *data)
 
257
                         int        stride,
 
258
                         void       *data)
255
259
{
256
 
    bool       status = false;
 
260
    bool       status   = false;
257
261
    CompString fileName = fileNameWithExtension (path);
258
262
 
259
263
    if (format == "jpeg" || format == "jpg" ||
260
264
        !(status = screen->imageToFile (path, format, size, stride, data)))
261
265
    {
262
 
        FILE *file;
263
 
        file = fopen (fileName.c_str (), "wb");
264
 
        if (file)
 
266
        FILE *file = fopen (fileName.c_str (), "wb");
 
267
 
 
268
        if (file)
265
269
        {
266
270
            status = writeJPEG ((unsigned char *) data, file, size, stride);
267
271
            fclose (file);
277
281
                         int        &stride,
278
282
                         void       *&data)
279
283
{
280
 
    bool       status = false;
281
 
    FILE       *file;
 
284
    bool       status   = false;
282
285
    CompString fileName = fileNameWithExtension (name);
 
286
    FILE       *file    = fopen (fileName.c_str (), "rb");
283
287
 
284
 
    file = fopen (fileName.c_str (), "rb");
285
288
    if (file)
286
289
    {
287
290
        status = readJPEG (file, size, data);
307
310
bool
308
311
JpegPluginVTable::init ()
309
312
{
310
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
311
 
        return false;
 
313
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
 
314
        return true;
312
315
 
313
 
    return true;
 
316
    return false;
314
317
}
315