Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 08-31-2012, 01:23 PM   #1
jackie_w
Wizard
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: 2,913
Karma: 4329601
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
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
Old 08-31-2012, 02:00 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,438
Karma: 5383257
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Try

image.type = 'GrayscaleType'

and then dont use save_cover_data_to, instead directly do image.save(path)

instead of using quantize, though in imagemagick, there is no easy way to force the output to be a particular image sub-type.
kovidgoyal is offline   Reply With Quote
Old 08-31-2012, 02:10 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,438
Karma: 5383257
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Here's what it should look like:

image.type = 'GrayscaleType'
image.save(path, 'BMP3')

On my linux machine that produces an 8-bit bmp grayscale image
kovidgoyal is offline   Reply With Quote
Old 08-31-2012, 02:23 PM   #4
jackie_w
Wizard
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: 2,913
Karma: 4329601
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
OK, I'll create a beta version with that code and hope one of the Linux users will test it for me.

I'll report back with the outcome. Thank you for the fast reply
jackie_w is offline   Reply With Quote
Old 08-31-2012, 02:54 PM   #5
jackie_w
Wizard
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: 2,913
Karma: 4329601
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
Quote:
Originally Posted by kovidgoyal View Post
Here's what it should look like:

image.type = 'GrayscaleType'
image.save(path, 'BMP3')

On my linux machine that produces an 8-bit bmp grayscale image
I've just tried your suggestion on my Windows PC. However, without the img.quantize(...) the bmps are produced as 24BPP, so I don't think this is going to work for everyone.

Just in case this may prompt any further ideas, the first Linux user had modified his own version of the plugin zip with
Code:
save_cover_data_to(img, dest)
os.system("/usr/bin/convert - colors 8 %s %s" % (dest, dest))
but it looks Linux-specific or maybe even specific to just his machine???
jackie_w is offline   Reply With Quote
Old 08-31-2012, 03:46 PM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,438
Karma: 5383257
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Hmm well them I'm at a loss. I dont see a method in the imagemagick api to set the number of colors,other than quantize, and you say that doesn't work.
kovidgoyal is offline   Reply With Quote
Old 08-31-2012, 04:00 PM   #7
jackie_w
Wizard
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: 2,913
Karma: 4329601
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
Quote:
Originally Posted by kovidgoyal View Post
Hmm well them I'm at a loss. I dont see a method in the imagemagick api to set the number of colors,other than quantize, and you say that doesn't work.
Oh well, that's a pity. It seems to work for some but not others.

Whether it's always OK for Windows and always not-OK for Linux, I don't know. Based on previous feedback (or lack thereof) I suspect there are very few Pocketbook users of this plugin and even less who also use Linux, so I'll leave as-is and change the documentation accordingly.

Thanks for trying
jackie_w is offline   Reply With Quote
Old 08-31-2012, 04:06 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,438
Karma: 5383257
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
One more try:

Code:
im.quantize(16, 'GRAYColorspace')
im.type='PaletteType'
im.save('t.bmp', 'BMP3')
This should make the image use a color palette, which on my system results in a 4-bit image
kovidgoyal is offline   Reply With Quote
Old 08-31-2012, 04:23 PM   #9
jackie_w
Wizard
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: 2,913
Karma: 4329601
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
Quote:
Originally Posted by kovidgoyal View Post
One more try:

Code:
im.quantize(16, 'GRAYColorspace')
im.type='PaletteType'
im.save('t.bmp', 'BMP3')
This should make the image use a color palette, which on my system results in a 4-bit image
Now this looks more hopeful It also produces 4BPP on my PC.

I'll PM the Linux user and report back when I have some results.

Have a good weekend.
jackie_w is offline   Reply With Quote
Old 09-01-2012, 05:53 PM   #10
jackie_w
Wizard
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: 2,913
Karma: 4329601
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
Just a note to say that your suggestion worked well for the beta tester with a PB603 and Ubuntu.

Let's hope I didn't break it for other PB users...
jackie_w is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting up Calibre for email-not Gmail method. Tight Calibre 1 01-04-2012 04:44 PM
image dans Calibre morapat Software 0 08-15-2011 05:34 AM
Calibre, RTF and image conversion JasonPaulClaire Calibre 10 01-03-2011 04:18 PM
What is your method of organizing ebooks on your JB? Calibre? jerrywojo Ectaco jetBook 7 07-10-2010 05:09 PM
Cover image going odd in Calibre fading Calibre 6 10-05-2009 02:27 PM


All times are GMT -4. The time now is 06:14 PM.


MobileRead.com is a privately owned, operated and funded community.