2 #include "e_mod_main.h"
3 #include "e_mod_comp_update.h"
5 //////////////////////////////////////////////////////////////////////////
8 _e_mod_comp_tiles_alloc(E_Update *up)
10 if (up->tiles) return;
11 up->tiles = calloc(up->tw * up->th, sizeof(unsigned char));
14 //////////////////////////////////////////////////////////////////////////
17 e_mod_comp_update_new(void)
21 up = calloc(1, sizeof(E_Update));
26 up->pol = E_UPDATE_POLICY_RAW;
31 e_mod_comp_update_free(E_Update *up)
34 if (up->tiles) free(up->tiles);
39 e_mod_comp_update_policy_set(E_Update *up,
46 e_mod_comp_update_tile_size_set(E_Update *up,
50 if ((up->tsw == tsw) && (up->tsh == tsh)) return;
53 e_mod_comp_update_clear(up);
57 e_mod_comp_update_resize(E_Update *up,
61 unsigned char *ptiles, *p, *pp;
64 if ((!up) || ((up->w == w) && (up->h == h))) return;
72 up->tw = (up->w + up->tsw - 1) / up->tsw;
73 up->th = (up->h + up->tsh - 1) / up->tsh;
75 _e_mod_comp_tiles_alloc(up);
76 if ((ptiles) && (up->tiles))
80 for (y = 0; y < pth; y++)
82 p = up->tiles + (y * up->tw);
83 pp = ptiles + (y * ptw);
84 if (ptw <= up->tw) for (x = 0; x < ptw; x++) *p++ = *pp++;
85 else for (x = 0; x < up->tw; x++) *p++ = *pp++;
90 for (y = 0; y < up->th; y++)
92 p = up->tiles + (y * up->tw);
93 pp = ptiles + (y * ptw);
94 if (ptw <= up->tw) for (x = 0; x < ptw; x++) *p++ = *pp++;
95 else for (x = 0; x < up->tw; x++) *p++ = *pp++;
103 e_mod_comp_update_add(E_Update *up,
109 int tx, ty, txx, tyy, xx, yy;
110 unsigned char *t, *t2;
112 if ((w <= 0) || (h <= 0)) return;
113 if ((up->tw <= 0) || (up->th <= 0)) return;
115 _e_mod_comp_tiles_alloc(up);
117 E_RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, up->w, up->h);
118 if ((w <= 0) || (h <= 0)) return;
122 case E_UPDATE_POLICY_RAW:
125 case E_UPDATE_POLICY_HALF_WIDTH_OR_MORE_ROUND_UP_TO_FULL_WIDTH:
139 txx = (x + w - 1) / up->tsw;
140 tyy = (y + h - 1) / up->tsh;
141 t = up->tiles + (ty * up->tw) + tx;
142 for (yy = ty; yy <= tyy; yy++)
145 for (xx = tx; xx <= txx; xx++)
155 e_mod_comp_update_rects_get(E_Update *up)
160 unsigned char *t, *t2, *t3;
162 if (!up->tiles) return NULL;
163 r = calloc((up->tw * up->th) + 1, sizeof(E_Update_Rect));
166 for (y = 0; y < up->th; y++)
168 for (x = 0; x < up->tw; x++)
172 int can_expand_x = 1, can_expand_y = 1;
179 if ((x + xx) >= up->tw) can_expand_x = 0;
182 if (can_expand_x) *t2 = 0;
192 if ((y + yy) >= up->th) can_expand_y = 0;
196 for (i = 0; i < xx; i++)
209 for (i = 0; i < xx; i++)
217 r[ri].x = x * up->tsw;
218 r[ri].y = y * up->tsh;
219 r[ri].w = xx * up->tsw;
220 r[ri].h = yy * up->tsh;
221 if ((r[ri].x + r[ri].w) > up->w) r[ri].w = up->w - r[ri].x;
222 if ((r[ri].y + r[ri].h) > up->h) r[ri].h = up->h - r[ri].y;
223 if ((r[ri].w <= 0) || (r[ri].h <= 0)) r[ri].w = 0;
235 e_mod_comp_update_clear(E_Update *up)