示例#1
0
// Returns cbconvert options from qml
func (c *Comics) GetOptions() cbconvert.Options {
	var o cbconvert.Options
	o.Quiet = true

	r := c.Root.ObjectByName("checkBoxRecursive")
	o.Recursive = r.Bool("checked")

	r = c.Root.ObjectByName("checkBoxNoRGB")
	o.RGB = !r.Bool("checked")

	r = c.Root.ObjectByName("checkBoxConvertCover")
	o.ConvertCover = !r.Bool("checked")

	r = c.Root.ObjectByName("spinboxSize")
	o.Size = r.Int64("value")

	r = c.Root.ObjectByName("sliderBrightness")
	o.Brightness = r.Float64("value")

	r = c.Root.ObjectByName("sliderContrast")
	o.Contrast = r.Float64("value")

	r = c.Root.ObjectByName("checkBoxGrayscale")
	o.Grayscale = r.Bool("checked")

	r = c.Root.ObjectByName("comboBoxFlip")
	o.Flip = strings.ToLower(r.String("currentText"))

	r = c.Root.ObjectByName("comboBoxRotate")
	o.Rotate, _ = strconv.Atoi(r.String("currentText"))

	r = c.Root.ObjectByName("textFieldOutDir")
	o.Outdir = r.String("text")

	r = c.Root.ObjectByName("textFieldSuffix")
	o.Suffix = r.String("text")

	r = c.Root.ObjectByName("checkBoxNonImage")
	o.NonImage = !r.Bool("checked")

	r = c.Root.ObjectByName("comboBoxFormat")
	o.Format = strings.ToLower(r.String("currentText"))

	r = c.Root.ObjectByName("width")
	o.Width, _ = strconv.Atoi(r.String("text"))

	r = c.Root.ObjectByName("height")
	o.Height, _ = strconv.Atoi(r.String("text"))

	r = c.Root.ObjectByName("checkBoxFit")
	o.Fit = r.Bool("checked")

	r = c.Root.ObjectByName("comboBoxFilter")
	o.Filter = r.Int("currentIndex")

	r = c.Root.ObjectByName("sliderQuality")
	o.Quality = int(r.Float64("value"))

	r = c.Root.ObjectByName("spinboxLevelsInMin")
	o.LevelsInMin = r.Float64("value")

	r = c.Root.ObjectByName("spinboxLevelsInMax")
	o.LevelsInMax = r.Float64("value")

	r = c.Root.ObjectByName("spinboxLevelsGamma")
	o.LevelsGamma = r.Float64("value")

	r = c.Root.ObjectByName("spinboxLevelsOutMin")
	o.LevelsOutMin = r.Float64("value")

	r = c.Root.ObjectByName("spinboxLevelsOutMax")
	o.LevelsOutMax = r.Float64("value")

	return o
}
示例#2
0
// Parses command line flags
func parseFlags() (cbconvert.Options, []string) {
	opts := cbconvert.Options{}
	var args []string

	kingpin.Version("CBconvert 0.5.0")
	kingpin.CommandLine.Help = "Comic Book convert tool."
	kingpin.UsageTemplate(kingpin.CompactUsageTemplate)

	kingpin.Flag("outdir", "Output directory").Default(".").StringVar(&opts.Outdir)
	kingpin.Flag("size", "Process only files larger then size (in MB)").Default(strconv.Itoa(0)).Int64Var(&opts.Size)
	kingpin.Flag("recursive", "Process subdirectories recursively").BoolVar(&opts.Recursive)
	kingpin.Flag("quiet", "Hide console output").BoolVar(&opts.Quiet)

	convert := kingpin.Command("convert", "Convert archive or document (default command)").Default()
	convert.Arg("args", "filename or directory").Required().ExistingFilesOrDirsVar(&args)
	convert.Flag("width", "Image width").Default(strconv.Itoa(0)).IntVar(&opts.Width)
	convert.Flag("height", "Image height").Default(strconv.Itoa(0)).IntVar(&opts.Height)
	convert.Flag("fit", "Best fit for required width and height").BoolVar(&opts.Fit)
	convert.Flag("format", "Image format, valid values are jpeg, png, gif, tiff, bmp").Default("jpeg").StringVar(&opts.Format)
	convert.Flag("quality", "JPEG image quality").Default(strconv.Itoa(jpeg.DefaultQuality)).IntVar(&opts.Quality)
	convert.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Default(strconv.Itoa(cbconvert.Linear)).IntVar(&opts.Filter)
	convert.Flag("cover", "Convert cover image (use --no-cover if you want to exclude cover)").Default("true").BoolVar(&opts.ConvertCover)
	convert.Flag("rgb", "Convert images that have RGB colorspace (use --no-rgb if you only want to convert grayscaled images)").Default("true").BoolVar(&opts.RGB)
	convert.Flag("nonimage", "Leave non image files in archive (use --no-nonimage to remove non image files from archive)").Default("true").BoolVar(&opts.NonImage)
	convert.Flag("grayscale", "Convert images to grayscale (monochromatic)").BoolVar(&opts.Grayscale)
	convert.Flag("rotate", "Rotate images, valid values are 0, 90, 180, 270").Default(strconv.Itoa(0)).IntVar(&opts.Rotate)
	convert.Flag("flip", "Flip images, valid values are none, horizontal, vertical").Default("none").StringVar(&opts.Flip)
	convert.Flag("brightness", "Adjust brightness of the images, must be in range (-100, 100)").Default(strconv.Itoa(0)).Float64Var(&opts.Brightness)
	convert.Flag("contrast", "Adjust contrast of the images, must be in range (-100, 100)").Default(strconv.Itoa(0)).Float64Var(&opts.Contrast)
	convert.Flag("suffix", "Add suffix to file basename").StringVar(&opts.Suffix)
	convert.Flag("levels-inmin", "Shadow input value").Default(strconv.Itoa(0)).Float64Var(&opts.LevelsInMin)
	convert.Flag("levels-gamma", "Midpoint/Gamma").Default(strconv.Itoa(1.00)).Float64Var(&opts.LevelsGamma)
	convert.Flag("levels-inmax", "Highlight input value").Default(strconv.Itoa(255)).Float64Var(&opts.LevelsInMax)
	convert.Flag("levels-outmin", "Shadow output value").Default(strconv.Itoa(0)).Float64Var(&opts.LevelsOutMin)
	convert.Flag("levels-outmax", "Highlight output value").Default(strconv.Itoa(255)).Float64Var(&opts.LevelsOutMax)

	cover := kingpin.Command("cover", "Extract cover")
	cover.Arg("args", "filename or directory").Required().ExistingFilesOrDirsVar(&args)
	cover.Flag("width", "Image width").Default(strconv.Itoa(0)).IntVar(&opts.Width)
	cover.Flag("height", "Image height").Default(strconv.Itoa(0)).IntVar(&opts.Height)
	cover.Flag("fit", "Best fit for required width and height").BoolVar(&opts.Fit)
	cover.Flag("quality", "JPEG image quality").Default(strconv.Itoa(jpeg.DefaultQuality)).IntVar(&opts.Quality)
	cover.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Default(strconv.Itoa(cbconvert.Linear)).IntVar(&opts.Filter)

	thumbnail := kingpin.Command("thumbnail", "Extract cover thumbnail (freedesktop spec.)")
	thumbnail.Arg("args", "filename or directory").Required().ExistingFilesOrDirsVar(&args)
	thumbnail.Flag("outfile", "Output file").Default("").StringVar(&opts.Outfile)
	thumbnail.Flag("width", "Image width").Default(strconv.Itoa(0)).IntVar(&opts.Width)
	thumbnail.Flag("height", "Image height").Default(strconv.Itoa(0)).IntVar(&opts.Height)
	thumbnail.Flag("fit", "Best fit for required width and height").BoolVar(&opts.Fit)
	thumbnail.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Default(strconv.Itoa(cbconvert.Linear)).IntVar(&opts.Filter)

	switch kingpin.Parse() {
	case "cover":
		opts.Cover = true
	case "thumbnail":
		opts.Thumbnail = true
	}

	return opts, args
}