Encode this matrix in binary suitable for including in a PDF
165206
def encode(self):
        """"""
        return '{:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}'.format(
            self.a, self.b, self.c, self.d, self.e, self.f
        ).encode()
397273
def encode(self, value):
        '''
        
        '''
        kassert.is_of_types(value, Bits)
        result = BitArray(value)
        result.reverse()
        return result
872958
function encode(data, structure, separator) {
	var encoded = data.split('').map(function (val, idx) {
		return BINARIES[structure[idx]];
	}).map(function (val, idx) {
		return val ? val[data[idx]] : '';
	});

	if (separator) {
		var last = data.length - 1;
		encoded = encoded.map(function (val, idx) {
			return idx < last ? val + separator : val;
		});
	}

	return encoded.join('');
}
393967
def encode(self, b64=False, always_bytes=True):
        """"""
        if self.binary and not b64:
            encoded_packet = six.int2byte(self.packet_type)
        else:
            encoded_packet = six.text_type(self.packet_type)
            if self.binary and b64:
                encoded_packet = 'b' + encoded_packet
        if self.binary:
            if b64:
                encoded_packet += base64.b64encode(self.data).decode('utf-8')
            else:
                encoded_packet += self.data
        elif isinstance(self.data, six.string_types):
            encoded_packet += self.data
        elif isinstance(self.data, dict) or isinstance(self.data, list):
            encoded_packet += self.json.dumps(self.data,
                                              separators=(',', ':'))
        elif self.data is not None:
            encoded_packet += str(self.data)
        if always_bytes and not isinstance(encoded_packet, binary_types):
            encoded_packet = encoded_packet.encode('utf-8')
        return encoded_packet
1927
def encode_matrix_parameters(parameters):
    
    result = []

    for param in iter(sorted(parameters)):
        if isinstance(parameters[param], (list, tuple)):
            value = (';%s=' % (param)).join(parameters[param])
        else:
            value = parameters[param]

        result.append("%s=%s" % (param, value))

    return ';'.join(result)
317637
function(_binarray){
        var _index = 0,
            _result = [],
            _mode = _binarray.length%3;
        // this is for the padding
        if (_mode==1)
            _binarray.push(0,0);
        if (_mode==2)
            _binarray.push(0);
        // from here conversion
        while(_index<_binarray.length){
            _result.push(__b64char[_binarray[_index]>>2],
                         __b64char[((_binarray[_index]&3)<<4)|(_binarray[_index+1]>>4)],
                         __b64char[((_binarray[_index+1]&15)<<2)|(_binarray[_index+2]>>6)],
                         __b64char[_binarray[_index+2]&63]);
            _index += 3;
        }
        // this is again for the padding
        if (_mode == 1)
            _result[_result.length-1] =
            _result[_result.length-2] = '=';
        if (_mode == 2)
            _result[_result.length-1] = '=';
        // we join the array to return a textstring
        return _result.join('');
    }
114168
static private void encodeBytes(byte previous, byte current, int byteIndex, StringBuilder output) {
        int chunk;
        int offset = byteIndex % 5;
        switch (offset) {
            case 0:
                chunk = ((current & 0xF8) >>> 3);
                output.append(lookupTable.charAt(chunk));
                break;
            case 1:
                chunk = (((previous & 0x07) << 2) | ((current & 0xC0) >>> 6));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x3E) >>> 1);
                output.append(lookupTable.charAt(chunk));
                break;
            case 2:
                chunk = (((previous & 0x01) << 4) | ((current & 0xF0) >>> 4));
                output.append(lookupTable.charAt(chunk));
                break;
            case 3:
                chunk = (((previous & 0x0F) << 1) | ((current & 0x80) >>> 7));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x7C) >>> 2);
                output.append(lookupTable.charAt(chunk));
                break;
            case 4:
                chunk = (((previous & 0x03) << 3) | ((current & 0xE0) >>> 5));
                output.append(lookupTable.charAt(chunk));
                chunk = (current & 0x1F);
                output.append(lookupTable.charAt(chunk));
                break;
        }
    }
847094
private static byte[] encodeEnternal(byte[] d)
    {
        if (d == null) return null;
        byte data[] = new byte[d.length+2];
        System.arraycopy(d, 0, data, 0, d.length);
        byte dest[] = new byte[(data.length/3)*4];

        // 3-byte to 4-byte conversion
        for (int sidx = 0, didx=0; sidx < d.length; sidx += 3, didx += 4)
        {
            dest[didx]   = (byte) ((data[sidx] >>> 2) & 077);
            dest[didx+1] = (byte) ((data[sidx+1] >>> 4) & 017 |
                    (data[sidx] << 4) & 077);
            dest[didx+2] = (byte) ((data[sidx+2] >>> 6) & 003 |
                    (data[sidx+1] << 2) & 077);
            dest[didx+3] = (byte) (data[sidx+2] & 077);
        }

        // 0-63 to ascii printable conversion
        for (int idx = 0; idx <dest.length; idx++)
        {
            if (dest[idx] < 26)     dest[idx] = (byte)(dest[idx] + 'A');
            else if (dest[idx] < 52)  dest[idx] = (byte)(dest[idx] + 'a' - 26);
            else if (dest[idx] < 62)  dest[idx] = (byte)(dest[idx] + '0' - 52);
            else if (dest[idx] < 63)  dest[idx] = (byte)'+';
            else            dest[idx] = (byte)'/';
        }

        // add padding
        for (int idx = dest.length-1; idx > (d.length*4)/3; idx--)
        {
            dest[idx] = (byte)'=';
        }
        return dest;
    }
399087
def encode_chain_list(in_strings):
    """"""
    out_bytes = b""
    for in_s in in_strings:
        out_bytes+=in_s.encode('ascii')
        for i in range(mmtf.utils.constants.CHAIN_LEN -len(in_s)):
            out_bytes+= mmtf.utils.constants.NULL_BYTE.encode('ascii')
    return out_bytes
589524
private static BitMatrix matrixFromString(String uri, int width, int height) {
        Writer qrWriter = new QRCodeWriter();
        BitMatrix matrix;
        try {
            matrix = qrWriter.encode(uri, BarcodeFormat.QR_CODE, width, height);
        } catch (WriterException e) {
            throw new RuntimeException(e);
        }
        return matrix;
    }
274298
function binaryStringToArrayBuffer(bin) {
  var length = bin.length;
  var buf = new ArrayBuffer(length);
  var arr = new Uint8Array(buf);
  for (var i = 0; i < length; i++) {
    arr[i] = bin.charCodeAt(i);
  }
  return buf;
}
1060740
function bin2String(array) {
  var result = "";
  for (var i = 0; i < array.length; i++) {
    result += String.fromCharCode(array[i]);
  }
  return result;
}
714518
def encode(self, value):
        '''
        
        '''
        kassert.is_of_types(value, Bits)
        remainder = len(value) % 8
        if remainder:
            value += Bits(bin='0' * (8 - remainder))
        return value
1132623
function encode($barcode) {
	$encoded = $this->makeEncoding();
        $W = 0;
        $H = 0;
        $grid = "";
        $binary = array_fill(0, 4096, 0);
        $matrix = $this->makeEncoding();
        $encoding = $this->encodingList(strlen($barcode), $barcode, false);

        $encoded['valid'] = false;

        if (!$encoding) // there's nothing to encode ...
            return $encoded;

        //$this->debug("encoding: " . $encoding);
        //$this->debug("encodingLength: " . $encoding['encodingLength']);
        for ($i = 0; $i < count($this->Encodings); $i++) {
            $matrix = $this->Encodings[$i];
            if ($matrix['bytes'] > $encoding['encodingLength'])
                break;
        }

        if ($matrix['width'] == 0) {
            die("Cannot find suitable size, url is too long!");
            return $encoded;
        }

        $W = $matrix['width'];
        $H = $matrix['height'];

        if ($this->ecc200encode($binary, $matrix['bytes'], $barcode, strlen($barcode), $encoding) == 0) {
            die("URL too long for " + $W + "x" + $H);
            return $encoded;
        }

        // add error checking using ReedSolomon
        $this->rs($binary, $matrix['bytes'], $matrix['datablocks'], $matrix['rsblocks']);


        // block $placement
        {
            $NC = $W - 2 * floor($W / $matrix['fw']);
            $NR = $H - 2 * floor($H / $matrix['data']);
            $places = array_fill(0, $NC * $NR, 0);
            $this->place($places, $NR, $NC);
            $grid = array_fill(0, $W * $H, 0);
            for ($y = 0; $y < $H; $y += $matrix['data']) {
                for ($x = 0; $x < $W; $x++)
                    $grid[$y * $W + $x] = 1;
                for ($x = 0; $x < $W; $x += 2)
                    $grid[($y + $matrix['data'] - 1) * $W + $x] = 1;
            }
            for ($x = 0; $x < $W; $x += $matrix['fw']) {
                for ($y = 0; $y < $H; $y++)
                    $grid[$y * $W + $x] = 1;
                for ($y = 0; $y < $H; $y += 2)
                    $grid[$y * $W + $x + $matrix['fw'] - 1] = 1;
            }
            for ($y = 0; $y < $NR; $y++) {
                for ($x = 0; $x < $NC; $x++) {
                    $v = $places[($NR - $y - 1) * $NC + $x];
                    if ($v == 1 || $v > 7 && ($binary[($v >> 3) - 1] & (1 << ($v & 7))))
                        $grid[(1 + $y + 2 * floor($y / ($matrix['data'] - 2))) * $W + 1 + $x + 2 * floor($x / ($matrix['fw'] - 2))] = 1;
                }
            }
        }

        $encoded['width'] = $W;
        $encoded['height'] = $H;
        $encoded['data'] = $grid;
        $encoded['encoding'] = $encoding;
        $encoded['bytes'] = $matrix['bytes'];
        $encoded['ecc'] = floor(($matrix['bytes'] + 2) / $matrix['datablocks']) * $matrix['rsblocks']; //not used?

        return $encoded;
    }
51953
private static BitMatrix renderResult(QRCode code, int width, int height, int quietZone) {
    ByteMatrix input = code.getMatrix();
    if (input == null) {
      throw new IllegalStateException();
    }
    int inputWidth = input.getWidth();
    int inputHeight = input.getHeight();
    int qrWidth = inputWidth + (quietZone * 2);
    int qrHeight = inputHeight + (quietZone * 2);
    int outputWidth = Math.max(width, qrWidth);
    int outputHeight = Math.max(height, qrHeight);

    int multiple = Math.min(outputWidth / qrWidth, outputHeight / qrHeight);
    // Padding includes both the quiet zone and the extra white pixels to accommodate the requested
    // dimensions. For example, if input is 25x25 the QR will be 33x33 including the quiet zone.
    // If the requested size is 200x160, the multiple will be 4, for a QR of 132x132. These will
    // handle all the padding from 100x100 (the actual QR) up to 200x160.
    int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
    int topPadding = (outputHeight - (inputHeight * multiple)) / 2;

    BitMatrix output = new BitMatrix(outputWidth, outputHeight);

    for (int inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
      // Write the contents of this row of the barcode
      for (int inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
        if (input.get(inputX, inputY) == 1) {
          output.setRegion(outputX, outputY, multiple, multiple);
        }
      }
    }

    return output;
  }
1157934
static void buildMatrix(BitArray dataBits,
                          ErrorCorrectionLevel ecLevel,
                          Version version,
                          int maskPattern,
                          ByteMatrix matrix) throws WriterException {
    clearMatrix(matrix);
    embedBasicPatterns(version, matrix);
    // Type information appear with any version.
    embedTypeInfo(ecLevel, maskPattern, matrix);
    // Version info appear if version >= 7.
    maybeEmbedVersionInfo(version, matrix);
    // Data should be embedded at end.
    embedDataBits(dataBits, maskPattern, matrix);
  }
40880
def _encode_multipart(**kw):
    '  '
    boundary = '----------%s' % hex(int(time.time() * 1000))
    data = []
    for k, v in kw.iteritems():
        data.append('--%s' % boundary)
        if hasattr(v, 'read'):
            # file-like object:
            filename = getattr(v, 'name', '')
            content = v.read()
            data.append('Content-Disposition: form-data; name="%s"; filename="hidden"' % k)
            data.append('Content-Length: %d' % len(content))
            data.append('Content-Type: %s\r\n' % _guess_content_type(filename))
            data.append(content)
        else:
            data.append('Content-Disposition: form-data; name="%s"\r\n' % k)
            data.append(v.encode('utf-8') if isinstance(v, unicode) else v)
    data.append('--%s--\r\n' % boundary)
    return '\r\n'.join(data), boundary