private void printBlockUnsafe(AutoTypeImage image) {
    String sumType = image.getSumType();
    String bitWise = image.getBitWise();

    out.print(
        "\tpublic static "
            + sumType
            + " block_unsafe( "
            + image.getSingleBandName()
            + " integral , int x0 , int y0 , int x1 , int y1 )\n"
            + "\t{\n"
            + "\t\t"
            + sumType
            + " br = integral.data[ integral.startIndex + y1*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\t"
            + sumType
            + " tr = integral.data[ integral.startIndex + y0*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\t"
            + sumType
            + " bl = integral.data[ integral.startIndex + y1*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\t\t"
            + sumType
            + " tl = integral.data[ integral.startIndex + y0*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\treturn br-tr-bl+tl;\n"
            + "\t}\n\n");
  }
  private void printUnweighted() {
    String type = imageType.getDataType();
    String bitWise = imageType.getBitWise();

    out.print(
        "\t@Override\n"
            + "\tprotected void computeUnweightedScore() {\n"
            + "\t\t// compute the score for each angle in the histogram\n"
            + "\t\tfor( int y = rect.y0; y < rect.y1; y++ ) {\n"
            + "\t\t\tint indexX = derivX.startIndex + derivX.stride*y + rect.x0;\n"
            + "\t\t\tint indexY = derivY.startIndex + derivY.stride*y + rect.x0;\n"
            + "\n"
            + "\t\t\tfor( int x = rect.x0; x < rect.x1; x++ , indexX++ , indexY++ ) {\n"
            + "\t\t\t\t"
            + type
            + " dx = derivX.data[indexX]"
            + bitWise
            + ";\n"
            + "\t\t\t\t"
            + type
            + " dy = derivY.data[indexY]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tdouble angle = Math.atan2(dy,dx);\n"
            + "\t\t\t\t// compute which discretized angle it is\n"
            + "\t\t\t\tint discreteAngle = (int)((angle + angleRound)/angleDiv) % numAngles;\n"
            + "\t\t\t\t// sum up the \"score\" for this angle\n"
            + "\t\t\t\tsumDerivX[discreteAngle] += dx;\n"
            + "\t\t\t\tsumDerivY[discreteAngle] += dy;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
  private void sharpen4(AutoTypeImage image) {
    String name = image.getSingleBandName();
    String bitwise = image.getBitWise();
    String cast = image.getTypeCastFromSum();
    String sumtype = image.getSumType();

    out.print(
        "\tpublic static void sharpenInner4( "
            + name
            + " input , "
            + name
            + " output , "
            + sumtype
            + " minValue , "
            + sumtype
            + " maxValue ) {\n"
            + "\t\tfor( int y = 1; y < input.height-1; y++ ) {\n"
            + "\t\t\tint indexIn = input.startIndex + y*input.stride + 1;\n"
            + "\t\t\tint indexOut = output.startIndex + y*output.stride + 1;\n"
            + "\n"
            + "\t\t\tfor( int x = 1; x < input.width-1; x++ , indexIn++,indexOut++) {\n"
            + "\n"
            + "\t\t\t\t"
            + sumtype
            + " a = 5*(input.data[indexIn] "
            + bitwise
            + ") - (\n"
            + "\t\t\t\t\t\t(input.data[indexIn-1] "
            + bitwise
            + ")+(input.data[indexIn+1] "
            + bitwise
            + ") +\n"
            + "\t\t\t\t\t\t\t\t(input.data[indexIn-input.stride] "
            + bitwise
            + ") + (input.data[indexIn+input.stride] "
            + bitwise
            + "));\n"
            + "\n"
            + "\t\t\t\tif( a > maxValue )\n"
            + "\t\t\t\t\ta = maxValue;\n"
            + "\t\t\t\telse if( a < minValue )\n"
            + "\t\t\t\t\ta = minValue;\n"
            + "\n"
            + "\t\t\t\toutput.data[indexOut] = "
            + cast
            + "a;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
  private void printTransform(AutoTypeImage imageIn, AutoTypeImage imageOut) {

    String sumType = imageOut.getSumType();
    String bitWise = imageIn.getBitWise();
    String typeCast = imageOut.getTypeCastFromSum();

    out.print(
        "\tpublic static void transform( final "
            + imageIn.getSingleBandName()
            + " input , final "
            + imageOut.getSingleBandName()
            + " transformed )\n"
            + "\t{\n"
            + "\t\tint indexSrc = input.startIndex;\n"
            + "\t\tint indexDst = transformed.startIndex;\n"
            + "\t\tint end = indexSrc + input.width;\n"
            + "\n"
            + "\t\t"
            + sumType
            + " total = 0;\n"
            + "\t\tfor( ; indexSrc < end; indexSrc++ ) {\n"
            + "\t\t\ttransformed.data[indexDst++] = "
            + typeCast
            + "total += input.data[indexSrc]"
            + bitWise
            + ";\n"
            + "\t\t}\n"
            + "\n"
            + "\t\tfor( int y = 1; y < input.height; y++ ) {\n"
            + "\t\t\tindexSrc = input.startIndex + input.stride*y;\n"
            + "\t\t\tindexDst = transformed.startIndex + transformed.stride*y;\n"
            + "\t\t\tint indexPrev = indexDst - transformed.stride;\n"
            + "\n"
            + "\t\t\tend = indexSrc + input.width;\n"
            + "\n"
            + "\t\t\ttotal = 0;\n"
            + "\t\t\tfor( ; indexSrc < end; indexSrc++ ) {\n"
            + "\t\t\t\ttotal +=  input.data[indexSrc]"
            + bitWise
            + ";\n"
            + "\t\t\t\ttransformed.data[indexDst++] = transformed.data[indexPrev++] + total;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
  private void printBlockZero(AutoTypeImage image) {
    String sumType = image.getSumType();
    String bitWise = image.getBitWise();

    out.print(
        "\tpublic static "
            + sumType
            + " block_zero( "
            + image.getSingleBandName()
            + " integral , int x0 , int y0 , int x1 , int y1 )\n"
            + "\t{\n"
            + "\t\tx0 = Math.min(x0,integral.width-1);\n"
            + "\t\ty0 = Math.min(y0,integral.height-1);\n"
            + "\t\tx1 = Math.min(x1,integral.width-1);\n"
            + "\t\ty1 = Math.min(y1,integral.height-1);\n"
            + "\n"
            + "\t\t"
            + sumType
            + " br=0,tr=0,bl=0,tl=0;\n"
            + "\n"
            + "\t\tif( x1 >= 0 && y1 >= 0)\n"
            + "\t\t\tbr = integral.data[ integral.startIndex + y1*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\tif( y0 >= 0 && x1 >= 0)\n"
            + "\t\t\ttr = integral.data[ integral.startIndex + y0*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\tif( x0 >= 0 && y1 >= 0)\n"
            + "\t\t\tbl = integral.data[ integral.startIndex + y1*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\t\tif( x0 >= 0 && y0 >= 0)\n"
            + "\t\t\ttl = integral.data[ integral.startIndex + y0*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\treturn br-tr-bl+tl;\n"
            + "\t}\n\n");
  }
  private void printTheRest() {

    String bitWise = image.getBitWise();

    out.print(
        "\t@Override\n"
            + "\tpublic void setImage("
            + image.getImageName()
            + " image) {\n"
            + "\t\tthis.orig = image;\n"
            + "\t\tthis.data = orig.data;\n"
            + "\t\tthis.stride = orig.getStride();\n"
            + "\t}\n"
            + "\n"
            + "\t@Override\n"
            + "\tpublic "
            + image.getImageName()
            + " getImage() {\n"
            + "\t\treturn orig;\n"
            + "\t}\n"
            + "\n"
            + "\t@Override\n"
            + "\tpublic void region(float tl_x, float tl_y, ImageFloat32 output ) {\n"
            + "\t\tint xt = (int) tl_x;\n"
            + "\t\tint yt = (int) tl_y;\n"
            + "\t\tfloat ax = tl_x - xt;\n"
            + "\t\tfloat ay = tl_y - yt;\n"
            + "\n"
            + "\t\tfloat bx = 1.0f - ax;\n"
            + "\t\tfloat by = 1.0f - ay;\n"
            + "\n"
            + "\t\tfloat a0 = bx * by;\n"
            + "\t\tfloat a1 = ax * by;\n"
            + "\t\tfloat a2 = ax * ay;\n"
            + "\t\tfloat a3 = bx * ay;\n"
            + "\n"
            + "\t\tint regWidth = output.width;\n"
            + "\t\tint regHeight = output.height;\n"
            + "\t\tfinal float results[] = output.data;\n"
            + "\t\tboolean borderRight = false;\n"
            + "\t\tboolean borderBottom = false;\n"
            + "\n"
            + "\t\t// make sure it is in bounds or if its right on the image border\n"
            + "\t\tif (xt + regWidth >= orig.width || yt + regHeight >= orig.height) {\n"
            + "\t\t\tif( (xt + regWidth > orig.width || yt + regHeight > orig.height) )\n"
            + "\t\t\t\tthrow new IllegalArgumentException(\"requested region is out of bounds\");\n"
            + "\t\t\tif( xt+regWidth == orig.width ) {\n"
            + "\t\t\t\tregWidth--;\n"
            + "\t\t\t\tborderRight = true;\n"
            + "\t\t\t}\n"
            + "\t\t\tif( yt+regHeight == orig.height ) {\n"
            + "\t\t\t\tregHeight--;\n"
            + "\t\t\t\tborderBottom = true;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\n"
            + "\t\t// perform the interpolation while reducing the number of times the image needs to be accessed\n"
            + "\t\tfor (int i = 0; i < regHeight; i++) {\n"
            + "\t\t\tint index = orig.startIndex + (yt + i) * stride + xt;\n"
            + "\t\t\tint indexResults = output.startIndex + i*output.stride;\n"
            + "\n"
            + "\t\t\tfloat XY = data[index]"
            + bitWise
            + ";\n"
            + "\t\t\tfloat Xy = data[index + stride]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\tint indexEnd = index + regWidth;\n"
            + "\t\t\t// for( int j = 0; j < regWidth; j++, index++ ) {\n"
            + "\t\t\tfor (; index < indexEnd; index++) {\n"
            + "\t\t\t\tfloat xY = data[index + 1]"
            + bitWise
            + ";\n"
            + "\t\t\t\tfloat xy = data[index + stride + 1]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tfloat val = a0 * XY + a1 * xY + a2 * xy + a3 * Xy;\n"
            + "\n"
            + "\t\t\t\tresults[indexResults++] = val;\n"
            + "\t\t\t\tXY = xY;\n"
            + "\t\t\t\tXy = xy;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t\t\n"
            + "\t\t// if touching the image border handle the special case\n"
            + "\t\tif( borderBottom || borderRight )\n"
            + "\t\t\thandleBorder(output, xt, yt, ax, ay, bx, by, regWidth, regHeight, results, borderRight, borderBottom);\n"
            + "\t}\n"
            + "\n"
            + "\tprivate void handleBorder( ImageFloat32 output,\n"
            + "\t\t\t\t\t\t\t  int xt, int yt,\n"
            + "\t\t\t\t\t\t\t  float ax, float ay, float bx, float by,\n"
            + "\t\t\t\t\t\t\t  int regWidth, int regHeight, float[] results,\n"
            + "\t\t\t\t\t\t\t  boolean borderRight, boolean borderBottom) {\n"
            + "\n"
            + "\t\tif( borderRight ) {\n"
            + "\t\t\tfor( int y = 0; y < regHeight; y++ ) {\n"
            + "\t\t\t\tint index = orig.startIndex + (yt + y) * stride + xt + regWidth;\n"
            + "\t\t\t\tint indexResults = output.startIndex + y*output.stride + regWidth;\n"
            + "\n"
            + "\t\t\t\tfloat XY = data[index]"
            + bitWise
            + ";\n"
            + "\t\t\t\tfloat Xy = data[index + stride]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tresults[indexResults] = by*XY + ay*Xy;\n"
            + "\t\t\t}\n"
            + "\n"
            + "\t\t\tif( borderBottom ) {\n"
            + "\t\t\t\toutput.set(regWidth,regHeight, orig.get(xt+ regWidth,yt+regHeight));\n"
            + "\t\t\t} else {\n"
            + "\t\t\t\tfloat XY = orig.get(xt+ regWidth,yt+regHeight-1);\n"
            + "\t\t\t\tfloat Xy = orig.get(xt+ regWidth,yt+regHeight);\n"
            + "\n"
            + "\t\t\t\toutput.set(regWidth,regHeight-1, by*XY + ay*Xy);\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t\tif( borderBottom ) {\n"
            + "\t\t\tfor( int x = 0; x < regWidth; x++ ) {\n"
            + "\t\t\t\tint index = orig.startIndex + (yt + regHeight) * stride + xt + x;\n"
            + "\t\t\t\tint indexResults = output.startIndex + regHeight *output.stride + x;\n"
            + "\n"
            + "\t\t\t\tfloat XY = data[index]"
            + bitWise
            + ";\n"
            + "\t\t\t\tfloat Xy = data[index + 1]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tresults[indexResults] = bx*XY + ax*Xy;\n"
            + "\t\t\t}\n"
            + "\n"
            + "\t\t\tif( !borderRight ) {\n"
            + "\t\t\t\tfloat XY = orig.get(xt+regWidth-1,yt+ regHeight);\n"
            + "\t\t\t\tfloat Xy = orig.get(xt+regWidth, regHeight);\n"
            + "\n"
            + "\t\t\t\toutput.set(regWidth-1, regHeight, by*XY + ay*Xy);\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n");
  }
  private void sharpen8(AutoTypeImage image) {
    String name = image.getSingleBandName();
    String bitwise = image.getBitWise();
    String cast = image.getTypeCastFromSum();
    String sumtype = image.getSumType();

    out.print(
        "\tpublic static void sharpenInner8( "
            + name
            + " input , "
            + name
            + " output , "
            + sumtype
            + " minValue , "
            + sumtype
            + " maxValue ) {\n"
            + "\t\tfor( int y = 1; y < input.height-1; y++ ) {\n"
            + "\t\t\tint indexIn = input.startIndex + y*input.stride + 1;\n"
            + "\t\t\tint indexOut = output.startIndex + y*output.stride + 1;\n"
            + "\n"
            + "\t\t\tfor( int x = 1; x < input.width-1; x++ , indexIn++,indexOut++) {\n"
            + "\n"
            + "\t\t\t\t"
            + sumtype
            + " a11 = input.data[indexIn-input.stride-1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a12 = input.data[indexIn-input.stride] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a13 = input.data[indexIn-input.stride+1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a21 = input.data[indexIn-1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a22 = input.data[indexIn] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a23 = input.data[indexIn+1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a31 = input.data[indexIn+input.stride-1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a32 = input.data[indexIn+input.stride] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a33 = input.data[indexIn+input.stride+1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t\n"
            + "\t\t\t\t"
            + sumtype
            + " result = 9*a22 - (a11+a12+a13+a21+a23+a31+a32+a33);\n"
            + "\n"
            + "\t\t\t\tif( result > maxValue )\n"
            + "\t\t\t\t\tresult = maxValue;\n"
            + "\t\t\t\telse if( result < minValue )\n"
            + "\t\t\t\t\tresult = minValue;\n"
            + "\n"
            + "\t\t\t\toutput.data[indexOut] = "
            + cast
            + "result;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }