Images are now cached as wxBitmap, not wxImage. This should improve performance.

Fixed some more corner cases of rotation+zoom.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@630 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-08-25 21:24:28 +00:00
parent 741b987d54
commit 52ec7b38c0
38 changed files with 413 additions and 165 deletions
+2 -1
View File
@@ -110,6 +110,7 @@ void combine_image(Image& a, const Image& b, ImageCombine combine) {
// Combine image data, by dispatching to combineImageDo
switch(combine) {
#define DISPATCH(comb) case comb: combine_image_do<comb>(a,b); return
case COMBINE_DEFAULT:
case COMBINE_NORMAL: a = b; return; // no need to do a per pixel operation
DISPATCH(COMBINE_ADD);
DISPATCH(COMBINE_SUBTRACT);
@@ -138,7 +139,7 @@ void combine_image(Image& a, const Image& b, ImageCombine combine) {
}
void draw_combine_image(DC& dc, UInt x, UInt y, const Image& img, ImageCombine combine) {
if (combine == COMBINE_NORMAL) {
if (combine <= COMBINE_NORMAL) {
dc.DrawBitmap(img, x, y);
} else {
// Capture the current image in the target rectangle
+4
View File
@@ -68,6 +68,10 @@ Image conform_image(const Image& img, const GeneratedImage::Options& options) {
if (options.saturate) {
saturate(image, 40);
}
// rotate?
if (options.angle != 0) {
image = rotate_image(image, options.angle);
}
return image;
}
+5 -2
View File
@@ -28,10 +28,13 @@ class GeneratedImage : public ScriptValue {
/// Options for generating the image
struct Options {
Options(int width = 0, int height = 0, Package* package = nullptr, Package* local_package = nullptr, PreserveAspect preserve_aspect = ASPECT_STRETCH, bool saturate = false)
: width(width), height(height), preserve_aspect(preserve_aspect), saturate(saturate), package(package), local_package(local_package)
: width(width), height(height), angle(0)
, preserve_aspect(preserve_aspect), saturate(saturate)
, package(package), local_package(local_package)
{}
int width, height; ///< Width to force the image to, or 0 to keep the width of the input
int angle; ///< Angle to rotate image by afterwards
PreserveAspect preserve_aspect;
bool saturate;
Package* package; ///< Package to load images from
@@ -43,7 +46,7 @@ class GeneratedImage : public ScriptValue {
/// Generate the image
virtual Image generate(const Options&) const = 0;
/// How must the image be combined with the background?
virtual ImageCombine combine() const { return COMBINE_NORMAL; }
virtual ImageCombine combine() const { return COMBINE_DEFAULT; }
/// Equality should mean that every pixel in the generated images is the same if the same options are used
virtual bool operator == (const GeneratedImage& that) const = 0;
inline bool operator != (const GeneratedImage& that) const { return !(*this == that); }
+7 -1
View File
@@ -56,6 +56,10 @@ extern const int text_scaling;
// ----------------------------------------------------------------------------- : Image rotation
/// Is an angle sideways (90 or 270 degrees)?
// Note: angle & 2 == 0 for angle in {0, 180} and != 0 for angle in {90, 270)
inline bool sideways(int angle) { return (angle & 2) != 0; }
/// Rotates an image counter clockwise
/// angle must be a multiple of 90, i.e. {0,90,180,270}
Image rotate_image(const Image& image, int angle);
@@ -85,7 +89,9 @@ void saturate(Image& image, int amount);
/// Ways in which images can be combined, similair to what Photoshop supports
enum ImageCombine
{ COMBINE_NORMAL
{ COMBINE_DEFAULT // normal combine, but with a low priority, i.e. "apply default instead of add" == "add"
// it is not representable in scripting/files, so should only be used internally
, COMBINE_NORMAL
, COMBINE_ADD
, COMBINE_SUBTRACT
, COMBINE_STAMP
+1 -1
View File
@@ -163,7 +163,7 @@ void draw_resampled_text(DC& dc, const RealRect& rect, double stretch, int wc, i
mdc.SelectObject(wxNullBitmap);
Image img_large = buffer.ConvertToImage();
// step 2. sample down
if ((angle & 2) == 0) w *= stretch;
if (!sideways(angle)) w *= stretch;
else h *= stretch;
Image img_small(w, h, false);
fill_image(img_small, dc.GetTextForeground());