mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Update Cybook Orizon driver: create a thumbnail with the correct format, remove mobi/prc formats from the default supported list, add option for card folder
This commit is contained in:
parent
a79225f8ce
commit
90e3568d14
@ -15,6 +15,7 @@ from calibre import fsync
|
|||||||
from calibre.constants import isunix
|
from calibre.constants import isunix
|
||||||
from calibre.devices.usbms.driver import USBMS
|
from calibre.devices.usbms.driver import USBMS
|
||||||
import calibre.devices.cybook.t2b as t2b
|
import calibre.devices.cybook.t2b as t2b
|
||||||
|
import calibre.devices.cybook.t4b as t4b
|
||||||
|
|
||||||
class CYBOOK(USBMS):
|
class CYBOOK(USBMS):
|
||||||
|
|
||||||
@ -67,12 +68,40 @@ class ORIZON(CYBOOK):
|
|||||||
|
|
||||||
BCD = [0x319]
|
BCD = [0x319]
|
||||||
|
|
||||||
|
FORMATS = ['epub', 'html', 'pdf', 'rtf', 'txt']
|
||||||
|
|
||||||
VENDOR_NAME = ['BOOKEEN', 'LINUX']
|
VENDOR_NAME = ['BOOKEEN', 'LINUX']
|
||||||
WINDOWS_MAIN_MEM = re.compile(r'(CYBOOK_ORIZON__-FD)|(FILE-STOR_GADGET)')
|
WINDOWS_MAIN_MEM = re.compile(r'(CYBOOK_ORIZON__-FD)|(FILE-STOR_GADGET)')
|
||||||
WINDOWS_CARD_A_MEM = re.compile('(CYBOOK_ORIZON__-SD)|(FILE-STOR_GADGET)')
|
WINDOWS_CARD_A_MEM = re.compile('(CYBOOK_ORIZON__-SD)|(FILE-STOR_GADGET)')
|
||||||
|
|
||||||
EBOOK_DIR_MAIN = EBOOK_DIR_CARD_A = 'Digital Editions'
|
EBOOK_DIR_MAIN = EBOOK_DIR_CARD_A = 'Digital Editions'
|
||||||
|
|
||||||
|
EBOOK_DIR_CARD_A = [EBOOK_DIR_CARD_A]
|
||||||
|
EXTRA_CUSTOMIZATION_MESSAGE = [
|
||||||
|
_('Card A folder') + ':::<p>' +
|
||||||
|
_('Enter the folder where the books are to be stored when sent to the '
|
||||||
|
'memory card. This folder is prepended to any send_to_device template') + '</p>',
|
||||||
|
]
|
||||||
|
EXTRA_CUSTOMIZATION_DEFAULT = EBOOK_DIR_CARD_A
|
||||||
|
|
||||||
|
def upload_cover(self, path, filename, metadata, filepath):
|
||||||
|
coverdata = getattr(metadata, 'thumbnail', None)
|
||||||
|
if coverdata and coverdata[2]:
|
||||||
|
coverdata = coverdata[2]
|
||||||
|
else:
|
||||||
|
coverdata = None
|
||||||
|
with open('%s.thn' % filepath, 'wb') as thnfile:
|
||||||
|
t4b.write_t4b(thnfile, coverdata)
|
||||||
|
fsync(thnfile)
|
||||||
|
|
||||||
|
def post_open_callback(self):
|
||||||
|
opts = self.settings()
|
||||||
|
folder = opts.extra_customization
|
||||||
|
if not folder:
|
||||||
|
folder = ''
|
||||||
|
self.EBOOK_DIR_CARD_A = folder
|
||||||
|
print(folder)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_handle(cls, device_info, debug=False):
|
def can_handle(cls, device_info, debug=False):
|
||||||
if isunix:
|
if isunix:
|
||||||
|
42
src/calibre/devices/cybook/t4b.py
Normal file
42
src/calibre/devices/cybook/t4b.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2013, Jellby <jellby at yahoo.com>'
|
||||||
|
'''
|
||||||
|
Write a t4b file to disk.
|
||||||
|
'''
|
||||||
|
|
||||||
|
import StringIO
|
||||||
|
|
||||||
|
DEFAULT_T4B_DATA = ''
|
||||||
|
|
||||||
|
def reduce_color(c):
|
||||||
|
if (c < 0):
|
||||||
|
return 0
|
||||||
|
elif (c > 255):
|
||||||
|
return 15
|
||||||
|
else:
|
||||||
|
return c//16
|
||||||
|
|
||||||
|
def write_t4b(t4bfile, coverdata=None):
|
||||||
|
'''
|
||||||
|
t4bfile is a file handle ready to write binary data to disk.
|
||||||
|
coverdata is a string representation of a JPEG file.
|
||||||
|
'''
|
||||||
|
from PIL import Image
|
||||||
|
if coverdata != None:
|
||||||
|
coverdata = StringIO.StringIO(coverdata)
|
||||||
|
cover = Image.open(coverdata).convert("L")
|
||||||
|
cover.thumbnail((96, 144), Image.ANTIALIAS)
|
||||||
|
t4bcover = Image.new('L', (96, 144), 'white')
|
||||||
|
|
||||||
|
x, y = cover.size
|
||||||
|
t4bcover.paste(cover, ((96-x)/2, (144-y)/2))
|
||||||
|
|
||||||
|
pxs = t4bcover.getdata()
|
||||||
|
t4bfile.write('t4bp')
|
||||||
|
for i in range(0,len(pxs),2):
|
||||||
|
byte = reduce_color(pxs[i])
|
||||||
|
byte = 16*byte + reduce_color(pxs[i+1])
|
||||||
|
t4bfile.write(chr(byte))
|
||||||
|
else:
|
||||||
|
t4bfile.write(DEFAULT_T4B_DATA)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user