Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions invokeai/backend/image_util/imwatermark/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# `opencv-contrib-python`. It's easier to copy the code over than complicate the installation process by
# requiring an extra post-install step of removing `opencv-python` and installing `opencv-contrib-python`.

import struct
import uuid
import base64
import uuid

import cv2
import numpy as np
import pywt
Expand Down Expand Up @@ -111,14 +111,12 @@ def __init__(self, wm_type="bytes", length=0):
raise NameError("%s is unsupported" % wm_type)

def reconstruct_ipv4(self, bits):
ips = [str(ip) for ip in list(np.packbits(bits))]
return ".".join(ips)
packed = np.packbits(bits)
return "{}.{}.{}.{}".format(packed[0], packed[1], packed[2], packed[3])

def reconstruct_uuid(self, bits):
nums = np.packbits(bits)
bstr = b""
for i in range(16):
bstr += struct.pack(">B", nums[i])
bstr = bytes(nums[:16])

return str(uuid.UUID(bytes=bstr))

Expand All @@ -132,10 +130,10 @@ def reconstruct_b16(self, bits):

def reconstruct_bytes(self, bits):
nums = np.packbits(bits)
bstr = b""
for i in range(self._wmLen // 8):
bstr += struct.pack(">B", nums[i])
return bstr
# Equivalent to b''.join(struct.pack(">B", nums[i]) for i in range(self._wmLen // 8))
# Since all can be packed in one go:
end_idx = self._wmLen // 8
return bytes(nums[:end_idx])

def reconstruct(self, bits):
if len(bits) != self._wmLen:
Expand Down