コード例 #1
0
 def munge_params(self):
     txtw, txth = self.txtwh()
     if self.param_interleave_dir() and self.param_interleaves() > 1:
         print("interleaving")
         self.map_cr2oi = td_interleave_hor(
             self.map_cr2oi,
             txtw,
             txth,
             interleaves=self.param_interleaves(),
             interleave_dir=self.param_interleave_dir(),
             word_bits=self.word_bits())
     if self.param_flipx():
         self.map_cr2oi = mrom.td_flipx(self.map_cr2oi, txtw, txth)
     if self.param_rotate():
         self.map_cr2oi, wnew, hnew = mrom.td_rotate2(
             self.param_rotate(), self.map_cr2oi, txtw, txth)
         # Anything other than 180 will take a lot more thought
         assert (txtw, txth) == (wnew, hnew)
コード例 #2
0
ファイル: solver.py プロジェクト: lopessec/zorrom
def guess_layout(txtdict_raw, wraw, hraw, word_bits, verbose=False):
    for invert in (0, 1):
        for rotate in 0, 90, 180, 270:
            # only one flip is needed
            # Second would cancel out / redundant with rotate
            for flipx in (0, 1):
                verbose and print("rotate %u, flipx %u" % (rotate, flipx))
                txtdict, txtw, txth = mrom.td_rotate2(rotate, txtdict_raw,
                                                      wraw, hraw)
                if flipx:
                    txtdict = mrom.td_flipx(txtdict, txtw, txth)
                if invert:
                    txtdict = mrom.td_invert(txtdict, txtw, txth)

                alg_prefix = "r-%u_flipx-%u_invert-%u_" % (rotate, flipx,
                                                           invert)
                txtbuf = mrom.ret_txt(txtdict, txtw, txth)
                mr = gen_mr(txtw, txth, word_bits)
                for layout in guess_layout_cols_lr(mr, txtbuf, alg_prefix):
                    yield layout
                for layout in guess_layout_cols_ud(mr, txtbuf, alg_prefix):
                    yield layout
コード例 #3
0
ファイル: txtmunge.py プロジェクト: yusufm/zorrom
def munge_txt(txt,
              win,
              hin,
              rotate=None,
              flipx=False,
              flipy=False,
              invert=False):
    '''Return contents as char array of bits (ie string with no whitespace)'''
    assert rotate in (None, 0, 90, 180, 270)
    if rotate == 90 or rotate == 270:
        wout, hout = hin, win
    else:
        wout, hout = win, hin
    txtdict = mrom.txt2dict(txt, win, hin)
    if rotate not in (None, 0):
        txtdict = mrom.td_rotate(rotate, txtdict, wout, hout)
    if flipx:
        txtdict = mrom.td_flipx(txtdict, wout, hout)
    if flipy:
        txtdict = mrom.td_flipy(txtdict, wout, hout)
    if invert:
        txtdict = mrom.td_invert(txtdict, wout, hout)
    return txtdict, wout, hout
コード例 #4
0
def guess_layout(txtdict_raw,
                 wraw,
                 hraw,
                 word_bits=8,
                 endian_force=None,
                 words=None,
                 invert_force=None,
                 rotate_force=None,
                 flipx_force=None,
                 interleave_force=1,
                 interleave_dir_force=None,
                 layout_alg_force=None,
                 verbose=False):
    verbose and print("guess_layout()")
    # hashdbg(txtdict_raw)
    # print(txtdict_raw[(75, 4)])
    # assert 0

    if layout_alg_force:
        algs = ("cols-left", "cols-right", "cols-downl", "cols-downr",
                "squeeze-lr")
        assert layout_alg_force in algs, "Got %s, need one of %s" % (
            layout_alg_force, algs)

    for invert, rotate, flipx in basic_param_gen(invert_force, rotate_force,
                                                 flipx_force):
        verbose and print("rotate %u, flipx %u" % (rotate, flipx))

        txtdict_rotated, txtw, txth = mrom.td_rotate2(rotate, txtdict_raw,
                                                      wraw, hraw)

        if txtw % word_bits != 0:
            verbose and print("rotate %u: bad width" % rotate)
            continue

        for interleaves_hor, interleave_dir in interleave_param_gen(
                interleave_force, interleave_dir_force, txtw, word_bits,
                verbose):
            txtdict = dict(txtdict_rotated)

            # print("int %u, %u" % (interleave_lr, interleave_lr_exp))
            # assert interleave_lr <= interleave_max
            # print("interleave %u => %u" % (txtw, interleave_lr))

            if flipx:
                txtdict = mrom.td_flipx(txtdict, txtw, txth)
            if invert:
                txtdict = mrom.td_invert(txtdict, txtw, txth)

            interleave_str = ""
            if interleaves_hor != 1:
                txtdict = td_interleave_hor(txtdict,
                                            txtw,
                                            txth,
                                            interleaves=interleaves_hor,
                                            interleave_dir=interleave_dir,
                                            word_bits=word_bits,
                                            verbose=verbose)
                interleave_str = "_inverleave-%s-%u" % (interleave_dir,
                                                        interleaves_hor)

            alg_prefix = "r-%u_flipx-%u_invert-%u%s_" % (rotate, flipx, invert,
                                                         interleave_str)
            verbose and print("Trying %s" % alg_prefix)
            gcols = range(word_bits, txtw, word_bits)
            txtbuf = mrom.ret_txt(txtdict, txtw, txth, gcols=gcols)
            mr = gen_mr(txtw, txth, word_bits, endian=endian_force)
            for layout, name in guess_layout_cols_lr(mr,
                                                     txtbuf,
                                                     alg_prefix,
                                                     layout_alg_force,
                                                     verbose=verbose):
                yield layout, name, txtbuf
            for layout, name in guess_layout_cols_ud(mr,
                                                     txtbuf,
                                                     alg_prefix,
                                                     layout_alg_force,
                                                     verbose=verbose):
                yield layout, name, txtbuf