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

« back to all changes in this revision

Viewing changes to plugins/imgpng/src/imgpng.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:
130
130
 
131
131
    pixelSize = 4;
132
132
    d = (char *) malloc (pngWidth * pngHeight * pixelSize);
 
133
 
133
134
    if (!d)
134
135
        return false;
135
136
 
136
137
    data = d;
137
138
 
138
139
    rowPointers = new png_byte *[pngHeight];
 
140
 
139
141
    if (!rowPointers)
140
142
    {
141
143
        free (d);
142
144
        return false;
143
145
    }
144
146
 
145
 
    for (unsigned int i = 0; i < pngHeight; i++)
 
147
    for (unsigned int i = 0; i < pngHeight; ++i)
146
148
        rowPointers[i] = (png_byte *) (d + i * pngWidth * pixelSize);
147
149
 
148
150
    png_read_image (png, rowPointers);
161
163
    std::ifstream *file = (std::ifstream *) png_get_io_ptr (png);
162
164
 
163
165
    file->read ((char *) data, size);
 
166
 
164
167
    if (file->fail ())
165
168
        png_error (png, "Read Error");
166
169
}
171
174
                    void          *&data)
172
175
{
173
176
    unsigned char png_sig[PNG_SIG_SIZE];
174
 
    png_struct    *png;
175
 
    png_info      *info;
176
 
    bool          status;
177
177
 
178
178
    file.read ((char *) png_sig, PNG_SIG_SIZE);
179
 
    if (file.fail ())
180
 
        return false;
181
 
    if (png_sig_cmp (png_sig, 0, PNG_SIG_SIZE) != 0)
182
 
        return false;
183
 
 
184
 
    png = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
179
 
 
180
    if (file.fail () ||
 
181
        png_sig_cmp (png_sig, 0, PNG_SIG_SIZE))
 
182
        return false;
 
183
 
 
184
    png_struct *png = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
185
 
185
186
    if (!png)
186
187
        return false;
187
188
 
188
 
    info = png_create_info_struct (png);
 
189
    png_info *info = png_create_info_struct (png);
 
190
 
189
191
    if (!info)
190
192
    {
191
193
        png_destroy_read_struct (&png, NULL, NULL);
195
197
    png_set_read_fn (png, &file, stdioReadFunc);
196
198
    png_set_sig_bytes (png, PNG_SIG_SIZE);
197
199
 
198
 
    status = readPngData (png, info, data, size);
 
200
    bool status = readPngData (png, info, data, size);
199
201
 
200
202
    png_destroy_read_struct (&png, &info, NULL);
201
203
 
210
212
    std::ofstream *file = (std::ofstream *) png_get_io_ptr (png);
211
213
 
212
214
    file->write ((char *) data, size);
 
215
 
213
216
    if (file->bad ())
214
217
        png_error (png, "Write Error");
215
218
}
220
223
                     CompSize      &size,
221
224
                     int           stride)
222
225
{
223
 
    png_struct   *png;
224
 
    png_info     *info;
225
 
    png_byte     **rows;
226
 
    png_color_16 white;
227
 
    int          i, height = size.height ();
 
226
    int      height = size.height ();
 
227
    png_byte **rows = new png_byte *[height];
228
228
 
229
 
    rows = new png_byte *[height];
230
229
    if (!rows)
231
230
        return false;
232
231
 
233
 
    for (i = 0; i < height; i++)
 
232
    for (int i = 0; i < height; ++i)
234
233
        rows[height - i - 1] = buffer + i * stride;
235
234
 
236
 
    png = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
235
    png_struct *png = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
236
 
237
237
    if (!png)
238
238
    {
239
239
        delete [] rows;
240
240
        return false;
241
241
    }
242
242
 
243
 
    info = png_create_info_struct (png);
 
243
    png_info *info = png_create_info_struct (png);
 
244
 
244
245
    if (!info)
245
246
    {
246
247
        png_destroy_write_struct (&png, NULL);
264
265
                  PNG_COMPRESSION_TYPE_DEFAULT,
265
266
                  PNG_FILTER_TYPE_DEFAULT);
266
267
 
 
268
    png_color_16 white;
 
269
 
267
270
    white.red   = 0xff;
268
271
    white.blue  = 0xff;
269
272
    white.green = 0xff;
295
298
PngScreen::imageToFile (CompString &path,
296
299
                        CompString &format,
297
300
                        CompSize   &size,
298
 
                        int        stride,
299
 
                        void       *data)
 
301
                        int        stride,
 
302
                        void       *data)
300
303
{
301
 
    bool          status = false;
302
304
    std::ofstream file;
303
305
    CompString    fileName = fileNameWithExtension (path);
 
306
    bool          status   = false;
304
307
 
305
308
    if (format == "png")
306
309
    {
307
310
        file.open (fileName.c_str ());
 
311
 
308
312
        if (file.is_open ())
309
313
        {
310
314
            status = writePng ((unsigned char *) data, file, size, stride);
336
340
                        int        &stride,
337
341
                        void       *&data)
338
342
{
339
 
    bool          status = false;
340
343
    std::ifstream file;
341
344
    CompString    fileName = fileNameWithExtension (name);
 
345
    bool          status   = false;
342
346
 
343
347
    file.open (fileName.c_str ());
 
348
 
344
349
    if (file.is_open ())
345
350
    {
346
351
        status = readPng (file, size, data);
359
364
bool
360
365
PngPluginVTable::init ()
361
366
{
362
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
363
 
        return false;
 
367
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
 
368
        return true;
364
369
 
365
 
    return true;
 
370
    return false;
366
371
}
367