<commit_before>import getopt
from gl import *
from GL import *
from DEVICE import *
import time
import sys
import al
import AL
import colorsys

BUFFERSIZE = 32000

class Struct(): pass
epoch = Struct()
epoch.correcttiming = 1
EndOfFile = 'End of file'
bye = 'bye'

def openspkr():
    conf = al.newconfig()
    conf.setqueuesize(BUFFERSIZE)
    conf.setwidth(AL.SAMPLE_16)
    conf.setchannels(AL.MONO)
    return al.openport('spkr','w',conf)

def openvideo(name):
    try:
        f = open(name, 'r')
    except:
        sys.stderr.write(name + ': cannot open\n')
        sys.exit(1)
    line = f.readline()
    if not line: raise EndOfFile
    if line[:4] = 'CMIF':
	if line[:14] = 'CMIF video 2.0':
	    line = f.readline()
	    colorinfo = eval(line[:-1])
	else:
	    colorinfo = (8,0,0,0)
	line = f.readline()
    x = eval(line[:-1])
    if len(x) = 3: w, h, pf = x
    else: w, h = x; pf = 2
    return f, w, h, pf, colorinfo

def loadframe(f,w,h,pf,af,spkr, (ybits,ibits,qbits,chrompack),mf):
    line = f.readline()
    if line = '':
	raise EndOfFile
    x = eval(line[:-1])
    if type(x) = type(0) or type(x) = type(0.0):
    	tijd = x
    	if pf = 0:
    		size = w*h*4
    	else:
    		size = (w/pf) * (h/pf)
    else:
    	tijd, size = x
    data = f.read(size)
    if len(data) <> size:
	raise EndOfFile
    if pf:
    	w = w/pf
    	h = h/pf
    if chrompack:
	cw = (w+chrompack-1)/chrompack
	ch = (h+chrompack-1)/chrompack
	chromdata = f.read(2*cw*ch)
	rectzoom(pf*chrompack*mf,pf*chrompack*mf)
	pixmode(5,16)
	writemask(0x7ff - ((1<<ybits)-1))
	lrectwrite(0,0,cw-1,ch-1,chromdata)
	writemask((1<<ybits)-1)
	pixmode(5,8)
    if pf:
    	rectzoom(pf*mf, pf*mf)
    elif mf <> 1:
	rectzoom(mf,mf)
    lrectwrite(0,0,w-1,h-1,data)
    # This is ugly here, but the only way to get the two
    # channels started in sync
    #if af <> None:
    #	playsound(af,spkr)
    ct = time.millitimer() - epoch.epoch
    if epoch.correcttiming and tijd > 0 and ct < tijd:
    	time.millisleep(tijd-ct)
    #swapbuffers()
    return tijd

def initcmap(ybits,ibits,qbits,chrompack):
    if ybits+ibits+qbits > 11:
	raise 'Sorry, 11 bits max'
    maxy = pow(2,ybits)
    maxi = pow(2,ibits)
    maxq = pow(2,qbits)
    for i in range(2048,4096-256):
	mapcolor(i, 0, 255, 0)
    for y in range(maxy):
      yv = float(y)/float(maxy-1)
      for i in range(maxi):
	iv = (float(i)/float(maxi-1))-0.5
	for q in range(maxq):
	  qv = (float(q)/float(maxq-1))-0.5
	  index = 2048 + y + (i << ybits) + (q << (ybits+ibits))

	  rv,gv,bv = colorsys.yiq_to_rgb(yv,iv,qv)
	  r,g,b = int(rv*255.0), int(gv*255.0), int(bv*255.0)
	  if index < 4096 - 256:
	      mapcolor(index, r,g,b)

def playsound(af, spkr):
    nsamp = spkr.getfillable()<commit_msg>Fix division by zero in some cases.<commit_after>import getopt
from gl import *
from GL import *
from DEVICE import *
import time
import sys
import al
import AL
import colorsys

BUFFERSIZE = 32000

class Struct(): pass
epoch = Struct()
epoch.correcttiming = 1
EndOfFile = 'End of file'
bye = 'bye'

def openspkr():
    conf = al.newconfig()
    conf.setqueuesize(BUFFERSIZE)
    conf.setwidth(AL.SAMPLE_16)
    conf.setchannels(AL.MONO)
    return al.openport('spkr','w',conf)

def openvideo(name):
    try:
        f = open(name, 'r')
    except:
        sys.stderr.write(name + ': cannot open\n')
        sys.exit(1)
    line = f.readline()
    if not line: raise EndOfFile
    if line[:4] = 'CMIF':
	if line[:14] = 'CMIF video 2.0':
	    line = f.readline()
	    colorinfo = eval(line[:-1])
	else:
	    colorinfo = (8,0,0,0)
	line = f.readline()
    x = eval(line[:-1])
    if len(x) = 3: w, h, pf = x
    else: w, h = x; pf = 2
    return f, w, h, pf, colorinfo

def loadframe(f,w,h,pf,af,spkr, (ybits,ibits,qbits,chrompack),mf):
    line = f.readline()
    if line = '':
	raise EndOfFile
    x = eval(line[:-1])
    if type(x) = type(0) or type(x) = type(0.0):
    	tijd = x
    	if pf = 0:
    		size = w*h*4
    	else:
    		size = (w/pf) * (h/pf)
    else:
    	tijd, size = x
    data = f.read(size)
    if len(data) <> size:
	raise EndOfFile
    if pf:
    	w = w/pf
    	h = h/pf
    if chrompack:
	cw = (w+chrompack-1)/chrompack
	ch = (h+chrompack-1)/chrompack
	chromdata = f.read(2*cw*ch)
	rectzoom(pf*chrompack*mf,pf*chrompack*mf)
	pixmode(5,16)
	writemask(0x7ff - ((1<<ybits)-1))
	lrectwrite(0,0,cw-1,ch-1,chromdata)
	writemask((1<<ybits)-1)
	pixmode(5,8)
    if pf:
    	rectzoom(pf*mf, pf*mf)
    elif mf <> 1:
	rectzoom(mf,mf)
    lrectwrite(0,0,w-1,h-1,data)
    # This is ugly here, but the only way to get the two
    # channels started in sync
    #if af <> None:
    #	playsound(af,spkr)
    ct = time.millitimer() - epoch.epoch
    if epoch.correcttiming and tijd > 0 and ct < tijd:
    	time.millisleep(tijd-ct)
    #swapbuffers()
    return tijd

def initcmap(ybits,ibits,qbits,chrompack):
    if ybits+ibits+qbits > 11:
	raise 'Sorry, 11 bits max'
    maxy = pow(2,ybits)
    maxi = pow(2,ibits)
    maxq = pow(2,qbits)
    for i in range(2048,4096-256):
	mapcolor(i, 0, 255, 0)
    for y in range(maxy):
      yv = float(y)/float(maxy-1)
      for i in range(maxi):
      	if maxi = 1: iv = 0
	else: iv = (float(i)/float(maxi-1))-0.5
	for q in range(maxq):
	  if maxq = 1: qv = 0
	  else: qv = (float(q)/float(maxq-1))-0.5
	  index = 2048 + y + (i << ybits) + (q << (ybits+ibits))
	  rv,gv,bv = colorsys.yiq_to_rgb(yv,iv,qv)
	  r,g,b = int(rv*255.0), int(gv*255.0), int(bv*255.0)
	  if index < 4096 - 256:
	      mapcolor(index, r,g,b)

def playsound(af, spkr):
    nsamp = spkr.getfillable()
{'fraction_non_alphanumeric': 0.16141803131185892, 'fraction_numerical': 0.03850998740327515, 'mean_word_length': 2.7835262083049694, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, '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': '3706523', 'n_tokens_mistral': 2551, 'n_tokens_neox': 2424, 'n_words': 561}