def parsePage(cls, aInputFile):

        header = URFPageHeader.URFPageHeader.parse(aInputFile)

        reader = FileUtils.FileUtils(aInputFile)
        pixels = PixelUtils.PixelUtils(aInputFile, header.bitsPerPixel,
                                       header.colorSpace)

        # current line in image
        im = PIL.Image.new('RGB', (header.pageWidth, header.pageHeight))
        pix = im.load()
        currentLine = 0
        while currentLine < header.pageHeight:
            # get number of times to repeat line: + 1 because
            # we want to write the line at least once
            lineRepeatCount = reader.char() + 1

            # parse line info
            line = cls._parseLine(header, reader, pixels)

            # write line
            for i in range(0, lineRepeatCount):
                for x in range(0, len(line) / 3):
                    pix[x, currentLine] = (line[x * 3], line[x * 3 + 1],
                                           line[x * 3 + 2])
                # increment line index
                currentLine += 1

        # create a page from the data
        return URFPage(header, im)
Beispiel #2
0
def evaluate(evaluation_id):
    datastore_client = datastore.Client()
    storage_client = storage.Client()
    file_utils = FileUtils.FileUtils(evaluation_id)
    helper = Helper.Helper()

    evaluation_obj_key = datastore_client.key(GPC_DATASTORE_KIND_EVALUATION,
                                              int(evaluation_id))
    evaluation_obj = datastore_client.get(evaluation_obj_key)
    if evaluation_obj is None:
        return ("Invalid evaluation_id in body! The evaluation doesn't exist!",
                400)

    problem_id = int(evaluation_obj['problemId'])
    problem_obj_key = datastore_client.key(GPC_DATASTORE_KIND_PROBLEM,
                                           problem_id)
    problem_obj = datastore_client.get(problem_obj_key)
    if problem_obj is None:
        return (
            "Internal logic error! The evaluation contains an invalid problem_id!",
            500)

    evaluation_args = EvaluationArgsBuilder.EvaluationArgsBuilder() \
        .with_datastore_client(datastore_client) \
        .with_storage_client(storage_client) \
        .with_file_utils(file_utils) \
        .with_evaluation_id(evaluation_id) \
        .with_evaluation_obj(evaluation_obj) \
        .with_problem_obj(problem_obj) \
        .with_helper(helper) \
        .build()

    evaluation: EvaluationBase = None

    language = evaluation_obj['lang']
    if language == 'C++':
        evaluation = EvaluationCpp(evaluation_args)
    elif language == 'Python':
        evaluation = EvaluationPython(evaluation_args)
    elif language == 'C':
        evaluation = EvaluationC(evaluation_args)

    if evaluation is None:
        return (
            "Internal logic error! The evaluation contains an invalid programming language!",
            500)

    evaluation.init_evaluation()
    evaluation.evaluate()
    return evaluation.finish_evaluation()
    def encode(cls, pages, output_path):

        output_file = open(output_path, 'wb')

        writer = FileUtils.FileUtils(output_file)

        # write doc header
        output_file.write('UNIRAST')
        writer.write_char(0)

        # write page count
        writer.write_int(len(pages))

        for i in pages:
            i.encode(output_file)

        output_file.close()
    def encode(self, output_file):

        writer = FileUtils.FileUtils(output_file)

        writer.write_char(self.bitsPerPixel)
        writer.write_char(self.colorSpace)
        writer.write_char(self.isDuplex)
        writer.write_char(self.quality)

        writer.write_int(0)
        writer.write_int(0)

        writer.write_int(self.pageWidth)
        writer.write_int(self.pageHeight)
        writer.write_int(self.resolution)

        writer.write_int(0)
        writer.write_int(0)
    def encode(self, output_file):

        self.header.encode(output_file)

        writer = FileUtils.FileUtils(output_file)
        pix = self.image.load()
        for y in range(0, self.header.pageHeight):
            x = 0
            while x < self.header.pageWidth:
                left = self.header.pageWidth - x
                step = 128
                if left < 128:
                    step = left

                writer.write_schar(-(step - 1))

                while step > 0:
                    writer.write_char(pix[x, y][0])
                    writer.write_char(pix[x, y][1])
                    writer.write_char(pix[x, y][2])
                    x += 1
                    step -= 1
    def parse(cls, aFile):

        # create a reader for simplicity
        reader = FileUtils.FileUtils(aFile)

        bitsPerPixel = reader.char()
        colorSpace = reader.char()
        duplexMode = reader.char()
        quality = reader.char()

        # unknown data
        aFile.read(8)

        pageWidth = reader.int()
        pageHeight = reader.int()
        resolution = reader.int()

        # unknown data
        aFile.read(8)

        fillColor = 0xffffffff

        return URFPageHeader(bitsPerPixel, colorSpace, duplexMode, quality,
                             pageWidth, pageHeight, resolution, fillColor)
 def __init__(self, aFile, aBitDepth, aColorSpace):
     self.file = aFile
     self.reader = FileUtils.FileUtils(aFile)
     self.depth = aBitDepth
     self.colorSpace = aColorSpace