{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 b4a71505ff
commit 5f0328d1d2
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)): for numRow in range(len(canvasStore.outMap)):
if len(canvasStore.outMap[numRow]) != numRowCols: if len(canvasStore.outMap[numRow]) != numRowCols:
for numColOff in range(numRowCols - len(canvasStore.outMap[numRow])): for numColOff in range(numRowCols - len(canvasStore.outMap[numRow])):
canvasStore.outMap[numRow].append([[1, 1], 0, " "]) canvasStore.outMap[numRow].append([1, 1, 0, " "])
canvasStore.outMap[numRow].insert(0, [[1, 1], 0, " "]) canvasStore.outMap[numRow].insert(0, [1, 1, 0, " "])
canvasStore.outMap[numRow].append([[1, 1], 0, " "]) canvasStore.outMap[numRow].append([1, 1, 0, " "])
canvasStore.outMap.insert(0, [[[1, 1], 0, " "]] * len(canvasStore.outMap[0])) canvasStore.outMap.insert(0, [[1, 1, 0, " "]] * len(canvasStore.outMap[0]))
canvasStore.outMap.append([[[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) MiRCARTToPngFile(canvasStore.outMap, "DejaVuSansMono.ttf", 11).export(imgTmpFilePath)
imgurResponse = self._uploadToImgur(imgTmpFilePath, "MiRCART image", "MiRCART image", "c9a6efb3d7932fd") imgurResponse = self._uploadToImgur(imgTmpFilePath, "MiRCART image", "MiRCART image", "c9a6efb3d7932fd")
if imgurResponse[0] == 200: if imgurResponse[0] == 200:

View File

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