~henrix/ubuntu/precise/open-vm-dkms/lp-1416003

« back to all changes in this revision

Viewing changes to lib/image/imageUtilPng.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-23 15:32:00 UTC
  • mfrom: (1.1.2 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081023153200-gc1bfx89hj35c799
Tags: 2008.10.10-123053-2
* Correcting typo in dh_installinit call.
* Downgrading depends on module-assistant to recommends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
 *      data in the provided out parameters. 
76
76
 *
77
77
 * Results:
78
 
 *      Lots. 
 
78
 *      TRUE if successful, FALSE otherwise.
79
79
 *
80
80
 * Side effects:
81
 
 *      Reads PNG from disk. 
 
81
 *      Reads a PNG image from memory.
82
82
 *
83
83
 *----------------------------------------------------------------------------
84
84
 */
86
86
Bool 
87
87
ImageUtil_ReadPNGBuffer(ImageInfo *image,          // OUT
88
88
                        const unsigned char *data, // IN
89
 
                        size_t dataLen)            // IN
 
89
                        size_t dataLen,            // IN
 
90
                        int pngReadFlags)          // IN
90
91
{
91
92
   png_structp png_ptr;
92
93
   png_infop info_ptr;
104
105
      return FALSE;
105
106
   }
106
107
 
 
108
   memset(image, 0, sizeof *image);
 
109
 
107
110
   pngData = Util_SafeCalloc(1, sizeof *pngData);
108
111
   pngData->data = (char *) data;
109
112
   pngData->offset = 0;
150
153
   bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
151
154
 
152
155
   if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
153
 
      /*
154
 
       * Strip out alpha
155
 
       */
156
 
      png_set_strip_alpha(png_ptr);
157
 
 
158
 
      /* Update the bytes_per_line now that we've eliminated the alpha channel */
159
 
      png_read_update_info(png_ptr, info_ptr);
160
 
      bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
161
 
 
162
 
      png_get_IHDR(png_ptr, info_ptr, 
163
 
                   &width, &height, 
164
 
                   &channel_depth, &color_type, &interlace_type, 
165
 
                   &compression_type, &filter_type);
166
 
      image->bpp = 24;
 
156
      image->depth = 24;
 
157
      if (pngReadFlags & IMAGE_PNG_READ_KEEP_ALPHA) {
 
158
         image->bpp = 32;
 
159
      } else {
 
160
         png_set_strip_alpha(png_ptr);
 
161
 
 
162
         /* Update the bytes_per_line now that we've eliminated the alpha channel */
 
163
         png_read_update_info(png_ptr, info_ptr);
 
164
         bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
 
165
 
 
166
         png_get_IHDR(png_ptr, info_ptr, 
 
167
                      &width, &height, 
 
168
                      &channel_depth, &color_type, &interlace_type, 
 
169
                      &compression_type, &filter_type);
 
170
 
 
171
         image->bpp = 24;
 
172
      }
 
173
 
167
174
   } else if (color_type == PNG_COLOR_TYPE_RGB) {
168
 
      image->bpp = 24;  
 
175
      image->depth = image->bpp = 24;  
169
176
   } else if (color_type == PNG_COLOR_TYPE_PALETTE) {
170
177
      /*
171
178
       * Load palette
176
183
         bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
177
184
      }
178
185
 
179
 
      image->bpp = 8; 
 
186
      image->depth = image->bpp = 8; 
180
187
 
181
188
      png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
182
189
      ASSERT(num_palette <= 256); 
194
201
      goto exit;
195
202
   }
196
203
 
 
204
   ASSERT(image->depth != 0);
 
205
   ASSERT(image->bpp != 0);
 
206
 
197
207
   image->width = width;
198
208
   image->height = height;
199
209
   image->bytesPerLine = DWORD_ALIGN(bytes_per_line);
200
 
   image->depth = image->bpp;
201
210
   image->flags = 0;
202
211
 
203
212
   /* BGR instead of RGB - Intel byte-order is backwards */
289
298
                             DynBuf *imageData)      // OUT
290
299
 
291
300
{
292
 
   ImagePngOptions options;
 
301
   ImagePngWriteOptions options;
293
302
 
294
303
   options.zlibCompressLevel = -1;
295
304
   options.stripAlphaChannel = TRUE;
317
326
 */
318
327
 
319
328
Bool
320
 
ImageUtil_ConstructPNGBufferEx(const ImageInfo *image,         // IN
321
 
                               const ImagePngOptions *options, // IN
322
 
                               DynBuf *imageData)              // OUT
 
329
ImageUtil_ConstructPNGBufferEx(const ImageInfo *image,              // IN
 
330
                               const ImagePngWriteOptions *options, // IN
 
331
                               DynBuf *imageData)                   // OUT
323
332
{
324
333
   png_structp png_ptr;
325
334
   png_infop info_ptr;
475
484
      data = Util_SafeMalloc(bytes_per_line * image->height);
476
485
 
477
486
      Raster_ConvertPixels(data, bytes_per_line, 24,
478
 
                           image->data, image->bytesPerLine, image->depth,
 
487
                           image->data, image->bytesPerLine,
 
488
                           Raster_GetBPPDepth(image->depth, image->bpp),
479
489
                           FALSE, NULL, 0, 0, 0, 0,
480
490
                           image->width, image->height);
481
491
   }