1 Star 5 Fork 3

独一无二/CAJ_PDF_Word转换工具

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
jbigdec.py 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
独一无二 提交于 2023-03-06 10:37 . main
from ctypes import *
import os
import struct
import platform
arch = platform.architecture()
if (arch[1] == 'WindowsPE'):
if (arch[0] == '64bit'):
libjbigdec = cdll.LoadLibrary("./lib/bin/libjbigdec-w64.dll")
else:
libjbigdec = cdll.LoadLibrary("./lib/bin/libjbigdec-w32.dll")
else:
libjbigdec = cdll.LoadLibrary("./libjbigdec.so")
#SaveJbigAsBmp = libjbigdec.SaveJbigAsBmp
#SaveJbigAsBmp.restype = None
#SaveJbigAsBmp.argtypes = [c_void_p, c_int, c_char_p]
#SaveJbig2AsBmp = libjbigdec.SaveJbig2AsBmp
#SaveJbig2AsBmp.restype = None
#SaveJbig2AsBmp.argtypes = [c_void_p, c_int, c_char_p]
jbigDecode = libjbigdec.jbigDecode
jbigDecode.restype = None
jbigDecode.argtypes = [c_void_p, c_int, c_int, c_int, c_int, c_void_p]
class CImage:
def __init__(self, buffer):
self.buffer = buffer
self.buffer_size=len(buffer)
(self.width, self.height,
self.num_planes, self.bits_per_pixel) = struct.unpack("<IIHH", buffer[4:16])
self.bytes_per_line = ((self.width * self.bits_per_pixel + 31) >> 5) << 2
def DecodeJbig(self):
out = create_string_buffer(self.height * self.bytes_per_line)
jbigDecode(self.buffer[48:], self.buffer_size-48, self.height, self.width, self.bytes_per_line, out)
return out
if __name__ == '__main__':
import sys, os
if len(sys.argv) < 3:
print("Usage: %s input output" % sys.argv[0])
sys.exit()
f = open(sys.argv[1], "rb")
buffer_size = os.stat(sys.argv[1]).st_size
buffer = f.read()
#SaveJbigAsBmp(buffer, buffer_size, sys.argv[2].encode("ascii"))
cimage = CImage(buffer)
out = cimage.DecodeJbig()
# PBM is only padded to 8 rather than 32.
# If the padding is larger, write padded file.
width = cimage.width
if (cimage.bytes_per_line > ((cimage.width +7) >> 3)):
width = cimage.bytes_per_line << 3
fout = open(sys.argv[2].replace(".bmp", ".pbm"), "wb")
fout.write("P4\n".encode("ascii"))
fout.write(("%d %d\n" % (width, cimage.height)).encode("ascii"))
fout.write(out)
fout.close()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wanglidong666/caj--pdf--word-conversion-tool.git
git@gitee.com:wanglidong666/caj--pdf--word-conversion-tool.git
wanglidong666
caj--pdf--word-conversion-tool
CAJ_PDF_Word转换工具
WLD

搜索帮助