File: f16.c

package info (click to toggle)
xfractint 20.4.10-2
  • links: PTS
  • area: non-free
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 4,712 kB
  • ctags: 8,020
  • sloc: ansic: 77,316; asm: 430; cpp: 425; makefile: 379; sh: 38
file content (93 lines) | stat: -rw-r--r-- 2,805 bytes parent folder | download | duplicates (3)
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**************************************
**
** F16.C : Code to read 16-bit fractal data sets.  Uses
** strictly Targa16 type 10 files (run-length encoded 16-bit RGB).
*/

/* Lee Daniel Crocker      CompuServe: 73407,2030   <== Preferred
** 1380 Jewett Ave.               BIX: lcrocker
** Pittsburg, CA  94565        Usenet: ...!ames!pacbell!sactoh0!siva!lee
**
** This code is hereby placed in the public domain.  You are free to
** use, modify, usurp, laugh at, destroy, or otherwise abuse it in any
** way you see fit.
**
** "If you steal from one author it's plagiarism; if you steal from
** many it's research."  --Wilson Mizner
*/

/* 16 bit .tga files were generated for continuous potential "potfile"s
   from version 9.? thru version 14.  Replaced by double row gif type
   file (.pot) in version 15.  Delete this code after a few more revs.
   The part which wrote 16 bit .tga files has already been deleted.
*/

#include <string.h>
#include <ctype.h>
  /* see Fractint.c for a description of the "include"  hierarchy */
#include "port.h"
#include "prototyp.h"
#include "targa_lc.h"

#ifdef XFRACT
char rlebuf[258];    /* RLE-state variables */
#endif
static int state, count, bufp;

/**************************************
**
** Open previously saved Targa16 type 10 file filling in hs, vs, and
** csize with values in the header.  If *csize is not zero, the block
** pointed to by cp is filled with the comment block.  The caller
** _must_ allocate 256 bytes for this purpose before calling.
*/

FILE *t16_open(char *fname, int *hs, int *vs, int *csize, U8 *cp)
{
    char filename[64];
    U8 header[HEADERSIZE];
    FILE *fp;
    int dummy; /* to quiet compiler */

    strcpy(filename, fname);
    if (has_ext(filename) == NULL) strcat(filename, ".TGA");
    if ((fp = fopen(filename, READMODE)) == NULL) return NULL;

    dummy = fread(header, HEADERSIZE, 1, fp);
    if ((header[O_FILETYPE] != T_RLERGB) || (header[O_ESIZE] != 16)) {
        fclose(fp);
        return NULL;
    }
    GET16(header[O_HSIZE], *hs);
    GET16(header[O_VSIZE], *vs);
    if ((*csize = header[O_COMMENTLEN]) != 0) dummy = fread(cp, *csize, 1, fp);

    state = count = bufp = 0;
    return fp;
}

int t16_getline(FILE *fp, int hs, U16 *data)
{
    int i;

    for (i=0; i<hs; ++i) {
        if (state == 0) {
            int dummy; /* to quiet compiler */
            bufp = 0;
            if ((count = getc(fp)) > 127) {
                state = 1;
                count -= 127;
                dummy = fread(rlebuf, 2, 1, fp);
            } else {
                state = 2;
                ++count;
                dummy = fread(rlebuf, 2, count, fp);
            }
        }
        GET16(rlebuf[bufp], data[i]);
        if (--count == 0) state = 0;
        if (state == 2) bufp += 2;
    }
    return 0;
}