-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pinfort/feature-separated
ファイルに分けてわかりやすく
- Loading branch information
Showing
19 changed files
with
620 additions
and
433 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from markers import Markers | ||
from segments.SOI import SOI | ||
from segments.EOI import EOI | ||
from segments.SOF import SOF | ||
from segments.DQT import DQT | ||
from segments.DHT import DHT | ||
from segments.COM import COM | ||
from segments.APP import APP | ||
from segments.SOS import SOS | ||
|
||
class analyzeSegment(object): | ||
def __init__(self): | ||
super(analyzeSegment, self).__init__() | ||
|
||
def analyze(self, marker, body): | ||
if marker == Markers.JUST_FF: | ||
return None | ||
if marker == Markers.SOI: | ||
# SOI (FFD8) has no body | ||
return SOI().analyze(marker, body) | ||
elif marker == Markers.EOI: | ||
# EOI (FFD9) has no body | ||
return EOI().analyze(marker, body) | ||
if marker in Markers.SOF: | ||
# do sof | ||
return SOF().analyze(marker, body) | ||
elif marker == Markers.DQT: | ||
# do dqt | ||
return DQT().analyze(marker, body) | ||
elif marker == Markers.DHT: | ||
# do dht | ||
return DHT().analyze(marker, body) | ||
elif marker == Markers.DRI: | ||
# do dri | ||
pass | ||
elif marker == Markers.COM: | ||
# do com | ||
return COM().analyze(marker, body) | ||
elif marker in Markers.APP: | ||
# do app | ||
return APP().analyze(marker, body) | ||
elif marker == Markers.SOS: | ||
# do sos | ||
return SOS().analyze(marker, body) | ||
elif marker in Markers.RST: | ||
# do rst | ||
pass | ||
else: | ||
raise ValueError(str(b'\xFF') + str(marker.to_bytes(1, 'big')) + " is not supported marker") | ||
return { | ||
"segmentName": "Not Implemented", | ||
"length": 0, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from markers import Markers | ||
|
||
class File(object): | ||
IS_SCANNING = False | ||
IMAGES = [] | ||
IMG_DATA = [] | ||
|
||
def __init__(self, path): | ||
super(File, self).__init__() | ||
self.f = open(path, 'rb') | ||
|
||
def __del__(self): | ||
self.f.close() | ||
|
||
def getData(self, count): | ||
bt = list(self.f.read(count)) | ||
if self.IS_SCANNING: | ||
self.IMG_DATA.extend(bt) | ||
return bt | ||
|
||
def __getSegmentBodyLength(self, length_for_length_data): | ||
length = 0 | ||
for i in range(length_for_length_data): | ||
length = length + (self.getData(1)[0] * (0x100 ** (length_for_length_data - i - 1))) | ||
return length - length_for_length_data | ||
|
||
def __getSegmentBody(self, length_for_length_data = 2): | ||
body_length = self.__getSegmentBodyLength(length_for_length_data) | ||
return self.getData(body_length) | ||
|
||
# return dict | ||
def getSegment(self, marker): | ||
if marker not in Markers.REGISTERED_MARKERS: | ||
raise Exception("unexpected marker found. it's not supported.") | ||
if marker != Markers.JUST_FF: | ||
# データの最後にマーカー(2ビット)がついているので末尾2ビット削除 | ||
self.IMG_DATA = self.IMG_DATA[0:len(self.IMG_DATA) - 2] | ||
self.IMAGES.append(self.IMG_DATA) | ||
self.IMG_DATA = [] | ||
self.IS_SCANNING = False | ||
if marker in [Markers.JUST_FF, Markers.SOI, Markers.EOI]: | ||
return { | ||
"marker": marker, | ||
"body": None, | ||
} | ||
body = self.__getSegmentBody() | ||
if marker == Markers.SOS: | ||
self.IS_SCANNING = True | ||
return { | ||
"marker": marker, | ||
"body": body, | ||
} |
Oops, something went wrong.