Skip to content

Commit

Permalink
Update ipsw-patch/ibootim.c
Browse files Browse the repository at this point in the history
Removed deprecated libpng struct errors. It will now build on the latest libpng.
  • Loading branch information
squiffy committed Mar 4, 2013
1 parent 4fe9edd commit 65cbc2d
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions ipsw-patch/ibootim.c
Expand Up @@ -256,7 +256,7 @@ int convertToPNG(AbstractFile* imageWrapper, const unsigned int* key, const unsi


png_bytepp row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info->header.height); png_bytepp row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info->header.height);
int i; int i;
for(i = 0; i < info_ptr->height; i++) { for(i = 0; i < png_get_image_height(png_ptr, info_ptr); i++) {
row_pointers[i] = imageBuffer + (info->header.width * bytes_per_pixel * i); row_pointers[i] = imageBuffer + (info->header.width * bytes_per_pixel * i);
} }


Expand Down Expand Up @@ -317,15 +317,15 @@ void* replaceBootImage(AbstractFile* imageWrapper, const unsigned int* key, cons


png_read_info(png_ptr, info_ptr); png_read_info(png_ptr, info_ptr);


if(info_ptr->bit_depth > 8) { if(png_get_bit_depth(png_ptr, info_ptr) > 8) {
XLOG(0, "warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", info_ptr->bit_depth); XLOG(0, "warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", png_get_bit_depth(png_ptr, info_ptr));
} }


if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) { if(png_get_color_type(png_ptr,info_ptr) == PNG_COLOR_TYPE_GRAY || png_get_color_type(png_ptr,info_ptr) == PNG_COLOR_TYPE_RGB) {
XLOG(0, "notice: attempting to add dummy transparency channel\n"); XLOG(0, "notice: attempting to add dummy transparency channel\n");
} }


if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { if(png_get_color_type(png_ptr,info_ptr) == PNG_COLOR_TYPE_PALETTE) {
XLOG(0, "notice: attempting to expand palette into full rgb\n"); XLOG(0, "notice: attempting to expand palette into full rgb\n");
} }


Expand All @@ -338,35 +338,35 @@ void* replaceBootImage(AbstractFile* imageWrapper, const unsigned int* key, cons
png_read_update_info(png_ptr, info_ptr); png_read_update_info(png_ptr, info_ptr);




if(info_ptr->width > 320 || info_ptr->height > 480) { if(png_get_image_width(png_ptr, info_ptr) > 320 || png_get_image_height(png_ptr, info_ptr) > 480) {
XLOG(0, "error: dimensions out of range, must be within 320x480, not %lux%lu\n", info_ptr->width, info_ptr->height); XLOG(0, "error: dimensions out of range, must be within 320x480, not %lux%lu\n", png_get_image_width(png_ptr, info_ptr), png_get_image_height(png_ptr, info_ptr));
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL; return NULL;
} }


if(info_ptr->bit_depth != 8) { if(png_get_bit_depth(png_ptr, info_ptr) != 8) {
XLOG(0, "error: bit depth per channel must be 8 not %d!\n", info_ptr->bit_depth); XLOG(0, "error: bit depth per channel must be 8 not %d!\n", png_get_bit_depth(png_ptr, info_ptr));
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL; return NULL;
} }


if(info_ptr->color_type != PNG_COLOR_TYPE_GRAY_ALPHA && info_ptr->color_type != PNG_COLOR_TYPE_RGB_ALPHA) { if(png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_GRAY_ALPHA && png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGB_ALPHA) {
XLOG(0, "error: incorrect color type, must be greyscale with alpha, or rgb with alpha\n"); XLOG(0, "error: incorrect color type, must be greyscale with alpha, or rgb with alpha\n");
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) { if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY || png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
XLOG(0, "It appears you're missing an alpha channel. Add transparency to your image\n"); XLOG(0, "It appears you're missing an alpha channel. Add transparency to your image\n");
} }
if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
XLOG(0, "This PNG is saved with the palette color type rather than ARGB.\n"); XLOG(0, "This PNG is saved with the palette color type rather than ARGB.\n");
} }
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);


return NULL; return NULL;
} }


row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info_ptr->height); row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * png_get_image_height(png_ptr, info_ptr));
imageBuffer = malloc(info_ptr->height * info_ptr->rowbytes); imageBuffer = malloc(png_get_image_height(png_ptr, info_ptr) * png_get_rowbytes(png_ptr, info_ptr));
for(i = 0; i < info_ptr->height; i++) { for(i = 0; i < png_get_image_height(png_ptr, info_ptr); i++) {
row_pointers[i] = imageBuffer + (info_ptr->rowbytes * i); row_pointers[i] = imageBuffer + (png_get_rowbytes(png_ptr, info_ptr) * i);
} }


png_read_image(png_ptr, row_pointers); png_read_image(png_ptr, row_pointers);
Expand All @@ -382,15 +382,15 @@ void* replaceBootImage(AbstractFile* imageWrapper, const unsigned int* key, cons
} }
info = (InfoIBootIM*) (imageFile->data); info = (InfoIBootIM*) (imageFile->data);


info->header.width = (uint16_t) info_ptr->width; info->header.width = (uint16_t) png_get_image_width(png_ptr, info_ptr);
info->header.height = (uint16_t) info_ptr->height; info->header.height = (uint16_t) png_get_image_height(png_ptr, info_ptr);
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA) {
info->header.format = IBOOTIM_GREY; info->header.format = IBOOTIM_GREY;
} else { } else {
info->header.format = IBOOTIM_ARGB; info->header.format = IBOOTIM_ARGB;
} }


imageFile->write(imageFile, imageBuffer, info_ptr->height * info_ptr->rowbytes); imageFile->write(imageFile, imageBuffer, png_get_image_height(png_ptr, info_ptr) * png_get_rowbytes(png_ptr, info_ptr));


imageFile->close(imageFile); imageFile->close(imageFile);


Expand All @@ -403,5 +403,4 @@ void* replaceBootImage(AbstractFile* imageWrapper, const unsigned int* key, cons
free(imageBuffer); free(imageBuffer);


return buffer; return buffer;
} }

0 comments on commit 65cbc2d

Please sign in to comment.