blob: 89f5add929df0b85c35ba28259b68fdfbd6a78cc (
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
45
46
47
48
49
50
51
52
53
54
55
56
|
# Copyright 2018 The glTF-Blender-IO authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
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)
|