<commit_before>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

from sys import exit
from struct import pack
from optparse import OptionParser
from os.path import exists
from array import array

from parse import DNG

class Collector:
	def __init__(self, bitspersample):
		self.bitspersample = bitspersample
		self.data = array("B")
		self.write = self.data.write
		self.have_bits = 0
		self.val = 0
	
	def _put_bits(self, val, bits):
		self.have_bits += bits
		self.val = (self.val << bits) | val
		diff = self.have_bits - 8
		if diff >= 0:
			self.data.append(self.val >> diff)
			self.val &= (1 << diff) - 1
			self.have_bits = diff
	
	def put(self, val):
		bits = self.bitspersample
		while bits > 8:
			self._put_bits((val >> (bits - 8)) & 0xff, 8)
			val >>= 8
			bits -= 8
		if bits:
			self._put_bits(val & ((1 << bits) - 1), bits)

p = OptionParser("Usage: %prog [-a] input1.dng input2.dng [input3.dng [...]] output.dng")
p.add_option("-a", "--average", action="store_true", help="Average sample values (instead of summing)")
p.add_option("-b", "--blacklevel", type="int", help="Override black level")
opts, args = p.parse_args()

if len(args) < 3:
	p.print_help()
	exit(1)

outfile = args[-1]
if exists(outfile):
	print "Cowardly refusing to overwrite", outfile
	exit(1)

raws = [DNG(open(fn, "rb")) for fn in args[:-1]]
count = len(raws)<commit_msg>Oops, fix incorrect bit fiddling in output.<commit_after>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

from sys import exit
from struct import pack
from optparse import OptionParser
from os.path import exists
from array import array

from parse import DNG

class Collector:
	def __init__(self, bitspersample):
		self.bitspersample = bitspersample
		self.data = array("B")
		self.write = self.data.write
		self.have_bits = 0
		self.val = 0
	
	def _put_bits(self, val, bits):
		self.have_bits += bits
		self.val = (self.val << bits) | val
		diff = self.have_bits - 8
		if diff >= 0:
			self.data.append(self.val >> diff)
			self.val &= (1 << diff) - 1
			self.have_bits = diff
	
	def put(self, val):
		bits = self.bitspersample
		while bits > 8:
			self._put_bits((val >> (bits - 8)) & 0xff, 8)
			bits -= 8
		if bits:
			self._put_bits(val & ((1 << bits) - 1), bits)

p = OptionParser("Usage: %prog [-a] input1.dng input2.dng [input3.dng [...]] output.dng")
p.add_option("-a", "--average", action="store_true", help="Average sample values (instead of summing)")
p.add_option("-b", "--blacklevel", type="int", help="Override black level")
opts, args = p.parse_args()

if len(args) < 3:
	p.print_help()
	exit(1)

outfile = args[-1]
if exists(outfile):
	print "Cowardly refusing to overwrite", outfile
	exit(1)

raws = [DNG(open(fn, "rb")) for fn in args[:-1]]
count = len(raws)
{'fraction_non_alphanumeric': 0.16077287641268684, 'fraction_numerical': 0.01932191031717098, 'mean_word_length': 3.635135135135135, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '151789', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1001, 'n_words': 287}