diff options
author | Tor Norbye <tnorbye@google.com> | 2012-04-20 08:06:44 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-04-20 08:06:45 -0700 |
commit | 1724df30e1dbf62c799ac833caffa05913532d4d (patch) | |
tree | 8344b6aa4e438024c61b42e07978c8e67dc809fe | |
parent | 05dbf354c8808ce2122a4057381d59730b098525 (diff) | |
parent | 8e83f43ab1ebd0a2a6edd2619842b80b30d6d423 (diff) | |
download | sdk-1724df30e1dbf62c799ac833caffa05913532d4d.zip sdk-1724df30e1dbf62c799ac833caffa05913532d4d.tar.gz sdk-1724df30e1dbf62c799ac833caffa05913532d4d.tar.bz2 |
Merge "Fix asset studio generator cropping and clipart foreground color"
2 files changed, 82 insertions, 5 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java index b9ecfbc..105892a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java @@ -16,6 +16,8 @@ package com.android.ide.eclipse.adt.internal.assetstudio; +import static java.awt.image.BufferedImage.TYPE_INT_ARGB; + import com.android.assetstudiolib.ActionBarIconGenerator; import com.android.assetstudiolib.GraphicGenerator; import com.android.assetstudiolib.GraphicGeneratorContext; @@ -24,6 +26,7 @@ import com.android.assetstudiolib.MenuIconGenerator; import com.android.assetstudiolib.NotificationIconGenerator; import com.android.assetstudiolib.TabIconGenerator; import com.android.assetstudiolib.TextRenderUtil; +import com.android.assetstudiolib.Util; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.ImageControl; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.ImageUtils; @@ -69,6 +72,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Slider; import org.eclipse.swt.widgets.Text; +import java.awt.Paint; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -272,10 +276,10 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen new Label(mConfigurationArea, SWT.NONE); mTrimCheckBox = new Button(mConfigurationArea, SWT.CHECK); - mTrimCheckBox.setEnabled(false); mTrimCheckBox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); mTrimCheckBox.setSelection(false); mTrimCheckBox.setText("Trim Surrounding Blank Space"); + mTrimCheckBox.addSelectionListener(this); new Label(mConfigurationArea, SWT.NONE); Label paddingLabel = new Label(mConfigurationArea, SWT.NONE); @@ -912,6 +916,7 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen CreateAssetSetWizard wizard = (CreateAssetSetWizard) getWizard(); AssetType type = wizard.getAssetType(); + boolean crop = mTrimCheckBox.getSelection(); BufferedImage sourceImage = null; if (mImageRadio.getSelection()) { @@ -930,6 +935,15 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen setErrorMessage(null); sourceImage = getImage(path, false); + if (sourceImage != null) { + if (crop) { + sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB); + } + int padding = getPadding(); + if (padding != 0) { + sourceImage = Util.paddedImage(sourceImage, padding); + } + } } else if (mTextRadio.getSelection()) { String text = mText.getText(); TextRenderUtil.Options options = new TextRenderUtil.Options(); @@ -942,11 +956,36 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen } options.foregroundColor = color; sourceImage = TextRenderUtil.renderTextImage(text, getPadding(), options); + + if (crop) { + sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB); + } + + int padding = getPadding(); + if (padding != 0) { + sourceImage = Util.paddedImage(sourceImage, padding); + } } else { assert mClipartRadio.getSelection(); assert mSelectedClipart != null; try { sourceImage = GraphicGenerator.getClipartImage(mSelectedClipart); + + if (crop) { + sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB); + } + + if (type.needsColors()) { + int color = 0xFF000000 | (mFgColor.red << 16) | (mFgColor.green << 8) + | mFgColor.blue; + Paint paint = new java.awt.Color(color); + sourceImage = Util.filledImage(sourceImage, paint); + } + + int padding = getPadding(); + if (padding != 0) { + sourceImage = Util.paddedImage(sourceImage, padding); + } } catch (IOException e) { AdtPlugin.log(e, null); return categoryMap; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java index aa8f0e4..e912f53 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtils.java @@ -125,6 +125,23 @@ public class ImageUtils { * and cropping completely removed everything */ public static BufferedImage cropBlank(BufferedImage image, Rect initialCrop) { + return cropBlank(image, initialCrop, image.getType()); + } + + /** + * Crops blank pixels from the edges of the image and returns the cropped result. We + * crop off pixels that are blank (meaning they have an alpha value = 0). Note that + * this is not the same as pixels that aren't opaque (an alpha value other than 255). + * + * @param image the image to be cropped + * @param initialCrop If not null, specifies a rectangle which contains an initial + * crop to continue. This can be used to crop an image where you already + * know about margins in the image + * @param imageType the type of {@link BufferedImage} to create + * @return a cropped version of the source image, or null if the whole image was blank + * and cropping completely removed everything + */ + public static BufferedImage cropBlank(BufferedImage image, Rect initialCrop, int imageType) { CropFilter filter = new CropFilter() { @Override public boolean crop(BufferedImage bufferedImage, int x, int y) { @@ -134,7 +151,7 @@ public class ImageUtils { // visual results -- e.g. check <= 0x80000000 } }; - return crop(image, filter, initialCrop); + return crop(image, filter, initialCrop, imageType); } /** @@ -152,13 +169,32 @@ public class ImageUtils { */ public static BufferedImage cropColor(BufferedImage image, final int blankArgb, Rect initialCrop) { + return cropColor(image, blankArgb, initialCrop, image.getType()); + } + + /** + * Crops pixels of a given color from the edges of the image and returns the cropped + * result. + * + * @param image the image to be cropped + * @param blankArgb the color considered to be blank, as a 32 pixel integer with 8 + * bits of alpha, red, green and blue + * @param initialCrop If not null, specifies a rectangle which contains an initial + * crop to continue. This can be used to crop an image where you already + * know about margins in the image + * @param imageType the type of {@link BufferedImage} to create + * @return a cropped version of the source image, or null if the whole image was blank + * and cropping completely removed everything + */ + public static BufferedImage cropColor(BufferedImage image, + final int blankArgb, Rect initialCrop, int imageType) { CropFilter filter = new CropFilter() { @Override public boolean crop(BufferedImage bufferedImage, int x, int y) { return blankArgb == bufferedImage.getRGB(x, y); } }; - return crop(image, filter, initialCrop); + return crop(image, filter, initialCrop, imageType); } /** @@ -177,7 +213,8 @@ public class ImageUtils { boolean crop(BufferedImage image, int x, int y); } - private static BufferedImage crop(BufferedImage image, CropFilter filter, Rect initialCrop) { + private static BufferedImage crop(BufferedImage image, CropFilter filter, Rect initialCrop, + int imageType) { if (image == null) { return null; } @@ -265,7 +302,8 @@ public class ImageUtils { int height = y2 - y1; // Now extract the sub-image - BufferedImage cropped = new BufferedImage(width, height, image.getType()); + BufferedImage cropped = new BufferedImage(width, height, + imageType != -1 ? imageType : image.getType()); Graphics g = cropped.getGraphics(); g.drawImage(image, 0, 0, width, height, x1, y1, x2, y2, null); |