Implement #985 (comic2lrf, added a wide-aspect scaling option)

This commit is contained in:
Kovid Goyal 2008-08-29 17:39:33 -07:00
commit cf55451ecc
3 changed files with 51 additions and 20 deletions

View File

@ -37,7 +37,7 @@ except:
PROFILES = {
# Name : (width, height) in pixels
'prs500':(584, 754),
'prs500':(584, 754),
}
def extract_comic(path_to_comic_file):
@ -143,7 +143,7 @@ class PageProcessor(list):
SCRWIDTH, SCRHEIGHT = PROFILES[self.opts.profile]
print 77777, threading.currentThread()
if self.opts.keep_aspect_ratio:
if self.opts.keep_aspect_ratio:
# Preserve the aspect ratio by adding border
aspect = float(sizex) / float(sizey)
if aspect <= (float(SCRWIDTH) / float(SCRHEIGHT)):
@ -159,6 +159,27 @@ class PageProcessor(list):
MagickResizeImage(wand, newsizex, newsizey, CatromFilter, 1.0)
MagickSetImageBorderColor(wand, pw)
MagickBorderImage(wand, pw, deltax, deltay)
elif self.opts.wide:
# Keep aspect and Use device height as scaled image width so landscape mode is clean
aspect = float(sizex) / float(sizey)
screen_aspect = float(SCRWIDTH) / float(SCRHEIGHT)
# Get dimensions of the landscape mode screen
# Add 25px back to height for the battery bar.
wscreenx = SCRHEIGHT + 25
wscreeny = int(wscreenx / screen_aspect)
if aspect <= screen_aspect:
newsizey = wscreeny
newsizex = int(newsizey * aspect)
deltax = (wscreenx - newsizex) / 2
deltay = 0
else:
newsizex = wscreenx
newsizey = int(newsizex / aspect)
deltax = 0
deltay = (wscreeny - newsizey) / 2
MagickResizeImage(wand, newsizex, newsizey, CatromFilter, 1.0)
MagickSetImageBorderColor(wand, pw)
MagickBorderImage(wand, pw, deltax, deltay)
else:
MagickResizeImage(wand, SCRWIDTH, SCRHEIGHT, CatromFilter, 1.0)
@ -234,34 +255,36 @@ def config(defaults=None):
c = Config('comic', desc)
else:
c = StringConfig(defaults, desc)
c.add_opt('title', ['-t', '--title'],
c.add_opt('title', ['-t', '--title'],
help=_('Title for generated ebook. Default is to use the filename.'))
c.add_opt('author', ['-a', '--author'],
help=_('Set the author in the metadata of the generated ebook. Default is %default'),
c.add_opt('author', ['-a', '--author'],
help=_('Set the author in the metadata of the generated ebook. Default is %default'),
default=_('Unknown'))
c.add_opt('output', ['-o', '--output'],
c.add_opt('output', ['-o', '--output'],
help=_('Path to output LRF file. By default a file is created in the current directory.'))
c.add_opt('colors', ['-c', '--colors'], type='int', default=64,
help=_('Number of colors for grayscale image conversion. Default: %default'))
c.add_opt('dont_normalize', ['-n', '--disable-normalize'], default=False,
c.add_opt('dont_normalize', ['-n', '--disable-normalize'], default=False,
help=_('Disable normalize (improve contrast) color range for pictures. Default: False'))
c.add_opt('keep_aspect_ratio', ['-r', '--keep-aspect-ratio'], default=False,
help=_('Maintain picture aspect ratio. Default is to fill the screen.'))
c.add_opt('dont_sharpen', ['-s', '--disable-sharpen'], default=False,
c.add_opt('dont_sharpen', ['-s', '--disable-sharpen'], default=False,
help=_('Disable sharpening.'))
c.add_opt('landscape', ['-l', '--landscape'], default=False,
c.add_opt('landscape', ['-l', '--landscape'], default=False,
help=_("Don't split landscape images into two portrait images"))
c.add_opt('wide', ['-w', '--wide-aspect'], default=False,
help=_("Keep aspect ratio and scale image using screen height as image width for viewing in landscape mode."))
c.add_opt('right2left', ['--right2left'], default=False, action='store_true',
help=_('Used for right-to-left publications like manga. Causes landscape pages to be split into portrait pages from right to left.'))
c.add_opt('despeckle', ['-d', '--despeckle'], default=False,
c.add_opt('despeckle', ['-d', '--despeckle'], default=False,
help=_('Enable Despeckle. Reduces speckle noise. May greatly increase processing time.'))
c.add_opt('no_sort', ['--no-sort'], default=False,
c.add_opt('no_sort', ['--no-sort'], default=False,
help=_("Don't sort the files found in the comic alphabetically by name. Instead use the order they were added to the comic."))
c.add_opt('profile', ['-p', '--profile'], default='prs500', choices=PROFILES.keys(),
c.add_opt('profile', ['-p', '--profile'], default='prs500', choices=PROFILES.keys(),
help=_('Choose a profile for the device you are generating this LRF for. The default is the SONY PRS-500 with a screen size of 584x754 pixels. Choices are %s')%PROFILES.keys())
c.add_opt('verbose', ['--verbose'], default=0, action='count',
c.add_opt('verbose', ['--verbose'], default=0, action='count',
help=_('Be verbose, useful for debugging. Can be specified multiple times for greater verbosity.'))
c.add_opt('no_progress_bar', ['--no-progress-bar'], default=False,
c.add_opt('no_progress_bar', ['--no-progress-bar'], default=False,
help=_("Don't show progress bar."))
return c

View File

@ -58,6 +58,7 @@ class ComicConf(QDialog, Ui_Dialog):
self.opt_landscape.setChecked(opts.landscape)
self.opt_no_sort.setChecked(opts.no_sort)
self.opt_despeckle.setChecked(opts.despeckle)
self.opt_wide.setChecked(opts.wide)
self.opt_right2left.setChecked(opts.right2left)
for opt in self.config.option_set.preferences:
@ -80,4 +81,4 @@ class ComicConf(QDialog, Ui_Dialog):
else:
raise Exception('Bad coding')
self.config.set(opt.name, val)
return QDialog.accept(self)
return QDialog.accept(self)

View File

@ -100,21 +100,21 @@
</property>
</widget>
</item>
<item row="7" column="0" >
<item row="8" column="0" >
<widget class="QCheckBox" name="opt_landscape" >
<property name="text" >
<string>&amp;Landscape</string>
</property>
</widget>
</item>
<item row="9" column="0" >
<item row="10" column="0" >
<widget class="QCheckBox" name="opt_no_sort" >
<property name="text" >
<string>Don't so&amp;rt</string>
</property>
</widget>
</item>
<item row="11" column="1" >
<item row="12" column="1" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
@ -124,20 +124,27 @@
</property>
</widget>
</item>
<item row="8" column="0" >
<item row="9" column="0" >
<widget class="QCheckBox" name="opt_right2left" >
<property name="text" >
<string>&amp;Right to left</string>
</property>
</widget>
</item>
<item row="10" column="0" >
<item row="11" column="0" >
<widget class="QCheckBox" name="opt_despeckle" >
<property name="text" >
<string>De&amp;speckle</string>
</property>
</widget>
</item>
<item row="7" column="0" >
<widget class="QCheckBox" name="opt_wide" >
<property name="text" >
<string>&amp;Wide</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources>