App
BrushGenerator.java
Go to the documentation of this file.
1 package mhr.appcore.generators;
2 
3 import mhr.appcore.bitmap.BitmapInfo;
4 import mhr.appcore.bitmap.ChannelCount;
5 import mhr.appcore.bitmap.ColorMode;
6 import mhr.appcore.bitmap.Depth;
7 import mhr.appcore.bitmap.NBitmap;
8 import mhr.appcore.bitmap.NativeType;
9 import mhr.appcore.bitmap.exceptions.BitmapAllocationException;
10 import mhr.appcore.bitmap.exceptions.UnsupportedBitmapException;
11 
15 public class BrushGenerator {
16 
18  protected static native long createRoundBrush(int nativeType, int size, double hardness);
19 
20  @Deprecated // C implementace je neefektivni, vysledny stetec se stejne vytvari cely a kopiruje do cilove bitmapy, dokud nebude opraveno, nema valny vyznam, spise naopak.
21  protected static native int createRoundBrushIn(int nativeType, long dstAdress, int size, double hardness);
22 
23  //----- Pole --------------------------------------------------------------------------------------------------------------------------------//
24  //----- Accessory a primitivní metody -------------------------------------------------------------------------------------------------------//
25  //----- Pomocné metody ----------------------------------------------------------------------------------------------------------------------//
26  //----- Konstruktory ------------------------------------------------------------------------------------------------------------------------//
30  protected BrushGenerator() {}
31  //----- Destruktory -------------------------------------------------------------------------------------------------------------------------//
32  //----- Metody ------------------------------------------------------------------------------------------------------------------------------//
33 
43  public static NBitmap createRoundBrush(int size, double hardness, Depth depth) throws UnsupportedBitmapException, BitmapAllocationException {
44  BitmapInfo info = new BitmapInfo(size, size, ChannelCount.SINGLE_CHANNEL, depth, ColorMode.MONO, false);
45  NativeType type = info.getNativeType();
46  if (type == NativeType.INVALID_TYPE) {
47  throw new UnsupportedBitmapException("Requested bitmap type is not supported.");
48  }
49  long adress = createRoundBrush(type.getValue(), size, hardness);
50  if (adress == 0) {
51  throw new BitmapAllocationException("Could allocate bitmap");
52  }
53  return new NBitmap(adress, info);
54  }
55 
56  @Deprecated // C implementace je neefektivni, vysledny stetec se stejne vytvari cely a kopiruje do cilove bitmapy, dokud nebude opraveno, nema valny vyznam, spise naopak.
57  public static int createRoundBrushIn(NBitmap dst, int size, double hardness) {
58  BitmapInfo info = dst.getInfo();
60  throw new IllegalArgumentException("Brush must be created in single channel bitmap.");
61  }
62  long adress = dst.getAdress();
63  if (adress == 0) {
64  throw new IllegalStateException("Bitmap is already disposed.");
65  }
66  return createRoundBrushIn(info.getNativeType().getValue(), adress, size, hardness);
67  }
68 
69 }