Skip to content

Commit 1f38624

Browse files
committed
perf: EXRHeader에 변경사항을 적용하다
1 parent e16848b commit 1f38624

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

openexr_python/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@
99

1010
__version__ = "0.0.0" # dynamic
1111

12-
from .exr_enums import *
13-
from .exr_channel_info import *
14-
from .exr_channel_sampling_rate import *
1512
from .exr_header import *
1613
from .exr_window import *

openexr_python/exr_header.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,63 @@
11
from dataclasses import dataclass
2-
from typing import Any, Dict, Tuple
3-
from openexr_python.exr_enums import EXRCompressionType, EXRLineOrderType
4-
from openexr_python.exr_channel_info import EXRChannelInfo
5-
from openexr_python.exr_window import EXRWindow
2+
from typing import Any, Dict
3+
import OpenEXR
4+
import Imath
65

76

87
@dataclass
98
class EXRHeader:
10-
_header_raw_dict: Dict[str, Any]
9+
raw_header: Dict[str, Any]
1110

1211
def __getitem__(self, key: str) -> Any:
13-
return self._header_raw_dict[key]
12+
return self.raw_header[key]
13+
14+
def add_channel(self, channel_name: str, channel_info: Imath.Channel):
15+
self.channels[channel_name] = channel_info
16+
17+
def remove_channel(self, channel_name: str):
18+
self.channels.pop(channel_name)
1419

1520
@property
16-
def channels(self) -> Dict[str, EXRChannelInfo]:
17-
raw_channels: Dict[str, Any] = self["channels"]
18-
return {
19-
key: EXRChannelInfo.parse_raw2pyobj(raw_channel_info=value)
20-
for key, value in raw_channels.items()
21-
}
21+
def channels(self) -> Dict[str, Imath.Channel]:
22+
raw_channels: Dict[str, Imath.Channel] = self["channels"]
23+
return raw_channels
2224

2325
@property
24-
def compression(self) -> EXRCompressionType:
25-
raw_compression: Any = self["compression"]
26-
return EXRCompressionType.parse_raw2pyobj(raw_compression=raw_compression)
26+
def compression(self) -> Imath.Compression:
27+
raw_compression: Imath.Compression = self["compression"]
28+
return raw_compression
2729

2830
@property
29-
def data_window(self) -> EXRWindow:
30-
raw_dataWindow: Any = self["dataWindow"]
31-
return EXRWindow.parse_raw_to_window(raw_dataWindow)
31+
def data_window(self) -> Imath.Box2i:
32+
raw_dataWindow: Imath.Box2i = self["dataWindow"]
33+
return raw_dataWindow
3234

3335
@property
34-
def display_window(self) -> EXRWindow:
35-
raw_dataWindow: Any = self["displayWindow"]
36-
return EXRWindow.parse_raw_to_window(raw_dataWindow)
36+
def display_window(self) -> Imath.Box2i:
37+
raw_dataWindow: Imath.Box2i = self["displayWindow"]
38+
return raw_dataWindow
3739

3840
@property
39-
def line_order(self) -> EXRLineOrderType:
40-
raw_line_order: Any = self["lineOrder"]
41-
return EXRLineOrderType.parse_raw2pyobj(raw_line_order=raw_line_order)
41+
def line_order(self) -> Imath.LineOrder:
42+
raw_line_order: Imath.LineOrder = self["lineOrder"]
43+
return raw_line_order
4244

4345
@property
4446
def pixel_aspect_ratio(self) -> float:
4547
raw_pixel_aspect_ratio: float = self["pixelAspectRatio"]
4648
return raw_pixel_aspect_ratio
4749

4850
@property
49-
def screen_window_center(self) -> Tuple[float, float]:
50-
raw_screen_window_center: Any = self["screenWindowCenter"]
51-
return (raw_screen_window_center.x, raw_screen_window_center.y)
51+
def screen_window_center(self) -> Imath.V2f:
52+
raw_screen_window_center: Imath.V2f = self["screenWindowCenter"]
53+
return raw_screen_window_center
5254

5355
@property
5456
def screen_window_width(self) -> float:
5557
raw_screen_window_width: float = self["screenWindowWidth"]
5658
return raw_screen_window_width
59+
60+
@classmethod
61+
def create_header(cls, width: int, height: int):
62+
raw_header = OpenEXR.Header(width, height)
63+
return EXRHeader(raw_header=raw_header)

0 commit comments

Comments
 (0)