forked from scummvm-director/continuity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreview.py
89 lines (81 loc) · 2.93 KB
/
preview.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from PySide.QtCore import *
from PySide.QtGui import *
from dutils import *
from movie import *
class Preview(QWidget):
def __init__(self, parent, movie):
QWidget.__init__(self, parent)
parent.setBackgroundRole(QPalette.Dark)
self.movie = movie
self.resize(self.movie.movieRect.width(), self.movie.movieRect.height())
self.parent().parent().parent().parent().selectionChanged.connect(self.selectionChanged)
def selectionChanged(self):
self.update()
def paintEvent(self, ev):
if self.movie.currFrame == -1:
return
painter = QPainter(self)
palette = getPaletteFor(self.movie.currFrame, self.movie)
bgcol = self.movie.stageColor & (2**self.movie.colorDepth - 1)
if bgcol < len(palette)/4: # TODO: ??
painter.setBrush(QBrush(QColor(ord(palette[4*bgcol+2]), ord(palette[4*bgcol+1]), ord(palette[4*bgcol]))))
painter.drawRect(0, 0, self.movie.movieRect.width(), self.movie.movieRect.height())
painter.setBrush(QBrush())
for i in range(channelCount):
info = self.movie.frames[self.movie.currFrame].sprites[i+1]
if not info.enabled:
continue
myId = 1024 + info.castId
mystr = str(info.castId)
if myId in self.movie.dibs:
dib = self.movie.dibs[myId]
dib.seek(0)
data = dib.read()
imgdata = imageFromDIB(data, palette)
img = QImage.fromData(imgdata, "bmp")
pixmap = QPixmap.fromImage(img)
ink = info.flags & 0x3f
mask = None
if ink == 8: # matte
mask = img.createHeuristicMask()
if ink == 0x24: # background transparent
depth = ord(data[14])
if depth == 1:
if qGray(img.color(0)) >= qGray(img.color(1)):
# qt's bmp decoder deliberately sabotages the image in this case!
# see the swapPixel01 call in qbmphandler.cpp
colorkey = 0
else:
colorkey = 1
elif depth == 4:
colorkey = 15
else:
colorkey = 255
mask = QImage(img.size(), QImage.Format_Mono)
for x in range(img.size().width()):
for y in range(img.size().height()):
if img.pixelIndex(x, y) == colorkey:
mask.setPixel(x, y, 1)
else:
mask.setPixel(x, y, 0)
if mask:
bitmask = QBitmap.fromImage(mask)
pixmap.setMask(bitmask)
castinfo = self.movie.cast[info.castId]
offx = info.x + castinfo.initialRect.left - castinfo.regX
offy = info.y + castinfo.initialRect.top - castinfo.regY
painter.drawPixmap(offx, offy, pixmap)
if self.movie.currChannel != None and self.movie.currChannel > 0:
info = self.movie.frames[self.movie.currFrame].sprites[self.movie.currChannel]
pen = QPen("black")
pen.setStyle(Qt.PenStyle.DashDotLine)
painter.setPen(pen)
painter.setBackgroundMode(Qt.OpaqueMode)
castinfo = self.movie.cast[info.castId]
offx = info.x
offy = info.y
if castinfo.castType == castBitmap:
offx = offx + castinfo.initialRect.left - castinfo.regX
offy = offy + castinfo.initialRect.top - castinfo.regY
painter.drawRect(offx, offy, info.width, info.height)
return True