Last active
March 7, 2020 18:39
-
-
Save hal1932/268382f982a8d7ce27b8388aec195040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sqlite3 | |
from contextlib import closing | |
from PySide2.QtCore import QByteArray, QBuffer, QIODevice | |
from PySide2.QtGui import QImage | |
import timeit | |
source = QImage('test.png') | |
# print(timeit.timeit(lambda: source.save('testaaa.png'), number=100)) | |
bits = source.constBits() | |
width = source.width() | |
height = source.height() | |
bytes_per_line = source.bytesPerLine() | |
format = source.format() | |
db_file = 'test2.db' | |
if os.path.isfile(db_file): | |
os.remove(db_file) | |
with closing(sqlite3.connect(db_file)) as conn: | |
cursor = conn.cursor() | |
cursor.execute('create table images (width int, height int, bytes_per_line int, format int, bytes blob)') | |
for i in range(100): | |
cursor.execute( | |
'insert into images (width, height, bytes_per_line, format, bytes) values (?, ?, ?, ?, ?)', | |
[width, height, bytes_per_line, int(format), bits]) | |
conn.commit() | |
with closing(sqlite3.connect(db_file)) as conn: | |
cursor = conn.cursor() | |
def load(): | |
for i, (width, height, bytes_per_line, format, bytes) in enumerate(cursor.execute('select width, height, bytes_per_line, format, bytes from images')): | |
image = QImage(bytes, width, height, bytes_per_line, QImage.Format(format)) | |
# print(len(image.bits()), image.format()) | |
image.save(f'test_out/test_out_{i}.png') | |
print(timeit.timeit(load, number=10)) | |
# load() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment