View Single Post
Old 08-31-2012, 12:23 PM   #1
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,206
Karma: 16228558
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
Help with calibre Image quantize method, please

In the past week, a couple of Pocketbook users with Linux machines have reported a problem with my Copy Cover plugin. The problem is with the format of the images being produced. PBs needs them to be greyscale BMP at 4BPP (maybe 8BPP also OK?). However, on the 2 Linux machines the BMPs come out as greyscale 24BPP - which PBs won't use.

A sample of 2 users is not really enough to draw conclusions but testing on my WinXP PC correctly produces greyscale BMPs with 4BPP. I don't know if this is just dumb luck or whether there is something different about images produced on Windows than on Linux. I've also had the plugin beta-tested by a user with a Pocketbook903. She had no problems, but I suspect she was also a Windows user (still to confirm).

Am I missing something obvious? I need to find a method which works on Win/Linux/OSX.

The code I've been using since Jan 2011 is along these lines:
Code:
from calibre.utils.magick import Image
from calibre.utils.magick.draw import save_cover_data_to

dest_path = r'/fullpath/to/device/imagedir/calibre_cover.bmp'
cdata = self.db.cover(book_id, index_is_id=False, as_path=False)
rescale = (600, 800)

img = Image()
img.load(cdata)
img.size = rescale
img.quantize(number_colors=16, colorspace='GRAYColorspace')
save_cover_data_to(img, dest_path)
I can see that img.quantize has 3 other parameters (treedepth, dither, measure_error), but I'm not sure what they do.

I've tried various combinations, including not using img.quantize at all, but instead using the grayscale=True parameter of save_cover_data_to. However, the only combination I found which created 4BPP BMPs on my PC was the one above.

All other reader models supported by the plugin, Sony/Kindle/Nook, are happy to receive colour jpg/png so a simple
save_cover_data_to(cdata, dest_path, resize_to=rescale)
suffices - no quantize necessary.

As a non-Linux user, the following doesn't mean a lot to me but this is how each of the 2 Linux users described their setup
  • PB603 with linux debian wheezy, python 2.7.3-rc2 with internal PIL library
  • PB603 with Calibre 0.8.66 on Ubuntu 10.04 up-to-date
jackie_w is offline   Reply With Quote