4 ** $VER: prefs.c 2.3 (24.5.98)
5 ** gifanim.datatype 2.3
9 ** Written 1997/1998 by Roland 'Gizzy' Mainz
10 ** Original example source from David N. Junod
17 #include <aros/debug.h>
19 struct MyStackSwapStruct
;
20 struct GIFAnimInstData
;
24 #include "classbase.h"
25 #include "classdata.h"
32 /*****************************************************************************/
34 /* local prototypes */
35 static STRPTR
GetPrefsVar( struct ClassBase
*, STRPTR
);
36 static BOOL
matchstr( struct ClassBase
*, STRPTR
, STRPTR
);
38 /*****************************************************************************/
40 /****** gifanim.datatype/preferences *****************************************
46 * The "ENV:Classes/DataTypes/gifanim.prefs" file contains global
47 * settings for the datatype.
48 * The preferences file is an ASCII file containing one line where the
49 * preferences can be set.
50 * It can be superset by a local variable with the same name.
52 * Each line can contain settings, special settings for some projects
53 * can be set using the MATCHPROJECT option.
54 * Lines beginning with a '#' or ';' chars are treated as comments.
55 * Lines are limitted to 256 chars.
58 * MATCHPROJECT/K,VERBOSE/S,NOVERBOSE/S,STRICTSYNTAX/S,NOSTRICTSYNTAX/S,
59 * MODEID/K/N,16BITCHUNKY=24BITCHUNKY=TRUECOLOR/S,
60 * NO16BITCHUNKY=NO24BITCHUNKY=NOTRUECOLOR/S,FPS/K/N,
61 * SAMPLE/K,SAMPLESPERFRAME=SPF/K/N,VOLUME/K/N,LOADALL/S,
62 * NOLOADALL/S,ENC_INTERLACE/S,ENC_NO_INTERLACE/S,
63 * ENC_BACKGROUNDPEN=ENC_BG/K/N,ENC_TRANSPARENTPEN=ENC_TRANSPARENT/K/N
65 * MATCHPROJECT -- The settings in this line belongs only to this
66 * project(s), e.g. if the case-insensitive pattern does not match,
67 * this line is ignored.
68 * The maximum length of the pattern is 128 chars.
69 * Defaults to #?, which matches any project.
71 * VERBOSE -- Print information about the animation. Currently
72 * the frame numbers and the used compression are printed, after all
73 * number of scanned/loaded frames, set FPS rate, dimensions (width/
74 * height/depth), sample information etc.
76 * NOVERBOSE -- Turns verbose output and error messages OFF.
77 * Be carefull, you won't see any error messages any more !!!
79 * STRICTSYNTAX -- Prompt syntax errors in the gif streams.
81 * NOSTRICTSYNTAX -- Turns STRICTSYNTAX off
83 * MODEID -- Select screen mode id of datatype (will be stored in
84 * ADTA_ModeID). Note that the DOS ReadArgs function used for parsing
85 * fetches a SIGNED long. The bit 31 will be represented by minus
86 * '-'. (example: "MODEID=266240" sets the mode to the A2024 screen
88 * Defaults to -1, which means: Use the best screenmode available for
89 * the given width, height and depth.
93 * TRUECOLOR -- Create 24 bit chunky bitmaps, if possible.
94 * Note that the 16BITCHUNKY and the 24BITCHUNKY options will be
95 * seperated in the future. The TRUECOLOR option selects the
96 * best truecolor depth in this case...
100 * NOTRUECOLOR -- Turns 24BITCHUNKY option off. (Default)
101 * Note that the 16BITCHUNKY and the 24BITCHUNKY options will be
102 * seperated in the future. The TRUECOLOR option selects the
103 * best truecolor depth in this case...
105 * FPS -- Frames Per Second
106 * A value of 0 here means: Use default FPS.
108 * SAMPLE -- Attach the given sample to the animation. The sample will
109 * be loaded using datatypes (GID_SOUND).
110 * Only one sample can be attached to one animation stream, any
111 * following attempt to attach a sample will be ignored.
113 * SAMPLESPERFRAME -- Set samples per frame rate for sound. This
114 * overrides the own internal calculations to get rid of rounding
117 * VOLUME -- Volume of the sound when playing.
118 * Defaults to 64, which is the maximum. A value greater than 64 will
121 * LOADALL -- Load all frames into memory.
123 * NOLOADALL -- Turns off the LOADALL flag, which may be set in a prefs-
124 * line before. This switch is set per default, and can be turned off
125 * by the LOADALL option, later it can be turned on again by this
128 * Encoder related options:
129 * ENC_INTERLACE - create interlaced gif animation
131 * ENC_NO_INTERLACE - create non-interlaced gif animation
135 * ENC_BG - background pen number
136 * Defaults to 0 (e.g. default bg pen)
139 * ENC_TRANSPARENT - transparent pen number
140 * Defaults to -1 (means: no transparent pen).
144 * - An invalid prefs file line will be ignored and forces the VERBOSE
148 * - Low memory may cause that the prefs file won't be parsed.
150 * - Lines are limitted to 256 chars
152 * - An invalid prefs file line will be ignored.
154 * - The sample path length is limitted to 200 chars. A larger
155 * value may crash the machine if an error occurs.
157 ******************************************************************************
163 STRPTR
GetPrefsVar( struct ClassBase
*cb
, STRPTR name
)
166 const ULONG buffsize
= 16UL;
168 if ((buff
= (STRPTR
)AllocVec( (buffsize
+ 2UL), (MEMF_PUBLIC
| MEMF_CLEAR
) ) ) != NULL
)
170 if( GetVar( name
, buff
, buffsize
, GVF_BINARY_VAR
) != (-1L) )
172 ULONG varsize
= IoErr();
176 if( varsize
> buffsize
)
180 if ((buff
= (STRPTR
)AllocVec( (varsize
+ 2UL), (MEMF_PUBLIC
| MEMF_CLEAR
) ) ) != NULL
)
182 if( GetVar( name
, buff
, varsize
, GVF_BINARY_VAR
) != (-1L) )
202 BOOL
matchstr( struct ClassBase
*cb
, STRPTR pat
, STRPTR s
)
208 if( ParsePatternNoCase( pat
, buff
, (sizeof( buff
) - 1) ) != (-1L) )
210 if( MatchPatternNoCase( buff
, s
) )
220 void ReadENVPrefs( struct ClassBase
*cb
, struct GIFAnimInstData
*gaid
, struct GIFEncoder
*genc
)
222 struct RDArgs envvarrda
=
241 IPTR nouse24bitchunky
;
244 IPTR
*samplesperframe
;
249 IPTR enc_no_interlace
;
250 IPTR
*enc_backgroundpen
;
251 IPTR
*enc_transparentpen
;
257 if ((var
= GetPrefsVar( cb
, "Classes/DataTypes/gifanim.prefs" ) ) != NULL
)
259 STRPTR prefsline
= var
,
261 ULONG linecount
= 1UL;
263 /* Be sure that "var" contains at least one break-char */
266 while ((nextprefsline
= strpbrk( prefsline
, "\n" ) ) != NULL
)
268 stccpy( varbuff
, prefsline
, (int)MIN( (sizeof( varbuff
) - 2UL), (((ULONG
)(nextprefsline
- prefsline
)) + 1UL) ) );
270 /* be sure that this line isn't a comment line or an empty line */
271 if( (varbuff
[ 0 ] != '#') && (varbuff
[ 0 ] != ';') && (varbuff
[ 0 ] != '\n') && (strlen( varbuff
) > 2UL) )
273 /* Prepare ReadArgs processing */
274 strcat( varbuff
, "\n" ); /* Add NEWLINE-char */
275 envvarrda
. RDA_Source
. CS_Buffer
= varbuff
; /* Buffer */
276 envvarrda
. RDA_Source
. CS_Length
= strlen( varbuff
) + 1UL; /* Set up input buffer length */
277 envvarrda
. RDA_Source
. CS_CurChr
= 0L;
278 envvarrda
. RDA_Buffer
= NULL
;
279 envvarrda
. RDA_BufSiz
= 0L;
280 memset( (void *)(&gifanimargs
), 0, sizeof( gifanimargs
) ); /* Clear result array */
282 if( ReadArgs( "MATCHPROJECT/K,"
288 "16BITCHUNKY=24BITCHUNKY=TRUECOLOR/S,"
289 "NO16BITCHUNKY=NO24BITCHUNKY=NOTRUECOLOR/S,"
292 "SAMPLESPERFRAME=SPF/K/N,"
297 "ENC_NO_INTERLACE/S,"
298 "ENC_BACKGROUNDPEN=ENC_BG/K/N,"
299 "ENC_TRANSPARENTPEN=ENC_TRANSPARENT/K/N", (IPTR
*)(&gifanimargs
), (&envvarrda
) ) )
301 BOOL noignore
= TRUE
;
303 if( (gifanimargs
. matchproject
) && (gaid
-> gaid_ProjectName
) )
305 noignore
= matchstr( cb
, (gifanimargs
. matchproject
), (gaid
-> gaid_ProjectName
) );
310 /* Read encoder prefs ? */
313 if( gifanimargs
. enc_interlace
)
315 genc
-> interlace
= TRUE
;
318 if( gifanimargs
. enc_no_interlace
)
320 genc
-> interlace
= FALSE
;
323 if( gifanimargs
. enc_backgroundpen
)
325 genc
-> backgroundpen
= (WORD
)(*(gifanimargs
. enc_backgroundpen
));
328 if( gifanimargs
. enc_transparentpen
)
330 genc
-> transparentpen
= (WORD
)(*(gifanimargs
. enc_transparentpen
));
335 if( gifanimargs
. verbose
)
337 OpenLogfile( cb
, gaid
);
340 if( gifanimargs
. noverbose
)
342 if( (gaid
-> gaid_VerboseOutput
) && ((gaid
-> gaid_VerboseOutput
) != (BPTR
)-1L) )
344 Close( (gaid
-> gaid_VerboseOutput
) );
347 gaid
-> gaid_VerboseOutput
= (BPTR
)-1L;
350 if( gifanimargs
. strictsyntax
)
352 gaid
-> gaid_StrictSyntax
= TRUE
;
355 if( gifanimargs
. nostrictsyntax
)
357 gaid
-> gaid_StrictSyntax
= FALSE
;
360 if( gifanimargs
. modeid
)
362 gaid
-> gaid_ModeID
= *(gifanimargs
. modeid
);
365 if( gifanimargs
. use24bitchunky
)
367 #if !defined(__AROS__)
368 /* Check if we have animation.datatype V41 (or higher) as superclass */
369 if( (cb
-> cb_SuperClassBase
-> lib_Version
) >= 41U )
371 /* Check here if we opened the cybergraphics.library. After this point, I'll assume
372 * that (gaid_UseChunkyMap == TRUE) implies a opened CyberGfxBase !!
377 gaid
-> gaid_UseChunkyMap
= TRUE
;
378 #if !defined(__AROS__)
382 error_printf( cb
, gaid
, "no cybergraphics.library available, can't output a 24 bit chunky map\n" );
387 error_printf( cb
, gaid
, "Requires at least animation.datatype V41 for non-planar bitmap support\n" );
391 if( gifanimargs
. nouse24bitchunky
)
393 gaid
-> gaid_UseChunkyMap
= FALSE
;
396 if( gifanimargs
. fps
)
398 gaid
-> gaid_FPS
= *(gifanimargs
. fps
);
401 if( gifanimargs
. loadall
)
403 gaid
-> gaid_LoadAll
= TRUE
;
406 if( gifanimargs
. noloadall
)
408 gaid
-> gaid_LoadAll
= FALSE
;
411 if( (gifanimargs
. sample
) && ((gaid
-> gaid_Sample
) == NULL
) )
416 verbose_printf( cb
, gaid
, "loading sample \"%s\"...\n", (gifanimargs
. sample
) );
418 if ((so
= NewDTObject( (gifanimargs
. sample
), DTA_GroupID
, GID_SOUND
, TAG_DONE
) ) != NULL
)
424 /* Get sample data from object */
425 if( GetDTAttrs( so
, SDTA_Sample
, (&sample
),
426 SDTA_SampleLength
, (&length
),
427 SDTA_Period
, (&period
),
430 if ((gaid
-> gaid_Sample
= (STRPTR
)AllocPooled( (gaid
-> gaid_Pool
), (length
+ 1UL) ) ) != NULL
)
432 /* Copy sample and context */
433 CopyMem( (APTR
)sample
, (APTR
)(gaid
-> gaid_Sample
), length
);
434 gaid
-> gaid_SampleLength
= length
;
435 gaid
-> gaid_Period
= period
;
439 /* Can't alloc sample */
440 ioerr
= ERROR_NO_FREE_STORE
;
445 /* Object does not support the requested attributes */
446 ioerr
= ERROR_OBJECT_WRONG_TYPE
;
449 DisposeDTObject( so
);
453 /* NewDTObjectA failed, cannot load sample... */
457 if( (gaid
-> gaid_Sample
) == NULL
)
461 if( ioerr
>= DTERROR_UNKNOWN_DATATYPE
)
463 mysprintf( cb
, errbuff
, GetDTString( ioerr
), (gifanimargs
. sample
) );
467 Fault( ioerr
, (gifanimargs
. sample
), errbuff
, sizeof( errbuff
) );
470 error_printf( cb
, gaid
, "can't load sample: \"%s\" line %lu\n", errbuff
, linecount
);
474 if( gifanimargs
. samplesperframe
)
476 gaid
-> gaid_SamplesPerFrame
= *(gifanimargs
. samplesperframe
);
479 if( gifanimargs
. volume
)
481 gaid
-> gaid_Volume
= *(gifanimargs
. volume
);
483 if( (gaid
-> gaid_Volume
) > 64UL )
485 gaid
-> gaid_Volume
= 64UL;
492 verbose_printf( cb
, gaid
, "prefs line %lu ignored\n", linecount
);
495 FreeArgs( (&envvarrda
) );
499 LONG ioerr
= IoErr();
502 Fault( ioerr
, "Classes/DataTypes/gifanim.prefs", errbuff
, (LONG
)sizeof( errbuff
) );
504 error_printf( cb
, gaid
, "preferences \"%s\" line %lu\n", errbuff
, linecount
);
508 prefsline
= ++nextprefsline
;