Unnamed Fossil Project

Check-in [275cb8f754]
Login

Check-in [275cb8f754]

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

Overview
Comment:bmp picture
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 275cb8f754d85d43321e46e32c01fd02f6f040f4
User & Date: alexey@sudachen.name 2012-02-07 06:44:19.000
Context
2012-02-23
09:34
cl10 compatibility fixed check-in: df6b1db1dc user: alexey@sudachen.name tags: trunk
2012-02-07
06:44
bmp picture check-in: 275cb8f754 user: alexey@sudachen.name tags: trunk
2012-01-11
15:05
updated check-in: 9d693e4f86 user: alexey@sudachen.name tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Added pictbmp.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

/*

Copyright © 2010-2011, Alexéy Sudáchen, alexey@sudachen.name, Chile

In USA, UK, Japan and other countries allowing software patents:

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    http://www.gnu.org/licenses/

Otherwise:

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_F02ABD1D_F661_464B_8226_CBED6A3DA7CE
#define C_once_F02ABD1D_F661_464B_8226_CBED6A3DA7CE

#ifdef _LIBYOYO
#define _YOYO_PICTBMP_BUILTIN
#endif

#include "picture.hc"  
#include "buffer.hc"
#include "file.hc"

#ifdef _YOYO_PICTBMP_BUILTIN

enum { YOYO_BI_BITFIELDS = 3, YOYO_BI_RGB = 0, };

#pragma pack(push,2)
typedef struct _YOYO_BITMAPFILEHEADER 
  {
    u16_t  bfType;
    u32_t  bfSize;
    u16_t  bfReserved1;
    u16_t  bfReserved2;
    u32_t  bfOffBits;
  } YOYO_BITMAPFILEHEADER;
typedef struct _YOYO_BITMAPINFOHEADER
  {
    u32_t  biSize;
    i32_t  biWidth;
    i32_t  biHeight;
    u16_t  biPlanes;
    u16_t  biBitCount;
    u32_t  biCompression;
    u32_t  biSizeImage;
    i32_t  biXPelsPerMeter;
    i32_t  biYPelsPerMeter;
    u32_t  biClrUsed;
    u32_t  biClrImportant;
  } YOYO_BITMAPINFOHEADER;
#pragma pack(pop)

#endif

#define Pict_From_BMP(Bytes,Count) Pict_From_BMP_Specific(Bytes,Count,YOYO_RGBA8_PICTURE)
YOYO_PICTURE *Pict_From_BMP_Specific(void *bytes, int count, int format)
#ifdef _YOYO_PICTBMP_BUILTIN
  {
    YOYO_PICTURE *pict = __Object_Dtor(sizeof(YOYO_PICTURE),YOYO_PICTURE_Destruct);
    pict->format = format;

    if ( !pict->format ) pict->format = YOYO_RGBA8_PICTURE;
    
    __Auto_Release
      {
        YOYO_BITMAPFILEHEADER *bmFH = bytes;
        YOYO_BITMAPINFOHEADER *bmIH = (YOYO_BITMAPINFOHEADER *)((char*)bytes + sizeof(YOYO_BITMAPFILEHEADER));
        u32_t  *palette = (u32_t*)((char*)bmIH+bmIH->biSize);
        byte_t *image  = (byte_t*)bmFH+bmFH->bfOffBits;
        
        if ( (bmFH->bfType == 0x4D42) && (bmFH->bfSize <= count) )
          {
            int bpp = (bmIH->biBitCount/8);
            int stride, jformat, i;
            byte_t *row = 0;
            if ( bmIH->biCompression != YOYO_BI_RGB )
              __Raise(YOYO_ERROR_CORRUPTED,"supporting BI_RGB comression bitmaps only");
            
            switch ( bmIH->biBitCount )
              {
                case 32: jformat = YOYO_BGRA8_PICTURE; break;
                case 24: jformat = YOYO_BGR8_PICTURE; break;
                case 8:  jformat = YOYO_PAL8_PICTURE; break;
                case 16:
                  if ( bmIH->biCompression == YOYO_BI_BITFIELDS && palette[1] != 0x03e0 )
                    jformat = YOYO_BGR6_PICTURE;
                  else
                    jformat = YOYO_BGR5A1_PICTURE; 
                  break;
                default:
                  __Raise_Format(YOYO_ERROR_CORRUPTED,("bitCount %d is not supported",bmIH->biBitCount));
              }
            
            stride = (bmIH->biWidth*Pict_Format_Bytes_PP(jformat) + 3) & ~3;
            pict->width  = bmIH->biWidth;
            pict->height = Yo_Absi(bmIH->biHeight); /* sign selects direction of rendering rows down-to-up or up-to-down*/
            Pict_Allocate_Buffer(pict);

            for ( i = 0; i < pict->height; ++i )
              {
                int l = (bmIH->biHeight < 0) ? i : pict->height - i - 1; 
                if ( jformat != pict->format )
                  {
                    if ( jformat == YOYO_PAL8_PICTURE )
                      Pict_Convert_Pixels_Row_Pal(
                        image + l*stride, YOYO_BGRX8_PICTURE,
                        pict->pixels+i*pict->pitch, pict->format,
                        pict->width,
                        palette, bmIH->biClrUsed);
                    else
                      Pict_Convert_Pixels_Row(
                        image + l*stride, jformat,
                        pict->pixels+i*pict->pitch, pict->format,
                        pict->width);
                  }
                else
                  memcpy(pict->pixels+i*pict->pitch, image + l*stride, pict->width*Pict_Format_Bytes_PP(jformat));
              }
          }
      }
      
    return pict;
  }
#endif
  ;
  
#define Pict_From_BMP_File(Filename) Pict_From_BMP_File_Specific(Filename,YOYO_RGBA8_PICTURE)
YOYO_PICTURE *Pict_From_BMP_File_Specific(char *filename, int format)
#ifdef _YOYO_PICTBMP_BUILTIN
  {
    YOYO_PICTURE *pict = 0;
    __Auto_Ptr(pict)
      {
        YOYO_BUFFER *bf = Oj_Read_All(Cfile_Open(filename,"r"));
        pict = Pict_From_BMP_Specific(bf->at,bf->count,format);
      }
    return pict;
  }
#endif
  ;

#endif /* C_once_F02ABD1D_F661_464B_8226_CBED6A3DA7CE */
Changes to pictpng.hc.
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
            pict->height = png_get_image_height(png_ptr,info_ptr);

            if (  png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA )
              bpp = 4;
            else 
              bpp = 3;

            stride = (bpp*pict->width + 7) & ~3;
            jformat = (bpp==4?YOYO_RGBA8_PICTURE:YOYO_RGB8_PICTURE);
            if ( jformat != pict->format )
              row = __Malloc(stride);
          }
        else
          {
            if ( !setjmp(png_jmpbuf(png_ptr)) )







|







111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
            pict->height = png_get_image_height(png_ptr,info_ptr);

            if (  png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA )
              bpp = 4;
            else 
              bpp = 3;

            stride = (bpp*pict->width + 3) & ~3;
            jformat = (bpp==4?YOYO_RGBA8_PICTURE:YOYO_RGB8_PICTURE);
            if ( jformat != pict->format )
              row = __Malloc(stride);
          }
        else
          {
            if ( !setjmp(png_jmpbuf(png_ptr)) )
Changes to picture.hc.
56
57
58
59
60
61
62

63
64
65
66
67

68
69


70
71
72
73
74
75
76
  {
    YOYO_PAL8_PICTURE  = __FOUR_CHARS('P',1,'8',0),
    YOYO_RGBAf_PICTURE = __FOUR_CHARS('R',16,'f','A'),
    YOYO_RGB8_PICTURE  = __FOUR_CHARS('R',3,'8',0),
    YOYO_RGB5_PICTURE  = __FOUR_CHARS('R',2,'5',0),
    YOYO_RGB6_PICTURE  = __FOUR_CHARS('R',2,'6',0),
    YOYO_RGBA8_PICTURE = __FOUR_CHARS('R',4,'8','A'),

    YOYO_RGB5A1_PICTURE= __FOUR_CHARS('R',2,'5','A'),
    YOYO_BGR8_PICTURE  = __FOUR_CHARS('B',3,'8',0),
    YOYO_BGR5_PICTURE  = __FOUR_CHARS('B',2,'5',0),
    YOYO_BGR6_PICTURE  = __FOUR_CHARS('B',2,'6',0),
    YOYO_BGRA8_PICTURE = __FOUR_CHARS('B',4,'8','A'),

    YOYO_BGB5A1_PICTURE= __FOUR_CHARS('B',2,'5','A'),
  };



typedef struct _YOYO_PICTURE
  {
    int width;
    int height;
    int pitch;
    int weight;







>





>
|

>
>







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
  {
    YOYO_PAL8_PICTURE  = __FOUR_CHARS('P',1,'8',0),
    YOYO_RGBAf_PICTURE = __FOUR_CHARS('R',16,'f','A'),
    YOYO_RGB8_PICTURE  = __FOUR_CHARS('R',3,'8',0),
    YOYO_RGB5_PICTURE  = __FOUR_CHARS('R',2,'5',0),
    YOYO_RGB6_PICTURE  = __FOUR_CHARS('R',2,'6',0),
    YOYO_RGBA8_PICTURE = __FOUR_CHARS('R',4,'8','A'),
    YOYO_RGBX8_PICTURE = __FOUR_CHARS('R',4,'8',0),
    YOYO_RGB5A1_PICTURE= __FOUR_CHARS('R',2,'5','A'),
    YOYO_BGR8_PICTURE  = __FOUR_CHARS('B',3,'8',0),
    YOYO_BGR5_PICTURE  = __FOUR_CHARS('B',2,'5',0),
    YOYO_BGR6_PICTURE  = __FOUR_CHARS('B',2,'6',0),
    YOYO_BGRA8_PICTURE = __FOUR_CHARS('B',4,'8','A'),
    YOYO_BGRX8_PICTURE = __FOUR_CHARS('B',4,'8',0),
    YOYO_BGR5A1_PICTURE= __FOUR_CHARS('B',2,'5','A'),
  };

#define Pict_Format_Bytes_PP(Fmt) ((Fmt>>8)&0x0ff)

typedef struct _YOYO_PICTURE
  {
    int width;
    int height;
    int pitch;
    int weight;
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
    byte_t g;
    byte_t r;
  } YOYO_BGR8;

YOYO_RGBA8 Pict_Get_RGBA8_Pixel(byte_t *ptr, int format)
#ifdef _YOYO_PICTURE_BUILTIN
  {


    if ( format == YOYO_RGBA8_PICTURE )
      return *(YOYO_RGBA8*)ptr;
    else if ( format == YOYO_RGB8_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = ((YOYO_RGB8*)ptr)->r;
        rgba.g = ((YOYO_RGB8*)ptr)->g;
        rgba.b = ((YOYO_RGB8*)ptr)->b;
        rgba.a = 0xff;
        return rgba;
      }









    else if ( format == YOYO_BGR8_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = ((YOYO_BGR8*)ptr)->r;
        rgba.g = ((YOYO_BGR8*)ptr)->g;
        rgba.b = ((YOYO_BGR8*)ptr)->b;
        rgba.a = 0xff;
        return rgba;
      }









    else if ( format == YOYO_BGRA8_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = ((YOYO_BGRA8*)ptr)->r;
        rgba.g = ((YOYO_BGRA8*)ptr)->g;
        rgba.b = ((YOYO_BGRA8*)ptr)->b;
        rgba.a = ((YOYO_BGRA8*)ptr)->a;
        return rgba;
      }
    else if ( format == YOYO_RGBAf_PICTURE )
      {
        YOYO_RGBA8 rgba;
        rgba.r = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->r + .5f ,1.f) * 255.f);
        rgba.g = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->g + .5f ,1.f) * 255.f);
        rgba.b = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->b + .5f ,1.f) * 255.f);
        rgba.a = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->a + .5f ,1.f) * 255.f);
        return rgba;
      }
    else
      {
        YOYO_RGBA8 rgba = {0};
        __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
        return rgba;

      }
  }
#endif
  ;

YOYO_RGBA8 Pict_Get_RGBA8(YOYO_PICTURE *pict, int x, int y)
#ifdef _YOYO_PICTURE_BUILTIN







>
>
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







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
193
194
195
196
197
198
199
200
201
202
203
204
205
    byte_t g;
    byte_t r;
  } YOYO_BGR8;

YOYO_RGBA8 Pict_Get_RGBA8_Pixel(byte_t *ptr, int format)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    switch ( format )
      {
        case YOYO_RGBA8_PICTURE:
          return *(YOYO_RGBA8*)ptr;
        case YOYO_RGB8_PICTURE:
          {
            YOYO_RGBA8 rgba;
            rgba.r = ((YOYO_RGB8*)ptr)->r;
            rgba.g = ((YOYO_RGB8*)ptr)->g;
            rgba.b = ((YOYO_RGB8*)ptr)->b;
            rgba.a = 0xff;
            return rgba;
          }
        case YOYO_RGBX8_PICTURE:
          {
            YOYO_RGBA8 rgba;
            rgba.r = ((YOYO_RGB8*)ptr)->r;
            rgba.g = ((YOYO_RGB8*)ptr)->g;
            rgba.b = ((YOYO_RGB8*)ptr)->b;
            rgba.a = 0xff;
            return rgba;
          }
        case YOYO_BGR8_PICTURE:
          {
            YOYO_RGBA8 rgba;
            rgba.r = ((YOYO_BGR8*)ptr)->r;
            rgba.g = ((YOYO_BGR8*)ptr)->g;
            rgba.b = ((YOYO_BGR8*)ptr)->b;
            rgba.a = 0xff;
            return rgba;
          }
        case YOYO_BGRX8_PICTURE:
          {
            YOYO_RGBA8 rgba;
            rgba.r = ((YOYO_BGRA8*)ptr)->r;
            rgba.g = ((YOYO_BGRA8*)ptr)->g;
            rgba.b = ((YOYO_BGRA8*)ptr)->b;
            rgba.a = 0xff;
            return rgba;
          }
        case YOYO_BGRA8_PICTURE:
          {
            YOYO_RGBA8 rgba;
            rgba.r = ((YOYO_BGRA8*)ptr)->r;
            rgba.g = ((YOYO_BGRA8*)ptr)->g;
            rgba.b = ((YOYO_BGRA8*)ptr)->b;
            rgba.a = ((YOYO_BGRA8*)ptr)->a;
            return rgba;
          }
        case YOYO_RGBAf_PICTURE:
          {
            YOYO_RGBA8 rgba;
            rgba.r = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->r + .5f ,1.f) * 255.f);
            rgba.g = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->g + .5f ,1.f) * 255.f);
            rgba.b = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->b + .5f ,1.f) * 255.f);
            rgba.a = (byte_t)(Yo_MAX(((YOYO_RGBAf*)ptr)->a + .5f ,1.f) * 255.f);
            return rgba;
          }
        default:
          {
            YOYO_RGBA8 rgba = {0};
            __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
            return rgba;
          }
      }
  }
#endif
  ;

YOYO_RGBA8 Pict_Get_RGBA8(YOYO_PICTURE *pict, int x, int y)
#ifdef _YOYO_PICTURE_BUILTIN
216
217
218
219
220
221
222


223
224

225
226
227
228
229
230

231
232
233





234
235
236
237

238
239
240
241
242
243








244
245
246
247
248
249
250
251

252

253
254
255
256
257
258
259
  }
#endif
  ;

void Pict_Set_RGBA8_Pixel(byte_t *ptr, YOYO_RGBA8 pix, int format)
#ifdef _YOYO_PICTURE_BUILTIN
  {


    if ( format == YOYO_RGBA8_PICTURE )
      *(YOYO_RGBA8*)ptr = pix;

    else if ( format == YOYO_RGB8_PICTURE )
      {
        ((YOYO_RGB8*)ptr)->r = pix.r;
        ((YOYO_RGB8*)ptr)->g = pix.g;
        ((YOYO_RGB8*)ptr)->b = pix.b;
      }

    else if ( format == YOYO_BGRA8_PICTURE )
      {
        ((YOYO_BGRA8*)ptr)->r = pix.r;





        ((YOYO_BGRA8*)ptr)->g = pix.g;
        ((YOYO_BGRA8*)ptr)->b = pix.b;
        ((YOYO_BGRA8*)ptr)->a = pix.a;
      }

    else if ( format == YOYO_BGR8_PICTURE )
      {
        ((YOYO_BGR8*)ptr)->r = pix.r;
        ((YOYO_BGR8*)ptr)->g = pix.g;
        ((YOYO_BGR8*)ptr)->b = pix.b;
      }








    else if ( format == YOYO_RGBAf_PICTURE )
      {
        ((YOYO_RGBAf*)ptr)->r = (pix.r + .5f) / 255.f;
        ((YOYO_RGBAf*)ptr)->g = (pix.g + .5f) / 255.f;
        ((YOYO_RGBAf*)ptr)->b = (pix.b + .5f) / 255.f;
        ((YOYO_RGBAf*)ptr)->a = (pix.a + .5f) / 255.f;
      }
    else

      __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");

  }
#endif
  ;

void Pict_Set_RGBA8(YOYO_PICTURE *pict, int x, int y, YOYO_RGBA8 pix)
#ifdef _YOYO_PICTURE_BUILTIN
  {







>
>
|
|
>
|
<
|
|
|
<
>
|
<
|
>
>
>
>
>
|
|
|
<
>
|
<
|
|
|
<
>
>
>
>
>
>
>
>
|
<
|
|
|
|
<
|
>
|
>







241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256

257
258

259
260
261
262
263
264
265
266
267

268
269

270
271
272

273
274
275
276
277
278
279
280
281

282
283
284
285

286
287
288
289
290
291
292
293
294
295
296
  }
#endif
  ;

void Pict_Set_RGBA8_Pixel(byte_t *ptr, YOYO_RGBA8 pix, int format)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    switch ( format )
      {
        case YOYO_RGBA8_PICTURE:
          *(YOYO_RGBA8*)ptr = pix;
          break;
        case YOYO_RGB8_PICTURE:

          ((YOYO_RGB8*)ptr)->r = pix.r;
          ((YOYO_RGB8*)ptr)->g = pix.g;
          ((YOYO_RGB8*)ptr)->b = pix.b;

          break;
        case YOYO_RGBX8_PICTURE:

          ((YOYO_RGBA8*)ptr)->r = pix.r;
          ((YOYO_RGBA8*)ptr)->g = pix.g;
          ((YOYO_RGBA8*)ptr)->b = pix.b;
          ((YOYO_RGBA8*)ptr)->a = 0;
          break;
        case YOYO_BGR8_PICTURE:
          ((YOYO_BGRA8*)ptr)->r = pix.r;
          ((YOYO_BGRA8*)ptr)->g = pix.g;
          ((YOYO_BGRA8*)ptr)->b = pix.b;

          break;
        case YOYO_BGRX8_PICTURE:

          ((YOYO_BGRA8*)ptr)->r = pix.r;
          ((YOYO_BGRA8*)ptr)->g = pix.g;
          ((YOYO_BGRA8*)ptr)->b = pix.b;

          ((YOYO_BGRA8*)ptr)->a = 0;
          break;
        case YOYO_BGRA8_PICTURE:
          ((YOYO_BGRA8*)ptr)->r = pix.r;
          ((YOYO_BGRA8*)ptr)->g = pix.g;
          ((YOYO_BGRA8*)ptr)->b = pix.b;
          ((YOYO_BGRA8*)ptr)->a = pix.a;
          break;
        case YOYO_RGBAf_PICTURE:

          ((YOYO_RGBAf*)ptr)->r = (pix.r + .5f) / 255.f;
          ((YOYO_RGBAf*)ptr)->g = (pix.g + .5f) / 255.f;
          ((YOYO_RGBAf*)ptr)->b = (pix.b + .5f) / 255.f;
          ((YOYO_RGBAf*)ptr)->a = (pix.a + .5f) / 255.f;

          break;
        default:
          __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
      }
  }
#endif
  ;

void Pict_Set_RGBA8(YOYO_PICTURE *pict, int x, int y, YOYO_RGBA8 pix)
#ifdef _YOYO_PICTURE_BUILTIN
  {
269
270
271
272
273
274
275
276
277


278
279
280

281
282
283
284
285

286
287

288
289
290

291
292
293
294
295

296
297
298
299
300
301

302
303

304
305
306
307
308
309
310
311
312
313
314
315
316

void Pict_Allocate_Buffer(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( pict->pixels ) 
      __Raise(YOYO_ERROR_ALREADY_EXISTS,"pixel buffer already exists");
    
    if ( pict->format == YOYO_RGBA8_PICTURE )
      {


        pict->pitch  = sizeof(YOYO_RGBA8)*pict->width;
        pict->weight = sizeof(YOYO_RGBA8);
      }

    else if ( pict->format == YOYO_RGBAf_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_RGBAf)*pict->width;
        pict->weight = sizeof(YOYO_RGBAf);
      }

    else if ( pict->format == YOYO_RGB8_PICTURE )
      {

        pict->pitch  = sizeof(YOYO_RGB8)*pict->width;
        pict->weight = sizeof(YOYO_RGB8);
      }

    else if ( pict->format == YOYO_BGR8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_BGR8)*pict->width;
        pict->weight = sizeof(YOYO_BGR8);
      }

    else if ( pict->format == YOYO_BGRA8_PICTURE )
      {
        pict->pitch  = sizeof(YOYO_BGRA8)*pict->width;
        pict->weight = sizeof(YOYO_BGRA8);
      }
    else

      __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
      

    pict->pixels = __Malloc_Npl(pict->pitch*pict->height);
  }
#endif
  ;
  
void Pict_Nullify_Transpoarent_Pixels(YOYO_PICTURE *pict, byte_t threshold)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( pict->format == YOYO_RGBA8_PICTURE || pict->format == YOYO_BGRA8_PICTURE )
      {
        int i;
        for ( i = 0; i < pict->height; ++i )
          {







|

>
>
|
|
<
>
|
<
|
|
<
>
|
<
>
|
|
<
>
|
<
|
|
<
>
|
<
|
|
<
|
>
|
|
>





|







306
307
308
309
310
311
312
313
314
315
316
317
318

319
320

321
322

323
324

325
326
327

328
329

330
331

332
333

334
335

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

void Pict_Allocate_Buffer(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( pict->pixels ) 
      __Raise(YOYO_ERROR_ALREADY_EXISTS,"pixel buffer already exists");
    
    switch( pict->format )
      {
        case YOYO_RGBA8_PICTURE:
        case YOYO_RGBX8_PICTURE:
          pict->pitch  = sizeof(YOYO_RGBA8)*pict->width;
          pict->weight = sizeof(YOYO_RGBA8);

          break;
        case YOYO_RGB8_PICTURE:

          pict->pitch  = sizeof(YOYO_RGB8)*pict->width;
          pict->weight = sizeof(YOYO_RGB8);

          break;
        case YOYO_BGRA8_PICTURE:

        case YOYO_BGRX8_PICTURE:
          pict->pitch  = sizeof(YOYO_BGRA8)*pict->width;
          pict->weight = sizeof(YOYO_BGRA8);

          break;
        case YOYO_BGR8_PICTURE:

          pict->pitch  = sizeof(YOYO_BGR8)*pict->width;
          pict->weight = sizeof(YOYO_BGR8);

          break;
        case YOYO_RGBAf_PICTURE:

          pict->pitch  = sizeof(YOYO_RGBAf)*pict->width;
          pict->weight = sizeof(YOYO_RGBAf);

          break;
        default:
          __Raise(YOYO_ERROR_UNSUPPORTED,"bad pixel format");
      }
      
    pict->pixels = __Malloc_Npl(pict->pitch*pict->height);
  }
#endif
  ;
  
void Pict_Nullify_Transparent_Pixels(YOYO_PICTURE *pict, byte_t threshold)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    if ( pict->format == YOYO_RGBA8_PICTURE || pict->format == YOYO_BGRA8_PICTURE )
      {
        int i;
        for ( i = 0; i < pict->height; ++i )
          {
359
360
361
362
363
364
365



















366
367
368
369
370
371
372
          src_pixel += src_weight;
          dst_pixel += dst_weight;
        }
  }
#endif
  ;
  



















#ifdef __windoze
HBITMAP Pict_Create_HBITMAP(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    BITMAPINFOHEADER bi;
    HDC dc;
    HBITMAP bmp;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
          src_pixel += src_weight;
          dst_pixel += dst_weight;
        }
  }
#endif
  ;
  
void Pict_Convert_Pixels_Row_Pal(byte_t *src, int src_format, byte_t *dst, int dst_format, int count, void *pal, int pal_count )
#ifdef _YOYO_PICTURE_BUILTIN
  {
    int i, bpp = Pict_Format_Bytes_PP(dst_format);
    byte_t palx[256*16]; /* sizeof(rgbaf) == 16 */
    Pict_Convert_Pixels_Row(pal,src_format,palx,dst_format,pal_count);
    if ( bpp == 4 )
      for ( i = 0; i < count; ++i )
        ((u32_t*)dst)[i] = ((u32_t*)palx)[src[i]];
    else if ( bpp == 2 )
      for ( i = 0; i < count; ++i )
        ((u32_t*)dst)[i] = ((u32_t*)palx)[src[i]];
    else
      for ( i = 0; i < count; ++i )
        memcpy((dst + i * bpp),palx + src[i]*bpp,bpp);
  }
#endif
  ;

#ifdef __windoze
HBITMAP Pict_Create_HBITMAP(YOYO_PICTURE *pict)
#ifdef _YOYO_PICTURE_BUILTIN
  {
    BITMAPINFOHEADER bi;
    HDC dc;
    HBITMAP bmp;
Changes to yoyo.hc.
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
193
194
195
196
197
198
199
200
201








202

203
204

205

206








207
208








209
210
211
212
213
214
215
#elif defined __GNUC__
# include <unwind.h>
  int backtrace( void **cbk, int count );
#else
# define backtrace(Cbk,Count) (0)
#endif


#define Isspace(x)   isspace((byte_t)(x))
#define Isdigit(x)   isdigit((byte_t)(x))
#define Isxdigit(x)  isxdigit((byte_t)(x))
#define Toupper(x)   toupper((byte_t)(x))
#define Tolower(x)   tolower((byte_t)(x))


#define iszof(x)     ((int)sizeof(x))
#define iszof_double ((int)sizeof(double))
#define iszof_long   ((int)sizeof(long))
#define iszof_wchar  ((int)sizeof(wchar_t))
#define iszof_arr(x) ((int)(sizeof(x)/sizeof(*x)))

#define __Offset_Of(T,Memb) ((longptr_t)(&((T*)0)->Memb))

typedef signed char    ioct_t;
typedef unsigned char  byte_t;

typedef unsigned short ushort_t;



typedef unsigned int   uint_t;



typedef unsigned long  ulong_t;

#ifndef __windoze
  typedef unsigned long long  uquad_t;
# if defined __APPLE__
    typedef long long  quad_t;
# endif
#else
  typedef unsigned __int64  uquad_t;
  typedef __int64  quad_t;
#endif









#ifdef __x86_64

  typedef uint_t   halflong_t;
  typedef ulong_t  longptr_t;

#else

  typedef ushort_t halflong_t;








  typedef ulong_t  longptr_t;
#endif









#ifndef _NO__FILE__
# define __Yo_FILE__ __FILE__
# define __Yo_Expr__(Expr) #Expr
# define Yo_Raise(Error,Msg,File,Line) _Yo_Raise(Error,Msg,File,Line)
# define Yo_Fatal(Error,Msg,File,Line) _Yo_Fatal(Error,Msg,File,Line)
#else







>






>





>


|

>

>
>
>

>
>
>



|
|
|






>
>
>
>
>
>
>
>

>
|
|
>

>
|
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>







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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#elif defined __GNUC__
# include <unwind.h>
  int backtrace( void **cbk, int count );
#else
# define backtrace(Cbk,Count) (0)
#endif

/* Only if x is one-byte symbol! */
#define Isspace(x)   isspace((byte_t)(x))
#define Isdigit(x)   isdigit((byte_t)(x))
#define Isxdigit(x)  isxdigit((byte_t)(x))
#define Toupper(x)   toupper((byte_t)(x))
#define Tolower(x)   tolower((byte_t)(x))

/* ATTENTION! int is always less then size_t! use it carefully */
#define iszof(x)     ((int)sizeof(x))
#define iszof_double ((int)sizeof(double))
#define iszof_long   ((int)sizeof(long))
#define iszof_wchar  ((int)sizeof(wchar_t))
#define iszof_arr(x) ((int)(sizeof(x)/sizeof(*x)))

#define __Offset_Of(T,Memb) ((longptr_t)(&((T*)0)->Memb))

typedef signed   char  ioct_t;
typedef unsigned char  byte_t;

typedef unsigned short ushort_t;
typedef unsigned short uhalf_t; /* 16 bit unsigned ( half word )*/
typedef short          half_t;  /* 16 bit signed ( half word )  */

typedef unsigned int   uint_t;
typedef unsigned int   udword_t; /* 32 bit unsigned ( i386 word ) */
typedef int            dword_t;  /* 32 bit signed ( i386 word )   */

typedef unsigned long  ulong_t;

#ifndef __windoze
  typedef unsigned long long  uquad_t; /* 64-bit unsigned ( double word ) historically named as quad word */
# if !defined __APPLE__
    typedef long long  quad_t; /* 64-bit signed word ( double word ) */
# endif
#else
  typedef unsigned __int64  uquad_t;
  typedef __int64  quad_t;
#endif

/* halflong_t is half of unsigned long value can be 16 or 32 bit, depends on platform */
#if defined __x86_64 && !defined __windoze
  typedef uint_t   halflong_t;  /* windows has 32-bit long always */
#else
  typedef ushort_t halflong_t;
#endif

/* maxint_t is max integer value supporting natively by CPU, depends on platform */
#ifdef __x86_64
  typedef uquad_t   umaxint_t; 
  typedef uint_t    halfumi_t; 
  typedef quad_t    maxint_t; 
  typedef int       halfmi_t; 
#else
  typedef ulong_t   umaxint_t; 
  typedef ushort_t  halfumi_t;
  typedef int       maxint_t;
  typedef short     halfmi_t;
#endif

/* longptr_t is unsigned integer value enough to store pointer value */
#ifdef __x86_64
  typedef uquad_t  longptr_t; /* windows has 32-bit long always */
#else
  typedef ulong_t  longptr_t;
#endif

/* compatibility with legacy TeggoSoft/MoleStudio code */
typedef uhalf_t  u16_t;
typedef udword_t u32_t;
typedef uquad_t  u64_t;
typedef half_t   i16_t;
typedef dword_t  i32_t;
typedef quad_t   i64_t;

#ifndef _NO__FILE__
# define __Yo_FILE__ __FILE__
# define __Yo_Expr__(Expr) #Expr
# define Yo_Raise(Error,Msg,File,Line) _Yo_Raise(Error,Msg,File,Line)
# define Yo_Fatal(Error,Msg,File,Line) _Yo_Fatal(Error,Msg,File,Line)
#else
230
231
232
233
234
235
236

237
238
239
240
241
242
243
#else
# define _YOYO_CORE_BUILTIN_CODE(Code)
# define _YOYO_CORE_EXTERN extern 
#endif

#define Yo_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define Yo_MAX(a,b) ( (a) > (b) ? (a) : (b) )

#define Yo_ALIGNU(a,n) ( ((a) + ((n) - 1))&~((n) - 1) )

#define YOYO_REPN_2(Val)   Val,Val
#define YOYO_REPN_4(Val)   YOYO_REPN_2(Val),YOYO_REPN_2(Val)
#define YOYO_REPN_8(Val)   YOYO_REPN_4(Val),YOYO_REPN_4(Val)
#define YOYO_REPN_16(Val)  YOYO_REPN_8(Val),YOYO_REPN_8(Val)
#define YOYO_REPN_32(Val)  YOYO_REPN_16(Val),YOYO_REPN_16(Val)







>







267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#else
# define _YOYO_CORE_BUILTIN_CODE(Code)
# define _YOYO_CORE_EXTERN extern 
#endif

#define Yo_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define Yo_MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define Yo_ABS(a) ( (a) > 0 ? (a) : -(a) ) /* a > 0  does not produce warning on unsigned types */
#define Yo_ALIGNU(a,n) ( ((a) + ((n) - 1))&~((n) - 1) )

#define YOYO_REPN_2(Val)   Val,Val
#define YOYO_REPN_4(Val)   YOYO_REPN_2(Val),YOYO_REPN_2(Val)
#define YOYO_REPN_8(Val)   YOYO_REPN_4(Val),YOYO_REPN_4(Val)
#define YOYO_REPN_16(Val)  YOYO_REPN_8(Val),YOYO_REPN_8(Val)
#define YOYO_REPN_32(Val)  YOYO_REPN_16(Val),YOYO_REPN_16(Val)
568
569
570
571
572
573
574

575
576
577
578
579
580
581
#endif
  ;

int Yo_Mini(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
int Yo_Maxi(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });
uint_t Yo_Minu(uint_t a, uint_t b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
uint_t Yo_Maxu(uint_t a, uint_t b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });


uint_t Align_To_Pow2(uint_t a, uint_t mod)
#ifdef _YOYO_CORE_BUILTIN
  {
    uint_t Q;
    if ( !mod ) mod = 1;
    Q = Min_Pow2(mod) - 1;







>







606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
#endif
  ;

int Yo_Mini(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
int Yo_Maxi(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });
uint_t Yo_Minu(uint_t a, uint_t b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
uint_t Yo_Maxu(uint_t a, uint_t b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });
uint_t Yo_Absi(int a) _YOYO_CORE_BUILTIN_CODE({ return Yo_ABS(a); });

uint_t Align_To_Pow2(uint_t a, uint_t mod)
#ifdef _YOYO_CORE_BUILTIN
  {
    uint_t Q;
    if ( !mod ) mod = 1;
    Q = Min_Pow2(mod) - 1;
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
    else if ( !p )
      Yo_Pool(q);
    return q;
  }
#endif
  ;
  
#ifdef __windoze
  #ifdef __VSCPRINTF
int _vscprintf(char *fmt,va_list va)
  {
    static char simulate[4096*4] = {0};
    return vsprintf(simulate,fmt,va);
  }
  #endif
#endif
  
  
int Yo_Detect_Required_Buffer_Size(char *fmt,va_list va)
#ifdef _YOYO_CORE_BUILTIN
  {
  #ifdef __windoze







<
|





<







1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
    else if ( !p )
      Yo_Pool(q);
    return q;
  }
#endif
  ;
  

#if defined _YOYO_CORE_BUILTIN && defined __windoze && defined __VSCPRINTF
int _vscprintf(char *fmt,va_list va)
  {
    static char simulate[4096*4] = {0};
    return vsprintf(simulate,fmt,va);
  }

#endif
  
  
int Yo_Detect_Required_Buffer_Size(char *fmt,va_list va)
#ifdef _YOYO_CORE_BUILTIN
  {
  #ifdef __windoze
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358



1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
  {
    int (*count)(void *) = Yo_Find_Method_Of(&self,Oj_Count_OjMID,YO_RAISE_ERROR);
    return count(self);
  }
#endif
  ;

#define __Try  \
  switch ( setjmp(Yo_Push_JmpBuf()->b) ) \
    while ( 1 ) \
      if ( 1 ) \
        { Yo_Pop_JmpBuf(); break; } \
      else if ( 0 ) \
        default: Yo_Raise_Occured(); \
      else if ( 0 ) \
        case 0:

#define __Try_Abort  \
  switch ( setjmp(Yo_Push_JmpBuf()->b) ) \
    while ( 1 ) \
      if ( 1 ) \
        { Yo_Pop_JmpBuf(); break; } \
      else if ( 0 ) \
        default: Error_Abort(); \
      else if ( 0 ) \
        case 0:

#define __Try_Exit(pfx)  \
  switch ( setjmp(Yo_Push_JmpBuf()->b) ) \
    while ( 1 ) \
      if ( 1 ) \
        { Yo_Pop_JmpBuf(); break; } \
      else if ( 0 ) \
        default: Error_Exit(pfx); \
      else if ( 0 ) \
        case 0:

#define __Try_Except  \
  switch ( setjmp(Yo_Push_JmpBuf()->b) ) \
    while ( 1 ) \
      if ( 1 ) \
        { Yo_Pop_JmpBuf(); break; } \
      else if ( 0 ) \



        case 0:

#define __Catch(Code) \
    else if ( 0 ) \
      case (Code):

#define __Except \
    else \
      default:

YOYO_ERROR_INFO *Error_Info()
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && nfo->err.code )







<
<
<
<
<
<
<
<
<

|
<
<
<
<
<
|
<
<
|
|
<
<
<
<
<
<
<
<

|

|
|

|
>
>
>



|


|
|







1353
1354
1355
1356
1357
1358
1359









1360
1361





1362


1363
1364








1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
  {
    int (*count)(void *) = Yo_Find_Method_Of(&self,Oj_Count_OjMID,YO_RAISE_ERROR);
    return count(self);
  }
#endif
  ;











#define __Try __Try_Specific(default: Yo_Raise_Occured())





#define __Try_Abort __Try_Specific(default: Error_Abort())


#define __Try_Exit(pfx) __Try_Specific(default: Error_Exit(pfx))
#define __Try_Except __Try_Specific((void)0)









#define __Try_Specific(What)  \
  switch ( setjmp(Yo_Push_JmpBuf()->b) ) \
    if (1) /* guards exception way */ while (1) \
      if (1) /* on second while's step if executed without errors */ \
        { Yo_Pop_JmpBuf(); break; } \
      else if (0) /* if unexpected */ \
        /* default: */ What; \
      else /* there is protected code */ \
        /* switch jumps to here */ \
        case 0:

#define __Catch(Code) \
    else if (0) /* else branch of guards if */ \
      case (Code):

#define __Except /* using with __Try_Except */ \
    else /* else branch of guards if */ \
      default:

YOYO_ERROR_INFO *Error_Info()
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && nfo->err.code )