资源简介
Apple 对 iPhone 应用程序中的 png 图片进行了特殊的处理,在 png 文件头之后加了一个非标准的 CgBI 数据段,IDAT 段图像数据也没有传统的压缩数据头和尾,并且红色和蓝色是反的,这样就无法在 Mac 或 Windows 正常使用了。将本python文件放于导出的png文件目录下,并执行python ipin.py,可用将png图片还原正常。
代码片段和文件信息
#---
# iPIN - iPhone PNG Images Normalizer v1.0
# Copyright (C) 2007
#
# Author:
# Axel E. Brzostowski
# http://www.axelbrz.com.ar/
# axelbrz@gmail.com
#
# References:
# http://iphone.fiveforty.net/wiki/index.php/PNG_Images
# http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html
#
# Changes:
# 2011.6.14. handle cases of multiple IDAT chunks
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation either version 3 of the License.
#
# This program is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#---
from struct import *
from zlib import *
import stat
import sys
import os
def getNormalizedPNG(filename):
pngheader = “\x89PNG\r\n\x1a\n“
file = open(filename “rb“)
oldPNG = file.read()
file.close()
if oldPNG[:8] != pngheader:
return None
newPNG = oldPNG[:8]
chunkPos = len(newPNG)
pendingIDATChunks = []
# For each chunk in the PNG file
while chunkPos < len(oldPNG):
# Reading chunk
chunkLength = oldPNG[chunkPos:chunkPos+4]
chunkLength = unpack(“>L“ chunkLength)[0]
chunkType = oldPNG[chunkPos+4 : chunkPos+8]
chunkData = oldPNG[chunkPos+8:chunkPos+8+chunkLength]
chunkCRC = oldPNG[chunkPos+chunkLength+8:chunkPos+chunkLength+12]
chunkCRC = unpack(“>L“ chunkCRC)[0]
chunkPos += chunkLength + 12
# Parsing the header chunk
if chunkType == “IHDR“:
width = unpack(“>L“ chunkData[0:4])[0]
height = unpack(“>L“ chunkData[4:8])[0]
# Parsing the image chunk
if chunkType == “IDAT“:
try:
# Uncompressing the image chunk
bufSize = width * height * 4 + height
if pendingIDATChunks:
chunkData = decompress( ‘‘.join(pendingIDATChunks) + chunkData -8 bufSize)
else:
chunkData = decompress( chunkData -8 bufSize)
except Exception e:
# The PNG image is normalized
pendingIDATChunks.append(chunkData)
continue
else:
pendingIDATChunks = []
# Swapping red & blue bytes for each pixel
newdata = ““
for y in xrange(height):
i = len(newdata)
newdata += chunkData[i]
for x in xrange(width):
i = len(newdata)
- 上一篇:线性回归做房价预测 python源码
- 下一篇:进程管理实验
相关资源
- csv文件行列转换python实现代码
- ENU与WGS84相互转换,基于python与matla
- python坐标转换程序
- python 实现KML转换为Excel的工具
- 编写高质量代码改善Python程序的91个建
- excel批量转换成txt文件的转换工具
- matlab代码转换为python代码
- 遥感格式转换工具FWTools247
- dbc文件转excel
- 基于VGG模型的图片风格转换
- 百度坐标转WGS84坐标程序
- 基于python实现把json数据转换成Excel表
- Python3中的2to3转换工具使用
- 度分秒与十进制批量转换
- 图片转换成字符画源码文件
- widerFace转VOC格式标注工具
- python实现百度坐标和世界经纬度坐标
- Python读取Las与转换为TXT.zip
- 大地坐标转换为空间直角坐标
- Python 球面墨卡托投影和地体坐标大批
- Qt界面文件(.ui)和资源文件(.qrc)
- Python将Excel网络关系转换为邻接矩阵
- 将mat文件转换成lmdb文件,用于caffe
- 基于python语言的坐标信息转换为shap
-
txt数据集转VOC格式xm
l系列程序全 - 操作系统课程设计-进程状态模拟转换
- 中间代码生成代码中缀表达式转换为
- json_to_dataset.py labelme json批量转化
- 四行Python代码实现将word文件转换为
- QT文件转换成Python的自动化工具*.ui转
评论
共有 条评论