hack to fix completely transparent images

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@161 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-12-24 00:41:46 +00:00
parent 40606d975e
commit 77c6acf90f
2 changed files with 25 additions and 21 deletions
+4 -21
View File
@@ -141,28 +141,10 @@ void resample_and_clip(const Image& img_in, Image& img_out, wxRect rect) {
// ----------------------------------------------------------------------------- : Aspect ratio preserving
// fill an image with 100% transparent, except for the given rectangle
void fill_transparent(Image& img, int dx, int dy, int w, int h) {
// fill an image with 100% transparent
void fill_transparent(Image& img) {
if (!img.HasAlpha()) img.InitAlpha();
memset(img.GetAlpha(), 0, img.GetWidth() * img.GetHeight());
/*/?
int iw = img.GetWidth(), ih = img.GetHeight();
Byte* data = img.GetAlpha();
// fill
int y = 0;
for (; y < dy ; ++y) {
for (int x = 0 ; x < iw ; ++x) *data++ = 0;
}
for (; y < dy + h ; ++y) {
int x = 0;
for (; x < dx ; ++x) *data++ = 0;
for (; x < dx + w ; ++x) *data++ = 255;
for (; x < iw ; ++x) *data++ = 0;
}
for (; y < ih ; ++y) {
for (int x = 0 ; x < iw ; ++x) *data++ = 0;
}
*/
}
void resample_preserve_aspect(const Image& img_in, Image& img_out) {
@@ -175,10 +157,11 @@ void resample_preserve_aspect(const Image& img_in, Image& img_out) {
int dx = (img_out.GetWidth() - rwidth) / 2;
int dy = (img_out.GetHeight() - rheight) / 2;
// transparent background
fill_transparent(img_out, dx, dy, rwidth, rheight);
fill_transparent(img_out);
// resample
int offset_out = dx + img_out.GetWidth() * dy;
Image img_temp(rwidth, img_in.GetHeight(), false);
img_temp.InitAlpha();
resample_pass(img_in, img_temp, 0, 0, img_in.GetWidth(), 1, rwidth, 1, img_in.GetHeight(), img_in.GetWidth(), img_temp.GetWidth());
resample_pass(img_temp, img_out, 0, offset_out, img_in.GetHeight(), img_temp.GetWidth(), rheight, img_out.GetWidth(), rwidth, 1, 1);
}