
                   -------------------------------------
                   *************************************
                   -------------------------------------

                                  C P I C

                           © Copyright  1990 by
                              Thomas Zipproth
                            Dr. Jochner Weg 10
                              8948 Mindelheim
                                  Germany
                              Tel. 08261/4838

         --------------------------------------------------------
            Programs and procedures for an efficent handling of
               Pictures and graphics in connection with the
                               CPic - Format
                           V 1.0 (first release)

                 Short version of the german documentation
         ---------------------------------------------------------


Copyright:

All programs and sourcecodes of the CPic package in exception of the module
CPicSupport (.mod .sym .obj .def .asm) are Freeware.

CPicSupport is Shareware.  I think about 10 $ are correct.  (If this is not
possible I would also be glad about a disk with good pictures (of course in
the CPic - Format) or something like that).

No commercial use of CPic is allowed without my written permission.


Short Overview:

CPic  (Crunched  -  Picture) is a graphic - format wich allows an efficient
handling of pictures and graphics.
The  main  advantages  are the better compressing - algorithm which reduces
the length of IFF-ILBM Files about 10 - 60 % (especially in connection with
the  Palette  - Program), the high speed of decrunching and the possibility
to load crunched Pictures direct from Memory.
You  can  hold  a  large  amount of graphics in memory (in form of the com-
pressed CPic - Format) and directly and very fast load from there.  You can
convert  the  IFF-ILBM  format  into the CPic-Format and convert the CPic -
Format  back  into  the  IFF - format.  CPic saves only the Picture - data,
other information like color - cycling is lost.

The  package  includes the CPicSupport - Import Modul which contains proce-
dures  to  load and save the CPic - format (with many possibilities and op-
tions),  programs  for  converting,  displaying  and optimizing, and demo -
programs for the procedures in CPicSupport.

---------------------------------------------------------------------------

The whole package:

CPic.dok           German documentation.
CPic.doc           English documentation.

CPicSupport :

CPicSupport.def
CPicSupport.mod
CPicSupport.sym
CPicSupport.obj    The procedures which you can import.
CPicSupport.asm    The assembler - Sources.
CPicSupport.dok    German documentation of CPicSupport.

CPicTools :

CPic               Converts the IFF - format into the CPic - format ( CLI )
ILBM               Converts the CPic - format into the IFF - Format ( CLI )
Disp               Shows CPic - Pictures.   (CLI + WB)
Disp.info
Show               Picture - show program for CPic - pictures. (CLI)
Palette            Optimizes compression of CPic - Files.      (CLI)
CPicTools.dok      German documentation of CPicTools.

CPicDemos :

Speed                      Demo - program.
Speed.info
Speed.mod
M0 M1 M2 M3 M4 M5 M6 M7    Pictures used from Speed.
Colors1                    Demo - program.
Colors1.mod
Colors2                    Demo - program.
Colors2.mod
C1 C2 C3 C4                Pictures used from Colors.
Picture.CPic               Demo - picture.
CPicDemos.dok              German documentation of CPicDemos.

CPicSource :

CPic.mod                   Sourcecodes of the CPicTools - Programs.
ILBM.mod
Disp.mod
Show.mod
Palette.mod
ToolSupport.def
ToolSupport.mod
ToolSupport.sym
ToolSupport.obj


---------------------------------------------------------------------------


CPicTools :

(If  the  arguments  from  CLI  are not explained call the programs without
arguments or refer to the Sourcecode - Headers.)


CPic :

This  program  converts the IFF-ILBM format into the CPic-format.  It auto-
matically searches the smallest rectangle which contains all picture - data
(every  pixel  which  is not from the color of the background) and saves it
together  with  all  information  about the Screen (bitmap and viewport) in
which the rectangle is (for example Viewmode). This rectangle is efficient-
ly  compressed and saved together with a variable from the type CPicInfo as
Fileheader  which  contains all information (Size of screen and position of
left upper corner of the rectangle and its size).
Only the picture - data is converted,  other information like color-cycling
is lost !


Important  !!!
-------------------->
Everything which has to do with the X - Axis works only with Byte - values.
This  means  that  you  can save and load rectangles with the CPicSupport -
procedures only in 8 - pixel steps.
You  can  save  a rectangle starting from byte 0 wich means pixel 0, byte 1
which  means  pixel  8  and  so on.  You have to stop at byte 1 which means
pixel  7,  byte  2  which  means  pixel  15 and so on.  So the width of the
rectangle always can be divide through 8 which means a number of bytes.

In  CPicSupport every variable which has to do with the x-Axis means byte -
steps and not pixel - steps.  The reason is efficiency.  In most cases this
restriction  is  not  a disadvantage.  (You can also blit a rectangle on an
other bitmap and save from there). In the y-Axis everything is normal.

IF the Screen (Bitmap) is empty, the whole Bitmap is saved.


The output of the program :

Screen :   320 * 200 * 4

CPic :  (  0   12 )    14  *   88  =  1232  Byte for one Plane

Crunched Planes :     792    788    732    569  /    3013


This means :

The  Screen  which  was  used has the size 320 * 200 Pixel and 4 bitplanes.
The  left  upper corner of the rectangle located in the Screen is at (0 12)
which means byte 0 in the x - axis and row 12 in the y - axis.  The size of
the  rectangle  is  14 bytes (= 112 pixel) * 88 pixel.  One bitplane of the
rectangle  has  a  size  of  1232 Byte.  At last the length of the crunched
bitplanes and the length of the whole file are displayed.

--------------------------------------------------------

ILBM :

Converts the CPic - Format into the IFF - Format.

As  result  you have exactly the same IFF - Picture as before converting it
into  the  CPic  -  format  with the program CPic.  (But only the picture -
data, not information like color - cycling !).

--------------------------------------------------------

Disp :

Shows a CPic - picture (One Argument from CLI or WB).

If  you want to pull down the screen, first press the left mouse button and
then  the  right  without  releasing  the left.  Now release first the left
mouse  button  and  then  the right.  (This sounds more complicated than it
is).   Now the screen bar appears permanently.  The same again will let him
disappear.   To stop the programm, click on the left side of the picture or
press the Esc - button.

--------------------------------------------------------

Show :

Slideshow - programm :

Show <script> <mode> <time> <count>

script : Name of a textfile which contains one name in every line.
mode   : 0 : The screens will be flipped.
         1 : The new Screen is scrolled up. (not good with lace)
time   : Time in seconds to show every picture.
count  : How often to show all pictures.

--------------------------------------------------------

Palette :

Not an easy program :

You  can  reduce the size of CPic - Pictures and ILBM - Pictures (!) if you
change  the  sequence  of  colors  in  the palette in a special way.  (Yes,
really  !).   Of  course  the  picture itself is not changed.  This program
works  with  CPic  -  Pictures,  but  you  can convert IFF - Files, use the
program and convert them back (If you want to use the IFF - format).

If  you  want  that  some  colors  don't change their position, this is not
possible.   You only can put these colors into the positions which are used
at  last  from  the program and don't use these colors in the picture.  The
positions  are  still changed but they can be sorted back (Butcher, Pixmate
and  so on).  (16 17 19 18 22 23 21 20 backwards).  There are 8 Modes which
have  differnt results.  Try mode 4 first.  If the gain is good enough, you
can  proceed  all  8  modes  automatically.   If you want to understand the
program, look at the magic numbers in the german documentation.


Usage : Palette <inputfile> <outputfile> [mode]

inputfile  : a CPic - Picture File
outputfile : name of the improved CPic - File
mode       : a number from 0 to 7 (optional)


Without the parameter mode all 8 modes are tried and the best one is saved.
In  this case Current Directory and all files must be in RAM:  or RAD:  The
inputfile  will  be  loaded  for every mode and saved after converting in a
file  named  CPicTemp.   This file is renamed into the outputfile, if it is
shorter than the others.
Normally  the  results  of the eight modes are relatively equal, with digi-
tized black-white pictures all modes normally have equal results.

An example:

Picture : Library (Amok 6 or Fish 72).

    Library (128 KB)
->  Library ( 96 KB)  ( CPic )
->  Library ( 83 KB)  ( Palette mode 4 )
->  Library ( 97 KB)  ( ILBM )


-----------------------------------------------------------------------

CPicSupport:


The procedures :


SaveRect   :  Saves a rectangular region (x0 and x in byte - steps !).
              x0 : x-position of the left upper corner of the rectangle.
              y0 : y-position of the left upper corner of the rectangle.
              x  : width of the rectangle.
              y  : height of the rectangle.

SaveBitMap :  Searches automaticallay the smallest rectangle which contains
              all data and saves it.

SaveScreen :  The same as SaveBitmap with a Screen - Pointer.

ReadInfo   :  Reads a CPic - Info variable from a file and returns a
              FileHandlePtr in the VAR - parameter fp. Returns FALSE
              if an error occurs.

OpenCPicScreen : Opens a screen with the information from a CPic - Info
                 Variable. Returns the ScreenPtr and the BitMapPtr be-
                 longing to the Screen in the VAR - parameters sp and bp.
                 If an error occcurs, both are set to NIL and FALSE is
                 returned.

LoadBitPlanes  : Loads a picture (or rectangle) in a Bitmap. Needs the
                 CPicInfo - variable and the FileHandlePtr from ReadInfo
                 and a BitMap - Pointer for example from LoadCPicScreen.
                 It is possible to load less - color pictures into screens
                 with more colors into the first or last colors.

                 mode = 0 : Not used Bitmaps are not changed.
                        1 : Not used Bitmaps are set to 0 (This means
                            load into first colors)
                        2 : Not used Bitmaps are set to 255 (This means
                            load into last colors).
                 IF the number of colors are equal, the parameter mode
                 is not used.

                 x0,y0 : left upper corner of the rectangle. IF you want to
                 use the saved position, use ci.PicX0 and ci.PicY0 from the
                 CPicInfo - variable. The rectangle must be complete on the
                 Bitmap. The procedure returns FALSE if the picture could
                 not be loaded. (Then you can read the error - type from
                 the variable Cle).

LoadCPicScreen : Loads a complete picture (opens a Screen and returns the
                 ScreenPointer in the VAR - paramter sp). Returns FALSE
                 if the Screen could not be opened.

LoadBitPlanesMem : The same as LoadBitplanes but with high speed from
                   memory.
                   Needs the address of an allocated Decrunch - Buffer in
                   the parameter Buffer. (length = size of one Bitplane
                   from the rectangle = ci.PicX * ci.PicY) and the start -
                   address of the (complete loaded into Memory) CPic - File
                   (parameter Pic).
                   The variable ci must not be initialized. The fileheader
                   is written into it. No Error - checking in this
                   procedure (efficiency).


LoadColors : Loads the Colors from a CPic - Info variable. (Into first
             or last Colors if the destination Screen has more colors.)
             This supports LoadBitplanes, the parameter mode works in the
             same way. (bp is needed for information about the number of
             colors in the destination - screen).



Types und Variables :


TYPE CPicInfo = RECORD
  Ident  : LONGINT;
  Width  : INTEGER;
  Height : INTEGER;
  PicX0  : INTEGER;
  PicY0  : INTEGER;
  PicX   : INTEGER;
  PicY   : INTEGER;
  Depth  : INTEGER;
  Planes : ARRAY[0..5] OF LONGINT;
  Length : ARRAY[0..5] OF LONGINT;
  Mode   : ViewModeSet;
  Colors : ARRAY[0..31] OF INTEGER;
END;

VAR ci : CPicInfo;
    Cse,Cle : INTEGER;  ( CPicSaveError, CPicLoadError )

The variable ci (Type CPicInfo) contains after loading and saving all data
and is identical with the FileHeader).


The recordelements :

Ident  : Has the Value 1129343331 which is identical with "CPic"
Width  : Width of Screen.
Height : Height of Screen.
PixX0  : x - Position of left upper corner in Byte - steps !!!
         (refer to CPic)
PicY0  : y - Position (starting at 0 from up to down)
PicX   : Width of the rectangle in Byte !!!
PicY   : Heigth of the rectangle in pixels
Depth  : Number of Bitplanes.
Planes : Address of the crunched Bitplanes in the File.
Lenght : Length of the crunched Bitplanes.
Mode   : ViewMode (HAM LACE HIRES EHB) in the internal Amiga - format.
Colors : Always 32 Colors (but only 64 Byte) in the internal Amiga - format.

------------------------------------------------------------------------

Error - variables Cle and Cse:
Cse : Save - Error
Cle : Load - Error


Cse = 10 :  Incorrect parameters in SaveRect.
      11 :  Rectangle not in the BitMap - borders.
      12 :  File could not be opened.
      13 :  Write - Error.
      14 :  Couldn't allocate Crunch - Buffer.
      15 :  The ScreenPtr in SaveScreen is NIL.

Cle = 10 :  File could not be opened.
      11 :  File is not a CPic - File (in ReadInfo)
      12 :  Screen couldn't be opened (in OpenCPicScreen)
      13 :  Rectangle not in bitplane - borders. (in LoadBitplanes)
      14 :  Number of Bitplanes to load greater than the number
            of Bitplanes of the Destination - Bitmap.
      15 :  Decrunch - Buffer could not be allocated.
      16 :  Read - Error.
      17 :  File contains wrong data.
--------------------------------------------------------------------------

I hope, that the important things are now explained and everything should
be clear if you look at the parameters and the demos and demo - sourcecodes.
