added: a new winix function: imgcrop
for cropping images (and thumbnails) www.domain.com/dir/file.jpg/imgcrop -- crop an image www.domain.com/dir/file.jpg/imgcrop/thumb -- crop an image's thumbnail www.domain.com/dir/file.jpg/imgcrop/newthumb -- crop and create a new thumbnail (from an original image) www.domain.com/dir/imgcrop -- show images' list with above options added: to Image class: some methods for cropping git-svn-id: svn://ttmath.org/publicrep/winix/trunk@919 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
80
core/image.h
80
core/image.h
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* Copyright (c) 2010-2013, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -22,7 +22,7 @@
|
||||
class System;
|
||||
|
||||
|
||||
|
||||
// aspect modes:
|
||||
// Width given, height automagically selected to preserve aspect ratio.
|
||||
#define WINIX_IMAGE_MODE_1 1
|
||||
|
||||
@@ -45,25 +45,74 @@ class System;
|
||||
#define WINIX_IMAGE_MODE_7 7
|
||||
|
||||
|
||||
|
||||
|
||||
// resizing
|
||||
#define WINIX_IMAGE_TYPE_RESIZE 1
|
||||
|
||||
// generating a thumbnail
|
||||
#define WINIX_IMAGE_TYPE_CREATE_THUMB 2
|
||||
|
||||
// cropping an image
|
||||
#define WINIX_IMAGE_TYPE_CROP 3
|
||||
|
||||
// cropping an thumbnail
|
||||
#define WINIX_IMAGE_TYPE_CROP_THUMB 4
|
||||
|
||||
// creating by cropping a new thumbnail (from an original image)
|
||||
#define WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB 5
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
class Image : public BaseThread
|
||||
{
|
||||
public:
|
||||
|
||||
struct Scale
|
||||
{
|
||||
size_t cx;
|
||||
size_t cy;
|
||||
int aspect_mode;
|
||||
int quality;
|
||||
|
||||
Scale()
|
||||
{
|
||||
cx = cy = 1;
|
||||
aspect_mode = 2;
|
||||
quality = 100;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
void SetDb(Db * pdb);
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetSystem(System * psystem);
|
||||
|
||||
void Resize(const Item & item, size_t cx, size_t cy, int aspect_mode, int quality);
|
||||
void CreateThumb(const Item & item, size_t cx, size_t cy, int aspect_mode, int quality);
|
||||
|
||||
// returning scale info for a directory
|
||||
Scale GetImageScale(long dir_id);
|
||||
|
||||
// returning scale info (for thumbnails) for a directory
|
||||
Scale GetThumbScale(long dir_id);
|
||||
|
||||
|
||||
|
||||
void Resize(long file_id, size_t cx, size_t cy, int aspect_mode, int quality);
|
||||
|
||||
// creating a new thumbnail from an original image
|
||||
void CreateThumb(long file_id, size_t thumb_cx, size_t thumb_cy, int aspect_mode, int quality);
|
||||
|
||||
// cropping an image (the thumbnail is not changed)
|
||||
void Crop(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy, int quality);
|
||||
|
||||
// cropping an existing thumbnail
|
||||
void CropThumb(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy, int quality);
|
||||
|
||||
// creating and cropping a new thumbnail (from an original image)
|
||||
void CropNewThumb(long file_id, size_t xoffset, size_t yoffset, size_t cx, size_t cy,
|
||||
size_t thumb_cx, size_t thumb_cy, int aspect_mode, int quality);
|
||||
|
||||
|
||||
private:
|
||||
@@ -75,13 +124,29 @@ private:
|
||||
struct ImageItem
|
||||
{
|
||||
int type; // WINIX_IMAGE_TYPE_*
|
||||
Item file;
|
||||
long file_id;
|
||||
size_t cx;
|
||||
size_t cy;
|
||||
size_t xoffset; // xoffset and yoffset are used when cropping
|
||||
size_t yoffset;
|
||||
size_t thumb_cx;
|
||||
size_t thumb_cy;
|
||||
int aspect_mode;
|
||||
int quality;
|
||||
};
|
||||
|
||||
|
||||
template<typename int_type>
|
||||
void SetMinMax(int_type & var, int var_min, int var_max)
|
||||
{
|
||||
if( static_cast<int>(var) < var_min )
|
||||
var = var_min;
|
||||
|
||||
if( static_cast<int>(var) > var_max )
|
||||
var = var_max;
|
||||
}
|
||||
|
||||
|
||||
// queue of thumbnails to create
|
||||
typedef std::list<ImageItem> ImageTab;
|
||||
ImageTab image_tab;
|
||||
@@ -96,6 +161,7 @@ private:
|
||||
std::string add_tempa;
|
||||
std::string input_file_name;
|
||||
std::string tmp_file_name;
|
||||
Item file_work;
|
||||
|
||||
virtual bool SignalReceived();
|
||||
virtual void Do();
|
||||
@@ -104,10 +170,12 @@ private:
|
||||
void CreateTmpFileName();
|
||||
void SaveImage();
|
||||
void CreateImage();
|
||||
void SelectAspect();
|
||||
void SelectAspect(size_t cx, size_t cy);
|
||||
void EscapePath(const std::string & path, TextStream<std::string> & out, bool clear_stream = true);
|
||||
void CheckParam(ImageItem & item);
|
||||
void Add(const std::wstring & in, TextStream<std::string> & out);
|
||||
void ImageSavedCorrectly();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user