{IrcMiRCARTBot,MiRCARTToPngFile}.py: reduce memory usage by folding nested patch {coordinate,colour} list(s).

Followup to <b4a71505ffa68757931f633baf511f7863682e8e>.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-30 20:34:02 +01:00
parent 6d5e081dfb
commit 8e91d1269e
2 changed files with 22 additions and 22 deletions

View File

@ -148,11 +148,11 @@ class IrcMiRCARTBot(IrcClient.IrcClient):
for numRow in range(len(canvasStore.outMap)):
if len(canvasStore.outMap[numRow]) != numRowCols:
for numColOff in range(numRowCols - len(canvasStore.outMap[numRow])):
canvasStore.outMap[numRow].append([[1, 1], 0, " "])
canvasStore.outMap[numRow].insert(0, [[1, 1], 0, " "])
canvasStore.outMap[numRow].append([[1, 1], 0, " "])
canvasStore.outMap.insert(0, [[[1, 1], 0, " "]] * len(canvasStore.outMap[0]))
canvasStore.outMap.append([[[1, 1], 0, " "]] * len(canvasStore.outMap[0]))
canvasStore.outMap[numRow].append([1, 1, 0, " "])
canvasStore.outMap[numRow].insert(0, [1, 1, 0, " "])
canvasStore.outMap[numRow].append([1, 1, 0, " "])
canvasStore.outMap.insert(0, [[1, 1, 0, " "]] * len(canvasStore.outMap[0]))
canvasStore.outMap.append([[1, 1, 0, " "]] * len(canvasStore.outMap[0]))
MiRCARTToPngFile(canvasStore.outMap, "DejaVuSansMono.ttf", 11).export(imgTmpFilePath)
imgurResponse = self._uploadToImgur(imgTmpFilePath, "MiRCART image", "MiRCART image", "c9a6efb3d7932fd")
if imgurResponse[0] == 200:

View File

@ -89,35 +89,35 @@ class MiRCARTToPngFile:
for inCurCol in range(len(self.inCanvasMap[inCurRow])):
inCurCell = self.inCanvasMap[inCurRow][inCurCol]
outColours = [0, 0]
if inCurCell[1] & MiRCARTCanvasImportStore.MiRCARTCanvasImportStore._CellState.CS_BOLD:
if inCurCell[2] != " ":
if inCurCell[2] == "":
outColours[1] = self._ColourMapNormal[inCurCell[0][0]]
if inCurCell[2] & MiRCARTCanvasImportStore.MiRCARTCanvasImportStore._CellState.CS_BOLD:
if inCurCell[3] != " ":
if inCurCell[3] == "":
outColours[1] = self._ColourMapNormal[inCurCell[0]]
else:
outColours[0] = self._ColourMapBold[inCurCell[0][0]]
outColours[1] = self._ColourMapNormal[inCurCell[0][1]]
outColours[0] = self._ColourMapBold[inCurCell[0]]
outColours[1] = self._ColourMapNormal[inCurCell[1]]
else:
outColours[1] = self._ColourMapNormal[inCurCell[0][1]]
outColours[1] = self._ColourMapNormal[inCurCell[1]]
else:
if inCurCell[2] != " ":
if inCurCell[2] == "":
outColours[1] = self._ColourMapNormal[inCurCell[0][0]]
if inCurCell[3] != " ":
if inCurCell[3] == "":
outColours[1] = self._ColourMapNormal[inCurCell[0]]
else:
outColours[0] = self._ColourMapNormal[inCurCell[0][0]]
outColours[1] = self._ColourMapNormal[inCurCell[0][1]]
outColours[0] = self._ColourMapNormal[inCurCell[0]]
outColours[1] = self._ColourMapNormal[inCurCell[1]]
else:
outColours[1] = self._ColourMapNormal[inCurCell[0][1]]
outColours[1] = self._ColourMapNormal[inCurCell[1]]
outImgDraw.rectangle((*outCurPos, \
outCurPos[0] + self.outImgFontSize[0], \
outCurPos[1] + self.outImgFontSize[1]), \
fill=(*outColours[1], 255))
if not inCurCell[2] in "" \
if not inCurCell[3] in "" \
and outColours[0] != outColours[1]:
# XXX implement italic
outImgDraw.text(outCurPos, \
inCurCell[2], (*outColours[0], 255), self.outImgFont)
if inCurCell[1] & MiRCARTCanvasImportStore.MiRCARTCanvasImportStore._CellState.CS_UNDERLINE:
outColours[0] = self._ColourMapNormal[inCurCell[0][0]]
inCurCell[3], (*outColours[0], 255), self.outImgFont)
if inCurCell[2] & MiRCARTCanvasImportStore.MiRCARTCanvasImportStore._CellState.CS_UNDERLINE:
outColours[0] = self._ColourMapNormal[inCurCell[0]]
self._drawUnderLine(outCurPos, \
self.outImgFontSize, \
outImgDraw, (*outColours[0], 255))