Unnamed Fossil Project

Check-in [91394f2a1f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:removed 'extra' directory
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:91394f2a1fb5aeb2481f84800e74a3f0d4172b38
User & Date: alexey@sudachen.name 2011-11-07 00:37:11
Context
2011-11-07
00:40
updated check-in: 7834397c45 user: alexey@sudachen.name tags: trunk
00:37
removed 'extra' directory check-in: 91394f2a1f user: alexey@sudachen.name tags: trunk
2011-10-17
15:03
updated check-in: 3497207bc2 user: alexey@sudachen.name tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Deleted extra/gif89a.hc.

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

/*

(C)2010-2011, Alexéy Sudáchen, alexey@sudachen.name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.

*/

#ifndef C_once_E194EBE7_E43F_4305_A75C_3872532B12DB
#define C_once_E194EBE7_E43F_4305_A75C_3872532B12DB

#include "../libyoyo.hc"

enum
  {
    YOYO_RGBA8_PICTURE = __FOUR_CHARS('R','3','8','A'),
    YOYO_RGBAf_PICTURE = __FOUR_CHARS('R','3','f','A'),
  };

typedef struct _YOYO_PICTURE
  {
    int width;
    int height;
    int pitch;
    int weight;
    int format;
    byte_t *pixels;
  } YOYO_PICTURE;

typedef struct _YOYO_RGBA8
  {
    byte_t r;
    byte_t g;
    byte_t b;
    byte_t a;
  } YOYO_RGBA8;

typedef struct _YOYO_RGBAf
  {
    float r;
    float g;
    float b;
    float a;
  } YOYO_RGBAf;

//YOYO_PICTURE *Pict_Convert(YOYO_PICTURE *pict, int format)
//  {
//  }

#ifdef __windoze
HBITMAP Pict_Create_HBITMAP(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
  }
#endif
  ;
#endif

//YOYO_RGBA8 Pict_Get_RGBA8(YOYO_PICTURE *pic, int x, int y)
//  {
//  }
//
//void Pict_Set_RGBA8(YOYO_PICTURE *pic, int x, int y, YOYO_RGBA8 pix)
//  {
//  }

void Pict_Allocate_Buffer(YOYO_PICTIRE *pict)
  {
    if ( pict->pixels ) 
      __Raise(YOYO_ERROR_ALREADY_EXISTS,"pixel buffer already allocated");
    
    if ( pict->format == YOYO_RGBA8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGBA8)*pict->width;
        pict->wight  = sizeof(YOYO_RGBA8);
      }
    else if ( pict->format == YOYO_RGBAf_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGBAf)*pict->width;
        pict->wight  = sizeof(YOYO_RGBAf);
      }
    else
      __Raise(YOYO_ERROR_UNSUPPORTED,"pixel format unsupported");
      
    pict->pixels = __Malloc_Npl(pict->pitch*pict->height);
  }

#define Pict_From_Gif89a(Bytes,Count) Pict_From_Gif89a_Specific(Bytes,Count,YOYO_RGBA8_PICTURE)
YOYO_PICTIRE *Pict_From_Gif89a_Specific(void *bytes, int count, int format)
#ifdef _YOYO_GIF89A_BUILTIN
  {
    YOYO_PICTURE *pict = __Object_Dtor(sizeof(YOYO_PICTURE),YOYO_PICTURE_Destruct);
    int i,j;
    int ptx = 6;
    int bgcolor_idx;
    int sizeof_color_table;
    int sizeof_local_table;
    int has_local_colors;
    
    YOYO_RGBA8 color_table[256] = {0};
    YOYO_RGBA8 local_table[256] = {0};
    YOYO_RGBA8 *colors = 0;

    if ( memcmp(bytes,"GIF89a",6) && memcmp(bytes,"GIF87a",6) )
      __Raise(YOYO_ERROR_UNSUPPORTED,"is not GIF image");
    
    pict->format = format;
    pict->width  = Two_To_Unsigned(bytes+ptx); ptx += 2;
    pict->height = Two_To_Unsigned(bytes+ptx); ptx += 2;
    sizeof_color_table = 1<<((*bytes&0x07)+1);
    ++ptx; /* Packed Value */
    bgcolor_idx = bytes[ptx++];
    ++ptx; /* Pixel Aspect Ratio */
    
    for ( i = 0; i < sizeof_color_table; ++i )
      {
        color_table[i].r = bytes[ptx++];
        color_table[i].g = bytes[ptx++];
        color_table[i].b = bytes[ptx++];
      }
      
    if ( *bytes[ptx++] != 0x2c )
      __Raise(YOYO_ERROR_CORRUPTED,"expected image separator");
      
    ptx += 2; /* left */
    ptx += 2; /* top */
    pict->width  = Two_To_Unsigned(bytes+ptx); ptx += 2;
    pict->height = Two_To_Unsigned(bytes+ptx); ptx += 2;
    has_local_colors = *bytes & 0x80;
    ++ptx;
    
    if ( has_local_colors )
      {
        for ( i = 0; i < sizeof_local_table; ++i )
          {
            local_table[i].r = bytes[ptx++];
            local_table[i].g = bytes[ptx++];
            local_table[i].b = bytes[ptx++];
          }
        colors = local_table;
      }
    else
      colors = color_table;
      
    Pict_Allocate_Buffer(pict);
    
    __Gogo /* LZW decoder */
      {
        int mincodelen = bytes[ptx++];
        int codelen = mincodelen;
        int bitsread = 0;
        byte_t *pixel_ptr = pict->pixels;
        
        for (;;)
          {
            /* get n bits */
            int code = 
            
            if ( format == YOYO_RGBA8_PICTURE )
              (YOYO_RGBA8*)pixel_ptr = colors[pixel];
            else
              Pict_Set_Pixel_From_RGBA8(pixel_ptr,colors[pixel],format);
            
            pixel_ptr += pict->weight;
          }
      }
  }
#endif
  ;
#endif /* C_once_E194EBE7_E43F_4305_A75C_3872532B12DB */

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<