-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteProcessor.py
More file actions
51 lines (41 loc) · 1.06 KB
/
Copy pathByteProcessor.py
File metadata and controls
51 lines (41 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class ByteProcessor:
def slice(self,x,flag):
if flag==1:
arr = [(x&224)>>5 , (x&28)>>2 , (x&3)]
elif flag==2:
arr = [(x&224)>>5 , (x&24)>>3 , (x&7)]
else:
arr = [(x&192)>>6 , (x&56)>>3 , (x&7)]
return arr
def merge(self,r,g,b,arr,flag):
if flag==1:
result = [ (r&(~7))|arr[0] , (g&(~7))|arr[1] , (b&(~3))|arr[2] ]
elif flag==2:
result = [ (r&(~7))|arr[0] , (g&(~3))|arr[1] , (b&(~7))|arr[2] ]
else:
result = [ (r&(~3))|arr[0] , (g&(~7))|arr[1] , (b&(~7))|arr[2] ]
return result
def extract(self,r,g,b,flag):
if flag==1:
result = [ r&7 , g&7 , b&3 ]
elif flag==2:
result = [ r&7 , g&3 , b&7 ]
else:
result = [ r&3 , g&7 , b&7 ]
return result
def combine(self,arr,flag):
if flag==1:
return arr[0] <<5 | (arr[1]<<2) |arr[2]
elif flag==2:
return arr[0] <<5 | (arr[1]<<3) |arr[2]
else:
return arr[0] <<6 | (arr[1]<<3) |arr[2]
'''
b = ByteProcessor()
ar=[35,35,35,35,35,35,35,35,35,35,35,98,46,106,112,103,126,35,35,51,53,51,48,53,51]
flag=1
for n in ar:
temp=b.slice(n,flag)
print(temp)
flag=(flag+1)%3+1
'''