blob: 7e15a52cd66c1da16bbea39a0e9316ba2303cd2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# SPDX-License-Identifier: Apache-2.0
# Copyright 2018-2021 The glTF-Blender-IO authors.
import re
class ImageData:
"""Contains encoded images"""
# FUTURE_WORK: as a method to allow the node graph to be better supported, we could model some of
# the node graph elements with numpy functions
def __init__(self, data: bytes, mime_type: str, name: str):
self._data = data
self._mime_type = mime_type
self._name = name
def __eq__(self, other):
return self._data == other.data
def __hash__(self):
return hash(self._data)
def adjusted_name(self):
regex_dot = re.compile("\.")
adjusted_name = re.sub(regex_dot, "_", self.name)
new_name = "".join([char for char in adjusted_name if char not in "!#$&'()*+,/:;<>?@[\]^`{|}~"])
return new_name
@property
def data(self):
return self._data
@property
def name(self):
return self._name
@property
def file_extension(self):
if self._mime_type == "image/jpeg":
return ".jpg"
return ".png"
@property
def byte_length(self):
return len(self._data)
|