/*
 * MandelVroom 2.0
 *
 * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
 *
 * All rights reserved.
 *
 * Permission is hereby granted to distribute this program's source
 * executable, and documentation for non-comercial purposes, so long as the
 * copyright notices are not removed from the sources, executable or
 * documentation.  This program may not be distributed for a profit without
 * the express written consent of the author Kevin L. Clague.
 *
 * This program is not in the public domain.
 *
 * Fred Fish is expressly granted permission to distribute this program's
 * source and executable as part of the "Fred Fish freely redistributable
 * Amiga software library."
 *
 * Permission is expressly granted for this program and it's source to be
 * distributed as part of the Amicus Amiga software disks, and the
 * First Amiga User Group's Hot Mix disks.
 *
 * contents: this file contains the functions to create and initialize
 * a preset project selected by the user.
 */

#include "mandp.h"

#define NUMPRESETS 10

extern struct NewScreen NewScreen;

struct Preset {
  char   *Name;
  int     Type;
  double  StartX, StartY, EndX, EndY;
  SHORT   CountX, CountY;
  SHORT   MaxCount;
  UBYTE   MandType;
  USHORT  ViewModes;
  USHORT  Depth;
  ULONG   BorderType;
  SHORT  *ColorMap;
  SHORT   NumContours;
  USHORT *Contours;
  UBYTE  *Pens;
};


extern int Num_vp_Colors;

extern struct Preset Preset[];

extern USHORT NewViewModes;
extern UBYTE  NewDepth;

DefaultColors()
{
  LoadRGB4( vp, Preset[0].ColorMap, Num_vp_Colors );
}

/*
 * Generate a preset picture
 */
ClonePict( Pict, Type )
  register struct Picture *Pict;
  register SHORT Type;
{
  register struct Picture *ClonedPict;
  struct Picture *NewPict();

  extern int Num_vp_Colors;

  if ( (ClonedPict = NewPict( Type )) == NULL ) {
    ErrNoPict();
    return;
  }

  CopyPict( ClonedPict, Pict );

  strcpy(ClonedPict->Title,Pict->Title);

  ClonedPict->Flags = 0;
  ClonedPict->ZoomType == GENPENDSTATE;

  if ( Pict->pNode.ln_Type != Type ) {

    if ( Type == JULIAPICT ) {
      ClonedPict->Real     = Pict->RealLow;
      ClonedPict->Imag     = Pict->ImagLow;
      InitJulia( ClonedPict );

    } else {
      InitMand( ClonedPict );
    }
  }

  if ( OpenPicture( ClonedPict ) != 0 ) {
    ThrowPict( ClonedPict );
  }

  GetCurPict();
}

ErrNoPict()
{
  DispErrMsg( "Can't Allocate Picture.",0);
}

CopyPict( DstPict, SrcPict )
  register struct Picture *DstPict;
  register struct Picture *SrcPict;
{
  movmem( &SrcPict->Real, &DstPict->Real, sizeof(struct Picture)-
          ((char *) &SrcPict->Real - (char *) SrcPict) );
}

/*
 * Generate a preset picture
 */
int
SetPreset(Number)
  int Number;
{
  return( NewPreset( Number, Preset[Number].Type ));
}

/*
 * Generate a preset picture
 */
int
NewPreset(Number, Type)
  int Number;
  int Type;
{
  register struct Picture *Pict;

  struct Picture *NewPict();

  extern int Num_vp_Colors;

  if ( (Pict = NewPict( Type )) == NULL ) {
    ErrNoPict();
    return(UNSUCCESSFUL);
  }

  if (Number == -1) {
    InitPreset( 0, Pict );

#define VIEW_MODE_MASK (HIRES|INTERLACE|EXTRA_HALFBRITE)

    Pict->ViewModes = NewViewModes = screen->ViewPort.Modes & VIEW_MODE_MASK;
    Pict->Depth     = NewDepth     = screen->BitMap.Depth;

    if ( OpenPicture( Pict ) != 0 ) {

      ThrowPict( Pict );
      return(UNSUCCESSFUL);

    }
  } else {
    InitPreset( Number, Pict );

    if (MaybeNewScreen() == 0) {

      if ( OpenPicture( Pict ) != 0 ) {

        ThrowPict( Pict );
        return(UNSUCCESSFUL);

      } else {

        Generate( Pict );
      }
    }
  }
  GetCurPict();

  if (CurPict)
    LoadRGB4( vp, CurPict->RGBs, Num_vp_Colors );

  return(SUCCESSFUL);
}

InitJulia( Pict )
  register struct Picture *Pict;
{
  double JCountX, JCountY;

  double AspectRatio();

  JCountX        = (double) Pict->CountX;
  JCountY        = (double) Pict->CountY;

  Pict->ImagLow  = -1.0;
  Pict->ImagHigh =  1.0;

  Pict->RealLow  =  Pict->ImagLow * AspectRatio() * JCountX / JCountY;
  Pict->RealHigh = -Pict->RealLow;
}

/*
 * Set up system from preset list
 */
InitPreset(Number, Pict)
  int Number;
  register struct Picture *Pict;
{
  register LONG  i;

  register struct Preset  *CurPreset;

  register SHORT  *CurColors;
  register USHORT *CurContours;
  register UBYTE  *CurPens;

  register struct Node *pNode = (struct Node *) Pict;

  extern USHORT NewViewModes;
  extern UBYTE  NewDepth;

  if (Pict == NULL) {
    DispErrMsg("Initing NULL Pict",0);
    return(0);
  }

  if (Number < NUMPRESETS) {

    Pict->GenState = GENPENDSTATE;

    FreeCounts( Pict );

    CurPreset = &Preset[Number];

    sprintf(Pict->Title,"* %s",CurPreset->Name);

    Pict->CountX = CurPreset->CountX;
    Pict->CountY = CurPreset->CountY;

    if ( pNode->ln_Type == JULIAPICT ) {

      Pict->Real     = CurPreset->StartX;
      Pict->Imag     = CurPreset->StartY;

      InitJulia( Pict );

    } else {
      Pict->RealLow  = CurPreset->StartX;
      Pict->ImagLow  = CurPreset->StartY;
      Pict->RealHigh = CurPreset->EndX;
      Pict->ImagHigh = CurPreset->EndY;
    }

    Pict->MaxIteration = CurPreset->MaxCount;

    Pict->MathMode = CurPreset->MandType;

    Pict->ViewModes = CurPreset->ViewModes;
    Pict->Depth     = CurPreset->Depth;

    if ( Number != 0 ) {
      NewViewModes = CurPreset->ViewModes;
      NewDepth = CurPreset->Depth;
    }

    CurColors = CurPreset->ColorMap;

    for (i = 0; i < 32; i++) {
      Pict->RGBs[i] = *CurColors++;
    }

    CurContours = CurPreset->Contours;
    CurPens = CurPreset->Pens;

    for (i = 0; i < CurPreset->NumContours; i++) {
      *(Pict->Heights + i) = *CurContours++;
      *(Pict->Pens + i) = *CurPens++;
    }

    for ( ; i < NumContours; i++ ) {
      *(Pict->Heights + i) = 0;
      *(Pict->Pens + i) = NORMALPEN;
    }

    MakeColorXlate( Pict );

    CalculateGaps( Pict );

    return(0);
  } else {
    DispErrMsg("Invalid Preset",0);
    return(1);
  }
}

/**************************************************************************
 *
 *  Preset arrays for generating pictures
 *
 *************************************************************************/

SHORT big_brotPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0114,  0x0225,  0x0337,  0x0448,
  0x055a,  0x066b,  0x077c,  0x088e,  0x099f,  0x0bbf,  0x0ccf,  0x0eef,
  0x0fff,  0x0eee,  0x0dde,  0x0ccd,  0x0ccd,  0x0bbc,  0x0aab,  0x099b,
  0x088a,  0x077a,  0x0669,  0x0558,  0x0558,  0x0447,  0x0337,  0x0226
};
USHORT big_brotHeights[] =
{
  128,
  29,19, 13,  10, 9,  8,  7,  6,
  5,  4,  3,  2,  1,  0,  0,  0,
  0,  0,  0,  0,  0,  0,  0,  0,
  0,  0,  0,  0,  0,  0,  0,  0,
};
UBYTE big_brotPens[] =
{
  0,  16,  17,  18,  19,  20,  21,  22,
  23,  24,  25,  26,  27,  28,  29,  30,
  31,  4,  5,  6,  7,  8,  9,  10,
  11,  12,  13,  14,  15,  16,  17,  18,
  19,  20,  21,  22,  23,  24,  25,  26,
  27,  28,  29,  30,  31,  4,  1,  1,
};

SHORT Hey_BabyPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0c9b,  0x0b6a,  0x0a49,  0x0927,
  0x0806,  0x0716,  0x0727,  0x0637,  0x0658,  0x0568,  0x0579,  0x0489,
  0x0000,  0x0fff,  0x0dee,  0x0bcd,  0x09bc,  0x06aa,  0x0499,  0x0278,
  0x0067,  0x059a,  0x0acc,  0x0fff,  0x0bdd,  0x08bb,  0x0489,  0x0067
};

USHORT Hey_BabyHeights[] =
{
  1023,  247,  220,  193,  167,  160,  154,  147,
  141,  134,  128,  122,  115,  110,  106,  102,
  98,  93,  89,  85,  81,  77,  74,  73,
  72,  71,  70,  69,  68,  67,  66,  65
};

UBYTE Hey_BabyPens[] =
{
  0,  1,  2,  3,  4,  5,  6,  7,
  8,  9,  10,  11,  12,  13,  14,  15,
  30,  29,  28,  27,  26,  25,  24,  23,
  22,  21,  20,  19,  18,  17,  20,  23
};

SHORT coverPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0f58,  0x0f46,  0x0e46,  0x0d35,
  0x0c35,  0x0b34,  0x0a33,  0x0923,  0x0822,  0x0611,  0x0511,  0x0400,
  0x0fe7,  0x0f9d,  0x0f8c,  0x0f7a,  0x009f,  0x0ade,  0x0cee,  0x009f,
  0x03af,  0x05bf,  0x05bd,  0x09de,  0x0ade,  0x0cee,  0x09cd,  0x06bc
};
USHORT coverHeights[] =
{
  1023,  111, 106,  96,  86,  76,  75,  74,
  73,  72,  71,  70,  69,  68,  67,  66,
  65,  64,  62,  61,  60,  59,  58,  57,
  48,  47,  46,  45,  42,  39,  36,  35,
  34,  33,  32,  31,  30,  29,  28,  27,
  26,  25,  24,  23,  22,  21,  20,  19,
  18,  17,  16,  15,  14,  13,  12,  11,
  10,  14,  13,  12,  11,  10,  9,  8,
  3,  0,  0,  0,  0,  0,  0,  0,
};
UBYTE coverPens[] =
{
  0,  16,  17,  18,  4,  5,  6,  7,
  8,  9,  10,  11,  12,  13,  14,  15,
  17,  17,  18,  19,  4,  5,  6,  7,
  8,  9,  10,  11,  12,  13,  14,  15,
  15,  14,  13,  12,  11,  10,  8,  7,
  6,  5,  4,  19,  18,  17,  11,  10,
  9,  8,  7,  6,  5,  4,  19,  18,
  1,  1,  1,  1,  1,  1,  1,  1,
  1,  1,  1,  1,  1,  1,  1,  1,
};

SHORT sea_horsePalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0fff,  0x0bbb,  0x0888,  0x0444,
  0x0000,  0x0002,  0x0003,  0x0005,  0x0006,  0x0007,  0x0009,  0x000a,
  0x002a,  0x003a,  0x0059,  0x0003,  0x0020,  0x0030,  0x0040,  0x0040,
  0x0050,  0x0060,  0x0050,  0x0040,  0x0030,  0x0020,  0x0010,  0x0fff
};
USHORT sea_horseHeights[] =
{
  1023,  635,  542,  449,  356,  263,  171,  145,
  142,  140,  139,  138,  137,  136,  135,  134,
  133,  132,  131,  130,  129,  128,  127,  126,
  125,  124,  123,  122,  121,  120,  119,  118,
  117,  116,  115,  114,  113,  112,  111,  110,
  109,  108,  107,  106,  105,  104,  103,  102,
  101,  100,  99,  98,  97,  96,  95,  94,
  93,  92,  91,  90,  89,  88,  87,  86,
  85,  84,  83,  82,  81,  80,  79,  78,
  77,  76,  75,  74,  73,  72,  71,  70,
  69,  68,  67,  66,  65,  64,  63,  62,
  61,  60,  59,  58,  57,  56,  55,  54,
  53,  52,  51,  50,  49,  48,  47,  46,
  45,  44,  43,  42,  41,  40,  39,  38,
  37,  36,  35,  34,  33,  32,  31,  30,
  29,  28,  27,  26,  25,  24,  23,  22,
  21,  20,  19,  18,  17,  16,  15,  14,
  13,  12,  11,  10,  9,  8,  7,  6,
  5,  4,  3,  2,  1,  0,  0,  0,
};
UBYTE sea_horsePens[] =
{
  0,  7,  6,  5,  4,  4,  5,  6,
  7,  8,  10,  20,  11,  21,  12,  22,
  13,  23,  14,  24,  15,  25,  16,  26,
  17,  27,  18,  28,  17,  29,  16,  30,
  15,  20,  14,  21,  13,  22,  12,  23,
  11,  24,  10,  25,  10,  26,  11,  27,
  12,  28,  13,  29,  14,  30,  15,  20,
  16,  21,  17,  22,  18,  23,  17,  24,
  16,  25,  15,  26,  14,  27,  13,  28,
  12,  29,  11,  30,  10,  20,  10,  21,
  11,  22,  12,  23,  13,  24,  14,  25,
  15,  26,  16,  27,  17,  28,  18,  29,
  17,  30,  16,  20,  15,  21,  14,  22,
  13,  23,  12,  24,  11,  25,  10,  26,
  10,  27,  11,  28,  12,  29,  13,  30,
  14,  20,  15,  21,  16,  22,  17,  23,
  18,  24,  17,  25,  16,  26,  15,  27,
  14,  28,  13,  29,  12,  30,  11,  20,
  10,  21,  10,  22,  11,  23,  12,  1,
};

SHORT golden_dragonPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0f93,  0x0e83,  0x0c73,  0x0b53,
  0x0943,  0x0732,  0x0411,  0x0200,  0x0310,  0x0410,  0x0520,  0x0720,
  0x0850,  0x0930,  0x0c80,  0x0fb0,  0x0620,  0x0510,  0x0310,  0x0200,
  0x0521,  0x0742,  0x0a63,  0x0c84,  0x0a63,  0x0742,  0x0521,  0x0200
};
USHORT golden_dragonHeights[] =
{
  1023,  353,  316,  279,  274,  270,  266,  261,
  257,  253,  249,  226,  224,  222,  220,  219,
  217,  215,  213,  212,  210,  208,  207,  195,
  194,  193,  192,  191,  190,  189,  188,  187,
  186,  185,  184,  183,  182,  181,  180,  179,
  178,  177,  176,  175,  174,  173,  172,  171,
  170,  169,  168,  167,  166,  165,  164,  163,
  162,  161,  160,  159,  158,  157,  156,  155,
  154,  153,  152,  151,  150,  149,  148,  147,
  146,  145,  144,  0,    0,    0,    0,    0,
};
UBYTE golden_dragonPens[] =
{
  0,  4,  5,  6,  7,  8,  9,  10,
  11,  12,  14,  14,  15,  16,  17,  18,
  19,  20,  21,  22,  23,  24,  25,  26,
  27,  28,  29,  30,  23,  24,  25,  26,
  27,  28,  29,  30,  23,  24,  25,  26,
  27,  28,  29,  30,  23,  24,  25,  26,
  27,  28,  29,  30,  23,  24,  25,  26,
  27,  28,  29,  30,  23,  24,  25,  26,
  27,  28,  29,  30,  13,  24,  25,  26,
  27,  28,  29,  13,  1,  1,  1,  1,
};

SHORT dual_spiralPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0bbb,  0x0999,  0x0777,  0x0555,
  0x0333,  0x0246,  0x0357,  0x0468,  0x0479,  0x058b,  0x068c,  0x079d,
  0x0fff,  0x0eee,  0x0ccc,  0x0fd0,  0x0246,  0x0357,  0x0468,  0x079d,
  0x068c,  0x068b,  0x057a,  0x057a,  0x0469,  0x0358,  0x0357,  0x0246
};
USHORT dual_spiralHeights[] =
{
  1023,  283,  271,  260,  249,  238,  226,  225,
  224,  223,  222,  221,  220,  219,  218,  217,
  216,  215,  214,  213,  212,  211,  210,  209,
  208,  207,  206,  205,  204,  203,  202,  201,
  200,  199,  198,  197,  196,  195,  194,  193,
  192,  191,  190,  189,  188,  187,  186,  185,
  184,  183,  182,  181,  180,  179,  178,  177,
  176,  175,  174,  173,  172,  171,  170,  169,
  168,  167,  166,  165,  164,  163,  162,  161,
  160,  159,  158,  157,  156,  155,  154,  153,
  152,  151,  150,  149,  148,  147,  146,  145,
  144,  143,  142,  141,  140,  139,  138,  137,
  136,  135,  134,  133,  132,  131,  130,  129,
  128,  127,  126,  125,  124,  123,  122,  121,
  120,  119,  118,  117,  116,  115,  114,  113,
  112,  111,  110,  109,  108,  107,  106,  105,
  104,  103,  102,  101,  100,  99,  98,  97,
  96,  95,  94,  93,  92,  91,  90,  89,
  88,  87,  86,  85,  84,  83,  82,  81,
  80,  79,  78,  77,  76,  75,  74,  73,
  72,  71,  70,  69,  68,  67,  66,  65,
  64,  63,  62,  61,  60,  59,  58,  57,
  56,  55,  54,  53,  52,  51,  50,  49,
  48,  47,  46,  45,  44,  43,  42,  41,
  40,  39,  38,  37,  36,  35,  34,  33,
  32,  31,  30,  29,  28,  27,  26,  25,
  24,  23,  22,  21,  20,  19,  18,  17,
  16,  15,  14,  13,  12,  11,  10,  9,
  8,  7,  6,  5,  4,  3,  2,  1,
  0,  0,  0,  0,  0,  0,  0,  0,
};
UBYTE dual_spiralPens[] =
{
  0,  16,  17,  18,  5,  6,  7,  31,
  30,  29,  28,  27,  26,  25,  24,  23,
  24,  25,  26,  27,  28,  29,  30,  31,
  30,  29,  28,  27,  26,  25,  24,  23,
  24,  25,  26,  27,  28,  29,  30,  31,
  31,  30,  29,  28,  27,  26,  25,  24,
  23,  24,  25,  26,  27,  28,  29,  30,
  31,  31,  30,  29,  28,  27,  26,  25,
  24,  23,  24,  25,  26,  27,  28,  29,
  30,  31,  31,  30,  29,  28,  27,  26,
  25,  24,  23,  24,  25,  26,  27,  28,
  29,  30,  31,  31,  30,  29,  28,  27,
  26,  25,  24,  23,  24,  25,  26,  27,
  28,  29,  30,  31,  31,  30,  29,  28,
  27,  26,  25,  24,  23,  24,  25,  26,
  27,  28,  29,  30,  31,  31,  30,  29,
  28,  27,  26,  25,  24,  23,  24,  25,
  26,  27,  28,  29,  30,  31,  31,  30,
  29,  28,  27,  26,  25,  24,  23,  24,
  25,  26,  27,  28,  29,  30,  31,  31,
  30,  29,  28,  27,  26,  25,  24,  23,
  24,  25,  26,  27,  28,  29,  30,  31,
  31,  30,  29,  28,  27,  26,  25,  24,
  23,  24,  25,  26,  27,  28,  29,  30,
  31,  31,  30,  29,  28,  27,  26,  25,
  24,  23,  24,  25,  26,  27,  28,  29,
  30,  31,  31,  30,  29,  28,  27,  26,
  25,  24,  23,  24,  25,  26,  27,  28,
  29,  30,  31,  31,  30,  29,  28,  27,
  26,  25,  24,  23,  24,  25,  26,  27,
};

SHORT halfbritePalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0edd,  0x0dcc,  0x0dcc,  0x0cbb,
  0x0cbb,  0x0baa,  0x0baa,  0x0a99,  0x0a99,  0x0988,  0x0988,  0x0877,
  0x0445,  0x0fee,  0x0edd,  0x0dcc,  0x0cbb,  0x0a99,  0x0988,  0x0877,
  0x0e95,  0x0d84,  0x0d83,  0x0c73,  0x0b62,  0x0a51,  0x0a41,  0x0940
};
USHORT halfbriteHeights[] =
{
  1023,  355,  333,  311,  289,  267,  245,  223,
  201,  179,  173,  167,  161,  155,  149,  143,
  137,  131,  125,  119,  113,  107,  101,  95,
  94,  93,  92,  91,  90,  89,  88,  87,
  86,  85,  84,  83,  82,  81,  80,  79,
  78,  77,  76,  75,  74,  73,  72,  71,
  70,  69,  68,  67,  66,  65,  64,  63,
  62,  61,  60,  59,  58,  57,  56,  55,
  54,  53,  52,  51,  50,  49,  48,  47,
  46,  45,  44,  43,  42,  41,  40,  39,
  38,  37,  36,  35,  34,  33,  32,  31,
  30,  29,  28,  27,  26,  25,  24,  23,
  22,  21,  20,  19,  18,  17,  16,  15,
  14,  13,  12,  11,  10,  9,  8,  7,
  6,  5,  4,  3,  2,  1,  0,  0,
};
UBYTE halfbritePens[] =
{
  17,  63,  62,  61,  60,  59,  58,  57,
  56,  31,  30,  29,  28,  27,  26,  25,
  24,  25,  26,  27,  28,  29,  30,  31,
  56,  57,  58,  59,  60,  61,  62,  63,
  55,  54,  53,  52,  51,  50,  49,  23,
  22,  21,  20,  19,  18,  17,  18,  19,
  20,  21,  22,  23,  49,  50,  51,  52,
  53,  54,  55,  47,  46,  45,  44,  43,
  42,  41,  40,  39,  38,  37,  36,  34,
  15,  14,  13,  12,  11,  10,  9,  8,
  7,  6,  5,  4,  5,  6,  7,  8,
  9,  10,  11,  12,  13,  14,  15,  34,
  36,  37,  38,  39,  40,  41,  42,  43,
  44,  45,  46,  47,  47,  47,  46,  45,
  44,  43,  42,  41,  40,  39,  38,  37,
};

SHORT Valley_GalPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x099f,  0x077c,  0x055a,  0x0337,
  0x0114,  0x0225,  0x0446,  0x0557,  0x0668,  0x0779,  0x099a,  0x0aab,
  0x0bbc,  0x0ccd,  0x0eee,  0x0fff,  0x0eee,  0x0dde,  0x0ccd,  0x0bbc,
  0x0aab,  0x099b,  0x077a,  0x0669,  0x0558,  0x0448,  0x0337,  0x0226
};
USHORT Valley_GalHeights[] =
{
  1023,  182,  137,  126,  115,  105,  94,  83,
  73,  72,  71,  70,  69,  68,  67,  66,
  65,  64,  63,  62,  61,  60,  59,  58,
  57,  56,  55,  54,  53,  52,  51,  50,
  49,  48,  47,  46,  45,  44,  43,  42,
  41,  40,  39,  38,  37,  36,  35,  34,
  33,  32,  31,  30,  29,  28,  27,  26,
  25,  24,  23,  22,  21,  20,  19,  18,
  17,  16,  15,  14,  13,  12,  11,  10,
  9,  8,  7,  6,  5,  4,  3,  2,
  1,  0,  0,  0,  0,  0,  0,  0,
};
UBYTE Valley_GalPens[] =
{
  0,  17,  15,  14,  13,  12,  11,  10,
  9,  8,  8,  9,  10,  11,  12,  13,
  14,  15,  16,  17,  18,  19,  20,  21,
  22,  23,  24,  25,  26,  27,  28,  29,
  30,  8,  9,  10,  11,  12,  13,  14,
  15,  16,  17,  18,  19,  20,  21,  22,
  23,  24,  25,  26,  27,  28,  29,  30,
  8,  9,  10,  11,  12,  13,  14,  15,
  16,  17,  18,  19,  20,  21,  22,  23,
  24,  25,  26,  27,  28,  29,  30,  8,
  9,  10,  11,  12,  13,  14,  15,  16,
};

SHORT dragon_juliaPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x0f60,  0x0f80,  0x0f90,  0x0fb0,
  0x0fd0,  0x0ff0,  0x0dd1,  0x0bb2,  0x0993,  0x0884,  0x0665,  0x0446,
  0x0227,  0x0008,  0x0207,  0x0406,  0x0605,  0x0804,  0x0903,  0x0b02,
  0x0d01,  0x0f00,  0x0f20,  0x0f40,  0x0f50,  0x0f70,  0x0f90,  0x0fb0
};
USHORT dragon_juliaHeights[] =
{
  1023,  142,  132,  123,  113,  104,  99,  94,
  89,  84,  79,  74,  71,  68,  66,  63,
  60,  58,  55,  52,  50,  48,  47,  45,
  44,  42,  41,  39,  38,  36,  35,  34,
  33,  32,  31,  30,  29,  28,  27,  26,
  25,  24,  23,  22,  21,  20,  19,  18,
  17,  16,  15,  14,  13,  12,  11,  10,
  9,  8,  7,  6,  5,  4,  3,  2,
  1,  0,  0,  0,  0,  0,  0,  0,
};
UBYTE dragon_juliaPens[] =
{
  0,  26,  27,  28,  4,  5,  6,  7,
  8,  9,  10,  11,  12,  13,  14,  15,
  16,  17,  18,  19,  20,  21,  22,  23,
  24,  25,  26,  27,  28,  29,  30,  31,
  9,  10,  11,  12,  13,  14,  15,  16,
  17,  18,  19,  20,  21,  22,  23,  24,
  25,  26,  27,  28,  29,  30,  31,  9,
  10,  11,  12,  13,  14,  15,  16,  17,
  18,  19,  20,  1,  1,  1,  1,  1,
};

SHORT haloPalette[] =
{
  0x0000,  0x0b98,  0x0fdc,  0x0765,  0x000f,  0x011f,  0x022f,  0x033f,
  0x055f,  0x066f,  0x077f,  0x088f,  0x099f,  0x0aaf,  0x0ccf,  0x0ddf,
  0x0eef,  0x0fff,  0x0eee,  0x0dde,  0x0ccd,  0x0bbc,  0x0aac,  0x099b,
  0x088a,  0x0779,  0x0669,  0x0558,  0x0447,  0x0337,  0x0226,  0x0fff
};
USHORT haloHeights[] =
{
  1023,  89,  88,  87,  86,  85,  84,  83,
  82,  81,  80,  79,  78,  77,  76,  75,
  74,  73,  72,  71,  70,  69,  68,  67,
  66,  65,  64,  63,  62,  61,  60,  59,
  58,  57,  56,  55,  54,  53,  52,  51,
  50,  49,  48,  47,  46,  45,  44,  43,
  42,  41,  40,  39,  38,  37,  36,  35,
  34,  33,  32,  31,  30,  29,  28,  27,
  26,  25,  24,  23,  22,  21,  20,  19,
  18,  17,  16,  15,  14,  13,  12,  11,
  10,  9,  8,  7,  6,  5,  4,  3,
  2,  1,  0,  0,  0,  0,  0,  0,
};
UBYTE haloPens[] =
{
  0,  15,  14,  13,  12,  11,  10,  9,
  8,  7,  6,  5,  4,  4,  5,  4,
  5,  6,  7,  8,  9,  10,  11,  12,
  13,  14,  15,  15,  14,  13,  12,  11,
  10,  9,  8,  7,  6,  5,  4,  4,
  5,  4,  5,  6,  7,  8,  9,  10,
  11,  12,  13,  14,  15,  15,  14,  13,
  12,  11,  10,  9,  8,  7,  6,  5,
  4,  4,  5,  4,  5,  6,  7,  8,
  9,  10,  11,  12,  13,  14,  15,  15,
  14,  13,  12,  11,  10,  9,  8,  7,
  6,  5,  4,  4,  5,  4,  5,  6,
};

#define NUM_CONTOURS(a) (sizeof(a)/sizeof(USHORT))

struct Preset Preset[] =
  {
    {
      "big_brot",  /* Preset Name */
      MANDPICT,
      -2.000000, -1.204545, /* StartX, StartY */
      2.820000, 1.204545, /* EndX, EndY */
      109, 78, /* CountX,CountY */
      128,      /* MaxCount */
      0,     /* MandType */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      &big_brotPalette[0], /* Palette colors */
      32,         /* NumContours */
      &big_brotHeights[0], /* ContourHeights */
      &big_brotPens[0]     /* ContourPens */
    },
    {
      "Hey_Baby",  /* Preset Name */
      MANDPICT,
      -0.143523, -1.019072, /* StartX, StartY */
      -0.143384, -1.018843, /* EndX, EndY */
      96, 65, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MandType */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      Hey_BabyPalette, /* Palette colors */
      32,         /* NumContours */
      Hey_BabyHeights, /* ContourHeights */
      Hey_BabyPens     /* ContourPens */
    },
    {
      "Aug_85_Cover",  /* Preset Name */
      MANDPICT,
      -0.948154, -0.296503, /* StartX, StartY */
      -0.888359, -0.232261, /* EndX, EndY */
      92, 86, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      coverPalette, /* Palette colors */
      NUM_CONTOURS( coverHeights ),    /* NumContours */
      coverHeights, /* ContourHeights */
      coverPens     /* ContourPens */
    },

    {
      "sea_horse",  /* Preset Name */
      MANDPICT,
      -0.750055,  0.105343, /* StartX, StartY */
      -0.742464,  0.113267, /* EndX, EndY */
      86, 79, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      sea_horsePalette, /* Palette colors */
      NUM_CONTOURS( sea_horseHeights ),         /* NumContours */
      sea_horseHeights, /* ContourHeights */
      sea_horsePens     /* ContourPens */
    },

    {
      "golden_dragon",  /* Preset Name */
      MANDPICT,
      -0.764140, -0.095187, /* StartX, StartY */
      -0.764031, -0.095102, /* EndX, EndY */
      117, 87, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      golden_dragonPalette, /* Palette colors */
      NUM_CONTOURS( golden_dragonHeights ), /* NumContours */
      golden_dragonHeights, /* ContourHeights */
      golden_dragonPens     /* ContourPens */
    },
    {
      "dual_spiral",  /* Preset Name */
      MANDPICT,
      -0.764616, -0.095488, /* StartX, StartY */
      -0.764312, -0.094471, /* EndX, EndY */
      94, 85, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      dual_spiralPalette, /* Palette colors */
      NUM_CONTOURS( dual_spiralHeights ), /* NumContours */
      dual_spiralHeights, /* ContourHeights */
      dual_spiralPens     /* ContourPens */
    },
    {
      "halfbrite",  /* Preset Name */
      MANDPICT,
      -0.655231, -0.366674, /* StartX, StartY */
      -0.654933, -0.366417, /* EndX, EndY */
      103, 84, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0080,   /* ViewModes */
      6,     /* Depth */
      0,     /* Border Type*/
      halfbritePalette, /* Palette colors */
      NUM_CONTOURS( halfbriteHeights ), /* NumContours */
      halfbriteHeights, /* ContourHeights */
      halfbritePens     /* ContourPens */
    },
    {
      "Valley_Gal",  /* Preset Name */
      JULIAPICT,
      -0.760314, -0.135554, /* StartX, StartY */
      1.707388, 1.064516, /* EndX, EndY */
      133, 77, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      Valley_GalPalette, /* Palette colors */
      NUM_CONTOURS( Valley_GalHeights ), /* NumContours */
      Valley_GalHeights, /* ContourHeights */
      Valley_GalPens     /* ContourPens */
    },
    {
      "dragon_julia",  /* Preset Name */
      JULIAPICT,
      -0.942986, -0.270764, /* StartX, StartY */
      1.288473, 0.974026, /* EndX, EndY */
      149, 77, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      dragon_juliaPalette, /* Palette colors */
      NUM_CONTOURS( dragon_juliaHeights ), /* NumContours */
      dragon_juliaHeights, /* ContourHeights */
      dragon_juliaPens     /* ContourPens */
    },
    {
      "halo",  /* Preset Name */
      JULIAPICT,
       0.263523,  0.000016, /* StartX, StartY */
      1.031916, 1.233333, /* EndX, EndY */
      79, 77, /* CountX,CountY */
      1023,     /* MaxCount */
      0,     /* MathMode */
      0x0000,   /* ViewModes */
      5,     /* Depth */
      0,     /* Border Type*/
      haloPalette, /* Palette colors */
      NUM_CONTOURS( haloHeights ),    /* NumContours */
      haloHeights, /* ContourHeights */
      haloPens     /* ContourPens */
    }
  };

#define DEVELOPMENT
#ifdef DEVELOPMENT

SavePreset(name,MPict)
  char *name;
  struct Picture *MPict;
{
  register struct Picture *Pict = MPict;
  int i;

  FILE *SaveFile;

  SaveFile = fopen(name,"a");

  if (SaveFile != (struct FILE *) NULL) {

    fprintf(SaveFile, "SHORT %sPalette[] =\n{\n",name);
    for (i = 0; i < 32; i++) {
      fprintf(SaveFile, "  0x%04x", GetRGB4(vp->ColorMap, i));

      if (i != 31)
        fprintf(SaveFile,",");

      if (i % 8 == 7)
        fprintf(SaveFile, "\n");
    }
    fprintf(SaveFile, "};\n");

    fprintf(SaveFile, "USHORT %sHeights[] =\n{\n",name);
    for (i = 0; i < NumContours; i++) {
      fprintf(SaveFile, "  %d", *(Pict->Heights + i) );

      if (i != NumContours - 1) {
        fprintf(SaveFile,",");
        if (i % 8 == 7)
          fprintf(SaveFile, "\n");
      }
    }
    fprintf(SaveFile, "\n};\n");

    fprintf(SaveFile, "UBYTE %sPens[] =\n{\n",name);
    for (i = 0; i < NumContours; i++) {
      fprintf(SaveFile, "  %d", *(Pict->Pens + i) );

      if (i != NumContours - 1) {
        fprintf(SaveFile,",");
        if (i % 8 == 7)
          fprintf(SaveFile, "\n");
      }
    }
    fprintf(SaveFile, "\n};\n");

    fprintf(SaveFile, "    {\n");
    fprintf(SaveFile, "      \"%s\",  /* Preset Name */\n", name);

    if (Pict->pNode.ln_Type == JULIAPICT) {
      fprintf(SaveFile, "      %f, %f, /* StartX, StartY */\n",
                                      Pict->Real, Pict->Imag);
    } else {
      fprintf(SaveFile, "      %f, %f, /* StartX, StartY */\n",
                                      Pict->RealLow, Pict->ImagLow);
    }

    fprintf(SaveFile, "      %f, %f, /* EndX, EndY */\n", Pict->RealHigh,
                                                          Pict->ImagHigh);
    fprintf(SaveFile, "      %d, %d, /* CountX,CountY */\n",
                             Pict->CountX, Pict->CountY);

    fprintf(SaveFile, "      %d,     /* MaxCount */\n", Pict->MaxIteration);
    fprintf(SaveFile, "      %d,     /* MathMode */\n", Pict->MathMode);

    fprintf(SaveFile, "      0x%04x,   /* ViewModes */\n",
                                    screen->ViewPort.Modes);

    fprintf(SaveFile, "      %d,     /* Depth */\n",
                                    screen->BitMap.Depth);

    fprintf(SaveFile, "      %d,     /* Border Type*/\n", 0);

    fprintf(SaveFile, "      %sPalette, /* Palette colors */\n",
                                    name);

    fprintf(SaveFile, "      %d,         /* NumContours */\n",
                                    NumContours);

    fprintf(SaveFile, "      %sHeights, /* ContourHeights */\n", name);
    fprintf(SaveFile, "      %sPens     /* ContourPens */\n", name);
    fprintf(SaveFile, "    },\n\n\n");

    fclose( SaveFile );
  }
}
#endif
