def insertPattern(self, oldbrotherfile, pattnum, imgfile, newbrotherfile): bf = brother.brotherFile(oldbrotherfile) pats = bf.getPatterns() # ok got a bank, now lets figure out how big this thing we want to insert is TheImage = Image.open(imgfile) TheImage.load() im_size = TheImage.size width = im_size[0] self.printInfoCallback("width:" + str(width)) height = im_size[1] self.printInfoCallback("height:" + str(height)) # find the program entry thePattern = None for pat in pats: if (int(pat["number"]) == int(pattnum)): #print "found it!" thePattern = pat if (thePattern == None): raise PatternNotFoundException(pattnum) if (height != thePattern["rows"] or width != thePattern["stitches"]): raise InserterException("Pattern is the wrong size, the BMP is ", height, "x", width, "and the pattern is ", thePattern["rows"], "x", thePattern["stitches"]) # debugging stuff here x = 0 y = 0 x = width - 1 for y in xrange(height): for x in xrange(width): value = TheImage.getpixel((x, y)) if value: self.printPattern('* ') else: self.printPattern(' ') print " " # debugging stuff done # now to make the actual, yknow memo+pattern data # the memo seems to be always blank. i have no idea really memoentry = [] for i in range(bytesForMemo(height)): memoentry.append(0x0) # now for actual real live pattern data! pattmemnibs = [] for r in range(height): row = [] # we'll chunk in bits and then put em into nibbles for s in range(width): x = s if methodWithPointers else width - s - 1 value = TheImage.getpixel((x, height - r - 1)) isBlack = (value == 0) if methodWithPointers else (value != 0) if (isBlack): row.append(1) else: row.append(0) #print row # turn it into nibz for s in range(roundfour(width) / 4): n = 0 for nibs in range(4): #print "row size = ", len(row), "index = ",s*4+nibs if (len(row) == (s * 4 + nibs)): break # padding! if (row[s * 4 + nibs]): n |= 1 << nibs pattmemnibs.append(n) #print hex(n), if (len(pattmemnibs) % 2): # odd nibbles, buffer to a byte pattmemnibs.append(0x0) #print len(pattmemnibs), "nibbles of data" # turn into bytes pattmem = [] for i in range(len(pattmemnibs) / 2): pattmem.append(pattmemnibs[i * 2] | (pattmemnibs[i * 2 + 1] << 4)) #print map(hex, pattmem) # whew. # now to insert this data into the file # now we have to figure out the -end- of the last pattern is endaddr = 0x6df beginaddr = thePattern["pattend"] endaddr = beginaddr + bytesForMemo(height) + len(pattmem) self.printInfoCallback("beginning will be at " + str(hex(beginaddr)) + ", end at " + str(hex(endaddr))) # Note - It's note certain that in all cases this collision test is needed. What's happening # when you write below this address (as the pattern grows downward in memory) in that you begin # to overwrite the pattern index data that starts at low memory. Since you overwrite the info # for highest memory numbers first, you may be able to get away with it as long as you don't # attempt to use higher memories. # Steve if beginaddr <= 0x2B8: self.printErrorCallback( "Sorry, this will collide with the pattern entry data since %s is <= 0x2B8!" % hex(beginaddr)) #exit # write the memo and pattern entry from the -end- to the -beginning- (up!) for i in range(len(memoentry)): bf.setIndexedByte(endaddr, 0) endaddr -= 1 for i in range(len(pattmem)): bf.setIndexedByte(endaddr, pattmem[i]) endaddr -= 1 # push the data to a file outfile = open(newbrotherfile, 'wb') d = bf.getFullData() outfile.write(d) outfile.close()
def dumppattern(self,argv): if len(argv) < 1: raise ArgumentsException() result = Result() if len(argv) == 2: patt = int(argv[1]) else: patt = 0 bf = brother.brotherFile(argv[0]) if patt == 0: result.patterns = bf.getPatterns() if DEBUG: print "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" print "Data file" print "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" # first dump the 99 'pattern id' blocks for i in range(99): print "program entry",i # each block is 7 bytes bytenum = i*7 pattused = bf.getIndexedByte(bytenum) print "\t",hex(bytenum),": ",hex(pattused), if (pattused == 1): print "\t(used)" else: print "\t(unused)" #print "\t-skipped-" #continue bytenum += 1 unk1 = bf.getIndexedByte(bytenum) print "\t",hex(bytenum),": ",hex(unk1),"\t(unknown)" bytenum += 1 rows100 = bf.getIndexedByte(bytenum) print "\t",hex(bytenum),": ",hex(rows100),"\t(rows = ", (rows100 >> 4)*100, " + ", (rows100 & 0xF)*10 bytenum += 1 rows1 = bf.getIndexedByte(bytenum) print "\t",hex(bytenum),": ",hex(rows1),"\t\t+ ", (rows1 >> 4), " stiches = ", (rows1 & 0xF)*100,"+" bytenum += 1 stitches10 = bf.getIndexedByte(bytenum) print "\t",hex(bytenum),": ",hex(stitches10),"\t\t+ ", (stitches10 >> 4)*10, " +", (stitches10 & 0xF),")" bytenum += 1 prog100 = bf.getIndexedByte(bytenum) print "\t",hex(bytenum),": ",hex(prog100),"\t(unknown , prog# = ", (prog100&0xF) * 100,"+" bytenum += 1 prog10 = bf.getIndexedByte(bytenum) print "\t",hex(bytenum),": ",hex(prog10),"\t\t + ", (prog10>>4) * 10,"+",(prog10&0xF),")" bytenum += 1 print "============================================" print "Program memory grows -up-" # now we're onto data data # dump the first program pointer = 0x6DF # this is the 'bottom' of the memory for i in range(99): # of course, not all patterns will get dumped pattused = bf.getIndexedByte(i*7) if (pattused != 1): # :( break # otherwise its a valid pattern print "pattern bank #", i # calc pattern size rows100 = bf.getIndexedByte(i*7 + 2) rows1 = bf.getIndexedByte(i*7 + 3) stitches10 = bf.getIndexedByte(i*7 + 4) rows = (rows100 >> 4)*100 + (rows100 & 0xF)*10 + (rows1 >> 4); stitches = (rows1 & 0xF)*100 + (stitches10 >> 4)*10 + (stitches10 & 0xF) print "rows = ", rows, "stitches = ", stitches # print "total nibs per row = ", nibblesPerRow(stitches) # dump the memo data print "memo length =",bytesForMemo(rows) for i in range (bytesForMemo(rows)): b = pointer - i print "\t",hex(b),": ",hex(bf.getIndexedByte(b)) pointer -= bytesForMemo(rows) print "pattern length = ", bytesPerPattern(stitches, rows) for i in range (bytesPerPattern(stitches, rows)): b = pointer - i print "\t",hex(b),": ",hex(bf.getIndexedByte(b)), for j in range(8): if (bf.getIndexedByte(b) & (1<<j)): print "*", else: print " ", print "" # print it out in nibbles per row? for row in range(rows): for nibs in range(nibblesPerRow(stitches)): n = bf.getIndexedNibble(pointer, nibblesPerRow(stitches)*row + nibs) print hex(n), for j in range(8): if (n & (1<<j)): print "*", else: print " ", print "" pointer -= bytesPerPattern(stitches, rows) #for i in range (0x06DF, 99*7, -1): # print "\t",hex(i),": ",hex(bf.getIndexedByte(i)) else: self.printInfoCallback( 'Searching for pattern number %d' % patt) pats = bf.getPatterns(patt) if len(pats) == 0: raise PatternNotFoundException(patt) else: stitches = pats[0]["stitches"] rows = pats[0]["rows"] self.printInfoCallback( '%3d Stitches, %3d Rows' % (stitches, rows)) result.pattern = bf.getPattern(patt) return result
def dumppattern(self, argv): if len(argv) < 1: raise ArgumentsException() result = Result() if len(argv) == 2: patt = int(argv[1]) else: patt = 0 bf = brother.brotherFile(argv[0]) if patt == 0: result.patterns = bf.getPatterns() if DEBUG: print "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" print "Data file" print "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" # first dump the 99 'pattern id' blocks for i in range(99): print "program entry", i # each block is 7 bytes bytenum = i * 7 pattused = bf.getIndexedByte(bytenum) print "\t", hex(bytenum), ": ", hex(pattused), if (pattused == 1): print "\t(used)" else: print "\t(unused)" #print "\t-skipped-" #continue bytenum += 1 unk1 = bf.getIndexedByte(bytenum) print "\t", hex(bytenum), ": ", hex(unk1), "\t(unknown)" bytenum += 1 rows100 = bf.getIndexedByte(bytenum) print "\t", hex(bytenum), ": ", hex( rows100), "\t(rows = ", (rows100 >> 4) * 100, " + ", ( rows100 & 0xF) * 10 bytenum += 1 rows1 = bf.getIndexedByte(bytenum) print "\t", hex(bytenum), ": ", hex(rows1), "\t\t+ ", ( rows1 >> 4), " stiches = ", (rows1 & 0xF) * 100, "+" bytenum += 1 stitches10 = bf.getIndexedByte(bytenum) print "\t", hex(bytenum), ": ", hex( stitches10), "\t\t+ ", (stitches10 >> 4) * 10, " +", ( stitches10 & 0xF), ")" bytenum += 1 prog100 = bf.getIndexedByte(bytenum) print "\t", hex(bytenum), ": ", hex( prog100), "\t(unknown , prog# = ", (prog100 & 0xF) * 100, "+" bytenum += 1 prog10 = bf.getIndexedByte(bytenum) print "\t", hex(bytenum), ": ", hex(prog10), "\t\t + ", ( prog10 >> 4) * 10, "+", (prog10 & 0xF), ")" bytenum += 1 print "============================================" print "Program memory grows -up-" # now we're onto data data # dump the first program pointer = 0x6DF # this is the 'bottom' of the memory for i in range(99): # of course, not all patterns will get dumped pattused = bf.getIndexedByte(i * 7) if (pattused != 1): # :( break # otherwise its a valid pattern print "pattern bank #", i # calc pattern size rows100 = bf.getIndexedByte(i * 7 + 2) rows1 = bf.getIndexedByte(i * 7 + 3) stitches10 = bf.getIndexedByte(i * 7 + 4) rows = (rows100 >> 4) * 100 + (rows100 & 0xF) * 10 + ( rows1 >> 4) stitches = (rows1 & 0xF) * 100 + (stitches10 >> 4) * 10 + ( stitches10 & 0xF) print "rows = ", rows, "stitches = ", stitches # print "total nibs per row = ", nibblesPerRow(stitches) # dump the memo data print "memo length =", bytesForMemo(rows) for i in range(bytesForMemo(rows)): b = pointer - i print "\t", hex(b), ": ", hex(bf.getIndexedByte(b)) pointer -= bytesForMemo(rows) print "pattern length = ", bytesPerPattern(stitches, rows) for i in range(bytesPerPattern(stitches, rows)): b = pointer - i print "\t", hex(b), ": ", hex(bf.getIndexedByte(b)), for j in range(8): if (bf.getIndexedByte(b) & (1 << j)): print "*", else: print " ", print "" # print it out in nibbles per row? for row in range(rows): for nibs in range(nibblesPerRow(stitches)): n = bf.getIndexedNibble( pointer, nibblesPerRow(stitches) * row + nibs) print hex(n), for j in range(8): if (n & (1 << j)): print "*", else: print " ", print "" pointer -= bytesPerPattern(stitches, rows) #for i in range (0x06DF, 99*7, -1): # print "\t",hex(i),": ",hex(bf.getIndexedByte(i)) else: self.printInfoCallback('Searching for pattern number %d' % patt) pats = bf.getPatterns(patt) if len(pats) == 0: raise PatternNotFoundException(patt) else: stitches = pats[0]["stitches"] rows = pats[0]["rows"] self.printInfoCallback('%3d Stitches, %3d Rows' % (stitches, rows)) result.pattern = bf.getPattern(patt) return result
def bytesForMemo(rows): bytes = roundeven(rows) / 2 return bytes ############## version = '1.0' if len(sys.argv) < 5: print 'Usage: %s oldbrotherfile pattern# image.bmp newbrotherfile' % sys.argv[ 0] sys.exit() bf = brother.brotherFile(sys.argv[1]) pattnum = sys.argv[2] imgfile = sys.argv[3] pats = bf.getPatterns() # ok got a bank, now lets figure out how big this thing we want to insert is TheImage = Image.open(imgfile) TheImage.load() im_size = TheImage.size width = im_size[0] print "width:", width height = im_size[1] print "height:", height
def insertPattern(self, oldbrotherfile, pattnum, imgfile, newbrotherfile): bf = brother.brotherFile(oldbrotherfile) pats = bf.getPatterns() # ok got a bank, now lets figure out how big this thing we want to insert is TheImage = Image.open(imgfile) TheImage.load() im_size = TheImage.size width = im_size[0] self.printInfoCallback( "width:" + str(width)) height = im_size[1] self.printInfoCallback( "height:" + str(height)) # find the program entry thePattern = None for pat in pats: if (int(pat["number"]) == int(pattnum)): #print "found it!" thePattern = pat if (thePattern == None): raise PatternNotFoundException(pattnum) if (height != thePattern["rows"] or width != thePattern["stitches"]): raise InserterException("Pattern is the wrong size, the BMP is ",height,"x",width,"and the pattern is ",thePattern["rows"], "x", thePattern["stitches"]) # debugging stuff here x = 0 y = 0 x = width - 1 for y in xrange(height): for x in xrange(width): value = TheImage.getpixel((x,y)) if value: self.printPattern('* ') else: self.printPattern(' ') print " " # debugging stuff done # now to make the actual, yknow memo+pattern data # the memo seems to be always blank. i have no idea really memoentry = [] for i in range(bytesForMemo(height)): memoentry.append(0x0) # now for actual real live pattern data! pattmemnibs = [] for r in range(height): row = [] # we'll chunk in bits and then put em into nibbles for s in range(width): x = s if methodWithPointers else width-s-1 value = TheImage.getpixel((x,height-r-1)) isBlack = (value == 0) if methodWithPointers else (value != 0) if (isBlack): row.append(1) else: row.append(0) #print row # turn it into nibz for s in range(roundfour(width) / 4): n = 0 for nibs in range(4): #print "row size = ", len(row), "index = ",s*4+nibs if (len(row) == (s*4+nibs)): break # padding! if (row[s*4 + nibs]): n |= 1 << nibs pattmemnibs.append(n) #print hex(n), if (len(pattmemnibs) % 2): # odd nibbles, buffer to a byte pattmemnibs.append(0x0) #print len(pattmemnibs), "nibbles of data" # turn into bytes pattmem = [] for i in range (len(pattmemnibs) / 2): pattmem.append( pattmemnibs[i*2] | (pattmemnibs[i*2 + 1] << 4)) #print map(hex, pattmem) # whew. # now to insert this data into the file # now we have to figure out the -end- of the last pattern is endaddr = 0x6df beginaddr = thePattern["pattend"] endaddr = beginaddr + bytesForMemo(height) + len(pattmem) self.printInfoCallback("beginning will be at " + str(hex(beginaddr)) + ", end at " + str(hex(endaddr))) # Note - It's note certain that in all cases this collision test is needed. What's happening # when you write below this address (as the pattern grows downward in memory) in that you begin # to overwrite the pattern index data that starts at low memory. Since you overwrite the info # for highest memory numbers first, you may be able to get away with it as long as you don't # attempt to use higher memories. # Steve if beginaddr <= 0x2B8: self.printErrorCallback("Sorry, this will collide with the pattern entry data since %s is <= 0x2B8!" % hex(beginaddr)) #exit # write the memo and pattern entry from the -end- to the -beginning- (up!) for i in range(len(memoentry)): bf.setIndexedByte(endaddr, 0) endaddr -= 1 for i in range(len(pattmem)): bf.setIndexedByte(endaddr, pattmem[i]) endaddr -= 1 # push the data to a file outfile = open(newbrotherfile, 'wb') d = bf.getFullData() outfile.write(d) outfile.close()
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import sys import brother if len(sys.argv) < 3: print 'Usage: %s fileA fileB' % sys.argv[0] sys.exit() b1 = brother.brotherFile(sys.argv[1]) b2 = brother.brotherFile(sys.argv[2]) # Selector Mode # Pattern Start # Motif information # Custom pattern list, patterns, memo info # Memo data # Pattern Number # Current Row Number # Unknowns from 0x0700 to 0x0715 # Unknowns from 0x07D0 to 0x07E9 sel1 = b1.selectorValue() sel2 = b2.selectorValue()
DEBUG = 0 version = '1.0' if len(sys.argv) < 2: print 'Usage: %s file [patternnum]' % sys.argv[0] print 'Dumps user programs (901-999) from brother data files' sys.exit() if len(sys.argv) == 3: patt = int(sys.argv[2]) else: patt = 0 bf = brother.brotherFile(sys.argv[1]) if patt == 0: pats = bf.getPatterns() print 'Pattern Stitches Rows' for pat in pats: print ' %3d %3d %3d' % (pat["number"], pat["stitches"], pat["rows"]) if DEBUG: print "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" print "Data file" print "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+" # first dump the 99 'pattern id' blocks for i in range(99): print "program entry",i