code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifndef SDL_shaders_gles2_h_ #define SDL_shaders_gles2_h_ #if SDL_VIDEO_RENDER_OGL_ES2 typedef struct GLES2_ShaderInstance { GLenum type; GLenum format; int length; const void *data; } GLES2_ShaderInstance; typedef struct GLES2_Shader { int instance_count; const GLES2_ShaderInstance *instances[4]; } GLES2_Shader; typedef enum { GLES2_SHADER_VERTEX_DEFAULT, GLES2_SHADER_FRAGMENT_SOLID_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT601_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT709_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709_SRC, GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES_SRC } GLES2_ShaderType; #define GLES2_SOURCE_SHADER (GLenum)-1 const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type); #endif /* SDL_VIDEO_RENDER_OGL_ES2 */ #endif /* SDL_shaders_gles2_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/opengles2/SDL_shaders_gles2.h
C
apache-2.0
2,300
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_PSP #include "SDL_hints.h" #include "SDL_assert.h" #include "../SDL_sysrender.h" #include <pspkernel.h> #include <pspdisplay.h> #include <pspgu.h> #include <pspgum.h> #include <stdio.h> #include <string.h> #include <math.h> #include <pspge.h> #include <stdarg.h> #include <stdlib.h> #include <vram.h> /* PSP renderer implementation, based on the PGE */ #define PSP_SCREEN_WIDTH 480 #define PSP_SCREEN_HEIGHT 272 #define PSP_FRAME_BUFFER_WIDTH 512 #define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT) static unsigned int __attribute__((aligned(16))) DisplayList[262144]; #define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11)) #define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0)) #define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12)) #define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24)) typedef struct { void* frontbuffer ; void* backbuffer ; SDL_bool initialized ; SDL_bool displayListAvail ; unsigned int psm ; unsigned int bpp ; SDL_bool vsync; unsigned int currentColor; int currentBlendMode; } PSP_RenderData; typedef struct { void *data; /**< Image data. */ unsigned int size; /**< Size of data in bytes. */ unsigned int width; /**< Image width. */ unsigned int height; /**< Image height. */ unsigned int textureWidth; /**< Texture width (power of two). */ unsigned int textureHeight; /**< Texture height (power of two). */ unsigned int bits; /**< Image bits per pixel. */ unsigned int format; /**< Image format - one of ::pgePixelFormat. */ unsigned int pitch; SDL_bool swizzled; /**< Is image swizzled. */ } PSP_TextureData; typedef struct { float x, y, z; } VertV; typedef struct { float u, v; float x, y, z; } VertTV; #define PI 3.14159265358979f #define radToDeg(x) ((x)*180.f/PI) #define degToRad(x) ((x)*PI/180.f) float MathAbs(float x) { float result; __asm__ volatile ( "mtv %1, S000\n" "vabs.s S000, S000\n" "mfv %0, S000\n" : "=r"(result) : "r"(x)); return result; } void MathSincos(float r, float *s, float *c) { __asm__ volatile ( "mtv %2, S002\n" "vcst.s S003, VFPU_2_PI\n" "vmul.s S002, S002, S003\n" "vrot.p C000, S002, [s, c]\n" "mfv %0, S000\n" "mfv %1, S001\n" : "=r"(*s), "=r"(*c): "r"(r)); } void Swap(float *a, float *b) { float n=*a; *a = *b; *b = n; } /* Return next power of 2 */ static int TextureNextPow2(unsigned int w) { if(w == 0) return 0; unsigned int n = 2; while(w > n) n <<= 1; return n; } static int PixelFormatToPSPFMT(Uint32 format) { switch (format) { case SDL_PIXELFORMAT_BGR565: return GU_PSM_5650; case SDL_PIXELFORMAT_ABGR1555: return GU_PSM_5551; case SDL_PIXELFORMAT_ABGR4444: return GU_PSM_4444; case SDL_PIXELFORMAT_ABGR8888: return GU_PSM_8888; default: return GU_PSM_8888; } } void StartDrawing(SDL_Renderer * renderer) { PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; if(data->displayListAvail) return; sceGuStart(GU_DIRECT, DisplayList); data->displayListAvail = SDL_TRUE; } int TextureSwizzle(PSP_TextureData *psp_texture) { if(psp_texture->swizzled) return 1; int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); int height = psp_texture->size / bytewidth; int rowblocks = (bytewidth>>4); int rowblocksadd = (rowblocks-1)<<7; unsigned int blockaddress = 0; unsigned int *src = (unsigned int*) psp_texture->data; unsigned char *data = NULL; data = malloc(psp_texture->size); int j; for(j = 0; j < height; j++, blockaddress += 16) { unsigned int *block; block = (unsigned int*)&data[blockaddress]; int i; for(i = 0; i < rowblocks; i++) { *block++ = *src++; *block++ = *src++; *block++ = *src++; *block++ = *src++; block += 28; } if((j & 0x7) == 0x7) blockaddress += rowblocksadd; } free(psp_texture->data); psp_texture->data = data; psp_texture->swizzled = SDL_TRUE; return 1; } int TextureUnswizzle(PSP_TextureData *psp_texture) { if(!psp_texture->swizzled) return 1; int blockx, blocky; int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3); int height = psp_texture->size / bytewidth; int widthblocks = bytewidth/16; int heightblocks = height/8; int dstpitch = (bytewidth - 16)/4; int dstrow = bytewidth * 8; unsigned int *src = (unsigned int*) psp_texture->data; unsigned char *data = NULL; data = malloc(psp_texture->size); if(!data) return 0; sceKernelDcacheWritebackAll(); int j; unsigned char *ydst = (unsigned char *)data; for(blocky = 0; blocky < heightblocks; ++blocky) { unsigned char *xdst = ydst; for(blockx = 0; blockx < widthblocks; ++blockx) { unsigned int *block; block = (unsigned int*)xdst; for(j = 0; j < 8; ++j) { *(block++) = *(src++); *(block++) = *(src++); *(block++) = *(src++); *(block++) = *(src++); block += dstpitch; } xdst += 16; } ydst += dstrow; } free(psp_texture->data); psp_texture->data = data; psp_texture->swizzled = SDL_FALSE; return 1; } static void PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) { } static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { /* PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; */ PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture)); if(!psp_texture) return -1; psp_texture->swizzled = SDL_FALSE; psp_texture->width = texture->w; psp_texture->height = texture->h; psp_texture->textureHeight = TextureNextPow2(texture->h); psp_texture->textureWidth = TextureNextPow2(texture->w); psp_texture->format = PixelFormatToPSPFMT(texture->format); switch(psp_texture->format) { case GU_PSM_5650: case GU_PSM_5551: case GU_PSM_4444: psp_texture->bits = 16; break; case GU_PSM_8888: psp_texture->bits = 32; break; default: return -1; } psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format); psp_texture->size = psp_texture->textureHeight*psp_texture->pitch; psp_texture->data = SDL_calloc(1, psp_texture->size); if(!psp_texture->data) { SDL_free(psp_texture); return SDL_OutOfMemory(); } texture->driverdata = psp_texture; return 0; } static int PSP_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) { return SDL_Unsupported(); } void TextureActivate(SDL_Texture * texture) { PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; int scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GU_NEAREST : GU_LINEAR; /* Swizzling is useless with small textures. */ if (texture->w >= 16 || texture->h >= 16) { TextureSwizzle(psp_texture); } sceGuEnable(GU_TEXTURE_2D); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled); sceGuTexFilter(scaleMode, scaleMode); /* GU_NEAREST good for tile-map */ /* GU_LINEAR good for scaling */ sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); } static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { /* PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; */ const Uint8 *src; Uint8 *dst; int row, length,dpitch; src = pixels; PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch); length = rect->w * SDL_BYTESPERPIXEL(texture->format); if (length == pitch && length == dpitch) { SDL_memcpy(dst, src, length*rect->h); } else { for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += dpitch; } } sceKernelDcacheWritebackAll(); return 0; } static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, void **pixels, int *pitch) { PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; *pixels = (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = psp_texture->pitch; return 0; } static void PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) { PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; SDL_Rect rect; /* We do whole texture updates, at least for now */ rect.x = 0; rect.y = 0; rect.w = texture->w; rect.h = texture->h; PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch); } static void PSP_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode) { /* Nothing to do because TextureActivate takes care of it */ } static int PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) { return 0; } static int PSP_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd) { return 0; /* nothing to do in this backend. */ } static int PSP_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count) { VertV *verts = (VertV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertV), 4, &cmd->data.draw.first); int i; if (!verts) { return -1; } cmd->data.draw.count = count; for (i = 0; i < count; i++, verts++, points++) { verts->x = points->x; verts->y = points->y; verts->z = 0.0f; } return 0; } static int PSP_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count) { VertV *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 2 * sizeof (VertV), 4, &cmd->data.draw.first); int i; if (!verts) { return -1; } cmd->data.draw.count = count; for (i = 0; i < count; i++, rects++) { const SDL_FRect *rect = &rects[i]; verts->x = rect->x; verts->y = rect->y; verts->z = 0.0f; verts++; verts->x = rect->x + rect->w; verts->y = rect->y + rect->h; verts->z = 0.0f; verts++; } return 0; } static int PSP_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { VertTV *verts; const float x = dstrect->x; const float y = dstrect->y; const float width = dstrect->w; const float height = dstrect->h; const float u0 = srcrect->x; const float v0 = srcrect->y; const float u1 = srcrect->x + srcrect->w; const float v1 = srcrect->y + srcrect->h; if((MathAbs(u1) - MathAbs(u0)) < 64.0f) { verts = (VertTV *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (VertTV), 4, &cmd->data.draw.first); if (!verts) { return -1; } cmd->data.draw.count = 1; verts->u = u0; verts->v = v0; verts->x = x; verts->y = y; verts->z = 0; verts++; verts->u = u1; verts->v = v1; verts->x = x + width; verts->y = y + height; verts->z = 0; verts++; } else { float start, end; float curU = u0; float curX = x; const float endX = x + width; const float slice = 64.0f; const size_t count = SDL_ceilf(width / slice); size_t i; float ustep = (u1 - u0)/width * slice; if(ustep < 0.0f) ustep = -ustep; cmd->data.draw.count = count; verts = (VertTV *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertTV), 4, &cmd->data.draw.first); if (!verts) { return -1; } for(i = 0, start = 0, end = width; i < count; i++, start += slice) { const float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice; const float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep; SDL_assert(start < end); verts->u = curU; verts->v = v0; verts->x = curX; verts->y = y; verts->z = 0; curU += sourceWidth; curX += polyWidth; verts->u = curU; verts->v = v1; verts->x = curX; verts->y = (y + height); verts->z = 0; } } return 0; } static int PSP_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) { VertTV *verts = (VertTV *) SDL_AllocateRenderVertices(renderer, 4 * sizeof (VertTV), 4, &cmd->data.draw.first); const float centerx = center->x; const float centery = center->y; const float x = dstrect->x + centerx; const float y = dstrect->y + centery; const float width = dstrect->w - centerx; const float height = dstrect->h - centery; float s, c; float u0 = srcrect->x; float v0 = srcrect->y; float u1 = srcrect->x + srcrect->w; float v1 = srcrect->y + srcrect->h; if (!verts) { return -1; } cmd->data.draw.count = 1; MathSincos(degToRad(angle), &s, &c); const float cw = c * width; const float sw = s * width; const float ch = c * height; const float sh = s * height; if (flip & SDL_FLIP_VERTICAL) { Swap(&v0, &v1); } if (flip & SDL_FLIP_HORIZONTAL) { Swap(&u0, &u1); } verts->u = u0; verts->v = v0; verts->x = x - cw + sh; verts->y = y - sw - ch; verts->z = 0; verts++; verts->u = u0; verts->v = v1; verts->x = x - cw - sh; verts->y = y - sw + ch; verts->z = 0; verts++; verts->u = u1; verts->v = v1; verts->x = x + cw - sh; verts->y = y + sw + ch; verts->z = 0; verts++; verts->u = u1; verts->v = v0; verts->x = x + cw + sh; verts->y = y + sw - ch; verts->z = 0; verts++; return 0; } static void PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode) { PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; if (blendMode != data-> currentBlendMode) { switch (blendMode) { case SDL_BLENDMODE_NONE: sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); sceGuDisable(GU_BLEND); break; case SDL_BLENDMODE_BLEND: sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 ); break; case SDL_BLENDMODE_ADD: sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF ); break; case SDL_BLENDMODE_MOD: sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0); break; case SDL_BLENDMODE_MUL: sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_DST_COLOR, GU_ONE_MINUS_SRC_ALPHA, 0, 0); break; } data->currentBlendMode = blendMode; } } static int PSP_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; size_t i; StartDrawing(renderer); /* note that before the renderer interface change, this would do extrememly small batches with sceGuGetMemory()--a few vertices at a time--and it's not clear that this won't fail if you try to push 100,000 draw calls in a single batch. I don't know what the limits on PSP hardware are. It might be useful to have rendering backends report a reasonable maximum, so the higher level can flush if we appear to be exceeding that. */ Uint8 *gpumem = (Uint8 *) sceGuGetMemory(vertsize); if (!gpumem) { return SDL_SetError("Couldn't obtain a %d-byte vertex buffer!", (int) vertsize); } SDL_memcpy(gpumem, vertices, vertsize); while (cmd) { switch (cmd->command) { case SDL_RENDERCMD_SETDRAWCOLOR: { break; /* !!! FIXME: we could cache drawstate like color */ } case SDL_RENDERCMD_SETVIEWPORT: { SDL_Rect *viewport = &data->drawstate.viewport; if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect)) != 0) { SDL_memcpy(viewport, &cmd->data.viewport.rect, sizeof (SDL_Rect)); data->drawstate.viewport_dirty = SDL_TRUE; } break; } case SDL_RENDERCMD_SETCLIPRECT: { const SDL_Rect *rect = &cmd->data.cliprect.rect; if (data->drawstate.cliprect_enabled != cmd->data.cliprect.enabled) { data->drawstate.cliprect_enabled = cmd->data.cliprect.enabled; data->drawstate.cliprect_enabled_dirty = SDL_TRUE; } if (SDL_memcmp(&data->drawstate.cliprect, rect, sizeof (SDL_Rect)) != 0) { SDL_memcpy(&data->drawstate.cliprect, rect, sizeof (SDL_Rect)); data->drawstate.cliprect_dirty = SDL_TRUE; } break; } case SDL_RENDERCMD_CLEAR: { const Uint8 r = cmd->data.color.r; const Uint8 g = cmd->data.color.g; const Uint8 b = cmd->data.color.b; const Uint8 a = cmd->data.color.a; const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r); /* !!! FIXME: we could cache drawstate like clear color */ sceGuClearColor(color); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT); break; } case SDL_RENDERCMD_DRAW_POINTS: { const size_t count = cmd->data.draw.count; const VertV *verts = (VertV *) (gpumem + cmd->data.draw.first); const Uint8 r = cmd->data.draw.r; const Uint8 g = cmd->data.draw.g; const Uint8 b = cmd->data.draw.b; const Uint8 a = cmd->data.draw.a; const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r); /* !!! FIXME: we could cache draw state like color, texturing, etc */ sceGuColor(color); sceGuDisable(GU_TEXTURE_2D); sceGuShadeModel(GU_FLAT); sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, verts); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_TEXTURE_2D); break; } case SDL_RENDERCMD_DRAW_LINES: { const size_t count = cmd->data.draw.count; const VertV *verts = (VertV *) (gpumem + cmd->data.draw.first); const Uint8 r = cmd->data.draw.r; const Uint8 g = cmd->data.draw.g; const Uint8 b = cmd->data.draw.b; const Uint8 a = cmd->data.draw.a; const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r); /* !!! FIXME: we could cache draw state like color, texturing, etc */ sceGuColor(color); sceGuDisable(GU_TEXTURE_2D); sceGuShadeModel(GU_FLAT); sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, verts); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_TEXTURE_2D); break; } case SDL_RENDERCMD_FILL_RECTS: { const size_t count = cmd->data.draw.count; const VertV *verts = (VertV *) (gpumem + cmd->data.draw.first); const Uint8 r = cmd->data.draw.r; const Uint8 g = cmd->data.draw.g; const Uint8 b = cmd->data.draw.b; const Uint8 a = cmd->data.draw.a; const Uint32 color = ((a << 24) | (b << 16) | (g << 8) | r); /* !!! FIXME: we could cache draw state like color, texturing, etc */ sceGuColor(color); sceGuDisable(GU_TEXTURE_2D); sceGuShadeModel(GU_FLAT); sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2 * count, 0, verts); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_TEXTURE_2D); break; } case SDL_RENDERCMD_COPY: { const size_t count = cmd->data.draw.count; const VertTV *verts = (VertTV *) (gpumem + cmd->data.draw.first); const Uint8 alpha = cmd->data.draw.a; TextureActivate(cmd->data.draw.texture); PSP_SetBlendMode(renderer, cmd->data.draw.blend); if(alpha != 255) { /* !!! FIXME: is this right? */ sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuColor(GU_RGBA(255, 255, 255, alpha)); } else { sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); sceGuColor(0xFFFFFFFF); } sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2 * count, 0, verts); if(alpha != 255) { sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); } break; } case SDL_RENDERCMD_COPY_EX: { const VertTV *verts = (VertTV *) (gpumem + cmd->data.draw.first); const Uint8 alpha = cmd->data.draw.a; TextureActivate(cmd->data.draw.texture); PSP_SetBlendMode(renderer, cmd->data.draw.blend); if(alpha != 255) { /* !!! FIXME: is this right? */ sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuColor(GU_RGBA(255, 255, 255, alpha)); } else { sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); sceGuColor(0xFFFFFFFF); } sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, verts); if(alpha != 255) { sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); } break; } case SDL_RENDERCMD_NO_OP: break; } cmd = cmd->next; } return 0; } static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 pixel_format, void * pixels, int pitch) { return SDL_Unsupported(); } static void PSP_RenderPresent(SDL_Renderer * renderer) { PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; if(!data->displayListAvail) return; data->displayListAvail = SDL_FALSE; sceGuFinish(); sceGuSync(0,0); /* if(data->vsync) */ sceDisplayWaitVblankStart(); data->backbuffer = data->frontbuffer; data->frontbuffer = vabsptr(sceGuSwapBuffers()); } static void PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) { PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; if (renderdata == 0) return; if(psp_texture == 0) return; SDL_free(psp_texture->data); SDL_free(psp_texture); texture->driverdata = NULL; } static void PSP_DestroyRenderer(SDL_Renderer * renderer) { PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata; if (data) { if (!data->initialized) return; StartDrawing(renderer); sceGuTerm(); /* vfree(data->backbuffer); */ /* vfree(data->frontbuffer); */ data->initialized = SDL_FALSE; data->displayListAvail = SDL_FALSE; SDL_free(data); } SDL_free(renderer); } SDL_Renderer * PSP_CreateRenderer(SDL_Window * window, Uint32 flags) { SDL_Renderer *renderer; PSP_RenderData *data; int pixelformat; renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); if (!renderer) { SDL_OutOfMemory(); return NULL; } data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data)); if (!data) { PSP_DestroyRenderer(renderer); SDL_OutOfMemory(); return NULL; } renderer->WindowEvent = PSP_WindowEvent; renderer->CreateTexture = PSP_CreateTexture; renderer->SetTextureColorMod = PSP_SetTextureColorMod; renderer->UpdateTexture = PSP_UpdateTexture; renderer->LockTexture = PSP_LockTexture; renderer->UnlockTexture = PSP_UnlockTexture; renderer->SetTextureScaleMode = PSP_SetTextureScaleMode; renderer->SetRenderTarget = PSP_SetRenderTarget; renderer->QueueSetViewport = PSP_QueueSetViewport; renderer->QueueSetDrawColor = PSP_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */ renderer->QueueDrawPoints = PSP_QueueDrawPoints; renderer->QueueDrawLines = PSP_QueueDrawPoints; /* lines and points queue vertices the same way. */ renderer->QueueFillRects = PSP_QueueFillRects; renderer->QueueCopy = PSP_QueueCopy; renderer->QueueCopyEx = PSP_QueueCopyEx; renderer->RunCommandQueue = PSP_RunCommandQueue; renderer->RenderReadPixels = PSP_RenderReadPixels; renderer->RenderPresent = PSP_RenderPresent; renderer->DestroyTexture = PSP_DestroyTexture; renderer->DestroyRenderer = PSP_DestroyRenderer; renderer->info = PSP_RenderDriver.info; renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); renderer->driverdata = data; renderer->window = window; if (data->initialized != SDL_FALSE) return 0; data->initialized = SDL_TRUE; if (flags & SDL_RENDERER_PRESENTVSYNC) { data->vsync = SDL_TRUE; } else { data->vsync = SDL_FALSE; } pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window)); switch(pixelformat) { case GU_PSM_4444: case GU_PSM_5650: case GU_PSM_5551: data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1); data->backbuffer = (unsigned int *)(0); data->bpp = 2; data->psm = pixelformat; break; default: data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2); data->backbuffer = (unsigned int *)(0); data->bpp = 4; data->psm = GU_PSM_8888; break; } sceGuInit(); /* setup GU */ sceGuStart(GU_DIRECT, DisplayList); sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH); sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH); sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1)); sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); data->frontbuffer = vabsptr(data->frontbuffer); data->backbuffer = vabsptr(data->backbuffer); /* Scissoring */ sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); /* Backface culling */ sceGuFrontFace(GU_CCW); sceGuEnable(GU_CULL_FACE); /* Texturing */ sceGuEnable(GU_TEXTURE_2D); sceGuShadeModel(GU_SMOOTH); sceGuTexWrap(GU_REPEAT, GU_REPEAT); /* Blending */ sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexFilter(GU_LINEAR,GU_LINEAR); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStartCB(); sceGuDisplay(GU_TRUE); return renderer; } SDL_RenderDriver PSP_RenderDriver = { .CreateRenderer = PSP_CreateRenderer, .info = { .name = "PSP", .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE, .num_texture_formats = 4, .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565, [1] = SDL_PIXELFORMAT_ABGR1555, [2] = SDL_PIXELFORMAT_ABGR4444, [3] = SDL_PIXELFORMAT_ABGR8888, }, .max_texture_width = 512, .max_texture_height = 512, } }; #endif /* SDL_VIDEO_RENDER_PSP */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/psp/SDL_render_psp.c
C
apache-2.0
31,253
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED #include "SDL_draw.h" #include "SDL_blendfillrect.h" static int SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555); break; case SDL_BLENDMODE_MUL: FILLRECT(Uint16, DRAW_SETPIXEL_MUL_RGB555); break; default: FILLRECT(Uint16, DRAW_SETPIXEL_RGB555); break; } return 0; } static int SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565); break; case SDL_BLENDMODE_MUL: FILLRECT(Uint16, DRAW_SETPIXEL_MUL_RGB565); break; default: FILLRECT(Uint16, DRAW_SETPIXEL_RGB565); break; } return 0; } static int SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888); break; case SDL_BLENDMODE_MUL: FILLRECT(Uint32, DRAW_SETPIXEL_MUL_RGB888); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_RGB888); break; } return 0; } static int SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888); break; case SDL_BLENDMODE_MUL: FILLRECT(Uint32, DRAW_SETPIXEL_MUL_ARGB8888); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888); break; } return 0; } static int SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; unsigned inva = 0xff - a; switch (fmt->BytesPerPixel) { case 2: switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB); break; case SDL_BLENDMODE_MUL: FILLRECT(Uint16, DRAW_SETPIXEL_MUL_RGB); break; default: FILLRECT(Uint16, DRAW_SETPIXEL_RGB); break; } return 0; case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB); break; case SDL_BLENDMODE_MUL: FILLRECT(Uint32, DRAW_SETPIXEL_MUL_RGB); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_RGB); break; } return 0; default: return SDL_Unsupported(); } } static int SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; unsigned inva = 0xff - a; switch (fmt->BytesPerPixel) { case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA); break; case SDL_BLENDMODE_MUL: FILLRECT(Uint32, DRAW_SETPIXEL_MUL_RGBA); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_RGBA); break; } return 0; default: return SDL_Unsupported(); } } int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_Rect clipped; if (!dst) { return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); } /* If 'rect' == NULL, then fill the whole surface */ if (rect) { /* Perform clipping */ if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { return 0; } rect = &clipped; } else { rect = &dst->clip_rect; } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } switch (dst->format->BitsPerPixel) { case 15: switch (dst->format->Rmask) { case 0x7C00: return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a); } break; case 16: switch (dst->format->Rmask) { case 0xF800: return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a); } break; case 32: switch (dst->format->Rmask) { case 0x00FF0000: if (!dst->format->Amask) { return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a); } else { return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a); } /* break; -Wunreachable-code-break */ } break; default: break; } if (!dst->format->Amask) { return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a); } else { return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a); } } int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_Rect rect; int i; int (*func)(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; int status = 0; if (!dst) { return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } /* FIXME: Does this function pointer slow things down significantly? */ switch (dst->format->BitsPerPixel) { case 15: switch (dst->format->Rmask) { case 0x7C00: func = SDL_BlendFillRect_RGB555; } break; case 16: switch (dst->format->Rmask) { case 0xF800: func = SDL_BlendFillRect_RGB565; } break; case 32: switch (dst->format->Rmask) { case 0x00FF0000: if (!dst->format->Amask) { func = SDL_BlendFillRect_RGB888; } else { func = SDL_BlendFillRect_ARGB8888; } break; } break; default: break; } if (!func) { if (!dst->format->Amask) { func = SDL_BlendFillRect_RGB; } else { func = SDL_BlendFillRect_RGBA; } } for (i = 0; i < count; ++i) { /* Perform clipping */ if (!SDL_IntersectRect(&rects[i], &dst->clip_rect, &rect)) { continue; } status = func(dst, &rect, blendMode, r, g, b, a); } return status; } #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_blendfillrect.c
C
apache-2.0
10,230
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_blendfillrect_h_ #define SDL_blendfillrect_h_ #include "../../SDL_internal.h" extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); #endif /* SDL_blendfillrect_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_blendfillrect.h
C
apache-2.0
1,383
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED #include "SDL_draw.h" #include "SDL_blendline.h" #include "SDL_blendpoint.h" static void SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end) { const SDL_PixelFormat *fmt = dst->format; unsigned r, g, b, a, inva; if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(_r, _a); g = DRAW_MUL(_g, _a); b = DRAW_MUL(_b, _a); a = _a; } else { r = _r; g = _g; b = _b; a = _a; } inva = (a ^ 0xff); if (y1 == y2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: HLINE(Uint16, DRAW_SETPIXEL_MUL_RGB, draw_end); break; default: HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); break; } } else if (x1 == x2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: VLINE(Uint16, DRAW_SETPIXEL_MUL_RGB, draw_end); break; default: VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); break; } } else if (ABS(x1 - x2) == ABS(y1 - y2)) { switch (blendMode) { case SDL_BLENDMODE_BLEND: DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: DLINE(Uint16, DRAW_SETPIXEL_MUL_RGB, draw_end); break; default: DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); break; } } else { switch (blendMode) { case SDL_BLENDMODE_BLEND: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_MUL_RGB, DRAW_SETPIXELXY2_MUL_RGB, draw_end); break; default: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB, draw_end); break; } } } static void SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end) { unsigned r, g, b, a, inva; if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(_r, _a); g = DRAW_MUL(_g, _a); b = DRAW_MUL(_b, _a); a = _a; } else { r = _r; g = _g; b = _b; a = _a; } inva = (a ^ 0xff); if (y1 == y2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); break; case SDL_BLENDMODE_ADD: HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); break; case SDL_BLENDMODE_MOD: HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); break; case SDL_BLENDMODE_MUL: HLINE(Uint16, DRAW_SETPIXEL_MUL_RGB555, draw_end); break; default: HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); break; } } else if (x1 == x2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); break; case SDL_BLENDMODE_ADD: VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); break; case SDL_BLENDMODE_MOD: VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); break; case SDL_BLENDMODE_MUL: VLINE(Uint16, DRAW_SETPIXEL_MUL_RGB555, draw_end); break; default: VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); break; } } else if (ABS(x1 - x2) == ABS(y1 - y2)) { switch (blendMode) { case SDL_BLENDMODE_BLEND: DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); break; case SDL_BLENDMODE_ADD: DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); break; case SDL_BLENDMODE_MOD: DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end); break; case SDL_BLENDMODE_MUL: DLINE(Uint16, DRAW_SETPIXEL_MUL_RGB555, draw_end); break; default: DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); break; } } else { switch (blendMode) { case SDL_BLENDMODE_BLEND: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, draw_end); break; case SDL_BLENDMODE_ADD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555, draw_end); break; case SDL_BLENDMODE_MOD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555, draw_end); break; case SDL_BLENDMODE_MUL: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MUL_RGB555, DRAW_SETPIXELXY_MUL_RGB555, draw_end); break; default: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, draw_end); break; } } } static void SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end) { unsigned r, g, b, a, inva; if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(_r, _a); g = DRAW_MUL(_g, _a); b = DRAW_MUL(_b, _a); a = _a; } else { r = _r; g = _g; b = _b; a = _a; } inva = (a ^ 0xff); if (y1 == y2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); break; case SDL_BLENDMODE_ADD: HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); break; case SDL_BLENDMODE_MOD: HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); break; case SDL_BLENDMODE_MUL: HLINE(Uint16, DRAW_SETPIXEL_MUL_RGB565, draw_end); break; default: HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); break; } } else if (x1 == x2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); break; case SDL_BLENDMODE_ADD: VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); break; case SDL_BLENDMODE_MOD: VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); break; case SDL_BLENDMODE_MUL: VLINE(Uint16, DRAW_SETPIXEL_MUL_RGB565, draw_end); break; default: VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); break; } } else if (ABS(x1 - x2) == ABS(y1 - y2)) { switch (blendMode) { case SDL_BLENDMODE_BLEND: DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); break; case SDL_BLENDMODE_ADD: DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); break; case SDL_BLENDMODE_MOD: DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end); break; case SDL_BLENDMODE_MUL: DLINE(Uint16, DRAW_SETPIXEL_MUL_RGB565, draw_end); break; default: DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); break; } } else { switch (blendMode) { case SDL_BLENDMODE_BLEND: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, draw_end); break; case SDL_BLENDMODE_ADD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565, draw_end); break; case SDL_BLENDMODE_MOD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565, draw_end); break; case SDL_BLENDMODE_MUL: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MUL_RGB565, DRAW_SETPIXELXY_MUL_RGB565, draw_end); break; default: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, draw_end); break; } } } static void SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end) { const SDL_PixelFormat *fmt = dst->format; unsigned r, g, b, a, inva; if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(_r, _a); g = DRAW_MUL(_g, _a); b = DRAW_MUL(_b, _a); a = _a; } else { r = _r; g = _g; b = _b; a = _a; } inva = (a ^ 0xff); if (y1 == y2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: HLINE(Uint32, DRAW_SETPIXEL_MUL_RGB, draw_end); break; default: HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); break; } } else if (x1 == x2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: VLINE(Uint32, DRAW_SETPIXEL_MUL_RGB, draw_end); break; default: VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); break; } } else if (ABS(x1 - x2) == ABS(y1 - y2)) { switch (blendMode) { case SDL_BLENDMODE_BLEND: DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: DLINE(Uint32, DRAW_SETPIXEL_MUL_RGB, draw_end); break; default: DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); break; } } else { switch (blendMode) { case SDL_BLENDMODE_BLEND: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB, draw_end); break; case SDL_BLENDMODE_ADD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB, draw_end); break; case SDL_BLENDMODE_MOD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB, draw_end); break; case SDL_BLENDMODE_MUL: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MUL_RGB, DRAW_SETPIXELXY4_MUL_RGB, draw_end); break; default: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB, draw_end); break; } } } static void SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end) { const SDL_PixelFormat *fmt = dst->format; unsigned r, g, b, a, inva; if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(_r, _a); g = DRAW_MUL(_g, _a); b = DRAW_MUL(_b, _a); a = _a; } else { r = _r; g = _g; b = _b; a = _a; } inva = (a ^ 0xff); if (y1 == y2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); break; case SDL_BLENDMODE_ADD: HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); break; case SDL_BLENDMODE_MOD: HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); break; case SDL_BLENDMODE_MUL: HLINE(Uint32, DRAW_SETPIXEL_MUL_RGBA, draw_end); break; default: HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); break; } } else if (x1 == x2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); break; case SDL_BLENDMODE_ADD: VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); break; case SDL_BLENDMODE_MOD: VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); break; case SDL_BLENDMODE_MUL: VLINE(Uint32, DRAW_SETPIXEL_MUL_RGBA, draw_end); break; default: VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); break; } } else if (ABS(x1 - x2) == ABS(y1 - y2)) { switch (blendMode) { case SDL_BLENDMODE_BLEND: DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); break; case SDL_BLENDMODE_ADD: DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); break; case SDL_BLENDMODE_MOD: DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end); break; case SDL_BLENDMODE_MUL: DLINE(Uint32, DRAW_SETPIXEL_MUL_RGBA, draw_end); break; default: DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); break; } } else { switch (blendMode) { case SDL_BLENDMODE_BLEND: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, draw_end); break; case SDL_BLENDMODE_ADD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA, draw_end); break; case SDL_BLENDMODE_MOD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA, draw_end); break; case SDL_BLENDMODE_MUL: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MUL_RGBA, DRAW_SETPIXELXY4_MUL_RGBA, draw_end); break; default: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, draw_end); break; } } } static void SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end) { unsigned r, g, b, a, inva; if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(_r, _a); g = DRAW_MUL(_g, _a); b = DRAW_MUL(_b, _a); a = _a; } else { r = _r; g = _g; b = _b; a = _a; } inva = (a ^ 0xff); if (y1 == y2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); break; case SDL_BLENDMODE_ADD: HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); break; case SDL_BLENDMODE_MOD: HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); break; case SDL_BLENDMODE_MUL: HLINE(Uint32, DRAW_SETPIXEL_MUL_RGB888, draw_end); break; default: HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); break; } } else if (x1 == x2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); break; case SDL_BLENDMODE_ADD: VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); break; case SDL_BLENDMODE_MOD: VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); break; case SDL_BLENDMODE_MUL: VLINE(Uint32, DRAW_SETPIXEL_MUL_RGB888, draw_end); break; default: VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); break; } } else if (ABS(x1 - x2) == ABS(y1 - y2)) { switch (blendMode) { case SDL_BLENDMODE_BLEND: DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); break; case SDL_BLENDMODE_ADD: DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); break; case SDL_BLENDMODE_MOD: DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end); break; case SDL_BLENDMODE_MUL: DLINE(Uint32, DRAW_SETPIXEL_MUL_RGB888, draw_end); break; default: DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); break; } } else { switch (blendMode) { case SDL_BLENDMODE_BLEND: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, draw_end); break; case SDL_BLENDMODE_ADD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888, draw_end); break; case SDL_BLENDMODE_MOD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888, draw_end); break; case SDL_BLENDMODE_MUL: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MUL_RGB888, DRAW_SETPIXELXY_MUL_RGB888, draw_end); break; default: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, draw_end); break; } } } static void SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, SDL_bool draw_end) { unsigned r, g, b, a, inva; if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(_r, _a); g = DRAW_MUL(_g, _a); b = DRAW_MUL(_b, _a); a = _a; } else { r = _r; g = _g; b = _b; a = _a; } inva = (a ^ 0xff); if (y1 == y2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); break; case SDL_BLENDMODE_ADD: HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MOD: HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MUL: HLINE(Uint32, DRAW_SETPIXEL_MUL_ARGB8888, draw_end); break; default: HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); break; } } else if (x1 == x2) { switch (blendMode) { case SDL_BLENDMODE_BLEND: VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); break; case SDL_BLENDMODE_ADD: VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MOD: VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MUL: VLINE(Uint32, DRAW_SETPIXEL_MUL_ARGB8888, draw_end); break; default: VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); break; } } else if (ABS(x1 - x2) == ABS(y1 - y2)) { switch (blendMode) { case SDL_BLENDMODE_BLEND: DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); break; case SDL_BLENDMODE_ADD: DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MOD: DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MUL: DLINE(Uint32, DRAW_SETPIXEL_MUL_ARGB8888, draw_end); break; default: DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); break; } } else { switch (blendMode) { case SDL_BLENDMODE_BLEND: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, draw_end); break; case SDL_BLENDMODE_ADD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MOD: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888, draw_end); break; case SDL_BLENDMODE_MUL: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MUL_ARGB8888, DRAW_SETPIXELXY_MUL_ARGB8888, draw_end); break; default: AALINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, draw_end); break; } } } typedef void (*BlendLineFunc) (SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_bool draw_end); static BlendLineFunc SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt) { switch (fmt->BytesPerPixel) { case 2: if (fmt->Rmask == 0x7C00) { return SDL_BlendLine_RGB555; } else if (fmt->Rmask == 0xF800) { return SDL_BlendLine_RGB565; } else { return SDL_BlendLine_RGB2; } /* break; -Wunreachable-code-break */ case 4: if (fmt->Rmask == 0x00FF0000) { if (fmt->Amask) { return SDL_BlendLine_ARGB8888; } else { return SDL_BlendLine_RGB888; } } else { if (fmt->Amask) { return SDL_BlendLine_RGBA4; } else { return SDL_BlendLine_RGB4; } } } return NULL; } int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { BlendLineFunc func; if (!dst) { return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); } func = SDL_CalculateBlendLineFunc(dst->format); if (!func) { return SDL_SetError("SDL_BlendLine(): Unsupported surface format"); } /* Perform clipping */ /* FIXME: We don't actually want to clip, as it may change line slope */ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { return 0; } func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE); return 0; } int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { int i; int x1, y1; int x2, y2; SDL_bool draw_end; BlendLineFunc func; if (!dst) { return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); } func = SDL_CalculateBlendLineFunc(dst->format); if (!func) { return SDL_SetError("SDL_BlendLines(): Unsupported surface format"); } for (i = 1; i < count; ++i) { x1 = points[i-1].x; y1 = points[i-1].y; x2 = points[i].x; y2 = points[i].y; /* Perform clipping */ /* FIXME: We don't actually want to clip, as it may change line slope */ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { continue; } /* Draw the end if it was clipped */ draw_end = (x2 != points[i].x || y2 != points[i].y); func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end); } if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { SDL_BlendPoint(dst, points[count-1].x, points[count-1].y, blendMode, r, g, b, a); } return 0; } #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_blendline.c
C
apache-2.0
28,190
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_blendline_h_ #define SDL_blendline_h_ #include "../../SDL_internal.h" extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); #endif /* SDL_blendline_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_blendline.h
C
apache-2.0
1,374
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED #include "SDL_draw.h" #include "SDL_blendpoint.h" static int SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: DRAW_SETPIXELXY_BLEND_RGB555(x, y); break; case SDL_BLENDMODE_ADD: DRAW_SETPIXELXY_ADD_RGB555(x, y); break; case SDL_BLENDMODE_MOD: DRAW_SETPIXELXY_MOD_RGB555(x, y); break; case SDL_BLENDMODE_MUL: DRAW_SETPIXELXY_MUL_RGB555(x, y); break; default: DRAW_SETPIXELXY_RGB555(x, y); break; } return 0; } static int SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: DRAW_SETPIXELXY_BLEND_RGB565(x, y); break; case SDL_BLENDMODE_ADD: DRAW_SETPIXELXY_ADD_RGB565(x, y); break; case SDL_BLENDMODE_MOD: DRAW_SETPIXELXY_MOD_RGB565(x, y); break; case SDL_BLENDMODE_MUL: DRAW_SETPIXELXY_MUL_RGB565(x, y); break; default: DRAW_SETPIXELXY_RGB565(x, y); break; } return 0; } static int SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: DRAW_SETPIXELXY_BLEND_RGB888(x, y); break; case SDL_BLENDMODE_ADD: DRAW_SETPIXELXY_ADD_RGB888(x, y); break; case SDL_BLENDMODE_MOD: DRAW_SETPIXELXY_MOD_RGB888(x, y); break; case SDL_BLENDMODE_MUL: DRAW_SETPIXELXY_MUL_RGB888(x, y); break; default: DRAW_SETPIXELXY_RGB888(x, y); break; } return 0; } static int SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: DRAW_SETPIXELXY_BLEND_ARGB8888(x, y); break; case SDL_BLENDMODE_ADD: DRAW_SETPIXELXY_ADD_ARGB8888(x, y); break; case SDL_BLENDMODE_MOD: DRAW_SETPIXELXY_MOD_ARGB8888(x, y); break; case SDL_BLENDMODE_MUL: DRAW_SETPIXELXY_MUL_ARGB8888(x, y); break; default: DRAW_SETPIXELXY_ARGB8888(x, y); break; } return 0; } static int SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; unsigned inva = 0xff - a; switch (fmt->BytesPerPixel) { case 2: switch (blendMode) { case SDL_BLENDMODE_BLEND: DRAW_SETPIXELXY2_BLEND_RGB(x, y); break; case SDL_BLENDMODE_ADD: DRAW_SETPIXELXY2_ADD_RGB(x, y); break; case SDL_BLENDMODE_MOD: DRAW_SETPIXELXY2_MOD_RGB(x, y); break; case SDL_BLENDMODE_MUL: DRAW_SETPIXELXY2_MUL_RGB(x, y); break; default: DRAW_SETPIXELXY2_RGB(x, y); break; } return 0; case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: DRAW_SETPIXELXY4_BLEND_RGB(x, y); break; case SDL_BLENDMODE_ADD: DRAW_SETPIXELXY4_ADD_RGB(x, y); break; case SDL_BLENDMODE_MOD: DRAW_SETPIXELXY4_MOD_RGB(x, y); break; case SDL_BLENDMODE_MUL: DRAW_SETPIXELXY4_MUL_RGB(x, y); break; default: DRAW_SETPIXELXY4_RGB(x, y); break; } return 0; default: return SDL_Unsupported(); } } static int SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; unsigned inva = 0xff - a; switch (fmt->BytesPerPixel) { case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: DRAW_SETPIXELXY4_BLEND_RGBA(x, y); break; case SDL_BLENDMODE_ADD: DRAW_SETPIXELXY4_ADD_RGBA(x, y); break; case SDL_BLENDMODE_MOD: DRAW_SETPIXELXY4_MOD_RGBA(x, y); break; case SDL_BLENDMODE_MUL: DRAW_SETPIXELXY4_MUL_RGBA(x, y); break; default: DRAW_SETPIXELXY4_RGBA(x, y); break; } return 0; default: return SDL_Unsupported(); } } int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { if (!dst) { return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { return SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); } /* Perform clipping */ if (x < dst->clip_rect.x || y < dst->clip_rect.y || x >= (dst->clip_rect.x + dst->clip_rect.w) || y >= (dst->clip_rect.y + dst->clip_rect.h)) { return 0; } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } switch (dst->format->BitsPerPixel) { case 15: switch (dst->format->Rmask) { case 0x7C00: return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a); } break; case 16: switch (dst->format->Rmask) { case 0xF800: return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a); } break; case 32: switch (dst->format->Rmask) { case 0x00FF0000: if (!dst->format->Amask) { return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b, a); } else { return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, a); } /* break; -Wunreachable-code-break */ } break; default: break; } if (!dst->format->Amask) { return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a); } else { return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a); } } int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { int minx, miny; int maxx, maxy; int i; int x, y; int (*func)(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; int status = 0; if (!dst) { return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { return SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } /* FIXME: Does this function pointer slow things down significantly? */ switch (dst->format->BitsPerPixel) { case 15: switch (dst->format->Rmask) { case 0x7C00: func = SDL_BlendPoint_RGB555; break; } break; case 16: switch (dst->format->Rmask) { case 0xF800: func = SDL_BlendPoint_RGB565; break; } break; case 32: switch (dst->format->Rmask) { case 0x00FF0000: if (!dst->format->Amask) { func = SDL_BlendPoint_RGB888; } else { func = SDL_BlendPoint_ARGB8888; } break; } break; default: break; } if (!func) { if (!dst->format->Amask) { func = SDL_BlendPoint_RGB; } else { func = SDL_BlendPoint_RGBA; } } minx = dst->clip_rect.x; maxx = dst->clip_rect.x + dst->clip_rect.w - 1; miny = dst->clip_rect.y; maxy = dst->clip_rect.y + dst->clip_rect.h - 1; for (i = 0; i < count; ++i) { x = points[i].x; y = points[i].y; if (x < minx || x > maxx || y < miny || y > maxy) { continue; } status = func(dst, x, y, blendMode, r, g, b, a); } return status; } #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_blendpoint.c
C
apache-2.0
9,891
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_blendpoint_h_ #define SDL_blendpoint_h_ #include "../../SDL_internal.h" extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); #endif /* SDL_blendpoint_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_blendpoint.h
C
apache-2.0
1,361
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include "../../video/SDL_blit.h" /* This code assumes that r, g, b, a are the source color, * and in the blend and add case, the RGB values are premultiplied by a. */ #define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255) #define DRAW_FASTSETPIXEL(type) \ *pixel = (type) color #define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8) #define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16) #define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32) #define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \ *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \ + (x) * bpp) = (type) color #define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color) #define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color) #define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color) #define DRAW_SETPIXEL(setpixel) \ do { \ unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \ setpixel; \ } while (0) #define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \ do { \ unsigned sr, sg, sb, sa = 0xFF; \ getpixel; \ sr = DRAW_MUL(inva, sr) + r; \ sg = DRAW_MUL(inva, sg) + g; \ sb = DRAW_MUL(inva, sb) + b; \ sa = DRAW_MUL(inva, sa) + a; \ setpixel; \ } while (0) #define DRAW_SETPIXEL_ADD(getpixel, setpixel) \ do { \ unsigned sr, sg, sb, sa; (void) sa; \ getpixel; \ sr += r; if (sr > 0xff) sr = 0xff; \ sg += g; if (sg > 0xff) sg = 0xff; \ sb += b; if (sb > 0xff) sb = 0xff; \ setpixel; \ } while (0) #define DRAW_SETPIXEL_MOD(getpixel, setpixel) \ do { \ unsigned sr, sg, sb, sa; (void) sa; \ getpixel; \ sr = DRAW_MUL(sr, r); \ sg = DRAW_MUL(sg, g); \ sb = DRAW_MUL(sb, b); \ setpixel; \ } while (0) #define DRAW_SETPIXEL_MUL(getpixel, setpixel) \ do { \ unsigned sr, sg, sb, sa; sa = 0xFF; \ getpixel; \ sr = DRAW_MUL(sr, r) + DRAW_MUL(inva, sr); if (sr > 0xff) sr = 0xff; \ sg = DRAW_MUL(sg, g) + DRAW_MUL(inva, sg); if (sg > 0xff) sg = 0xff; \ sb = DRAW_MUL(sb, b) + DRAW_MUL(inva, sb); if (sb > 0xff) sb = 0xff; \ sa = DRAW_MUL(sa, a) + DRAW_MUL(inva, sa); if (sa > 0xff) sa = 0xff; \ setpixel; \ } while (0) #define DRAW_SETPIXELXY(x, y, type, bpp, op) \ do { \ type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \ + (x) * bpp); \ op; \ } while (0) /* * Define draw operators for RGB555 */ #define DRAW_SETPIXEL_RGB555 \ DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_BLEND_RGB555 \ DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ RGB555_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_ADD_RGB555 \ DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ RGB555_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_MOD_RGB555 \ DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ RGB555_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_MUL_RGB555 \ DRAW_SETPIXEL_MUL(RGB_FROM_RGB555(*pixel, sr, sg, sb), \ RGB555_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXELXY_RGB555(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555) #define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555) #define DRAW_SETPIXELXY_ADD_RGB555(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555) #define DRAW_SETPIXELXY_MOD_RGB555(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555) #define DRAW_SETPIXELXY_MUL_RGB555(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB555) /* * Define draw operators for RGB565 */ #define DRAW_SETPIXEL_RGB565 \ DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_BLEND_RGB565 \ DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ RGB565_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_ADD_RGB565 \ DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ RGB565_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_MOD_RGB565 \ DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ RGB565_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_MUL_RGB565 \ DRAW_SETPIXEL_MUL(RGB_FROM_RGB565(*pixel, sr, sg, sb), \ RGB565_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXELXY_RGB565(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565) #define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565) #define DRAW_SETPIXELXY_ADD_RGB565(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565) #define DRAW_SETPIXELXY_MOD_RGB565(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565) #define DRAW_SETPIXELXY_MUL_RGB565(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB565) /* * Define draw operators for RGB888 */ #define DRAW_SETPIXEL_RGB888 \ DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_BLEND_RGB888 \ DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ RGB888_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_ADD_RGB888 \ DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ RGB888_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_MOD_RGB888 \ DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ RGB888_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXEL_MUL_RGB888 \ DRAW_SETPIXEL_MUL(RGB_FROM_RGB888(*pixel, sr, sg, sb), \ RGB888_FROM_RGB(*pixel, sr, sg, sb)) #define DRAW_SETPIXELXY_RGB888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888) #define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888) #define DRAW_SETPIXELXY_ADD_RGB888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888) #define DRAW_SETPIXELXY_MOD_RGB888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888) #define DRAW_SETPIXELXY_MUL_RGB888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB888) /* * Define draw operators for ARGB8888 */ #define DRAW_SETPIXEL_ARGB8888 \ DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) #define DRAW_SETPIXEL_BLEND_ARGB8888 \ DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) #define DRAW_SETPIXEL_ADD_ARGB8888 \ DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) #define DRAW_SETPIXEL_MOD_ARGB8888 \ DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) #define DRAW_SETPIXEL_MUL_ARGB8888 \ DRAW_SETPIXEL_MUL(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \ ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa)) #define DRAW_SETPIXELXY_ARGB8888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888) #define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888) #define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888) #define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888) #define DRAW_SETPIXELXY_MUL_ARGB8888(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_ARGB8888) /* * Define draw operators for general RGB */ #define DRAW_SETPIXEL_RGB \ DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) #define DRAW_SETPIXEL_BLEND_RGB \ DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) #define DRAW_SETPIXEL_ADD_RGB \ DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) #define DRAW_SETPIXEL_MOD_RGB \ DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) #define DRAW_SETPIXEL_MUL_RGB \ DRAW_SETPIXEL_MUL(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \ PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) #define DRAW_SETPIXELXY2_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB) #define DRAW_SETPIXELXY4_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB) #define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB) #define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB) #define DRAW_SETPIXELXY2_ADD_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB) #define DRAW_SETPIXELXY4_ADD_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB) #define DRAW_SETPIXELXY2_MOD_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB) #define DRAW_SETPIXELXY4_MOD_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB) #define DRAW_SETPIXELXY2_MUL_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB) #define DRAW_SETPIXELXY4_MUL_RGB(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB) /* * Define draw operators for general RGBA */ #define DRAW_SETPIXEL_RGBA \ DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) #define DRAW_SETPIXEL_BLEND_RGBA \ DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) #define DRAW_SETPIXEL_ADD_RGBA \ DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) #define DRAW_SETPIXEL_MOD_RGBA \ DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) #define DRAW_SETPIXEL_MUL_RGBA \ DRAW_SETPIXEL_MUL(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \ PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa)) #define DRAW_SETPIXELXY4_RGBA(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA) #define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA) #define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA) #define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA) #define DRAW_SETPIXELXY4_MUL_RGBA(x, y) \ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGBA) /* * Define line drawing macro */ #define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) /* Horizontal line */ #define HLINE(type, op, draw_end) \ { \ int length; \ int pitch = (dst->pitch / dst->format->BytesPerPixel); \ type *pixel; \ if (x1 <= x2) { \ pixel = (type *)dst->pixels + y1 * pitch + x1; \ length = draw_end ? (x2-x1+1) : (x2-x1); \ } else { \ pixel = (type *)dst->pixels + y1 * pitch + x2; \ if (!draw_end) { \ ++pixel; \ } \ length = draw_end ? (x1-x2+1) : (x1-x2); \ } \ while (length--) { \ op; \ ++pixel; \ } \ } /* Vertical line */ #define VLINE(type, op, draw_end) \ { \ int length; \ int pitch = (dst->pitch / dst->format->BytesPerPixel); \ type *pixel; \ if (y1 <= y2) { \ pixel = (type *)dst->pixels + y1 * pitch + x1; \ length = draw_end ? (y2-y1+1) : (y2-y1); \ } else { \ pixel = (type *)dst->pixels + y2 * pitch + x1; \ if (!draw_end) { \ pixel += pitch; \ } \ length = draw_end ? (y1-y2+1) : (y1-y2); \ } \ while (length--) { \ op; \ pixel += pitch; \ } \ } /* Diagonal line */ #define DLINE(type, op, draw_end) \ { \ int length; \ int pitch = (dst->pitch / dst->format->BytesPerPixel); \ type *pixel; \ if (y1 <= y2) { \ pixel = (type *)dst->pixels + y1 * pitch + x1; \ if (x1 <= x2) { \ ++pitch; \ } else { \ --pitch; \ } \ length = (y2-y1); \ } else { \ pixel = (type *)dst->pixels + y2 * pitch + x2; \ if (x2 <= x1) { \ ++pitch; \ } else { \ --pitch; \ } \ if (!draw_end) { \ pixel += pitch; \ } \ length = (y1-y2); \ } \ if (draw_end) { \ ++length; \ } \ while (length--) { \ op; \ pixel += pitch; \ } \ } /* Bresenham's line algorithm */ #define BLINE(x1, y1, x2, y2, op, draw_end) \ { \ int i, deltax, deltay, numpixels; \ int d, dinc1, dinc2; \ int x, xinc1, xinc2; \ int y, yinc1, yinc2; \ \ deltax = ABS(x2 - x1); \ deltay = ABS(y2 - y1); \ \ if (deltax >= deltay) { \ numpixels = deltax + 1; \ d = (2 * deltay) - deltax; \ dinc1 = deltay * 2; \ dinc2 = (deltay - deltax) * 2; \ xinc1 = 1; \ xinc2 = 1; \ yinc1 = 0; \ yinc2 = 1; \ } else { \ numpixels = deltay + 1; \ d = (2 * deltax) - deltay; \ dinc1 = deltax * 2; \ dinc2 = (deltax - deltay) * 2; \ xinc1 = 0; \ xinc2 = 1; \ yinc1 = 1; \ yinc2 = 1; \ } \ \ if (x1 > x2) { \ xinc1 = -xinc1; \ xinc2 = -xinc2; \ } \ if (y1 > y2) { \ yinc1 = -yinc1; \ yinc2 = -yinc2; \ } \ \ x = x1; \ y = y1; \ \ if (!draw_end) { \ --numpixels; \ } \ for (i = 0; i < numpixels; ++i) { \ op(x, y); \ if (d < 0) { \ d += dinc1; \ x += xinc1; \ y += yinc1; \ } else { \ d += dinc2; \ x += xinc2; \ y += yinc2; \ } \ } \ } /* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */ #define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ { \ Uint16 ErrorAdj, ErrorAcc; \ Uint16 ErrorAccTemp, Weighting; \ int DeltaX, DeltaY, Temp, XDir; \ unsigned r, g, b, a, inva; \ \ /* Draw the initial pixel, which is always exactly intersected by \ the line and so needs no weighting */ \ opaque_op(x1, y1); \ \ /* Draw the final pixel, which is always exactly intersected by the line \ and so needs no weighting */ \ if (draw_end) { \ opaque_op(x2, y2); \ } \ \ /* Make sure the line runs top to bottom */ \ if (y1 > y2) { \ Temp = y1; y1 = y2; y2 = Temp; \ Temp = x1; x1 = x2; x2 = Temp; \ } \ DeltaY = y2 - y1; \ \ if ((DeltaX = x2 - x1) >= 0) { \ XDir = 1; \ } else { \ XDir = -1; \ DeltaX = -DeltaX; /* make DeltaX positive */ \ } \ \ /* line is not horizontal, diagonal, or vertical */ \ ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \ \ /* Is this an X-major or Y-major line? */ \ if (DeltaY > DeltaX) { \ /* Y-major line; calculate 16-bit fixed-point fractional part of a \ pixel that X advances each time Y advances 1 pixel, truncating the \ result so that we won't overrun the endpoint along the X axis */ \ ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \ /* Draw all pixels other than the first and last */ \ while (--DeltaY) { \ ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \ ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \ if (ErrorAcc <= ErrorAccTemp) { \ /* The error accumulator turned over, so advance the X coord */ \ x1 += XDir; \ } \ y1++; /* Y-major, so always advance Y */ \ /* The IntensityBits most significant bits of ErrorAcc give us the \ intensity weighting for this pixel, and the complement of the \ weighting for the paired pixel */ \ Weighting = ErrorAcc >> 8; \ { \ a = DRAW_MUL(_a, (Weighting ^ 255)); \ r = DRAW_MUL(_r, a); \ g = DRAW_MUL(_g, a); \ b = DRAW_MUL(_b, a); \ inva = (a ^ 0xFF); \ blend_op(x1, y1); \ } \ { \ a = DRAW_MUL(_a, Weighting); \ r = DRAW_MUL(_r, a); \ g = DRAW_MUL(_g, a); \ b = DRAW_MUL(_b, a); \ inva = (a ^ 0xFF); \ blend_op(x1 + XDir, y1); \ } \ } \ } else { \ /* X-major line; calculate 16-bit fixed-point fractional part of a \ pixel that Y advances each time X advances 1 pixel, truncating the \ result to avoid overrunning the endpoint along the X axis */ \ ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \ /* Draw all pixels other than the first and last */ \ while (--DeltaX) { \ ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \ ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \ if (ErrorAcc <= ErrorAccTemp) { \ /* The error accumulator turned over, so advance the Y coord */ \ y1++; \ } \ x1 += XDir; /* X-major, so always advance X */ \ /* The IntensityBits most significant bits of ErrorAcc give us the \ intensity weighting for this pixel, and the complement of the \ weighting for the paired pixel */ \ Weighting = ErrorAcc >> 8; \ { \ a = DRAW_MUL(_a, (Weighting ^ 255)); \ r = DRAW_MUL(_r, a); \ g = DRAW_MUL(_g, a); \ b = DRAW_MUL(_b, a); \ inva = (a ^ 0xFF); \ blend_op(x1, y1); \ } \ { \ a = DRAW_MUL(_a, Weighting); \ r = DRAW_MUL(_r, a); \ g = DRAW_MUL(_g, a); \ b = DRAW_MUL(_b, a); \ inva = (a ^ 0xFF); \ blend_op(x1, y1 + 1); \ } \ } \ } \ } #ifdef AA_LINES #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) #else #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \ BLINE(x1, y1, x2, y2, opaque_op, draw_end) #endif /* * Define fill rect macro */ #define FILLRECT(type, op) \ do { \ int width = rect->w; \ int height = rect->h; \ int pitch = (dst->pitch / dst->format->BytesPerPixel); \ int skip = pitch - width; \ type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \ while (height--) { \ { int n = (width+3)/4; \ switch (width & 3) { \ case 0: do { op; pixel++; /* fallthrough */ \ case 3: op; pixel++; /* fallthrough */ \ case 2: op; pixel++; /* fallthrough */ \ case 1: op; pixel++; /* fallthrough */ \ } while ( --n > 0 ); \ } \ } \ pixel += skip; \ } \ } while (0) /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_draw.h
C
apache-2.0
20,528
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED #include "SDL_draw.h" #include "SDL_drawline.h" #include "SDL_drawpoint.h" static void SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end) { if (y1 == y2) { int length; int pitch = (dst->pitch / dst->format->BytesPerPixel); Uint8 *pixel; if (x1 <= x2) { pixel = (Uint8 *)dst->pixels + y1 * pitch + x1; length = draw_end ? (x2-x1+1) : (x2-x1); } else { pixel = (Uint8 *)dst->pixels + y1 * pitch + x2; if (!draw_end) { ++pixel; } length = draw_end ? (x1-x2+1) : (x1-x2); } SDL_memset(pixel, color, length); } else if (x1 == x2) { VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); } else if (ABS(x1 - x2) == ABS(y1 - y2)) { DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end); } else { BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end); } } static void SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end) { if (y1 == y2) { HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); } else if (x1 == x2) { VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); } else if (ABS(x1 - x2) == ABS(y1 - y2)) { DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end); } else { Uint8 _r, _g, _b, _a; const SDL_PixelFormat * fmt = dst->format; SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); if (fmt->Rmask == 0x7C00) { AALINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555, draw_end); } else if (fmt->Rmask == 0xF800) { AALINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565, draw_end); } else { AALINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB, draw_end); } } } static void SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end) { if (y1 == y2) { HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); } else if (x1 == x2) { VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); } else if (ABS(x1 - x2) == ABS(y1 - y2)) { DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end); } else { Uint8 _r, _g, _b, _a; const SDL_PixelFormat * fmt = dst->format; SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a); if (fmt->Rmask == 0x00FF0000) { if (!fmt->Amask) { AALINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888, draw_end); } else { AALINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888, draw_end); } } else { AALINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB, draw_end); } } } typedef void (*DrawLineFunc) (SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, SDL_bool draw_end); static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt) { switch (fmt->BytesPerPixel) { case 1: if (fmt->BitsPerPixel < 8) { break; } return SDL_DrawLine1; case 2: return SDL_DrawLine2; case 4: return SDL_DrawLine4; } return NULL; } int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) { DrawLineFunc func; if (!dst) { return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface"); } func = SDL_CalculateDrawLineFunc(dst->format); if (!func) { return SDL_SetError("SDL_DrawLine(): Unsupported surface format"); } /* Perform clipping */ /* FIXME: We don't actually want to clip, as it may change line slope */ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { return 0; } func(dst, x1, y1, x2, y2, color, SDL_TRUE); return 0; } int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color) { int i; int x1, y1; int x2, y2; SDL_bool draw_end; DrawLineFunc func; if (!dst) { return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface"); } func = SDL_CalculateDrawLineFunc(dst->format); if (!func) { return SDL_SetError("SDL_DrawLines(): Unsupported surface format"); } for (i = 1; i < count; ++i) { x1 = points[i-1].x; y1 = points[i-1].y; x2 = points[i].x; y2 = points[i].y; /* Perform clipping */ /* FIXME: We don't actually want to clip, as it may change line slope */ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { continue; } /* Draw the end if it was clipped */ draw_end = (x2 != points[i].x || y2 != points[i].y); func(dst, x1, y1, x2, y2, color, draw_end); } if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color); } return 0; } #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_drawline.c
C
apache-2.0
6,529
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_drawline_h_ #define SDL_drawline_h_ #include "../../SDL_internal.h" extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); #endif /* SDL_drawline_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_drawline.h
C
apache-2.0
1,275
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED #include "SDL_draw.h" #include "SDL_drawpoint.h" int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) { if (!dst) { return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { return SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); } /* Perform clipping */ if (x < dst->clip_rect.x || y < dst->clip_rect.y || x >= (dst->clip_rect.x + dst->clip_rect.w) || y >= (dst->clip_rect.y + dst->clip_rect.h)) { return 0; } switch (dst->format->BytesPerPixel) { case 1: DRAW_FASTSETPIXELXY1(x, y); break; case 2: DRAW_FASTSETPIXELXY2(x, y); break; case 3: return SDL_Unsupported(); case 4: DRAW_FASTSETPIXELXY4(x, y); break; } return 0; } int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color) { int minx, miny; int maxx, maxy; int i; int x, y; if (!dst) { return SDL_SetError("Passed NULL destination surface"); } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { return SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); } minx = dst->clip_rect.x; maxx = dst->clip_rect.x + dst->clip_rect.w - 1; miny = dst->clip_rect.y; maxy = dst->clip_rect.y + dst->clip_rect.h - 1; for (i = 0; i < count; ++i) { x = points[i].x; y = points[i].y; if (x < minx || x > maxx || y < miny || y > maxy) { continue; } switch (dst->format->BytesPerPixel) { case 1: DRAW_FASTSETPIXELXY1(x, y); break; case 2: DRAW_FASTSETPIXELXY2(x, y); break; case 3: return SDL_Unsupported(); case 4: DRAW_FASTSETPIXELXY4(x, y); break; } } return 0; } #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_drawpoint.c
C
apache-2.0
3,156
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_drawpoint_h_ #define SDL_drawpoint_h_ #include "../../SDL_internal.h" extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color); extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); #endif /* SDL_drawpoint_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_drawpoint.h
C
apache-2.0
1,262
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED #include "../SDL_sysrender.h" #include "SDL_render_sw_c.h" #include "SDL_hints.h" #include "SDL_assert.h" #include "SDL_draw.h" #include "SDL_blendfillrect.h" #include "SDL_blendline.h" #include "SDL_blendpoint.h" #include "SDL_drawline.h" #include "SDL_drawpoint.h" #include "SDL_rotate.h" /* SDL surface based renderer implementation */ typedef struct { const SDL_Rect *viewport; const SDL_Rect *cliprect; SDL_bool surface_cliprect_dirty; } SW_DrawStateCache; typedef struct { SDL_Surface *surface; SDL_Surface *window; } SW_RenderData; static SDL_Surface * SW_ActivateRenderer(SDL_Renderer * renderer) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; if (!data->surface) { data->surface = data->window; } if (!data->surface) { SDL_Surface *surface = SDL_GetWindowSurface(renderer->window); if (surface) { data->surface = data->window = surface; } } return data->surface; } static void SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { data->surface = NULL; data->window = NULL; } } static int SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; if (data->surface) { if (w) { *w = data->surface->w; } if (h) { *h = data->surface->h; } return 0; } if (renderer->window) { SDL_GetWindowSize(renderer->window, w, h); return 0; } SDL_SetError("Software renderer doesn't have an output surface"); return -1; } static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { int bpp; Uint32 Rmask, Gmask, Bmask, Amask; if (!SDL_PixelFormatEnumToMasks (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { return SDL_SetError("Unknown texture format"); } texture->driverdata = SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask, Bmask, Amask); SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g, texture->b); SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a); SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode); /* Only RLE encode textures without an alpha channel since the RLE coder * discards the color values of pixels with an alpha value of zero. */ if (texture->access == SDL_TEXTUREACCESS_STATIC && !Amask) { SDL_SetSurfaceRLE(texture->driverdata, 1); } if (!texture->driverdata) { return -1; } return 0; } static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; Uint8 *src, *dst; int row; size_t length; if(SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); src = (Uint8 *) pixels; dst = (Uint8 *) surface->pixels + rect->y * surface->pitch + rect->x * surface->format->BytesPerPixel; length = rect->w * surface->format->BytesPerPixel; for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += surface->pitch; } if(SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); return 0; } static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, void **pixels, int *pitch) { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; *pixels = (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch + rect->x * surface->format->BytesPerPixel); *pitch = surface->pitch; return 0; } static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) { } static void SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode) { } static int SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; if (texture) { data->surface = (SDL_Surface *) texture->driverdata; } else { data->surface = data->window; } return 0; } static int SW_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd) { return 0; /* nothing to do in this backend. */ } static int SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count) { SDL_Point *verts = (SDL_Point *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Point), 0, &cmd->data.draw.first); int i; if (!verts) { return -1; } cmd->data.draw.count = count; if (renderer->viewport.x || renderer->viewport.y) { const int x = renderer->viewport.x; const int y = renderer->viewport.y; for (i = 0; i < count; i++, verts++, points++) { verts->x = (int)(x + points->x); verts->y = (int)(y + points->y); } } else { for (i = 0; i < count; i++, verts++, points++) { verts->x = (int)points->x; verts->y = (int)points->y; } } return 0; } static int SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count) { SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Rect), 0, &cmd->data.draw.first); int i; if (!verts) { return -1; } cmd->data.draw.count = count; if (renderer->viewport.x || renderer->viewport.y) { const int x = renderer->viewport.x; const int y = renderer->viewport.y; for (i = 0; i < count; i++, verts++, rects++) { verts->x = (int)(x + rects->x); verts->y = (int)(y + rects->y); verts->w = SDL_max((int)rects->w, 1); verts->h = SDL_max((int)rects->h, 1); } } else { for (i = 0; i < count; i++, verts++, rects++) { verts->x = (int)rects->x; verts->y = (int)rects->y; verts->w = SDL_max((int)rects->w, 1); verts->h = SDL_max((int)rects->h, 1); } } return 0; } static int SW_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (SDL_Rect), 0, &cmd->data.draw.first); if (!verts) { return -1; } cmd->data.draw.count = 1; SDL_memcpy(verts, srcrect, sizeof (SDL_Rect)); verts++; if (renderer->viewport.x || renderer->viewport.y) { verts->x = (int)(renderer->viewport.x + dstrect->x); verts->y = (int)(renderer->viewport.y + dstrect->y); } else { verts->x = (int)dstrect->x; verts->y = (int)dstrect->y; } verts->w = (int)dstrect->w; verts->h = (int)dstrect->h; return 0; } typedef struct CopyExData { SDL_Rect srcrect; SDL_Rect dstrect; double angle; SDL_FPoint center; SDL_RendererFlip flip; } CopyExData; static int SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip) { CopyExData *verts = (CopyExData *) SDL_AllocateRenderVertices(renderer, sizeof (CopyExData), 0, &cmd->data.draw.first); if (!verts) { return -1; } cmd->data.draw.count = 1; SDL_memcpy(&verts->srcrect, srcrect, sizeof (SDL_Rect)); if (renderer->viewport.x || renderer->viewport.y) { verts->dstrect.x = (int)(renderer->viewport.x + dstrect->x); verts->dstrect.y = (int)(renderer->viewport.y + dstrect->y); } else { verts->dstrect.x = (int)dstrect->x; verts->dstrect.y = (int)dstrect->y; } verts->dstrect.w = (int)dstrect->w; verts->dstrect.h = (int)dstrect->h; verts->angle = angle; SDL_memcpy(&verts->center, center, sizeof (SDL_FPoint)); verts->flip = flip; return 0; } static int SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * final_rect, const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) { SDL_Surface *src = (SDL_Surface *) texture->driverdata; SDL_Rect tmp_rect; SDL_Surface *src_clone, *src_rotated, *src_scaled; SDL_Surface *mask = NULL, *mask_rotated = NULL; int retval = 0, dstwidth, dstheight, abscenterx, abscentery; double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y; SDL_BlendMode blendmode; Uint8 alphaMod, rMod, gMod, bMod; int applyModulation = SDL_FALSE; int blitRequired = SDL_FALSE; int isOpaque = SDL_FALSE; if (!surface) { return -1; } tmp_rect.x = 0; tmp_rect.y = 0; tmp_rect.w = final_rect->w; tmp_rect.h = final_rect->h; /* It is possible to encounter an RLE encoded surface here and locking it is * necessary because this code is going to access the pixel buffer directly. */ if (SDL_MUSTLOCK(src)) { SDL_LockSurface(src); } /* Clone the source surface but use its pixel buffer directly. * The original source surface must be treated as read-only. */ src_clone = SDL_CreateRGBSurfaceFrom(src->pixels, src->w, src->h, src->format->BitsPerPixel, src->pitch, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask); if (src_clone == NULL) { if (SDL_MUSTLOCK(src)) { SDL_UnlockSurface(src); } return -1; } SDL_GetSurfaceBlendMode(src, &blendmode); SDL_GetSurfaceAlphaMod(src, &alphaMod); SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod); /* SDLgfx_rotateSurface only accepts 32-bit surfaces with a 8888 layout. Everything else has to be converted. */ if (src->format->BitsPerPixel != 32 || SDL_PIXELLAYOUT(src->format->format) != SDL_PACKEDLAYOUT_8888 || !src->format->Amask) { blitRequired = SDL_TRUE; } /* If scaling and cropping is necessary, it has to be taken care of before the rotation. */ if (!(srcrect->w == final_rect->w && srcrect->h == final_rect->h && srcrect->x == 0 && srcrect->y == 0)) { blitRequired = SDL_TRUE; } /* srcrect is not selecting the whole src surface, so cropping is needed */ if (!(srcrect->w == src->w && srcrect->h == src->h && srcrect->x == 0 && srcrect->y == 0)) { blitRequired = SDL_TRUE; } /* The color and alpha modulation has to be applied before the rotation when using the NONE, MOD or MUL blend modes. */ if ((blendmode == SDL_BLENDMODE_NONE || blendmode == SDL_BLENDMODE_MOD || blendmode == SDL_BLENDMODE_MUL) && (alphaMod & rMod & gMod & bMod) != 255) { applyModulation = SDL_TRUE; SDL_SetSurfaceAlphaMod(src_clone, alphaMod); SDL_SetSurfaceColorMod(src_clone, rMod, gMod, bMod); } /* Opaque surfaces are much easier to handle with the NONE blend mode. */ if (blendmode == SDL_BLENDMODE_NONE && !src->format->Amask && alphaMod == 255) { isOpaque = SDL_TRUE; } /* The NONE blend mode requires a mask for non-opaque surfaces. This mask will be used * to clear the pixels in the destination surface. The other steps are explained below. */ if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) { mask = SDL_CreateRGBSurface(0, final_rect->w, final_rect->h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); if (mask == NULL) { retval = -1; } else { SDL_SetSurfaceBlendMode(mask, SDL_BLENDMODE_MOD); } } /* Create a new surface should there be a format mismatch or if scaling, cropping, * or modulation is required. It's possible to use the source surface directly otherwise. */ if (!retval && (blitRequired || applyModulation)) { SDL_Rect scale_rect = tmp_rect; src_scaled = SDL_CreateRGBSurface(0, final_rect->w, final_rect->h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); if (src_scaled == NULL) { retval = -1; } else { SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE); retval = SDL_BlitScaled(src_clone, srcrect, src_scaled, &scale_rect); SDL_FreeSurface(src_clone); src_clone = src_scaled; src_scaled = NULL; } } /* SDLgfx_rotateSurface is going to make decisions depending on the blend mode. */ SDL_SetSurfaceBlendMode(src_clone, blendmode); if (!retval) { SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, &dstwidth, &dstheight, &cangle, &sangle); src_rotated = SDLgfx_rotateSurface(src_clone, angle, dstwidth/2, dstheight/2, (texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle); if (src_rotated == NULL) { retval = -1; } if (!retval && mask != NULL) { /* The mask needed for the NONE blend mode gets rotated with the same parameters. */ mask_rotated = SDLgfx_rotateSurface(mask, angle, dstwidth/2, dstheight/2, SDL_FALSE, 0, 0, dstwidth, dstheight, cangle, sangle); if (mask_rotated == NULL) { retval = -1; } } if (!retval) { /* Find out where the new origin is by rotating the four final_rect points around the center and then taking the extremes */ abscenterx = final_rect->x + (int)center->x; abscentery = final_rect->y + (int)center->y; /* Compensate the angle inversion to match the behaviour of the other backends */ sangle = -sangle; /* Top Left */ px = final_rect->x - abscenterx; py = final_rect->y - abscentery; p1x = px * cangle - py * sangle + abscenterx; p1y = px * sangle + py * cangle + abscentery; /* Top Right */ px = final_rect->x + final_rect->w - abscenterx; py = final_rect->y - abscentery; p2x = px * cangle - py * sangle + abscenterx; p2y = px * sangle + py * cangle + abscentery; /* Bottom Left */ px = final_rect->x - abscenterx; py = final_rect->y + final_rect->h - abscentery; p3x = px * cangle - py * sangle + abscenterx; p3y = px * sangle + py * cangle + abscentery; /* Bottom Right */ px = final_rect->x + final_rect->w - abscenterx; py = final_rect->y + final_rect->h - abscentery; p4x = px * cangle - py * sangle + abscenterx; p4y = px * sangle + py * cangle + abscentery; tmp_rect.x = (int)MIN(MIN(p1x, p2x), MIN(p3x, p4x)); tmp_rect.y = (int)MIN(MIN(p1y, p2y), MIN(p3y, p4y)); tmp_rect.w = dstwidth; tmp_rect.h = dstheight; /* The NONE blend mode needs some special care with non-opaque surfaces. * Other blend modes or opaque surfaces can be blitted directly. */ if (blendmode != SDL_BLENDMODE_NONE || isOpaque) { if (applyModulation == SDL_FALSE) { /* If the modulation wasn't already applied, make it happen now. */ SDL_SetSurfaceAlphaMod(src_rotated, alphaMod); SDL_SetSurfaceColorMod(src_rotated, rMod, gMod, bMod); } retval = SDL_BlitSurface(src_rotated, NULL, surface, &tmp_rect); } else { /* The NONE blend mode requires three steps to get the pixels onto the destination surface. * First, the area where the rotated pixels will be blitted to get set to zero. * This is accomplished by simply blitting a mask with the NONE blend mode. * The colorkey set by the rotate function will discard the correct pixels. */ SDL_Rect mask_rect = tmp_rect; SDL_SetSurfaceBlendMode(mask_rotated, SDL_BLENDMODE_NONE); retval = SDL_BlitSurface(mask_rotated, NULL, surface, &mask_rect); if (!retval) { /* The next step copies the alpha value. This is done with the BLEND blend mode and * by modulating the source colors with 0. Since the destination is all zeros, this * will effectively set the destination alpha to the source alpha. */ SDL_SetSurfaceColorMod(src_rotated, 0, 0, 0); mask_rect = tmp_rect; retval = SDL_BlitSurface(src_rotated, NULL, surface, &mask_rect); if (!retval) { /* The last step gets the color values in place. The ADD blend mode simply adds them to * the destination (where the color values are all zero). However, because the ADD blend * mode modulates the colors with the alpha channel, a surface without an alpha mask needs * to be created. This makes all source pixels opaque and the colors get copied correctly. */ SDL_Surface *src_rotated_rgb; src_rotated_rgb = SDL_CreateRGBSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h, src_rotated->format->BitsPerPixel, src_rotated->pitch, src_rotated->format->Rmask, src_rotated->format->Gmask, src_rotated->format->Bmask, 0); if (src_rotated_rgb == NULL) { retval = -1; } else { SDL_SetSurfaceBlendMode(src_rotated_rgb, SDL_BLENDMODE_ADD); retval = SDL_BlitSurface(src_rotated_rgb, NULL, surface, &tmp_rect); SDL_FreeSurface(src_rotated_rgb); } } } SDL_FreeSurface(mask_rotated); } if (src_rotated != NULL) { SDL_FreeSurface(src_rotated); } } } if (SDL_MUSTLOCK(src)) { SDL_UnlockSurface(src); } if (mask != NULL) { SDL_FreeSurface(mask); } if (src_clone != NULL) { SDL_FreeSurface(src_clone); } return retval; } static void PrepTextureForCopy(const SDL_RenderCommand *cmd) { const Uint8 r = cmd->data.draw.r; const Uint8 g = cmd->data.draw.g; const Uint8 b = cmd->data.draw.b; const Uint8 a = cmd->data.draw.a; const SDL_BlendMode blend = cmd->data.draw.blend; SDL_Texture *texture = cmd->data.draw.texture; SDL_Surface *surface = (SDL_Surface *) texture->driverdata; const SDL_bool colormod = ((r & g & b) != 0xFF); const SDL_bool alphamod = (a != 0xFF); const SDL_bool blending = ((blend == SDL_BLENDMODE_ADD) || (blend == SDL_BLENDMODE_MOD) || (blend == SDL_BLENDMODE_MUL)); if (colormod || alphamod || blending) { SDL_SetSurfaceRLE(surface, 0); } /* !!! FIXME: we can probably avoid some of these calls. */ SDL_SetSurfaceColorMod(surface, r, g, b); SDL_SetSurfaceAlphaMod(surface, a); SDL_SetSurfaceBlendMode(surface, blend); } static void SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate) { if (drawstate->surface_cliprect_dirty) { const SDL_Rect *viewport = drawstate->viewport; const SDL_Rect *cliprect = drawstate->cliprect; SDL_assert(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */ if (cliprect != NULL) { SDL_Rect clip_rect; clip_rect.x = cliprect->x + viewport->x; clip_rect.y = cliprect->y + viewport->y; clip_rect.w = cliprect->w; clip_rect.h = cliprect->h; SDL_IntersectRect(viewport, &clip_rect, &clip_rect); SDL_SetClipRect(surface, &clip_rect); } else { SDL_SetClipRect(surface, drawstate->viewport); } drawstate->surface_cliprect_dirty = SDL_FALSE; } } static int SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { SDL_Surface *surface = SW_ActivateRenderer(renderer); SW_DrawStateCache drawstate; if (!surface) { return -1; } drawstate.viewport = NULL; drawstate.cliprect = NULL; drawstate.surface_cliprect_dirty = SDL_TRUE; while (cmd) { switch (cmd->command) { case SDL_RENDERCMD_SETDRAWCOLOR: { break; /* Not used in this backend. */ } case SDL_RENDERCMD_SETVIEWPORT: { drawstate.viewport = &cmd->data.viewport.rect; drawstate.surface_cliprect_dirty = SDL_TRUE; break; } case SDL_RENDERCMD_SETCLIPRECT: { drawstate.cliprect = cmd->data.cliprect.enabled ? &cmd->data.cliprect.rect : NULL; drawstate.surface_cliprect_dirty = SDL_TRUE; break; } case SDL_RENDERCMD_CLEAR: { const Uint8 r = cmd->data.color.r; const Uint8 g = cmd->data.color.g; const Uint8 b = cmd->data.color.b; const Uint8 a = cmd->data.color.a; /* By definition the clear ignores the clip rect */ SDL_SetClipRect(surface, NULL); SDL_FillRect(surface, NULL, SDL_MapRGBA(surface->format, r, g, b, a)); drawstate.surface_cliprect_dirty = SDL_TRUE; break; } case SDL_RENDERCMD_DRAW_POINTS: { const Uint8 r = cmd->data.draw.r; const Uint8 g = cmd->data.draw.g; const Uint8 b = cmd->data.draw.b; const Uint8 a = cmd->data.draw.a; const int count = (int) cmd->data.draw.count; const SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first); const SDL_BlendMode blend = cmd->data.draw.blend; SetDrawState(surface, &drawstate); if (blend == SDL_BLENDMODE_NONE) { SDL_DrawPoints(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a)); } else { SDL_BlendPoints(surface, verts, count, blend, r, g, b, a); } break; } case SDL_RENDERCMD_DRAW_LINES: { const Uint8 r = cmd->data.draw.r; const Uint8 g = cmd->data.draw.g; const Uint8 b = cmd->data.draw.b; const Uint8 a = cmd->data.draw.a; const int count = (int) cmd->data.draw.count; const SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first); const SDL_BlendMode blend = cmd->data.draw.blend; SetDrawState(surface, &drawstate); if (blend == SDL_BLENDMODE_NONE) { SDL_DrawLines(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a)); } else { SDL_BlendLines(surface, verts, count, blend, r, g, b, a); } break; } case SDL_RENDERCMD_FILL_RECTS: { const Uint8 r = cmd->data.draw.r; const Uint8 g = cmd->data.draw.g; const Uint8 b = cmd->data.draw.b; const Uint8 a = cmd->data.draw.a; const int count = (int) cmd->data.draw.count; const SDL_Rect *verts = (SDL_Rect *) (((Uint8 *) vertices) + cmd->data.draw.first); const SDL_BlendMode blend = cmd->data.draw.blend; SetDrawState(surface, &drawstate); if (blend == SDL_BLENDMODE_NONE) { SDL_FillRects(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a)); } else { SDL_BlendFillRects(surface, verts, count, blend, r, g, b, a); } break; } case SDL_RENDERCMD_COPY: { SDL_Rect *verts = (SDL_Rect *) (((Uint8 *) vertices) + cmd->data.draw.first); const SDL_Rect *srcrect = verts; SDL_Rect *dstrect = verts + 1; SDL_Texture *texture = cmd->data.draw.texture; SDL_Surface *src = (SDL_Surface *) texture->driverdata; SetDrawState(surface, &drawstate); PrepTextureForCopy(cmd); if ( srcrect->w == dstrect->w && srcrect->h == dstrect->h ) { SDL_BlitSurface(src, srcrect, surface, dstrect); } else { /* If scaling is ever done, permanently disable RLE (which doesn't support scaling) * to avoid potentially frequent RLE encoding/decoding. */ SDL_SetSurfaceRLE(surface, 0); SDL_BlitScaled(src, srcrect, surface, dstrect); } break; } case SDL_RENDERCMD_COPY_EX: { const CopyExData *copydata = (CopyExData *) (((Uint8 *) vertices) + cmd->data.draw.first); SetDrawState(surface, &drawstate); PrepTextureForCopy(cmd); SW_RenderCopyEx(renderer, surface, cmd->data.draw.texture, &copydata->srcrect, &copydata->dstrect, copydata->angle, &copydata->center, copydata->flip); break; } case SDL_RENDERCMD_NO_OP: break; } cmd = cmd->next; } return 0; } static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 format, void * pixels, int pitch) { SDL_Surface *surface = SW_ActivateRenderer(renderer); Uint32 src_format; void *src_pixels; if (!surface) { return -1; } /* NOTE: The rect is already adjusted according to the viewport by * SDL_RenderReadPixels. */ if (rect->x < 0 || rect->x+rect->w > surface->w || rect->y < 0 || rect->y+rect->h > surface->h) { return SDL_SetError("Tried to read outside of surface bounds"); } src_format = surface->format->format; src_pixels = (void*)((Uint8 *) surface->pixels + rect->y * surface->pitch + rect->x * surface->format->BytesPerPixel); return SDL_ConvertPixels(rect->w, rect->h, src_format, src_pixels, surface->pitch, format, pixels, pitch); } static void SW_RenderPresent(SDL_Renderer * renderer) { SDL_Window *window = renderer->window; if (window) { SDL_UpdateWindowSurface(window); } } static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; SDL_FreeSurface(surface); } static void SW_DestroyRenderer(SDL_Renderer * renderer) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; SDL_free(data); SDL_free(renderer); } SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface) { SDL_Renderer *renderer; SW_RenderData *data; if (!surface) { SDL_SetError("Can't create renderer for NULL surface"); return NULL; } renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); if (!renderer) { SDL_OutOfMemory(); return NULL; } data = (SW_RenderData *) SDL_calloc(1, sizeof(*data)); if (!data) { SW_DestroyRenderer(renderer); SDL_OutOfMemory(); return NULL; } data->surface = surface; data->window = surface; renderer->WindowEvent = SW_WindowEvent; renderer->GetOutputSize = SW_GetOutputSize; renderer->CreateTexture = SW_CreateTexture; renderer->UpdateTexture = SW_UpdateTexture; renderer->LockTexture = SW_LockTexture; renderer->UnlockTexture = SW_UnlockTexture; renderer->SetTextureScaleMode = SW_SetTextureScaleMode; renderer->SetRenderTarget = SW_SetRenderTarget; renderer->QueueSetViewport = SW_QueueSetViewport; renderer->QueueSetDrawColor = SW_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */ renderer->QueueDrawPoints = SW_QueueDrawPoints; renderer->QueueDrawLines = SW_QueueDrawPoints; /* lines and points queue vertices the same way. */ renderer->QueueFillRects = SW_QueueFillRects; renderer->QueueCopy = SW_QueueCopy; renderer->QueueCopyEx = SW_QueueCopyEx; renderer->RunCommandQueue = SW_RunCommandQueue; renderer->RenderReadPixels = SW_RenderReadPixels; renderer->RenderPresent = SW_RenderPresent; renderer->DestroyTexture = SW_DestroyTexture; renderer->DestroyRenderer = SW_DestroyRenderer; renderer->info = SW_RenderDriver.info; renderer->driverdata = data; SW_ActivateRenderer(renderer); return renderer; } static SDL_Renderer * SW_CreateRenderer(SDL_Window * window, Uint32 flags) { SDL_Surface *surface; surface = SDL_GetWindowSurface(window); if (!surface) { return NULL; } return SW_CreateRendererForSurface(surface); } SDL_RenderDriver SW_RenderDriver = { SW_CreateRenderer, { "software", SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE, 8, { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB555 }, 0, 0} }; #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_render_sw.c
C
apache-2.0
31,785
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_render_sw_c_h_ #define SDL_render_sw_c_h_ extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface); #endif /* SDL_render_sw_c_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_render_sw_c.h
C
apache-2.0
1,138
/* SDL_rotate.c: rotates 32bit or 8bit surfaces Shamelessly stolen from SDL_gfx by Andreas Schiffler. Original copyright follows: Copyright (C) 2001-2011 Andreas Schiffler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Andreas Schiffler -- aschiffler at ferzkopp dot net */ #include "../../SDL_internal.h" #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED #if defined(__WIN32__) #include "../../core/windows/SDL_windows.h" #endif #include <stdlib.h> #include <string.h> #include "SDL.h" #include "SDL_rotate.h" /* ---- Internally used structures */ /* ! \brief A 32 bit RGBA pixel. */ typedef struct tColorRGBA { Uint8 r; Uint8 g; Uint8 b; Uint8 a; } tColorRGBA; /* ! \brief A 8bit Y/palette pixel. */ typedef struct tColorY { Uint8 y; } tColorY; /* ! \brief Returns maximum of two numbers a and b. */ #define MAX(a,b) (((a) > (b)) ? (a) : (b)) /* ! \brief Number of guard rows added to destination surfaces. This is a simple but effective workaround for observed issues. These rows allocate extra memory and are then hidden from the surface. Rows are added to the end of destination surfaces when they are allocated. This catches any potential overflows which seem to happen with just the right src image dimensions and scale/rotation and can lead to a situation where the program can segfault. */ #define GUARD_ROWS (2) /* ! \brief Returns colorkey info for a surface */ static Uint32 _colorkey(SDL_Surface *src) { Uint32 key = 0; if (SDL_HasColorKey(src)) { SDL_GetColorKey(src, &key); } return key; } /* ! \brief Internal target surface sizing function for rotations with trig result return. \param width The source surface width. \param height The source surface height. \param angle The angle to rotate in degrees. \param dstwidth The calculated width of the destination surface. \param dstheight The calculated height of the destination surface. \param cangle The sine of the angle \param sangle The cosine of the angle */ void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle) { /* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */ int angle90 = (int)(angle/90); if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */ angle90 %= 4; if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ if(angle90 & 1) { *dstwidth = height; *dstheight = width; *cangle = 0; *sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */ } else { *dstwidth = width; *dstheight = height; *cangle = angle90 == 0 ? 1 : -1; *sangle = 0; } } else { double x, y, cx, cy, sx, sy; double radangle; int dstwidthhalf, dstheighthalf; /* * Determine destination width and height by rotating a centered source box */ radangle = angle * (M_PI / -180.0); /* reverse the angle because our rotations are clockwise */ *sangle = SDL_sin(radangle); *cangle = SDL_cos(radangle); x = (double)(width / 2); y = (double)(height / 2); cx = *cangle * x; cy = *cangle * y; sx = *sangle * x; sy = *sangle * y; dstwidthhalf = MAX((int) SDL_ceil(MAX(MAX(MAX(SDL_fabs(cx + sy), SDL_fabs(cx - sy)), SDL_fabs(-cx + sy)), SDL_fabs(-cx - sy))), 1); dstheighthalf = MAX((int) SDL_ceil(MAX(MAX(MAX(SDL_fabs(sx + cy), SDL_fabs(sx - cy)), SDL_fabs(-sx + cy)), SDL_fabs(-sx - cy))), 1); *dstwidth = 2 * dstwidthhalf; *dstheight = 2 * dstheighthalf; } } /* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */ static void computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy, int *sincx, int *sincy, int *signx, int *signy) { int pitch = flipy ? -src->pitch : src->pitch; if (flipx) { bpp = -bpp; } switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break; case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break; case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break; case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break; } if (flipx) { *signx = -*signx; } if (flipy) { *signy = -*signy; } } /* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */ #define TRANSFORM_SURFACE_90(pixelType) \ int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \ Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \ \ computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \ if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \ if (signy < 0) sp += (src->h-1)*src->pitch; \ \ for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \ if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */ \ SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \ sp += dst->w*sizeof(pixelType); \ dp += dst->w*sizeof(pixelType); \ } else { \ for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \ *(pixelType*)dp = *(pixelType*)sp; \ } \ } \ } static void transformSurfaceRGBA90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy) { TRANSFORM_SURFACE_90(tColorRGBA); } static void transformSurfaceY90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy) { TRANSFORM_SURFACE_90(tColorY); } #undef TRANSFORM_SURFACE_90 /* ! \brief Internal 32 bit rotozoomer with optional anti-aliasing. Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control parameters by scanning the destination surface and applying optionally anti-aliasing by bilinear interpolation. Assumes src and dst surfaces are of 32 bit depth. Assumes dst surface was allocated with the correct dimensions. \param src Source surface. \param dst Destination surface. \param cx Horizontal center coordinate. \param cy Vertical center coordinate. \param isin Integer version of sine of angle. \param icos Integer version of cosine of angle. \param flipx Flag indicating horizontal mirroring should be applied. \param flipy Flag indicating vertical mirroring should be applied. \param smooth Flag indicating anti-aliasing should be used. */ static void _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth) { int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh; tColorRGBA c00, c01, c10, c11, cswap; tColorRGBA *pc, *sp; int gap; /* * Variable setup */ xd = ((src->w - dst->w) << 15); yd = ((src->h - dst->h) << 15); ax = (cx << 16) - (icos * cx); ay = (cy << 16) - (isin * cx); sw = src->w - 1; sh = src->h - 1; pc = (tColorRGBA*) dst->pixels; gap = dst->pitch - dst->w * 4; /* * Switch between interpolating and non-interpolating code */ if (smooth) { for (y = 0; y < dst->h; y++) { dy = cy - y; sdx = (ax + (isin * dy)) + xd; sdy = (ay - (icos * dy)) + yd; for (x = 0; x < dst->w; x++) { dx = (sdx >> 16); dy = (sdy >> 16); if (flipx) dx = sw - dx; if (flipy) dy = sh - dy; if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) { sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx; c00 = *sp; sp += 1; c01 = *sp; sp += (src->pitch/4); c11 = *sp; sp -= 1; c10 = *sp; if (flipx) { cswap = c00; c00=c01; c01=cswap; cswap = c10; c10=c11; c11=cswap; } if (flipy) { cswap = c00; c00=c10; c10=cswap; cswap = c01; c01=c11; c11=cswap; } /* * Interpolate colors */ ex = (sdx & 0xffff); ey = (sdy & 0xffff); t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff; t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff; pc->r = (((t2 - t1) * ey) >> 16) + t1; t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff; t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff; pc->g = (((t2 - t1) * ey) >> 16) + t1; t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff; t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff; pc->b = (((t2 - t1) * ey) >> 16) + t1; t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff; t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff; pc->a = (((t2 - t1) * ey) >> 16) + t1; } sdx += icos; sdy += isin; pc++; } pc = (tColorRGBA *) ((Uint8 *) pc + gap); } } else { for (y = 0; y < dst->h; y++) { dy = cy - y; sdx = (ax + (isin * dy)) + xd; sdy = (ay - (icos * dy)) + yd; for (x = 0; x < dst->w; x++) { dx = (sdx >> 16); dy = (sdy >> 16); if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) { if(flipx) dx = sw - dx; if(flipy) dy = sh - dy; *pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx); } sdx += icos; sdy += isin; pc++; } pc = (tColorRGBA *) ((Uint8 *) pc + gap); } } } /* ! \brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing. Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control parameters by scanning the destination surface. Assumes src and dst surfaces are of 8 bit depth. Assumes dst surface was allocated with the correct dimensions. \param src Source surface. \param dst Destination surface. \param cx Horizontal center coordinate. \param cy Vertical center coordinate. \param isin Integer version of sine of angle. \param icos Integer version of cosine of angle. \param flipx Flag indicating horizontal mirroring should be applied. \param flipy Flag indicating vertical mirroring should be applied. */ static void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy) { int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay; tColorY *pc; int gap; /* * Variable setup */ xd = ((src->w - dst->w) << 15); yd = ((src->h - dst->h) << 15); ax = (cx << 16) - (icos * cx); ay = (cy << 16) - (isin * cx); pc = (tColorY*) dst->pixels; gap = dst->pitch - dst->w; /* * Clear surface to colorkey */ SDL_memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h); /* * Iterate through destination surface */ for (y = 0; y < dst->h; y++) { dy = cy - y; sdx = (ax + (isin * dy)) + xd; sdy = (ay - (icos * dy)) + yd; for (x = 0; x < dst->w; x++) { dx = (sdx >> 16); dy = (sdy >> 16); if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) { if (flipx) dx = (src->w-1)-dx; if (flipy) dy = (src->h-1)-dy; *pc = *((tColorY *)src->pixels + src->pitch * dy + dx); } sdx += icos; sdy += isin; pc++; } pc += gap; } } /* ! \brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing. Rotates a 32-bit or 8-bit 'src' surface to newly created 'dst' surface. 'angle' is the rotation in degrees, 'centerx' and 'centery' the rotation center. If 'smooth' is set then the destination 32-bit surface is anti-aliased. 8-bit surfaces must have a colorkey. 32-bit surfaces must have a 8888 layout with red, green, blue and alpha masks (any ordering goes). The blend mode of the 'src' surface has some effects on generation of the 'dst' surface: The NONE mode will set the BLEND mode on the 'dst' surface. The MOD mode either generates a white 'dst' surface and sets the colorkey or fills the it with the colorkey before copying the pixels. When using the NONE and MOD modes, color and alpha modulation must be applied before using this function. \param src The surface to rotozoom. \param angle The angle to rotate in degrees. \param centerx The horizontal coordinate of the center of rotation \param zoomy The vertical coordinate of the center of rotation \param smooth Antialiasing flag; set to SMOOTHING_ON to enable. \param flipx Set to 1 to flip the image horizontally \param flipy Set to 1 to flip the image vertically \param dstwidth The destination surface width \param dstheight The destination surface height \param cangle The angle cosine \param sangle The angle sine \return The new rotated surface. */ SDL_Surface * SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle) { SDL_Surface *rz_dst; int is8bit, angle90; int i; SDL_BlendMode blendmode; Uint32 colorkey = 0; int colorKeyAvailable = SDL_FALSE; double sangleinv, cangleinv; /* Sanity check */ if (src == NULL) return NULL; if (SDL_HasColorKey(src)) { if (SDL_GetColorKey(src, &colorkey) == 0) { colorKeyAvailable = SDL_TRUE; } } /* This function requires a 32-bit surface or 8-bit surface with a colorkey */ is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable; if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask))) return NULL; /* Calculate target factors from sin/cos and zoom */ sangleinv = sangle*65536.0; cangleinv = cangle*65536.0; /* Alloc space to completely contain the rotated surface */ rz_dst = NULL; if (is8bit) { /* Target surface is 8 bit */ rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0); if (rz_dst != NULL) { for (i = 0; i < src->format->palette->ncolors; i++) { rz_dst->format->palette->colors[i] = src->format->palette->colors[i]; } rz_dst->format->palette->ncolors = src->format->palette->ncolors; } } else { /* Target surface is 32 bit with source RGBA ordering */ rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 32, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask); } /* Check target */ if (rz_dst == NULL) return NULL; /* Adjust for guard rows */ rz_dst->h = dstheight; SDL_GetSurfaceBlendMode(src, &blendmode); if (colorKeyAvailable == SDL_TRUE) { /* If available, the colorkey will be used to discard the pixels that are outside of the rotated area. */ SDL_SetColorKey(rz_dst, SDL_TRUE, colorkey); SDL_FillRect(rz_dst, NULL, colorkey); } else if (blendmode == SDL_BLENDMODE_NONE) { blendmode = SDL_BLENDMODE_BLEND; } else if (blendmode == SDL_BLENDMODE_MOD || blendmode == SDL_BLENDMODE_MUL) { /* Without a colorkey, the target texture has to be white for the MOD and MUL blend mode so * that the pixels outside the rotated area don't affect the destination surface. */ colorkey = SDL_MapRGBA(rz_dst->format, 255, 255, 255, 0); SDL_FillRect(rz_dst, NULL, colorkey); /* Setting a white colorkey for the destination surface makes the final blit discard * all pixels outside of the rotated area. This doesn't interfere with anything because * white pixels are already a no-op and the MOD blend mode does not interact with alpha. */ SDL_SetColorKey(rz_dst, SDL_TRUE, colorkey); } SDL_SetSurfaceBlendMode(rz_dst, blendmode); /* Lock source surface */ if (SDL_MUSTLOCK(src)) { SDL_LockSurface(src); } /* check if the rotation is a multiple of 90 degrees so we can take a fast path and also somewhat reduce * the off-by-one problem in _transformSurfaceRGBA that expresses itself when the rotation is near * multiples of 90 degrees. */ angle90 = (int)(angle/90); if (angle90 == angle/90) { angle90 %= 4; if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */ } else { angle90 = -1; } if (is8bit) { /* Call the 8-bit transformation routine to do the rotation */ if(angle90 >= 0) { transformSurfaceY90(src, rz_dst, angle90, flipx, flipy); } else { transformSurfaceY(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv, flipx, flipy); } } else { /* Call the 32-bit transformation routine to do the rotation */ if (angle90 >= 0) { transformSurfaceRGBA90(src, rz_dst, angle90, flipx, flipy); } else { _transformSurfaceRGBA(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv, flipx, flipy, smooth); } } /* Unlock source surface */ if (SDL_MUSTLOCK(src)) { SDL_UnlockSurface(src); } /* Return rotated surface */ return rz_dst; } #endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_rotate.c
C
apache-2.0
20,365
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_rotate_h_ #define SDL_rotate_h_ #ifndef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle); extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle); #endif /* SDL_rotate_h_ */
YifuLiu/AliOS-Things
components/SDL2/src/render/software/SDL_rotate.h
C
apache-2.0
1,417
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" /* This is the sensor API for Simple DirectMedia Layer */ #include "SDL.h" #include "SDL_atomic.h" #include "SDL_events.h" #include "SDL_syssensor.h" #include "SDL_assert.h" #if !SDL_EVENTS_DISABLED #include "../events/SDL_events_c.h" #endif static SDL_SensorDriver *SDL_sensor_drivers[] = { #ifdef SDL_SENSOR_ANDROID &SDL_ANDROID_SensorDriver, #endif #ifdef SDL_SENSOR_COREMOTION &SDL_COREMOTION_SensorDriver, #endif #ifdef SDL_SENSOR_WINDOWS &SDL_WINDOWS_SensorDriver, #endif #if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED) &SDL_DUMMY_SensorDriver #endif }; static SDL_Sensor *SDL_sensors = NULL; static SDL_bool SDL_updating_sensor = SDL_FALSE; static SDL_mutex *SDL_sensor_lock = NULL; /* This needs to support recursive locks */ static SDL_atomic_t SDL_next_sensor_instance_id; void SDL_LockSensors(void) { if (SDL_sensor_lock) { SDL_LockMutex(SDL_sensor_lock); } } void SDL_UnlockSensors(void) { if (SDL_sensor_lock) { SDL_UnlockMutex(SDL_sensor_lock); } } int SDL_SensorInit(void) { int i, status; /* Create the sensor list lock */ if (!SDL_sensor_lock) { SDL_sensor_lock = SDL_CreateMutex(); } #if !SDL_EVENTS_DISABLED if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) { return -1; } #endif /* !SDL_EVENTS_DISABLED */ status = -1; for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) { if (SDL_sensor_drivers[i]->Init() >= 0) { status = 0; } } return status; } /* * Count the number of sensors attached to the system */ int SDL_NumSensors(void) { int i, total_sensors = 0; SDL_LockSensors(); for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) { total_sensors += SDL_sensor_drivers[i]->GetCount(); } SDL_UnlockSensors(); return total_sensors; } /* * Return the next available sensor instance ID * This may be called by drivers from multiple threads, unprotected by any locks */ SDL_SensorID SDL_GetNextSensorInstanceID() { return SDL_AtomicIncRef(&SDL_next_sensor_instance_id); } /* * Get the driver and device index for an API device index * This should be called while the sensor lock is held, to prevent another thread from updating the list */ static SDL_bool SDL_GetDriverAndSensorIndex(int device_index, SDL_SensorDriver **driver, int *driver_index) { int i, num_sensors, total_sensors = 0; if (device_index >= 0) { for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) { num_sensors = SDL_sensor_drivers[i]->GetCount(); if (device_index < num_sensors) { *driver = SDL_sensor_drivers[i]; *driver_index = device_index; return SDL_TRUE; } device_index -= num_sensors; total_sensors += num_sensors; } } SDL_SetError("There are %d sensors available", total_sensors); return SDL_FALSE; } /* * Get the implementation dependent name of a sensor */ const char * SDL_SensorGetDeviceName(int device_index) { SDL_SensorDriver *driver; const char *name = NULL; SDL_LockSensors(); if (SDL_GetDriverAndSensorIndex(device_index, &driver, &device_index)) { name = driver->GetDeviceName(device_index); } SDL_UnlockSensors(); /* FIXME: Really we should reference count this name so it doesn't go away after unlock */ return name; } SDL_SensorType SDL_SensorGetDeviceType(int device_index) { SDL_SensorDriver *driver; SDL_SensorType type = SDL_SENSOR_INVALID; SDL_LockSensors(); if (SDL_GetDriverAndSensorIndex(device_index, &driver, &device_index)) { type = driver->GetDeviceType(device_index); } SDL_UnlockSensors(); return type; } SDL_SensorType SDL_SensorGetDeviceNonPortableType(int device_index) { SDL_SensorDriver *driver; int type = -1; SDL_LockSensors(); if (SDL_GetDriverAndSensorIndex(device_index, &driver, &device_index)) { type = driver->GetDeviceNonPortableType(device_index); } SDL_UnlockSensors(); return type; } SDL_SensorID SDL_SensorGetDeviceInstanceID(int device_index) { SDL_SensorDriver *driver; SDL_SensorID instance_id = -1; SDL_LockSensors(); if (SDL_GetDriverAndSensorIndex(device_index, &driver, &device_index)) { instance_id = driver->GetDeviceInstanceID(device_index); } SDL_UnlockSensors(); return instance_id; } /* * Open a sensor for use - the index passed as an argument refers to * the N'th sensor on the system. This index is the value which will * identify this sensor in future sensor events. * * This function returns a sensor identifier, or NULL if an error occurred. */ SDL_Sensor * SDL_SensorOpen(int device_index) { SDL_SensorDriver *driver; SDL_SensorID instance_id; SDL_Sensor *sensor; SDL_Sensor *sensorlist; const char *sensorname = NULL; SDL_LockSensors(); if (!SDL_GetDriverAndSensorIndex(device_index, &driver, &device_index)) { SDL_UnlockSensors(); return NULL; } sensorlist = SDL_sensors; /* If the sensor is already open, return it * it is important that we have a single sensor * for each instance id */ instance_id = driver->GetDeviceInstanceID(device_index); while (sensorlist) { if (instance_id == sensorlist->instance_id) { sensor = sensorlist; ++sensor->ref_count; SDL_UnlockSensors(); return sensor; } sensorlist = sensorlist->next; } /* Create and initialize the sensor */ sensor = (SDL_Sensor *) SDL_calloc(sizeof(*sensor), 1); if (sensor == NULL) { SDL_OutOfMemory(); SDL_UnlockSensors(); return NULL; } sensor->driver = driver; sensor->instance_id = instance_id; sensor->type = driver->GetDeviceType(device_index); sensor->non_portable_type = driver->GetDeviceNonPortableType(device_index); if (driver->Open(sensor, device_index) < 0) { SDL_free(sensor); SDL_UnlockSensors(); return NULL; } sensorname = driver->GetDeviceName(device_index); if (sensorname) { sensor->name = SDL_strdup(sensorname); } else { sensor->name = NULL; } /* Add sensor to list */ ++sensor->ref_count; /* Link the sensor in the list */ sensor->next = SDL_sensors; SDL_sensors = sensor; SDL_UnlockSensors(); driver->Update(sensor); return sensor; } /* * Find the SDL_Sensor that owns this instance id */ SDL_Sensor * SDL_SensorFromInstanceID(SDL_SensorID instance_id) { SDL_Sensor *sensor; SDL_LockSensors(); for (sensor = SDL_sensors; sensor; sensor = sensor->next) { if (sensor->instance_id == instance_id) { break; } } SDL_UnlockSensors(); return sensor; } /* * Checks to make sure the sensor is valid. */ static int SDL_PrivateSensorValid(SDL_Sensor * sensor) { int valid; if (sensor == NULL) { SDL_SetError("Sensor hasn't been opened yet"); valid = 0; } else { valid = 1; } return valid; } /* * Get the friendly name of this sensor */ const char * SDL_SensorGetName(SDL_Sensor * sensor) { if (!SDL_PrivateSensorValid(sensor)) { return NULL; } return sensor->name; } /* * Get the type of this sensor */ SDL_SensorType SDL_SensorGetType(SDL_Sensor * sensor) { if (!SDL_PrivateSensorValid(sensor)) { return SDL_SENSOR_INVALID; } return sensor->type; } /* * Get the platform dependent type of this sensor */ int SDL_SensorGetNonPortableType(SDL_Sensor * sensor) { if (!SDL_PrivateSensorValid(sensor)) { return -1; } return sensor->non_portable_type; } /* * Get the instance id for this opened sensor */ SDL_SensorID SDL_SensorGetInstanceID(SDL_Sensor * sensor) { if (!SDL_PrivateSensorValid(sensor)) { return -1; } return sensor->instance_id; } /* * Get the current state of this sensor */ int SDL_SensorGetData(SDL_Sensor * sensor, float *data, int num_values) { if (!SDL_PrivateSensorValid(sensor)) { return -1; } num_values = SDL_min(num_values, SDL_arraysize(sensor->data)); SDL_memcpy(data, sensor->data, num_values*sizeof(*data)); return 0; } /* * Close a sensor previously opened with SDL_SensorOpen() */ void SDL_SensorClose(SDL_Sensor * sensor) { SDL_Sensor *sensorlist; SDL_Sensor *sensorlistprev; if (!SDL_PrivateSensorValid(sensor)) { return; } SDL_LockSensors(); /* First decrement ref count */ if (--sensor->ref_count > 0) { SDL_UnlockSensors(); return; } if (SDL_updating_sensor) { SDL_UnlockSensors(); return; } sensor->driver->Close(sensor); sensor->hwdata = NULL; sensorlist = SDL_sensors; sensorlistprev = NULL; while (sensorlist) { if (sensor == sensorlist) { if (sensorlistprev) { /* unlink this entry */ sensorlistprev->next = sensorlist->next; } else { SDL_sensors = sensor->next; } break; } sensorlistprev = sensorlist; sensorlist = sensorlist->next; } SDL_free(sensor->name); /* Free the data associated with this sensor */ SDL_free(sensor); SDL_UnlockSensors(); } void SDL_SensorQuit(void) { int i; /* Make sure we're not getting called in the middle of updating sensors */ SDL_assert(!SDL_updating_sensor); SDL_LockSensors(); /* Stop the event polling */ while (SDL_sensors) { SDL_sensors->ref_count = 1; SDL_SensorClose(SDL_sensors); } /* Quit the sensor setup */ for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) { SDL_sensor_drivers[i]->Quit(); } SDL_UnlockSensors(); #if !SDL_EVENTS_DISABLED SDL_QuitSubSystem(SDL_INIT_EVENTS); #endif if (SDL_sensor_lock) { SDL_DestroyMutex(SDL_sensor_lock); SDL_sensor_lock = NULL; } } /* These are global for SDL_syssensor.c and SDL_events.c */ int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values) { int posted; /* Allow duplicate events, for things like steps and heartbeats */ /* Update internal sensor state */ num_values = SDL_min(num_values, SDL_arraysize(sensor->data)); SDL_memcpy(sensor->data, data, num_values*sizeof(*data)); /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED if (SDL_GetEventState(SDL_SENSORUPDATE) == SDL_ENABLE) { SDL_Event event; event.type = SDL_SENSORUPDATE; event.sensor.which = sensor->instance_id; num_values = SDL_min(num_values, SDL_arraysize(event.sensor.data)); SDL_memset(event.sensor.data, 0, sizeof(event.sensor.data)); SDL_memcpy(event.sensor.data, data, num_values*sizeof(*data)); posted = SDL_PushEvent(&event) == 1; } #endif /* !SDL_EVENTS_DISABLED */ return posted; } void SDL_SensorUpdate(void) { int i; SDL_Sensor *sensor, *next; if (!SDL_WasInit(SDL_INIT_SENSOR)) { return; } SDL_LockSensors(); if (SDL_updating_sensor) { /* The sensors are already being updated */ SDL_UnlockSensors(); return; } SDL_updating_sensor = SDL_TRUE; /* Make sure the list is unlocked while dispatching events to prevent application deadlocks */ SDL_UnlockSensors(); for (sensor = SDL_sensors; sensor; sensor = sensor->next) { sensor->driver->Update(sensor); } SDL_LockSensors(); SDL_updating_sensor = SDL_FALSE; /* If any sensors were closed while updating, free them here */ for (sensor = SDL_sensors; sensor; sensor = next) { next = sensor->next; if (sensor->ref_count <= 0) { SDL_SensorClose(sensor); } } /* this needs to happen AFTER walking the sensor list above, so that any dangling hardware data from removed devices can be free'd */ for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) { SDL_sensor_drivers[i]->Detect(); } SDL_UnlockSensors(); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/SDL_sensor.c
C
apache-2.0
13,278
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_sensor_c_h_ #define SDL_sensor_c_h_ #include "SDL_config.h" struct _SDL_SensorDriver; /* Useful functions and variables from SDL_sensor.c */ #include "SDL_sensor.h" /* Function to get the next available sensor instance ID */ extern SDL_SensorID SDL_GetNextSensorInstanceID(void); /* Initialization and shutdown functions */ extern int SDL_SensorInit(void); extern void SDL_SensorQuit(void); /* Internal event queueing functions */ extern int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values); #endif /* SDL_sensor_c_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/SDL_sensor_c.h
C
apache-2.0
1,540
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_syssensor_c_h_ #define SDL_syssensor_c_h_ #include "SDL_config.h" /* This is the system specific header for the SDL sensor API */ #include "SDL_sensor.h" #include "SDL_sensor_c.h" /* The SDL sensor structure */ struct _SDL_Sensor { SDL_SensorID instance_id; /* Device instance, monotonically increasing from 0 */ char *name; /* Sensor name - system dependent */ SDL_SensorType type; /* Type of the sensor */ int non_portable_type; /* Platform dependent type of the sensor */ float data[16]; /* The current state of the sensor */ struct _SDL_SensorDriver *driver; struct sensor_hwdata *hwdata; /* Driver dependent information */ int ref_count; /* Reference count for multiple opens */ struct _SDL_Sensor *next; /* pointer to next sensor we have allocated */ }; typedef struct _SDL_SensorDriver { /* Function to scan the system for sensors. * sensor 0 should be the system default sensor. * This function should return 0, or -1 on an unrecoverable fatal error. */ int (*Init)(void); /* Function to return the number of sensors available right now */ int (*GetCount)(void); /* Function to check to see if the available sensors have changed */ void (*Detect)(void); /* Function to get the device-dependent name of a sensor */ const char *(*GetDeviceName)(int device_index); /* Function to get the type of a sensor */ SDL_SensorType (*GetDeviceType)(int device_index); /* Function to get the platform dependent type of a sensor */ int (*GetDeviceNonPortableType)(int device_index); /* Function to get the current instance id of the sensor located at device_index */ SDL_SensorID (*GetDeviceInstanceID)(int device_index); /* Function to open a sensor for use. The sensor to open is specified by the device index. It returns 0, or -1 if there is an error. */ int (*Open)(SDL_Sensor * sensor, int device_index); /* Function to update the state of a sensor - called as a device poll. * This function shouldn't update the sensor structure directly, * but instead should call SDL_PrivateSensorUpdate() to deliver events * and update sensor device state. */ void (*Update)(SDL_Sensor * sensor); /* Function to close a sensor after use */ void (*Close)(SDL_Sensor * sensor); /* Function to perform any system-specific sensor related cleanup */ void (*Quit)(void); } SDL_SensorDriver; /* The available sensor drivers */ extern SDL_SensorDriver SDL_ANDROID_SensorDriver; extern SDL_SensorDriver SDL_COREMOTION_SensorDriver; extern SDL_SensorDriver SDL_WINDOWS_SensorDriver; extern SDL_SensorDriver SDL_DUMMY_SensorDriver; #endif /* SDL_syssensor_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/SDL_syssensor.h
C
apache-2.0
3,813
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include "SDL_config.h" #ifdef SDL_SENSOR_ANDROID /* This is the system specific header for the SDL sensor API */ #include <android/sensor.h> #include "SDL_error.h" #include "SDL_sensor.h" #include "SDL_androidsensor.h" #include "../SDL_syssensor.h" #include "../SDL_sensor_c.h" //#include "../../core/android/SDL_android.h" #ifndef LOOPER_ID_USER #define LOOPER_ID_USER 3 #endif typedef struct { ASensorRef asensor; SDL_SensorID instance_id; } SDL_AndroidSensor; static ASensorManager* SDL_sensor_manager; static ALooper* SDL_sensor_looper; static SDL_AndroidSensor *SDL_sensors; static int SDL_sensors_count; static int SDL_ANDROID_SensorInit(void) { int i, sensors_count; ASensorList sensors; SDL_sensor_manager = ASensorManager_getInstance(); if (!SDL_sensor_manager) { return SDL_SetError("Couldn't create sensor manager"); } SDL_sensor_looper = ALooper_forThread(); if (!SDL_sensor_looper) { SDL_sensor_looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); if (!SDL_sensor_looper) { return SDL_SetError("Couldn't create sensor event loop"); } } /* FIXME: Is the sensor list dynamic? */ sensors_count = ASensorManager_getSensorList(SDL_sensor_manager, &sensors); if (sensors_count > 0) { SDL_sensors = (SDL_AndroidSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { return SDL_OutOfMemory(); } for (i = 0; i < sensors_count; ++i) { SDL_sensors[i].asensor = sensors[i]; SDL_sensors[i].instance_id = SDL_GetNextSensorInstanceID(); } SDL_sensors_count = sensors_count; } return 0; } static int SDL_ANDROID_SensorGetCount(void) { return SDL_sensors_count; } static void SDL_ANDROID_SensorDetect(void) { } static const char * SDL_ANDROID_SensorGetDeviceName(int device_index) { return ASensor_getName(SDL_sensors[device_index].asensor); } static SDL_SensorType SDL_ANDROID_SensorGetDeviceType(int device_index) { switch (ASensor_getType(SDL_sensors[device_index].asensor)) { case 0x00000001: return SDL_SENSOR_ACCEL; case 0x00000004: return SDL_SENSOR_GYRO; default: return SDL_SENSOR_UNKNOWN; } } static int SDL_ANDROID_SensorGetDeviceNonPortableType(int device_index) { return ASensor_getType(SDL_sensors[device_index].asensor); } static SDL_SensorID SDL_ANDROID_SensorGetDeviceInstanceID(int device_index) { return SDL_sensors[device_index].instance_id; } static int SDL_ANDROID_SensorOpen(SDL_Sensor *sensor, int device_index) { struct sensor_hwdata *hwdata; int delay_us, min_delay_us; hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (hwdata == NULL) { return SDL_OutOfMemory(); } hwdata->asensor = SDL_sensors[device_index].asensor; hwdata->eventqueue = ASensorManager_createEventQueue(SDL_sensor_manager, SDL_sensor_looper, LOOPER_ID_USER, NULL, NULL); if (!hwdata->eventqueue) { SDL_free(hwdata); return SDL_SetError("Couldn't create sensor event queue"); } if (ASensorEventQueue_enableSensor(hwdata->eventqueue, hwdata->asensor) < 0) { ASensorManager_destroyEventQueue(SDL_sensor_manager, hwdata->eventqueue); SDL_free(hwdata); return SDL_SetError("Couldn't enable sensor"); } /* Use 60 Hz update rate if possible */ /* FIXME: Maybe add a hint for this? */ delay_us = 1000000 / 60; min_delay_us = ASensor_getMinDelay(hwdata->asensor); if (delay_us < min_delay_us) { delay_us = min_delay_us; } ASensorEventQueue_setEventRate(hwdata->eventqueue, hwdata->asensor, delay_us); sensor->hwdata = hwdata; return 0; } static void SDL_ANDROID_SensorUpdate(SDL_Sensor *sensor) { int events; ASensorEvent event; struct android_poll_source* source; if (ALooper_pollAll(0, NULL, &events, (void**)&source) == LOOPER_ID_USER) { SDL_zero(event); while (ASensorEventQueue_getEvents(sensor->hwdata->eventqueue, &event, 1) > 0) { SDL_PrivateSensorUpdate(sensor, event.data, SDL_arraysize(event.data)); } } } static void SDL_ANDROID_SensorClose(SDL_Sensor *sensor) { if (sensor->hwdata) { ASensorEventQueue_disableSensor(sensor->hwdata->eventqueue, sensor->hwdata->asensor); ASensorManager_destroyEventQueue(SDL_sensor_manager, sensor->hwdata->eventqueue); SDL_free(sensor->hwdata); sensor->hwdata = NULL; } } static void SDL_ANDROID_SensorQuit(void) { if (SDL_sensors) { SDL_free(SDL_sensors); SDL_sensors = NULL; SDL_sensors_count = 0; } } SDL_SensorDriver SDL_ANDROID_SensorDriver = { SDL_ANDROID_SensorInit, SDL_ANDROID_SensorGetCount, SDL_ANDROID_SensorDetect, SDL_ANDROID_SensorGetDeviceName, SDL_ANDROID_SensorGetDeviceType, SDL_ANDROID_SensorGetDeviceNonPortableType, SDL_ANDROID_SensorGetDeviceInstanceID, SDL_ANDROID_SensorOpen, SDL_ANDROID_SensorUpdate, SDL_ANDROID_SensorClose, SDL_ANDROID_SensorQuit, }; #endif /* SDL_SENSOR_ANDROID */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/android/SDL_androidsensor.c
C
apache-2.0
6,190
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" /* The private structure used to keep track of a sensor */ struct sensor_hwdata { ASensorRef asensor; ASensorEventQueue *eventqueue; }; /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/android/SDL_androidsensor.h
C
apache-2.0
1,145
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" /* The private structure used to keep track of a sensor */ struct sensor_hwdata { float data[3]; }; /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/coremotion/SDL_coremotionsensor.h
C
apache-2.0
1,105
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #ifdef SDL_SENSOR_COREMOTION /* This is the system specific header for the SDL sensor API */ #include <CoreMotion/CoreMotion.h> #include "SDL_error.h" #include "SDL_sensor.h" #include "SDL_coremotionsensor.h" #include "../SDL_syssensor.h" #include "../SDL_sensor_c.h" typedef struct { SDL_SensorType type; SDL_SensorID instance_id; } SDL_CoreMotionSensor; static CMMotionManager *SDL_motion_manager; static SDL_CoreMotionSensor *SDL_sensors; static int SDL_sensors_count; static int SDL_COREMOTION_SensorInit(void) { int i, sensors_count = 0; if (!SDL_motion_manager) { SDL_motion_manager = [[CMMotionManager alloc] init]; } if (SDL_motion_manager.accelerometerAvailable) { ++sensors_count; } if (SDL_motion_manager.gyroAvailable) { ++sensors_count; } if (sensors_count > 0) { SDL_sensors = (SDL_CoreMotionSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { return SDL_OutOfMemory(); } i = 0; if (SDL_motion_manager.accelerometerAvailable) { SDL_sensors[i].type = SDL_SENSOR_ACCEL; SDL_sensors[i].instance_id = SDL_GetNextSensorInstanceID(); ++i; } if (SDL_motion_manager.gyroAvailable) { SDL_sensors[i].type = SDL_SENSOR_GYRO; SDL_sensors[i].instance_id = SDL_GetNextSensorInstanceID(); ++i; } SDL_sensors_count = sensors_count; } return 0; } static int SDL_COREMOTION_SensorGetCount(void) { return SDL_sensors_count; } static void SDL_COREMOTION_SensorDetect(void) { } static const char * SDL_COREMOTION_SensorGetDeviceName(int device_index) { switch (SDL_sensors[device_index].type) { case SDL_SENSOR_ACCEL: return "Accelerometer"; case SDL_SENSOR_GYRO: return "Gyro"; default: return "Unknown"; } } static SDL_SensorType SDL_COREMOTION_SensorGetDeviceType(int device_index) { return SDL_sensors[device_index].type; } static int SDL_COREMOTION_SensorGetDeviceNonPortableType(int device_index) { return SDL_sensors[device_index].type; } static SDL_SensorID SDL_COREMOTION_SensorGetDeviceInstanceID(int device_index) { return SDL_sensors[device_index].instance_id; } static int SDL_COREMOTION_SensorOpen(SDL_Sensor *sensor, int device_index) { struct sensor_hwdata *hwdata; hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (hwdata == NULL) { return SDL_OutOfMemory(); } sensor->hwdata = hwdata; switch (sensor->type) { case SDL_SENSOR_ACCEL: [SDL_motion_manager startAccelerometerUpdates]; break; case SDL_SENSOR_GYRO: [SDL_motion_manager startGyroUpdates]; break; default: break; } return 0; } static void SDL_COREMOTION_SensorUpdate(SDL_Sensor *sensor) { switch (sensor->type) { case SDL_SENSOR_ACCEL: { CMAccelerometerData *accelerometerData = SDL_motion_manager.accelerometerData; if (accelerometerData) { CMAcceleration acceleration = accelerometerData.acceleration; float data[3]; data[0] = acceleration.x * SDL_STANDARD_GRAVITY; data[1] = acceleration.y * SDL_STANDARD_GRAVITY; data[2] = acceleration.z * SDL_STANDARD_GRAVITY; if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) { SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data)); SDL_memcpy(sensor->hwdata->data, data, sizeof(data)); } } } break; case SDL_SENSOR_GYRO: { CMGyroData *gyroData = SDL_motion_manager.gyroData; if (gyroData) { CMRotationRate rotationRate = gyroData.rotationRate; float data[3]; data[0] = rotationRate.x; data[1] = rotationRate.y; data[2] = rotationRate.z; if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) { SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data)); SDL_memcpy(sensor->hwdata->data, data, sizeof(data)); } } } break; default: break; } } static void SDL_COREMOTION_SensorClose(SDL_Sensor *sensor) { if (sensor->hwdata) { switch (sensor->type) { case SDL_SENSOR_ACCEL: [SDL_motion_manager stopAccelerometerUpdates]; break; case SDL_SENSOR_GYRO: [SDL_motion_manager stopGyroUpdates]; break; default: break; } SDL_free(sensor->hwdata); sensor->hwdata = NULL; } } static void SDL_COREMOTION_SensorQuit(void) { } SDL_SensorDriver SDL_COREMOTION_SensorDriver = { SDL_COREMOTION_SensorInit, SDL_COREMOTION_SensorGetCount, SDL_COREMOTION_SensorDetect, SDL_COREMOTION_SensorGetDeviceName, SDL_COREMOTION_SensorGetDeviceType, SDL_COREMOTION_SensorGetDeviceNonPortableType, SDL_COREMOTION_SensorGetDeviceInstanceID, SDL_COREMOTION_SensorOpen, SDL_COREMOTION_SensorUpdate, SDL_COREMOTION_SensorClose, SDL_COREMOTION_SensorQuit, }; #endif /* SDL_SENSOR_COREMOTION */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/coremotion/SDL_coremotionsensor.m
Objective-C
apache-2.0
6,382
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include "SDL_config.h" #if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED) #include "SDL_error.h" #include "SDL_sensor.h" #include "SDL_dummysensor.h" #include "../SDL_syssensor.h" static int SDL_DUMMY_SensorInit(void) { return 0; } static int SDL_DUMMY_SensorGetCount(void) { return 0; } static void SDL_DUMMY_SensorDetect(void) { } static const char * SDL_DUMMY_SensorGetDeviceName(int device_index) { return NULL; } static SDL_SensorType SDL_DUMMY_SensorGetDeviceType(int device_index) { return SDL_SENSOR_INVALID; } static int SDL_DUMMY_SensorGetDeviceNonPortableType(int device_index) { return -1; } static SDL_SensorID SDL_DUMMY_SensorGetDeviceInstanceID(int device_index) { return -1; } static int SDL_DUMMY_SensorOpen(SDL_Sensor *sensor, int device_index) { return SDL_Unsupported(); } static void SDL_DUMMY_SensorUpdate(SDL_Sensor *sensor) { } static void SDL_DUMMY_SensorClose(SDL_Sensor *sensor) { } static void SDL_DUMMY_SensorQuit(void) { } SDL_SensorDriver SDL_DUMMY_SensorDriver = { SDL_DUMMY_SensorInit, SDL_DUMMY_SensorGetCount, SDL_DUMMY_SensorDetect, SDL_DUMMY_SensorGetDeviceName, SDL_DUMMY_SensorGetDeviceType, SDL_DUMMY_SensorGetDeviceNonPortableType, SDL_DUMMY_SensorGetDeviceInstanceID, SDL_DUMMY_SensorOpen, SDL_DUMMY_SensorUpdate, SDL_DUMMY_SensorClose, SDL_DUMMY_SensorQuit, }; #endif /* SDL_SENSOR_DUMMY || SDL_SENSOR_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/dummy/SDL_dummysensor.c
C
apache-2.0
2,468
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/dummy/SDL_dummysensor.h
C
apache-2.0
999
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include "SDL_config.h" #if defined(SDL_SENSOR_WINDOWS) #include "SDL_error.h" #include "SDL_mutex.h" #include "SDL_sensor.h" #include "SDL_windowssensor.h" #include "../SDL_syssensor.h" #include "../../core/windows/SDL_windows.h" #define COBJMACROS #include <initguid.h> #include <sensorsapi.h> #include <sensors.h> DEFINE_GUID(SDL_CLSID_SensorManager, 0x77A1C827, 0xFCD2, 0x4689, 0x89, 0x15, 0x9D, 0x61, 0x3C, 0xC5, 0xFA, 0x3E); DEFINE_GUID(SDL_IID_SensorManager, 0xBD77DB67, 0x45A8, 0x42DC, 0x8D, 0x00, 0x6D, 0xCF, 0x15, 0xF8, 0x37, 0x7A); DEFINE_GUID(SDL_IID_SensorManagerEvents, 0x9B3B0B86, 0x266A, 0x4AAD, 0xB2, 0x1F, 0xFD, 0xE5, 0x50, 0x10, 0x01, 0xB7); DEFINE_GUID(SDL_IID_SensorEvents, 0x5D8DCC91, 0x4641, 0x47E7, 0xB7, 0xC3, 0xB7, 0x4F, 0x48, 0xA6, 0xC3, 0x91); /* These constants aren't available in Visual Studio 2015 or earlier Windows SDK */ DEFINE_PROPERTYKEY(SDL_SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, 0X3F8A69A2, 0X7C5, 0X4E48, 0XA9, 0X65, 0XCD, 0X79, 0X7A, 0XAB, 0X56, 0XD5, 10); //[VT_R8] DEFINE_PROPERTYKEY(SDL_SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, 0X3F8A69A2, 0X7C5, 0X4E48, 0XA9, 0X65, 0XCD, 0X79, 0X7A, 0XAB, 0X56, 0XD5, 11); //[VT_R8] DEFINE_PROPERTYKEY(SDL_SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, 0X3F8A69A2, 0X7C5, 0X4E48, 0XA9, 0X65, 0XCD, 0X79, 0X7A, 0XAB, 0X56, 0XD5, 12); //[VT_R8] typedef struct { SDL_SensorID id; ISensor *sensor; SENSOR_ID sensor_id; char *name; SDL_SensorType type; SDL_Sensor *sensor_opened; } SDL_Windows_Sensor; static SDL_bool SDL_windowscoinit; static ISensorManager *SDL_sensor_manager; static int SDL_num_sensors; static SDL_Windows_Sensor *SDL_sensors; static int ConnectSensor(ISensor *sensor); static int DisconnectSensor(ISensor *sensor); static HRESULT STDMETHODCALLTYPE ISensorManagerEventsVtbl_QueryInterface(ISensorManagerEvents * This, REFIID riid, void **ppvObject) { if (!ppvObject) { return E_INVALIDARG; } *ppvObject = NULL; if (WIN_IsEqualIID(riid, &IID_IUnknown) || WIN_IsEqualIID(riid, &SDL_IID_SensorManagerEvents)) { *ppvObject = This; return S_OK; } return E_NOINTERFACE; } static ULONG STDMETHODCALLTYPE ISensorManagerEventsVtbl_AddRef(ISensorManagerEvents * This) { return 1; } static ULONG STDMETHODCALLTYPE ISensorManagerEventsVtbl_Release(ISensorManagerEvents * This) { return 1; } static HRESULT STDMETHODCALLTYPE ISensorManagerEventsVtbl_OnSensorEnter(ISensorManagerEvents * This, ISensor *pSensor, SensorState state) { ConnectSensor(pSensor); return S_OK; } static ISensorManagerEventsVtbl sensor_manager_events_vtbl = { ISensorManagerEventsVtbl_QueryInterface, ISensorManagerEventsVtbl_AddRef, ISensorManagerEventsVtbl_Release, ISensorManagerEventsVtbl_OnSensorEnter }; static ISensorManagerEvents sensor_manager_events = { &sensor_manager_events_vtbl }; static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_QueryInterface(ISensorEvents * This, REFIID riid, void **ppvObject) { if (!ppvObject) { return E_INVALIDARG; } *ppvObject = NULL; if (WIN_IsEqualIID(riid, &IID_IUnknown) || WIN_IsEqualIID(riid, &SDL_IID_SensorEvents)) { *ppvObject = This; return S_OK; } return E_NOINTERFACE; } static ULONG STDMETHODCALLTYPE ISensorEventsVtbl_AddRef(ISensorEvents * This) { return 1; } static ULONG STDMETHODCALLTYPE ISensorEventsVtbl_Release(ISensorEvents * This) { return 1; } static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnStateChanged(ISensorEvents * This, ISensor *pSensor, SensorState state) { #ifdef DEBUG_SENSORS int i; SDL_LockSensors(); for (i = 0; i < SDL_num_sensors; ++i) { if (pSensor == SDL_sensors[i].sensor) { SDL_Log("Sensor %s state changed to %d\n", SDL_sensors[i].name, state); } } SDL_UnlockSensors(); #endif return S_OK; } static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents * This, ISensor *pSensor, ISensorDataReport *pNewData) { int i; SDL_LockSensors(); for (i = 0; i < SDL_num_sensors; ++i) { if (pSensor == SDL_sensors[i].sensor) { if (SDL_sensors[i].sensor_opened) { HRESULT hrX, hrY, hrZ; PROPVARIANT valueX, valueY, valueZ; #ifdef DEBUG_SENSORS SDL_Log("Sensor %s data updated\n", SDL_sensors[i].name); #endif switch (SDL_sensors[i].type) { case SDL_SENSOR_ACCEL: hrX = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_X_G, &valueX); hrY = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_Y_G, &valueY); hrZ = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_Z_G, &valueZ); if (SUCCEEDED(hrX) && SUCCEEDED(hrY) && SUCCEEDED(hrZ) && valueX.vt == VT_R8 && valueY.vt == VT_R8 && valueZ.vt == VT_R8) { float values[3]; values[0] = (float)valueX.dblVal * SDL_STANDARD_GRAVITY; values[1] = (float)valueY.dblVal * SDL_STANDARD_GRAVITY; values[2] = (float)valueZ.dblVal * SDL_STANDARD_GRAVITY; SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, values, 3); } break; case SDL_SENSOR_GYRO: hrX = ISensorDataReport_GetSensorValue(pNewData, &SDL_SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, &valueX); hrY = ISensorDataReport_GetSensorValue(pNewData, &SDL_SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, &valueY); hrZ = ISensorDataReport_GetSensorValue(pNewData, &SDL_SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, &valueZ); if (SUCCEEDED(hrX) && SUCCEEDED(hrY) && SUCCEEDED(hrZ) && valueX.vt == VT_R8 && valueY.vt == VT_R8 && valueZ.vt == VT_R8) { const float DEGREES_TO_RADIANS = (float)(M_PI / 180.0f); float values[3]; values[0] = (float)valueX.dblVal * DEGREES_TO_RADIANS; values[1] = (float)valueY.dblVal * DEGREES_TO_RADIANS; values[2] = (float)valueZ.dblVal * DEGREES_TO_RADIANS; SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, values, 3); } break; default: /* FIXME: Need to know how to interpret the data for this sensor */ break; } } break; } } SDL_UnlockSensors(); return S_OK; } static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnEvent(ISensorEvents * This, ISensor *pSensor, REFGUID eventID, IPortableDeviceValues *pEventData) { #ifdef DEBUG_SENSORS int i; SDL_LockSensors(); for (i = 0; i < SDL_num_sensors; ++i) { if (pSensor == SDL_sensors[i].sensor) { SDL_Log("Sensor %s event occurred\n", SDL_sensors[i].name); } } SDL_UnlockSensors(); #endif return S_OK; } static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnLeave(ISensorEvents * This, REFSENSOR_ID ID) { int i; SDL_LockSensors(); for (i = 0; i < SDL_num_sensors; ++i) { if (WIN_IsEqualIID(ID, &SDL_sensors[i].sensor_id)) { #ifdef DEBUG_SENSORS SDL_Log("Sensor %s disconnected\n", SDL_sensors[i].name); #endif DisconnectSensor(SDL_sensors[i].sensor); } } SDL_UnlockSensors(); return S_OK; } static ISensorEventsVtbl sensor_events_vtbl = { ISensorEventsVtbl_QueryInterface, ISensorEventsVtbl_AddRef, ISensorEventsVtbl_Release, ISensorEventsVtbl_OnStateChanged, ISensorEventsVtbl_OnDataUpdated, ISensorEventsVtbl_OnEvent, ISensorEventsVtbl_OnLeave }; static ISensorEvents sensor_events = { &sensor_events_vtbl }; static int ConnectSensor(ISensor *sensor) { SDL_Windows_Sensor *new_sensor, *new_sensors; HRESULT hr; SENSOR_ID sensor_id; SENSOR_TYPE_ID type_id; SDL_SensorType type; BSTR bstr_name = NULL; char *name; hr = ISensor_GetID(sensor, &sensor_id); if (FAILED(hr)) { return WIN_SetErrorFromHRESULT("Couldn't get sensor ID", hr); } hr = ISensor_GetType(sensor, &type_id); if (FAILED(hr)) { return WIN_SetErrorFromHRESULT("Couldn't get sensor type", hr); } if (WIN_IsEqualIID(&type_id, &SENSOR_TYPE_ACCELEROMETER_3D)) { type = SDL_SENSOR_ACCEL; } else if (WIN_IsEqualIID(&type_id, &SENSOR_TYPE_GYROMETER_3D)) { type = SDL_SENSOR_GYRO; } else { return SDL_SetError("Unknown sensor type"); } hr = ISensor_GetFriendlyName(sensor, &bstr_name); if (SUCCEEDED(hr) && bstr_name) { name = WIN_StringToUTF8(bstr_name); } else { name = SDL_strdup("Unknown Sensor"); } if (bstr_name != NULL) { SysFreeString(bstr_name); } if (!name) { return SDL_OutOfMemory(); } SDL_LockSensors(); new_sensors = (SDL_Windows_Sensor *)SDL_realloc(SDL_sensors, (SDL_num_sensors + 1) * sizeof(SDL_Windows_Sensor)); if (new_sensors == NULL) { SDL_UnlockSensors(); return SDL_OutOfMemory(); } ISensor_AddRef(sensor); ISensor_SetEventSink(sensor, &sensor_events); SDL_sensors = new_sensors; new_sensor = &SDL_sensors[SDL_num_sensors]; ++SDL_num_sensors; SDL_zerop(new_sensor); new_sensor->id = SDL_GetNextSensorInstanceID(); new_sensor->sensor = sensor; new_sensor->type = type; new_sensor->name = name; SDL_UnlockSensors(); return 0; } static int DisconnectSensor(ISensor *sensor) { SDL_Windows_Sensor *old_sensor; int i; SDL_LockSensors(); for (i = 0; i < SDL_num_sensors; ++i) { old_sensor = &SDL_sensors[i]; if (sensor == old_sensor->sensor) { ISensor_SetEventSink(sensor, NULL); ISensor_Release(sensor); SDL_free(old_sensor->name); --SDL_num_sensors; if (i < SDL_num_sensors) { SDL_memmove(&SDL_sensors[i], &SDL_sensors[i + 1], (SDL_num_sensors - i) * sizeof(SDL_sensors[i])); } break; } } SDL_UnlockSensors(); return 0; } static int SDL_WINDOWS_SensorInit(void) { HRESULT hr; ISensorCollection *sensor_collection = NULL; if (WIN_CoInitialize() == S_OK) { SDL_windowscoinit = SDL_TRUE; } hr = CoCreateInstance(&SDL_CLSID_SensorManager, NULL, CLSCTX_INPROC_SERVER, &SDL_IID_SensorManager, (LPVOID *) &SDL_sensor_manager); if (FAILED(hr)) { return WIN_SetErrorFromHRESULT("Couldn't create the sensor manager", hr); } hr = ISensorManager_SetEventSink(SDL_sensor_manager, &sensor_manager_events); if (FAILED(hr)) { ISensorManager_Release(SDL_sensor_manager); return WIN_SetErrorFromHRESULT("Couldn't set the sensor manager event sink", hr); } hr = ISensorManager_GetSensorsByCategory(SDL_sensor_manager, &SENSOR_CATEGORY_ALL, &sensor_collection); if (SUCCEEDED(hr)) { ULONG i, count; hr = ISensorCollection_GetCount(sensor_collection, &count); if (SUCCEEDED(hr)) { for (i = 0; i < count; ++i) { ISensor *sensor; hr = ISensorCollection_GetAt(sensor_collection, i, &sensor); if (SUCCEEDED(hr)) { SensorState state; hr = ISensor_GetState(sensor, &state); if (SUCCEEDED(hr)) { ISensorManagerEventsVtbl_OnSensorEnter(&sensor_manager_events, sensor, state); } ISensorManager_Release(sensor); } } } ISensorCollection_Release(sensor_collection); } return 0; } static int SDL_WINDOWS_SensorGetCount(void) { return SDL_num_sensors; } static void SDL_WINDOWS_SensorDetect(void) { } static const char * SDL_WINDOWS_SensorGetDeviceName(int device_index) { return SDL_sensors[device_index].name; } static SDL_SensorType SDL_WINDOWS_SensorGetDeviceType(int device_index) { return SDL_sensors[device_index].type; } static int SDL_WINDOWS_SensorGetDeviceNonPortableType(int device_index) { return -1; } static SDL_SensorID SDL_WINDOWS_SensorGetDeviceInstanceID(int device_index) { return SDL_sensors[device_index].id; } static int SDL_WINDOWS_SensorOpen(SDL_Sensor *sensor, int device_index) { SDL_sensors[device_index].sensor_opened = sensor; return 0; } static void SDL_WINDOWS_SensorUpdate(SDL_Sensor *sensor) { } static void SDL_WINDOWS_SensorClose(SDL_Sensor *sensor) { int i; for (i = 0; i < SDL_num_sensors; ++i) { if (sensor == SDL_sensors[i].sensor_opened) { SDL_sensors[i].sensor_opened = NULL; break; } } } static void SDL_WINDOWS_SensorQuit(void) { while (SDL_num_sensors > 0) { DisconnectSensor(SDL_sensors[0].sensor); } if (SDL_sensor_manager) { ISensorManager_SetEventSink(SDL_sensor_manager, NULL); ISensorManager_Release(SDL_sensor_manager); SDL_sensor_manager = NULL; } if (SDL_windowscoinit) { WIN_CoUninitialize(); } } SDL_SensorDriver SDL_WINDOWS_SensorDriver = { SDL_WINDOWS_SensorInit, SDL_WINDOWS_SensorGetCount, SDL_WINDOWS_SensorDetect, SDL_WINDOWS_SensorGetDeviceName, SDL_WINDOWS_SensorGetDeviceType, SDL_WINDOWS_SensorGetDeviceNonPortableType, SDL_WINDOWS_SensorGetDeviceInstanceID, SDL_WINDOWS_SensorOpen, SDL_WINDOWS_SensorUpdate, SDL_WINDOWS_SensorClose, SDL_WINDOWS_SensorQuit, }; #endif /* SDL_SENSOR_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/windows/SDL_windowssensor.c
C
apache-2.0
14,936
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/sensor/windows/SDL_windowssensor.h
C
apache-2.0
999
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) #define SDL_DISABLE_ANALYZE_MACROS 1 #endif #include "../SDL_internal.h" #if defined(__WIN32__) #include "../core/windows/SDL_windows.h" #endif #if defined(__ANDROID__) #include "../core/android/SDL_android.h" #endif #include "SDL_stdinc.h" #if defined(__WIN32__) && (!defined(HAVE_SETENV) || !defined(HAVE_GETENV)) /* Note this isn't thread-safe! */ static char *SDL_envmem = NULL; /* Ugh, memory leak */ static size_t SDL_envmemlen = 0; #endif /* Put a variable into the environment */ /* Note: Name may not contain a '=' character. (Reference: http://www.unix.com/man-page/Linux/3/setenv/) */ #if defined(HAVE_SETENV) int SDL_setenv(const char *name, const char *value, int overwrite) { /* Input validation */ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) { return (-1); } return setenv(name, value, overwrite); } #elif defined(__WIN32__) int SDL_setenv(const char *name, const char *value, int overwrite) { /* Input validation */ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) { return (-1); } if (!overwrite) { if (GetEnvironmentVariableA(name, NULL, 0) > 0) { return 0; /* asked not to overwrite existing value. */ } } if (!SetEnvironmentVariableA(name, *value ? value : NULL)) { return -1; } return 0; } /* We have a real environment table, but no real setenv? Fake it w/ putenv. */ #elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) int SDL_setenv(const char *name, const char *value, int overwrite) { size_t len; char *new_variable; /* Input validation */ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) { return (-1); } if (getenv(name) != NULL) { if (overwrite) { unsetenv(name); } else { return 0; /* leave the existing one there. */ } } /* This leaks. Sorry. Get a better OS so we don't have to do this. */ len = SDL_strlen(name) + SDL_strlen(value) + 2; new_variable = (char *) SDL_malloc(len); if (!new_variable) { return (-1); } SDL_snprintf(new_variable, len, "%s=%s", name, value); return putenv(new_variable); } #else /* roll our own */ static char **SDL_env = (char **) 0; int SDL_setenv(const char *name, const char *value, int overwrite) { int added; size_t len, i; char **new_env; char *new_variable; /* Input validation */ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) { return (-1); } /* See if it already exists */ if (!overwrite && SDL_getenv(name)) { return 0; } /* Allocate memory for the variable */ len = SDL_strlen(name) + SDL_strlen(value) + 2; new_variable = (char *) SDL_malloc(len); if (!new_variable) { return (-1); } SDL_snprintf(new_variable, len, "%s=%s", name, value); value = new_variable + SDL_strlen(name) + 1; name = new_variable; /* Actually put it into the environment */ added = 0; i = 0; if (SDL_env) { /* Check to see if it's already there... */ len = (value - name); for (; SDL_env[i]; ++i) { if (SDL_strncmp(SDL_env[i], name, len) == 0) { break; } } /* If we found it, just replace the entry */ if (SDL_env[i]) { SDL_free(SDL_env[i]); SDL_env[i] = new_variable; added = 1; } } /* Didn't find it in the environment, expand and add */ if (!added) { new_env = SDL_realloc(SDL_env, (i + 2) * sizeof(char *)); if (new_env) { SDL_env = new_env; SDL_env[i++] = new_variable; SDL_env[i++] = (char *) 0; added = 1; } else { SDL_free(new_variable); } } return (added ? 0 : -1); } #endif /* Retrieve a variable named "name" from the environment */ #if defined(HAVE_GETENV) char * SDL_getenv(const char *name) { #if defined(__ANDROID__) /* Make sure variables from the application manifest are available */ Android_JNI_GetManifestEnvironmentVariables(); #endif /* Input validation */ if (!name || !*name) { return NULL; } return getenv(name); } #elif defined(__WIN32__) char * SDL_getenv(const char *name) { size_t bufferlen; /* Input validation */ if (!name || SDL_strlen(name)==0) { return NULL; } bufferlen = GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); if (bufferlen == 0) { return NULL; } if (bufferlen > SDL_envmemlen) { char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen); if (newmem == NULL) { return NULL; } SDL_envmem = newmem; SDL_envmemlen = bufferlen; GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); } return SDL_envmem; } #else char * SDL_getenv(const char *name) { size_t len, i; char *value; /* Input validation */ if (!name || SDL_strlen(name)==0) { return NULL; } value = (char *) 0; if (SDL_env) { len = SDL_strlen(name); for (i = 0; SDL_env[i] && !value; ++i) { if ((SDL_strncmp(SDL_env[i], name, len) == 0) && (SDL_env[i][len] == '=')) { value = &SDL_env[i][len + 1]; } } } return value; } #endif #ifdef TEST_MAIN #include <stdio.h> int main(int argc, char *argv[]) { char *value; printf("Checking for non-existent variable... "); fflush(stdout); if (!SDL_getenv("EXISTS")) { printf("okay\n"); } else { printf("failed\n"); } printf("Setting FIRST=VALUE1 in the environment... "); fflush(stdout); if (SDL_setenv("FIRST", "VALUE1", 0) == 0) { printf("okay\n"); } else { printf("failed\n"); } printf("Getting FIRST from the environment... "); fflush(stdout); value = SDL_getenv("FIRST"); if (value && (SDL_strcmp(value, "VALUE1") == 0)) { printf("okay\n"); } else { printf("failed\n"); } printf("Setting SECOND=VALUE2 in the environment... "); fflush(stdout); if (SDL_setenv("SECOND", "VALUE2", 0) == 0) { printf("okay\n"); } else { printf("failed\n"); } printf("Getting SECOND from the environment... "); fflush(stdout); value = SDL_getenv("SECOND"); if (value && (SDL_strcmp(value, "VALUE2") == 0)) { printf("okay\n"); } else { printf("failed\n"); } printf("Setting FIRST=NOVALUE in the environment... "); fflush(stdout); if (SDL_setenv("FIRST", "NOVALUE", 1) == 0) { printf("okay\n"); } else { printf("failed\n"); } printf("Getting FIRST from the environment... "); fflush(stdout); value = SDL_getenv("FIRST"); if (value && (SDL_strcmp(value, "NOVALUE") == 0)) { printf("okay\n"); } else { printf("failed\n"); } printf("Checking for non-existent variable... "); fflush(stdout); if (!SDL_getenv("EXISTS")) { printf("okay\n"); } else { printf("failed\n"); } return (0); } #endif /* TEST_MAIN */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/stdlib/SDL_getenv.c
C
apache-2.0
8,419
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) #define SDL_DISABLE_ANALYZE_MACROS 1 #endif #include "../SDL_internal.h" /* This file contains portable iconv functions for SDL */ #include "SDL_stdinc.h" #include "SDL_endian.h" #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H) #include <iconv.h> /* Depending on which standard the iconv() was implemented with, iconv() may or may not use const char ** for the inbuf param. If we get this wrong, it's just a warning, so no big deal. */ #if defined(_XGP6) || defined(__APPLE__) || defined(__RISCOS__) || defined(__FREEBSD__) || \ defined(__EMSCRIPTEN__) || \ (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \ (defined(_NEWLIB_VERSION))) #define ICONV_INBUF_NONCONST #endif #include <errno.h> SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t)); SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode) { return (SDL_iconv_t) ((size_t) iconv_open(tocode, fromcode)); } int SDL_iconv_close(SDL_iconv_t cd) { return iconv_close((iconv_t) ((size_t) cd)); } size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft) { size_t retCode; #ifdef ICONV_INBUF_NONCONST retCode = iconv((iconv_t) ((size_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft); #else retCode = iconv((iconv_t) ((size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft); #endif if (retCode == (size_t) - 1) { switch (errno) { case E2BIG: return SDL_ICONV_E2BIG; case EILSEQ: return SDL_ICONV_EILSEQ; case EINVAL: return SDL_ICONV_EINVAL; default: return SDL_ICONV_ERROR; } } return retCode; } #else /* Lots of useful information on Unicode at: http://www.cl.cam.ac.uk/~mgk25/unicode.html */ #define UNICODE_BOM 0xFEFF #define UNKNOWN_ASCII '?' #define UNKNOWN_UNICODE 0xFFFD enum { ENCODING_UNKNOWN, ENCODING_ASCII, ENCODING_LATIN1, ENCODING_UTF8, ENCODING_UTF16, /* Needs byte order marker */ ENCODING_UTF16BE, ENCODING_UTF16LE, ENCODING_UTF32, /* Needs byte order marker */ ENCODING_UTF32BE, ENCODING_UTF32LE, ENCODING_UCS2BE, ENCODING_UCS2LE, ENCODING_UCS4BE, ENCODING_UCS4LE, }; #if SDL_BYTEORDER == SDL_BIG_ENDIAN #define ENCODING_UTF16NATIVE ENCODING_UTF16BE #define ENCODING_UTF32NATIVE ENCODING_UTF32BE #define ENCODING_UCS2NATIVE ENCODING_UCS2BE #define ENCODING_UCS4NATIVE ENCODING_UCS4BE #else #define ENCODING_UTF16NATIVE ENCODING_UTF16LE #define ENCODING_UTF32NATIVE ENCODING_UTF32LE #define ENCODING_UCS2NATIVE ENCODING_UCS2LE #define ENCODING_UCS4NATIVE ENCODING_UCS4LE #endif struct _SDL_iconv_t { int src_fmt; int dst_fmt; }; static struct { const char *name; int format; } encodings[] = { /* *INDENT-OFF* */ { "ASCII", ENCODING_ASCII }, { "US-ASCII", ENCODING_ASCII }, { "8859-1", ENCODING_LATIN1 }, { "ISO-8859-1", ENCODING_LATIN1 }, { "UTF8", ENCODING_UTF8 }, { "UTF-8", ENCODING_UTF8 }, { "UTF16", ENCODING_UTF16 }, { "UTF-16", ENCODING_UTF16 }, { "UTF16BE", ENCODING_UTF16BE }, { "UTF-16BE", ENCODING_UTF16BE }, { "UTF16LE", ENCODING_UTF16LE }, { "UTF-16LE", ENCODING_UTF16LE }, { "UTF32", ENCODING_UTF32 }, { "UTF-32", ENCODING_UTF32 }, { "UTF32BE", ENCODING_UTF32BE }, { "UTF-32BE", ENCODING_UTF32BE }, { "UTF32LE", ENCODING_UTF32LE }, { "UTF-32LE", ENCODING_UTF32LE }, { "UCS2", ENCODING_UCS2BE }, { "UCS-2", ENCODING_UCS2BE }, { "UCS-2LE", ENCODING_UCS2LE }, { "UCS-2BE", ENCODING_UCS2BE }, { "UCS-2-INTERNAL", ENCODING_UCS2NATIVE }, { "UCS4", ENCODING_UCS4BE }, { "UCS-4", ENCODING_UCS4BE }, { "UCS-4LE", ENCODING_UCS4LE }, { "UCS-4BE", ENCODING_UCS4BE }, { "UCS-4-INTERNAL", ENCODING_UCS4NATIVE }, /* *INDENT-ON* */ }; static const char * getlocale(char *buffer, size_t bufsize) { const char *lang; char *ptr; lang = SDL_getenv("LC_ALL"); if (!lang) { lang = SDL_getenv("LC_CTYPE"); } if (!lang) { lang = SDL_getenv("LC_MESSAGES"); } if (!lang) { lang = SDL_getenv("LANG"); } if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) { lang = "ASCII"; } /* We need to trim down strings like "en_US.UTF-8@blah" to "UTF-8" */ ptr = SDL_strchr(lang, '.'); if (ptr != NULL) { lang = ptr + 1; } SDL_strlcpy(buffer, lang, bufsize); ptr = SDL_strchr(buffer, '@'); if (ptr != NULL) { *ptr = '\0'; /* chop end of string. */ } return buffer; } SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode) { int src_fmt = ENCODING_UNKNOWN; int dst_fmt = ENCODING_UNKNOWN; int i; char fromcode_buffer[64]; char tocode_buffer[64]; if (!fromcode || !*fromcode) { fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer)); } if (!tocode || !*tocode) { tocode = getlocale(tocode_buffer, sizeof(tocode_buffer)); } for (i = 0; i < SDL_arraysize(encodings); ++i) { if (SDL_strcasecmp(fromcode, encodings[i].name) == 0) { src_fmt = encodings[i].format; if (dst_fmt != ENCODING_UNKNOWN) { break; } } if (SDL_strcasecmp(tocode, encodings[i].name) == 0) { dst_fmt = encodings[i].format; if (src_fmt != ENCODING_UNKNOWN) { break; } } } if (src_fmt != ENCODING_UNKNOWN && dst_fmt != ENCODING_UNKNOWN) { SDL_iconv_t cd = (SDL_iconv_t) SDL_malloc(sizeof(*cd)); if (cd) { cd->src_fmt = src_fmt; cd->dst_fmt = dst_fmt; return cd; } } return (SDL_iconv_t) - 1; } size_t SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft) { /* For simplicity, we'll convert everything to and from UCS-4 */ const char *src; char *dst; size_t srclen, dstlen; Uint32 ch = 0; size_t total; if (!inbuf || !*inbuf) { /* Reset the context */ return 0; } if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) { return SDL_ICONV_E2BIG; } src = *inbuf; srclen = (inbytesleft ? *inbytesleft : 0); dst = *outbuf; dstlen = *outbytesleft; switch (cd->src_fmt) { case ENCODING_UTF16: /* Scan for a byte order marker */ { Uint8 *p = (Uint8 *) src; size_t n = srclen / 2; while (n) { if (p[0] == 0xFF && p[1] == 0xFE) { cd->src_fmt = ENCODING_UTF16BE; break; } else if (p[0] == 0xFE && p[1] == 0xFF) { cd->src_fmt = ENCODING_UTF16LE; break; } p += 2; --n; } if (n == 0) { /* We can't tell, default to host order */ cd->src_fmt = ENCODING_UTF16NATIVE; } } break; case ENCODING_UTF32: /* Scan for a byte order marker */ { Uint8 *p = (Uint8 *) src; size_t n = srclen / 4; while (n) { if (p[0] == 0xFF && p[1] == 0xFE && p[2] == 0x00 && p[3] == 0x00) { cd->src_fmt = ENCODING_UTF32BE; break; } else if (p[0] == 0x00 && p[1] == 0x00 && p[2] == 0xFE && p[3] == 0xFF) { cd->src_fmt = ENCODING_UTF32LE; break; } p += 4; --n; } if (n == 0) { /* We can't tell, default to host order */ cd->src_fmt = ENCODING_UTF32NATIVE; } } break; } switch (cd->dst_fmt) { case ENCODING_UTF16: /* Default to host order, need to add byte order marker */ if (dstlen < 2) { return SDL_ICONV_E2BIG; } *(Uint16 *) dst = UNICODE_BOM; dst += 2; dstlen -= 2; cd->dst_fmt = ENCODING_UTF16NATIVE; break; case ENCODING_UTF32: /* Default to host order, need to add byte order marker */ if (dstlen < 4) { return SDL_ICONV_E2BIG; } *(Uint32 *) dst = UNICODE_BOM; dst += 4; dstlen -= 4; cd->dst_fmt = ENCODING_UTF32NATIVE; break; } total = 0; while (srclen > 0) { /* Decode a character */ switch (cd->src_fmt) { case ENCODING_ASCII: { Uint8 *p = (Uint8 *) src; ch = (Uint32) (p[0] & 0x7F); ++src; --srclen; } break; case ENCODING_LATIN1: { Uint8 *p = (Uint8 *) src; ch = (Uint32) p[0]; ++src; --srclen; } break; case ENCODING_UTF8: /* RFC 3629 */ { Uint8 *p = (Uint8 *) src; size_t left = 0; SDL_bool overlong = SDL_FALSE; if (p[0] >= 0xFC) { if ((p[0] & 0xFE) != 0xFC) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x01); left = 5; } } else if (p[0] >= 0xF8) { if ((p[0] & 0xFC) != 0xF8) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x03); left = 4; } } else if (p[0] >= 0xF0) { if ((p[0] & 0xF8) != 0xF0) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x07); left = 3; } } else if (p[0] >= 0xE0) { if ((p[0] & 0xF0) != 0xE0) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x0F); left = 2; } } else if (p[0] >= 0xC0) { if ((p[0] & 0xE0) != 0xC0) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if ((p[0] & 0xDE) == 0xC0) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x1F); left = 1; } } else { if ((p[0] & 0x80) != 0x00) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { ch = (Uint32) p[0]; } } ++src; --srclen; if (srclen < left) { return SDL_ICONV_EINVAL; } while (left--) { ++p; if ((p[0] & 0xC0) != 0x80) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; break; } ch <<= 6; ch |= (p[0] & 0x3F); ++src; --srclen; } if (overlong) { /* Potential security risk return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } if ((ch >= 0xD800 && ch <= 0xDFFF) || (ch == 0xFFFE || ch == 0xFFFF) || ch > 0x10FFFF) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } } break; case ENCODING_UTF16BE: /* RFC 2781 */ { Uint8 *p = (Uint8 *) src; Uint16 W1, W2; if (srclen < 2) { return SDL_ICONV_EINVAL; } W1 = ((Uint16) p[0] << 8) | (Uint16) p[1]; src += 2; srclen -= 2; if (W1 < 0xD800 || W1 > 0xDFFF) { ch = (Uint32) W1; break; } if (W1 > 0xDBFF) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; break; } if (srclen < 2) { return SDL_ICONV_EINVAL; } p = (Uint8 *) src; W2 = ((Uint16) p[0] << 8) | (Uint16) p[1]; src += 2; srclen -= 2; if (W2 < 0xDC00 || W2 > 0xDFFF) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; break; } ch = (((Uint32) (W1 & 0x3FF) << 10) | (Uint32) (W2 & 0x3FF)) + 0x10000; } break; case ENCODING_UTF16LE: /* RFC 2781 */ { Uint8 *p = (Uint8 *) src; Uint16 W1, W2; if (srclen < 2) { return SDL_ICONV_EINVAL; } W1 = ((Uint16) p[1] << 8) | (Uint16) p[0]; src += 2; srclen -= 2; if (W1 < 0xD800 || W1 > 0xDFFF) { ch = (Uint32) W1; break; } if (W1 > 0xDBFF) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; break; } if (srclen < 2) { return SDL_ICONV_EINVAL; } p = (Uint8 *) src; W2 = ((Uint16) p[1] << 8) | (Uint16) p[0]; src += 2; srclen -= 2; if (W2 < 0xDC00 || W2 > 0xDFFF) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; break; } ch = (((Uint32) (W1 & 0x3FF) << 10) | (Uint32) (W2 & 0x3FF)) + 0x10000; } break; case ENCODING_UCS2LE: { Uint8 *p = (Uint8 *) src; if (srclen < 2) { return SDL_ICONV_EINVAL; } ch = ((Uint32) p[1] << 8) | (Uint32) p[0]; src += 2; srclen -= 2; } break; case ENCODING_UCS2BE: { Uint8 *p = (Uint8 *) src; if (srclen < 2) { return SDL_ICONV_EINVAL; } ch = ((Uint32) p[0] << 8) | (Uint32) p[1]; src += 2; srclen -= 2; } break; case ENCODING_UCS4BE: case ENCODING_UTF32BE: { Uint8 *p = (Uint8 *) src; if (srclen < 4) { return SDL_ICONV_EINVAL; } ch = ((Uint32) p[0] << 24) | ((Uint32) p[1] << 16) | ((Uint32) p[2] << 8) | (Uint32) p[3]; src += 4; srclen -= 4; } break; case ENCODING_UCS4LE: case ENCODING_UTF32LE: { Uint8 *p = (Uint8 *) src; if (srclen < 4) { return SDL_ICONV_EINVAL; } ch = ((Uint32) p[3] << 24) | ((Uint32) p[2] << 16) | ((Uint32) p[1] << 8) | (Uint32) p[0]; src += 4; srclen -= 4; } break; } /* Encode a character */ switch (cd->dst_fmt) { case ENCODING_ASCII: { Uint8 *p = (Uint8 *) dst; if (dstlen < 1) { return SDL_ICONV_E2BIG; } if (ch > 0x7F) { *p = UNKNOWN_ASCII; } else { *p = (Uint8) ch; } ++dst; --dstlen; } break; case ENCODING_LATIN1: { Uint8 *p = (Uint8 *) dst; if (dstlen < 1) { return SDL_ICONV_E2BIG; } if (ch > 0xFF) { *p = UNKNOWN_ASCII; } else { *p = (Uint8) ch; } ++dst; --dstlen; } break; case ENCODING_UTF8: /* RFC 3629 */ { Uint8 *p = (Uint8 *) dst; if (ch > 0x10FFFF) { ch = UNKNOWN_UNICODE; } if (ch <= 0x7F) { if (dstlen < 1) { return SDL_ICONV_E2BIG; } *p = (Uint8) ch; ++dst; --dstlen; } else if (ch <= 0x7FF) { if (dstlen < 2) { return SDL_ICONV_E2BIG; } p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F); p[1] = 0x80 | (Uint8) (ch & 0x3F); dst += 2; dstlen -= 2; } else if (ch <= 0xFFFF) { if (dstlen < 3) { return SDL_ICONV_E2BIG; } p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F); p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); p[2] = 0x80 | (Uint8) (ch & 0x3F); dst += 3; dstlen -= 3; } else if (ch <= 0x1FFFFF) { if (dstlen < 4) { return SDL_ICONV_E2BIG; } p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07); p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); p[3] = 0x80 | (Uint8) (ch & 0x3F); dst += 4; dstlen -= 4; } else if (ch <= 0x3FFFFFF) { if (dstlen < 5) { return SDL_ICONV_E2BIG; } p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03); p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F); p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); p[4] = 0x80 | (Uint8) (ch & 0x3F); dst += 5; dstlen -= 5; } else { if (dstlen < 6) { return SDL_ICONV_E2BIG; } p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01); p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F); p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F); p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F); p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F); p[5] = 0x80 | (Uint8) (ch & 0x3F); dst += 6; dstlen -= 6; } } break; case ENCODING_UTF16BE: /* RFC 2781 */ { Uint8 *p = (Uint8 *) dst; if (ch > 0x10FFFF) { ch = UNKNOWN_UNICODE; } if (ch < 0x10000) { if (dstlen < 2) { return SDL_ICONV_E2BIG; } p[0] = (Uint8) (ch >> 8); p[1] = (Uint8) ch; dst += 2; dstlen -= 2; } else { Uint16 W1, W2; if (dstlen < 4) { return SDL_ICONV_E2BIG; } ch = ch - 0x10000; W1 = 0xD800 | (Uint16) ((ch >> 10) & 0x3FF); W2 = 0xDC00 | (Uint16) (ch & 0x3FF); p[0] = (Uint8) (W1 >> 8); p[1] = (Uint8) W1; p[2] = (Uint8) (W2 >> 8); p[3] = (Uint8) W2; dst += 4; dstlen -= 4; } } break; case ENCODING_UTF16LE: /* RFC 2781 */ { Uint8 *p = (Uint8 *) dst; if (ch > 0x10FFFF) { ch = UNKNOWN_UNICODE; } if (ch < 0x10000) { if (dstlen < 2) { return SDL_ICONV_E2BIG; } p[1] = (Uint8) (ch >> 8); p[0] = (Uint8) ch; dst += 2; dstlen -= 2; } else { Uint16 W1, W2; if (dstlen < 4) { return SDL_ICONV_E2BIG; } ch = ch - 0x10000; W1 = 0xD800 | (Uint16) ((ch >> 10) & 0x3FF); W2 = 0xDC00 | (Uint16) (ch & 0x3FF); p[1] = (Uint8) (W1 >> 8); p[0] = (Uint8) W1; p[3] = (Uint8) (W2 >> 8); p[2] = (Uint8) W2; dst += 4; dstlen -= 4; } } break; case ENCODING_UCS2BE: { Uint8 *p = (Uint8 *) dst; if (ch > 0xFFFF) { ch = UNKNOWN_UNICODE; } if (dstlen < 2) { return SDL_ICONV_E2BIG; } p[0] = (Uint8) (ch >> 8); p[1] = (Uint8) ch; dst += 2; dstlen -= 2; } break; case ENCODING_UCS2LE: { Uint8 *p = (Uint8 *) dst; if (ch > 0xFFFF) { ch = UNKNOWN_UNICODE; } if (dstlen < 2) { return SDL_ICONV_E2BIG; } p[1] = (Uint8) (ch >> 8); p[0] = (Uint8) ch; dst += 2; dstlen -= 2; } break; case ENCODING_UTF32BE: if (ch > 0x10FFFF) { ch = UNKNOWN_UNICODE; } /* fallthrough */ case ENCODING_UCS4BE: if (ch > 0x7FFFFFFF) { ch = UNKNOWN_UNICODE; } { Uint8 *p = (Uint8 *) dst; if (dstlen < 4) { return SDL_ICONV_E2BIG; } p[0] = (Uint8) (ch >> 24); p[1] = (Uint8) (ch >> 16); p[2] = (Uint8) (ch >> 8); p[3] = (Uint8) ch; dst += 4; dstlen -= 4; } break; case ENCODING_UTF32LE: if (ch > 0x10FFFF) { ch = UNKNOWN_UNICODE; } /* fallthrough */ case ENCODING_UCS4LE: if (ch > 0x7FFFFFFF) { ch = UNKNOWN_UNICODE; } { Uint8 *p = (Uint8 *) dst; if (dstlen < 4) { return SDL_ICONV_E2BIG; } p[3] = (Uint8) (ch >> 24); p[2] = (Uint8) (ch >> 16); p[1] = (Uint8) (ch >> 8); p[0] = (Uint8) ch; dst += 4; dstlen -= 4; } break; } /* Update state */ *inbuf = src; *inbytesleft = srclen; *outbuf = dst; *outbytesleft = dstlen; ++total; } return total; } int SDL_iconv_close(SDL_iconv_t cd) { if (cd != (SDL_iconv_t)-1) { SDL_free(cd); } return 0; } #endif /* !HAVE_ICONV */ char * SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft) { SDL_iconv_t cd; char *string; size_t stringsize; char *outbuf; size_t outbytesleft; size_t retCode = 0; cd = SDL_iconv_open(tocode, fromcode); if (cd == (SDL_iconv_t) - 1) { /* See if we can recover here (fixes iconv on Solaris 11) */ if (!tocode || !*tocode) { tocode = "UTF-8"; } if (!fromcode || !*fromcode) { fromcode = "UTF-8"; } cd = SDL_iconv_open(tocode, fromcode); } if (cd == (SDL_iconv_t) - 1) { return NULL; } stringsize = inbytesleft > 4 ? inbytesleft : 4; string = (char *) SDL_malloc(stringsize); if (!string) { SDL_iconv_close(cd); return NULL; } outbuf = string; outbytesleft = stringsize; SDL_memset(outbuf, 0, 4); while (inbytesleft > 0) { const size_t oldinbytesleft = inbytesleft; retCode = SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); switch (retCode) { case SDL_ICONV_E2BIG: { char *oldstring = string; stringsize *= 2; string = (char *) SDL_realloc(string, stringsize); if (!string) { SDL_iconv_close(cd); return NULL; } outbuf = string + (outbuf - oldstring); outbytesleft = stringsize - (outbuf - string); SDL_memset(outbuf, 0, 4); } break; case SDL_ICONV_EILSEQ: /* Try skipping some input data - not perfect, but... */ ++inbuf; --inbytesleft; break; case SDL_ICONV_EINVAL: case SDL_ICONV_ERROR: /* We can't continue... */ inbytesleft = 0; break; } /* Avoid infinite loops when nothing gets converted */ if (oldinbytesleft == inbytesleft) { break; } } SDL_iconv_close(cd); return string; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/stdlib/SDL_iconv.c
C
apache-2.0
29,611
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) #define SDL_DISABLE_ANALYZE_MACROS 1 #endif #include "../SDL_internal.h" /* This file contains portable memory management functions for SDL */ #include "SDL_stdinc.h" #include "SDL_atomic.h" #include "SDL_error.h" #ifndef HAVE_MALLOC #define LACKS_SYS_TYPES_H #define LACKS_STDIO_H #define LACKS_STRINGS_H #define LACKS_STRING_H #define LACKS_STDLIB_H #define ABORT #define USE_LOCKS 1 #define USE_DL_PREFIX /* This is a version (aka dlmalloc) of malloc/free/realloc written by Doug Lea and released to the public domain, as explained at http://creativecommons.org/licenses/publicdomain. Send questions, comments, complaints, performance data, etc to dl@cs.oswego.edu * Version 2.8.3 Thu Sep 22 11:16:15 2005 Doug Lea (dl at gee) Note: There may be an updated version of this malloc obtainable at ftp://gee.cs.oswego.edu/pub/misc/malloc.c Check before installing! * Quickstart This library is all in one file to simplify the most common usage: ftp it, compile it (-O3), and link it into another program. All of the compile-time options default to reasonable values for use on most platforms. You might later want to step through various compile-time and dynamic tuning options. For convenience, an include file for code using this malloc is at: ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.3.h You don't really need this .h file unless you call functions not defined in your system include files. The .h file contains only the excerpts from this file needed for using this malloc on ANSI C/C++ systems, so long as you haven't changed compile-time options about naming and tuning parameters. If you do, then you can create your own malloc.h that does include all settings by cutting at the point indicated below. Note that you may already by default be using a C library containing a malloc that is based on some version of this malloc (for example in linux). You might still want to use the one in this file to customize settings or to avoid overheads associated with library versions. * Vital statistics: Supported pointer/size_t representation: 4 or 8 bytes size_t MUST be an unsigned type of the same width as pointers. (If you are using an ancient system that declares size_t as a signed type, or need it to be a different width than pointers, you can use a previous release of this malloc (e.g. 2.7.2) supporting these.) Alignment: 8 bytes (default) This suffices for nearly all current machines and C compilers. However, you can define MALLOC_ALIGNMENT to be wider than this if necessary (up to 128bytes), at the expense of using more space. Minimum overhead per allocated chunk: 4 or 8 bytes (if 4byte sizes) 8 or 16 bytes (if 8byte sizes) Each malloced chunk has a hidden word of overhead holding size and status information, and additional cross-check word if FOOTERS is defined. Minimum allocated size: 4-byte ptrs: 16 bytes (including overhead) 8-byte ptrs: 32 bytes (including overhead) Even a request for zero bytes (i.e., malloc(0)) returns a pointer to something of the minimum allocatable size. The maximum overhead wastage (i.e., number of extra bytes allocated than were requested in malloc) is less than or equal to the minimum size, except for requests >= mmap_threshold that are serviced via mmap(), where the worst case wastage is about 32 bytes plus the remainder from a system page (the minimal mmap unit); typically 4096 or 8192 bytes. Security: static-safe; optionally more or less The "security" of malloc refers to the ability of malicious code to accentuate the effects of errors (for example, freeing space that is not currently malloc'ed or overwriting past the ends of chunks) in code that calls malloc. This malloc guarantees not to modify any memory locations below the base of heap, i.e., static variables, even in the presence of usage errors. The routines additionally detect most improper frees and reallocs. All this holds as long as the static bookkeeping for malloc itself is not corrupted by some other means. This is only one aspect of security -- these checks do not, and cannot, detect all possible programming errors. If FOOTERS is defined nonzero, then each allocated chunk carries an additional check word to verify that it was malloced from its space. These check words are the same within each execution of a program using malloc, but differ across executions, so externally crafted fake chunks cannot be freed. This improves security by rejecting frees/reallocs that could corrupt heap memory, in addition to the checks preventing writes to statics that are always on. This may further improve security at the expense of time and space overhead. (Note that FOOTERS may also be worth using with MSPACES.) By default detected errors cause the program to abort (calling "abort()"). You can override this to instead proceed past errors by defining PROCEED_ON_ERROR. In this case, a bad free has no effect, and a malloc that encounters a bad address caused by user overwrites will ignore the bad address by dropping pointers and indices to all known memory. This may be appropriate for programs that should continue if at all possible in the face of programming errors, although they may run out of memory because dropped memory is never reclaimed. If you don't like either of these options, you can define CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION to do anything else. And if if you are sure that your program using malloc has no errors or vulnerabilities, you can define INSECURE to 1, which might (or might not) provide a small performance improvement. Thread-safety: NOT thread-safe unless USE_LOCKS defined When USE_LOCKS is defined, each public call to malloc, free, etc is surrounded with either a pthread mutex or a win32 spinlock (depending on WIN32). This is not especially fast, and can be a major bottleneck. It is designed only to provide minimal protection in concurrent environments, and to provide a basis for extensions. If you are using malloc in a concurrent program, consider instead using ptmalloc, which is derived from a version of this malloc. (See http://www.malloc.de). System requirements: Any combination of MORECORE and/or MMAP/MUNMAP This malloc can use unix sbrk or any emulation (invoked using the CALL_MORECORE macro) and/or mmap/munmap or any emulation (invoked using CALL_MMAP/CALL_MUNMAP) to get and release system memory. On most unix systems, it tends to work best if both MORECORE and MMAP are enabled. On Win32, it uses emulations based on VirtualAlloc. It also uses common C library functions like memset. Compliance: I believe it is compliant with the Single Unix Specification (See http://www.unix.org). Also SVID/XPG, ANSI C, and probably others as well. * Overview of algorithms This is not the fastest, most space-conserving, most portable, or most tunable malloc ever written. However it is among the fastest while also being among the most space-conserving, portable and tunable. Consistent balance across these factors results in a good general-purpose allocator for malloc-intensive programs. In most ways, this malloc is a best-fit allocator. Generally, it chooses the best-fitting existing chunk for a request, with ties broken in approximately least-recently-used order. (This strategy normally maintains low fragmentation.) However, for requests less than 256bytes, it deviates from best-fit when there is not an exactly fitting available chunk by preferring to use space adjacent to that used for the previous small request, as well as by breaking ties in approximately most-recently-used order. (These enhance locality of series of small allocations.) And for very large requests (>= 256Kb by default), it relies on system memory mapping facilities, if supported. (This helps avoid carrying around and possibly fragmenting memory used only for large chunks.) All operations (except malloc_stats and mallinfo) have execution times that are bounded by a constant factor of the number of bits in a size_t, not counting any clearing in calloc or copying in realloc, or actions surrounding MORECORE and MMAP that have times proportional to the number of non-contiguous regions returned by system allocation routines, which is often just 1. The implementation is not very modular and seriously overuses macros. Perhaps someday all C compilers will do as good a job inlining modular code as can now be done by brute-force expansion, but now, enough of them seem not to. Some compilers issue a lot of warnings about code that is dead/unreachable only on some platforms, and also about intentional uses of negation on unsigned types. All known cases of each can be ignored. For a longer but out of date high-level description, see http://gee.cs.oswego.edu/dl/html/malloc.html * MSPACES If MSPACES is defined, then in addition to malloc, free, etc., this file also defines mspace_malloc, mspace_free, etc. These are versions of malloc routines that take an "mspace" argument obtained using create_mspace, to control all internal bookkeeping. If ONLY_MSPACES is defined, only these versions are compiled. So if you would like to use this allocator for only some allocations, and your system malloc for others, you can compile with ONLY_MSPACES and then do something like... static mspace mymspace = create_mspace(0,0); // for example #define mymalloc(bytes) mspace_malloc(mymspace, bytes) (Note: If you only need one instance of an mspace, you can instead use "USE_DL_PREFIX" to relabel the global malloc.) You can similarly create thread-local allocators by storing mspaces as thread-locals. For example: static __thread mspace tlms = 0; void* tlmalloc(size_t bytes) { if (tlms == 0) tlms = create_mspace(0, 0); return mspace_malloc(tlms, bytes); } void tlfree(void* mem) { mspace_free(tlms, mem); } Unless FOOTERS is defined, each mspace is completely independent. You cannot allocate from one and free to another (although conformance is only weakly checked, so usage errors are not always caught). If FOOTERS is defined, then each chunk carries around a tag indicating its originating mspace, and frees are directed to their originating spaces. ------------------------- Compile-time options --------------------------- Be careful in setting #define values for numerical constants of type size_t. On some systems, literal values are not automatically extended to size_t precision unless they are explicitly casted. WIN32 default: defined if _WIN32 defined Defining WIN32 sets up defaults for MS environment and compilers. Otherwise defaults are for unix. MALLOC_ALIGNMENT default: (size_t)8 Controls the minimum alignment for malloc'ed chunks. It must be a power of two and at least 8, even on machines for which smaller alignments would suffice. It may be defined as larger than this though. Note however that code and data structures are optimized for the case of 8-byte alignment. MSPACES default: 0 (false) If true, compile in support for independent allocation spaces. This is only supported if HAVE_MMAP is true. ONLY_MSPACES default: 0 (false) If true, only compile in mspace versions, not regular versions. USE_LOCKS default: 0 (false) Causes each call to each public routine to be surrounded with pthread or WIN32 mutex lock/unlock. (If set true, this can be overridden on a per-mspace basis for mspace versions.) FOOTERS default: 0 If true, provide extra checking and dispatching by placing information in the footers of allocated chunks. This adds space and time overhead. INSECURE default: 0 If true, omit checks for usage errors and heap space overwrites. USE_DL_PREFIX default: NOT defined Causes compiler to prefix all public routines with the string 'dl'. This can be useful when you only want to use this malloc in one part of a program, using your regular system malloc elsewhere. ABORT default: defined as abort() Defines how to abort on failed checks. On most systems, a failed check cannot die with an "assert" or even print an informative message, because the underlying print routines in turn call malloc, which will fail again. Generally, the best policy is to simply call abort(). It's not very useful to do more than this because many errors due to overwriting will show up as address faults (null, odd addresses etc) rather than malloc-triggered checks, so will also abort. Also, most compilers know that abort() does not return, so can better optimize code conditionally calling it. PROCEED_ON_ERROR default: defined as 0 (false) Controls whether detected bad addresses cause them to bypassed rather than aborting. If set, detected bad arguments to free and realloc are ignored. And all bookkeeping information is zeroed out upon a detected overwrite of freed heap space, thus losing the ability to ever return it from malloc again, but enabling the application to proceed. If PROCEED_ON_ERROR is defined, the static variable malloc_corruption_error_count is compiled in and can be examined to see if errors have occurred. This option generates slower code than the default abort policy. DEBUG default: NOT defined The DEBUG setting is mainly intended for people trying to modify this code or diagnose problems when porting to new platforms. However, it may also be able to better isolate user errors than just using runtime checks. The assertions in the check routines spell out in more detail the assumptions and invariants underlying the algorithms. The checking is fairly extensive, and will slow down execution noticeably. Calling malloc_stats or mallinfo with DEBUG set will attempt to check every non-mmapped allocated and free chunk in the course of computing the summaries. ABORT_ON_ASSERT_FAILURE default: defined as 1 (true) Debugging assertion failures can be nearly impossible if your version of the assert macro causes malloc to be called, which will lead to a cascade of further failures, blowing the runtime stack. ABORT_ON_ASSERT_FAILURE cause assertions failures to call abort(), which will usually make debugging easier. MALLOC_FAILURE_ACTION default: sets errno to ENOMEM, or no-op on win32 The action to take before "return 0" when malloc fails to be able to return memory because there is none available. HAVE_MORECORE default: 1 (true) unless win32 or ONLY_MSPACES True if this system supports sbrk or an emulation of it. MORECORE default: sbrk The name of the sbrk-style system routine to call to obtain more memory. See below for guidance on writing custom MORECORE functions. The type of the argument to sbrk/MORECORE varies across systems. It cannot be size_t, because it supports negative arguments, so it is normally the signed type of the same width as size_t (sometimes declared as "intptr_t"). It doesn't much matter though. Internally, we only call it with arguments less than half the max value of a size_t, which should work across all reasonable possibilities, although sometimes generating compiler warnings. See near the end of this file for guidelines for creating a custom version of MORECORE. MORECORE_CONTIGUOUS default: 1 (true) If true, take advantage of fact that consecutive calls to MORECORE with positive arguments always return contiguous increasing addresses. This is true of unix sbrk. It does not hurt too much to set it true anyway, since malloc copes with non-contiguities. Setting it false when definitely non-contiguous saves time and possibly wasted space it would take to discover this though. MORECORE_CANNOT_TRIM default: NOT defined True if MORECORE cannot release space back to the system when given negative arguments. This is generally necessary only if you are using a hand-crafted MORECORE function that cannot handle negative arguments. HAVE_MMAP default: 1 (true) True if this system supports mmap or an emulation of it. If so, and HAVE_MORECORE is not true, MMAP is used for all system allocation. If set and HAVE_MORECORE is true as well, MMAP is primarily used to directly allocate very large blocks. It is also used as a backup strategy in cases where MORECORE fails to provide space from system. Note: A single call to MUNMAP is assumed to be able to unmap memory that may have be allocated using multiple calls to MMAP, so long as they are adjacent. HAVE_MREMAP default: 1 on linux, else 0 If true realloc() uses mremap() to re-allocate large blocks and extend or shrink allocation spaces. MMAP_CLEARS default: 1 on unix True if mmap clears memory so calloc doesn't need to. This is true for standard unix mmap using /dev/zero. USE_BUILTIN_FFS default: 0 (i.e., not used) Causes malloc to use the builtin ffs() function to compute indices. Some compilers may recognize and intrinsify ffs to be faster than the supplied C version. Also, the case of x86 using gcc is special-cased to an asm instruction, so is already as fast as it can be, and so this setting has no effect. (On most x86s, the asm version is only slightly faster than the C version.) malloc_getpagesize default: derive from system includes, or 4096. The system page size. To the extent possible, this malloc manages memory from the system in page-size units. This may be (and usually is) a function rather than a constant. This is ignored if WIN32, where page size is determined using getSystemInfo during initialization. USE_DEV_RANDOM default: 0 (i.e., not used) Causes malloc to use /dev/random to initialize secure magic seed for stamping footers. Otherwise, the current time is used. NO_MALLINFO default: 0 If defined, don't compile "mallinfo". This can be a simple way of dealing with mismatches between system declarations and those in this file. MALLINFO_FIELD_TYPE default: size_t The type of the fields in the mallinfo struct. This was originally defined as "int" in SVID etc, but is more usefully defined as size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set REALLOC_ZERO_BYTES_FREES default: not defined This should be set if a call to realloc with zero bytes should be the same as a call to free. Some people think it should. Otherwise, since this malloc returns a unique pointer for malloc(0), so does realloc(p, 0). LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H LACKS_STRINGS_H, LACKS_STRING_H, LACKS_SYS_TYPES_H, LACKS_ERRNO_H LACKS_STDLIB_H default: NOT defined unless on WIN32 Define these if your system does not have these header files. You might need to manually insert some of the declarations they provide. DEFAULT_GRANULARITY default: page size if MORECORE_CONTIGUOUS, system_info.dwAllocationGranularity in WIN32, otherwise 64K. Also settable using mallopt(M_GRANULARITY, x) The unit for allocating and deallocating memory from the system. On most systems with contiguous MORECORE, there is no reason to make this more than a page. However, systems with MMAP tend to either require or encourage larger granularities. You can increase this value to prevent system allocation functions to be called so often, especially if they are slow. The value must be at least one page and must be a power of two. Setting to 0 causes initialization to either page size or win32 region size. (Note: In previous versions of malloc, the equivalent of this option was called "TOP_PAD") DEFAULT_TRIM_THRESHOLD default: 2MB Also settable using mallopt(M_TRIM_THRESHOLD, x) The maximum amount of unused top-most memory to keep before releasing via malloc_trim in free(). Automatic trimming is mainly useful in long-lived programs using contiguous MORECORE. Because trimming via sbrk can be slow on some systems, and can sometimes be wasteful (in cases where programs immediately afterward allocate more large chunks) the value should be high enough so that your overall system performance would improve by releasing this much memory. As a rough guide, you might set to a value close to the average size of a process (program) running on your system. Releasing this much memory would allow such a process to run in memory. Generally, it is worth tuning trim thresholds when a program undergoes phases where several large chunks are allocated and released in ways that can reuse each other's storage, perhaps mixed with phases where there are no such chunks at all. The trim value must be greater than page size to have any useful effect. To disable trimming completely, you can set to MAX_SIZE_T. Note that the trick some people use of mallocing a huge space and then freeing it at program startup, in an attempt to reserve system memory, doesn't have the intended effect under automatic trimming, since that memory will immediately be returned to the system. DEFAULT_MMAP_THRESHOLD default: 256K Also settable using mallopt(M_MMAP_THRESHOLD, x) The request size threshold for using MMAP to directly service a request. Requests of at least this size that cannot be allocated using already-existing space will be serviced via mmap. (If enough normal freed space already exists it is used instead.) Using mmap segregates relatively large chunks of memory so that they can be individually obtained and released from the host system. A request serviced through mmap is never reused by any other request (at least not directly; the system may just so happen to remap successive requests to the same locations). Segregating space in this way has the benefits that: Mmapped space can always be individually released back to the system, which helps keep the system level memory demands of a long-lived program low. Also, mapped memory doesn't become `locked' between other chunks, as can happen with normally allocated chunks, which means that even trimming via malloc_trim would not release them. However, it has the disadvantage that the space cannot be reclaimed, consolidated, and then used to service later requests, as happens with normal chunks. The advantages of mmap nearly always outweigh disadvantages for "large" chunks, but the value of "large" may vary across systems. The default is an empirically derived value that works well in most systems. You can disable mmap by setting to MAX_SIZE_T. */ #ifndef WIN32 #ifdef _WIN32 #define WIN32 1 #endif /* _WIN32 */ #endif /* WIN32 */ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include <windows.h> #define HAVE_MMAP 1 #define HAVE_MORECORE 0 #define LACKS_UNISTD_H #define LACKS_SYS_PARAM_H #define LACKS_SYS_MMAN_H #define LACKS_STRING_H #define LACKS_STRINGS_H #define LACKS_SYS_TYPES_H #define LACKS_ERRNO_H #define LACKS_FCNTL_H #define MALLOC_FAILURE_ACTION #define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */ #endif /* WIN32 */ #ifdef __OS2__ #define INCL_DOS #include <os2.h> #define HAVE_MMAP 1 #define HAVE_MORECORE 0 #define LACKS_SYS_MMAN_H #endif /* __OS2__ */ #if defined(DARWIN) || defined(_DARWIN) /* Mac OSX docs advise not to use sbrk; it seems better to use mmap */ #ifndef HAVE_MORECORE #define HAVE_MORECORE 0 #define HAVE_MMAP 1 #endif /* HAVE_MORECORE */ #endif /* DARWIN */ #ifndef LACKS_SYS_TYPES_H #include <sys/types.h> /* For size_t */ #endif /* LACKS_SYS_TYPES_H */ /* The maximum possible size_t value has all bits set */ #define MAX_SIZE_T (~(size_t)0) #ifndef ONLY_MSPACES #define ONLY_MSPACES 0 #endif /* ONLY_MSPACES */ #ifndef MSPACES #if ONLY_MSPACES #define MSPACES 1 #else /* ONLY_MSPACES */ #define MSPACES 0 #endif /* ONLY_MSPACES */ #endif /* MSPACES */ #ifndef MALLOC_ALIGNMENT #define MALLOC_ALIGNMENT ((size_t)8U) #endif /* MALLOC_ALIGNMENT */ #ifndef FOOTERS #define FOOTERS 0 #endif /* FOOTERS */ #ifndef ABORT #define ABORT abort() #endif /* ABORT */ #ifndef ABORT_ON_ASSERT_FAILURE #define ABORT_ON_ASSERT_FAILURE 1 #endif /* ABORT_ON_ASSERT_FAILURE */ #ifndef PROCEED_ON_ERROR #define PROCEED_ON_ERROR 0 #endif /* PROCEED_ON_ERROR */ #ifndef USE_LOCKS #define USE_LOCKS 0 #endif /* USE_LOCKS */ #ifndef INSECURE #define INSECURE 0 #endif /* INSECURE */ #ifndef HAVE_MMAP #define HAVE_MMAP 1 #endif /* HAVE_MMAP */ #ifndef MMAP_CLEARS #define MMAP_CLEARS 1 #endif /* MMAP_CLEARS */ #ifndef HAVE_MREMAP #ifdef linux #define HAVE_MREMAP 1 #else /* linux */ #define HAVE_MREMAP 0 #endif /* linux */ #endif /* HAVE_MREMAP */ #ifndef MALLOC_FAILURE_ACTION #define MALLOC_FAILURE_ACTION errno = ENOMEM; #endif /* MALLOC_FAILURE_ACTION */ #ifndef HAVE_MORECORE #if ONLY_MSPACES #define HAVE_MORECORE 0 #else /* ONLY_MSPACES */ #define HAVE_MORECORE 1 #endif /* ONLY_MSPACES */ #endif /* HAVE_MORECORE */ #if !HAVE_MORECORE #define MORECORE_CONTIGUOUS 0 #else /* !HAVE_MORECORE */ #ifndef MORECORE #define MORECORE sbrk #endif /* MORECORE */ #ifndef MORECORE_CONTIGUOUS #define MORECORE_CONTIGUOUS 1 #endif /* MORECORE_CONTIGUOUS */ #endif /* HAVE_MORECORE */ #ifndef DEFAULT_GRANULARITY #if MORECORE_CONTIGUOUS #define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */ #else /* MORECORE_CONTIGUOUS */ #define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U) #endif /* MORECORE_CONTIGUOUS */ #endif /* DEFAULT_GRANULARITY */ #ifndef DEFAULT_TRIM_THRESHOLD #ifndef MORECORE_CANNOT_TRIM #define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) #else /* MORECORE_CANNOT_TRIM */ #define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T #endif /* MORECORE_CANNOT_TRIM */ #endif /* DEFAULT_TRIM_THRESHOLD */ #ifndef DEFAULT_MMAP_THRESHOLD #if HAVE_MMAP #define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U) #else /* HAVE_MMAP */ #define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T #endif /* HAVE_MMAP */ #endif /* DEFAULT_MMAP_THRESHOLD */ #ifndef USE_BUILTIN_FFS #define USE_BUILTIN_FFS 0 #endif /* USE_BUILTIN_FFS */ #ifndef USE_DEV_RANDOM #define USE_DEV_RANDOM 0 #endif /* USE_DEV_RANDOM */ #ifndef NO_MALLINFO #define NO_MALLINFO 0 #endif /* NO_MALLINFO */ #ifndef MALLINFO_FIELD_TYPE #define MALLINFO_FIELD_TYPE size_t #endif /* MALLINFO_FIELD_TYPE */ #ifndef memset #define memset SDL_memset #endif #ifndef memcpy #define memcpy SDL_memcpy #endif /* mallopt tuning options. SVID/XPG defines four standard parameter numbers for mallopt, normally defined in malloc.h. None of these are used in this malloc, so setting them has no effect. But this malloc does support the following options. */ #define M_TRIM_THRESHOLD (-1) #define M_GRANULARITY (-2) #define M_MMAP_THRESHOLD (-3) /* ------------------------ Mallinfo declarations ------------------------ */ #if !NO_MALLINFO /* This version of malloc supports the standard SVID/XPG mallinfo routine that returns a struct containing usage properties and statistics. It should work on any system that has a /usr/include/malloc.h defining struct mallinfo. The main declaration needed is the mallinfo struct that is returned (by-copy) by mallinfo(). The malloinfo struct contains a bunch of fields that are not even meaningful in this version of malloc. These fields are are instead filled by mallinfo() with other numbers that might be of interest. HAVE_USR_INCLUDE_MALLOC_H should be set if you have a /usr/include/malloc.h file that includes a declaration of struct mallinfo. If so, it is included; else a compliant version is declared below. These must be precisely the same for mallinfo() to work. The original SVID version of this struct, defined on most systems with mallinfo, declares all fields as ints. But some others define as unsigned long. If your system defines the fields using a type of different width than listed here, you MUST #include your system version and #define HAVE_USR_INCLUDE_MALLOC_H. */ /* #define HAVE_USR_INCLUDE_MALLOC_H */ #ifdef HAVE_USR_INCLUDE_MALLOC_H #include "/usr/include/malloc.h" #else /* HAVE_USR_INCLUDE_MALLOC_H */ struct mallinfo { MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ MALLINFO_FIELD_TYPE smblks; /* always 0 */ MALLINFO_FIELD_TYPE hblks; /* always 0 */ MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ MALLINFO_FIELD_TYPE fordblks; /* total free space */ MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ }; #endif /* HAVE_USR_INCLUDE_MALLOC_H */ #endif /* NO_MALLINFO */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #if !ONLY_MSPACES /* ------------------- Declarations of public routines ------------------- */ #ifndef USE_DL_PREFIX #define dlcalloc calloc #define dlfree free #define dlmalloc malloc #define dlmemalign memalign #define dlrealloc realloc #define dlvalloc valloc #define dlpvalloc pvalloc #define dlmallinfo mallinfo #define dlmallopt mallopt #define dlmalloc_trim malloc_trim #define dlmalloc_stats malloc_stats #define dlmalloc_usable_size malloc_usable_size #define dlmalloc_footprint malloc_footprint #define dlmalloc_max_footprint malloc_max_footprint #define dlindependent_calloc independent_calloc #define dlindependent_comalloc independent_comalloc #endif /* USE_DL_PREFIX */ /* malloc(size_t n) Returns a pointer to a newly allocated chunk of at least n bytes, or null if no space is available, in which case errno is set to ENOMEM on ANSI C systems. If n is zero, malloc returns a minimum-sized chunk. (The minimum size is 16 bytes on most 32bit systems, and 32 bytes on 64bit systems.) Note that size_t is an unsigned type, so calls with arguments that would be negative if signed are interpreted as requests for huge amounts of space, which will often fail. The maximum supported value of n differs across systems, but is in all cases less than the maximum representable value of a size_t. */ void *dlmalloc(size_t); /* free(void* p) Releases the chunk of memory pointed to by p, that had been previously allocated using malloc or a related routine such as realloc. It has no effect if p is null. If p was not malloced or already freed, free(p) will by default cause the current program to abort. */ void dlfree(void *); /* calloc(size_t n_elements, size_t element_size); Returns a pointer to n_elements * element_size bytes, with all locations set to zero. */ void *dlcalloc(size_t, size_t); /* realloc(void* p, size_t n) Returns a pointer to a chunk of size n that contains the same data as does chunk p up to the minimum of (n, p's size) bytes, or null if no space is available. The returned pointer may or may not be the same as p. The algorithm prefers extending p in most cases when possible, otherwise it employs the equivalent of a malloc-copy-free sequence. If p is null, realloc is equivalent to malloc. If space is not available, realloc returns null, errno is set (if on ANSI) and p is NOT freed. if n is for fewer bytes than already held by p, the newly unused space is lopped off and freed if possible. realloc with a size argument of zero (re)allocates a minimum-sized chunk. The old unix realloc convention of allowing the last-free'd chunk to be used as an argument to realloc is not supported. */ void *dlrealloc(void *, size_t); /* memalign(size_t alignment, size_t n); Returns a pointer to a newly allocated chunk of n bytes, aligned in accord with the alignment argument. The alignment argument should be a power of two. If the argument is not a power of two, the nearest greater power is used. 8-byte alignment is guaranteed by normal malloc calls, so don't bother calling memalign with an argument of 8 or less. Overreliance on memalign is a sure way to fragment space. */ void *dlmemalign(size_t, size_t); /* valloc(size_t n); Equivalent to memalign(pagesize, n), where pagesize is the page size of the system. If the pagesize is unknown, 4096 is used. */ void *dlvalloc(size_t); /* mallopt(int parameter_number, int parameter_value) Sets tunable parameters The format is to provide a (parameter-number, parameter-value) pair. mallopt then sets the corresponding parameter to the argument value if it can (i.e., so long as the value is meaningful), and returns 1 if successful else 0. SVID/XPG/ANSI defines four standard param numbers for mallopt, normally defined in malloc.h. None of these are use in this malloc, so setting them has no effect. But this malloc also supports other options in mallopt. See below for details. Briefly, supported parameters are as follows (listed defaults are for "typical" configurations). Symbol param # default allowed param values M_TRIM_THRESHOLD -1 2*1024*1024 any (MAX_SIZE_T disables) M_GRANULARITY -2 page size any power of 2 >= page size M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support) */ int dlmallopt(int, int); /* malloc_footprint(); Returns the number of bytes obtained from the system. The total number of bytes allocated by malloc, realloc etc., is less than this value. Unlike mallinfo, this function returns only a precomputed result, so can be called frequently to monitor memory consumption. Even if locks are otherwise defined, this function does not use them, so results might not be up to date. */ size_t dlmalloc_footprint(void); /* malloc_max_footprint(); Returns the maximum number of bytes obtained from the system. This value will be greater than current footprint if deallocated space has been reclaimed by the system. The peak number of bytes allocated by malloc, realloc etc., is less than this value. Unlike mallinfo, this function returns only a precomputed result, so can be called frequently to monitor memory consumption. Even if locks are otherwise defined, this function does not use them, so results might not be up to date. */ size_t dlmalloc_max_footprint(void); #if !NO_MALLINFO /* mallinfo() Returns (by copy) a struct containing various summary statistics: arena: current total non-mmapped bytes allocated from system ordblks: the number of free chunks smblks: always zero. hblks: current number of mmapped regions hblkhd: total bytes held in mmapped regions usmblks: the maximum total allocated space. This will be greater than current total if trimming has occurred. fsmblks: always zero uordblks: current total allocated space (normal or mmapped) fordblks: total free space keepcost: the maximum number of bytes that could ideally be released back to system via malloc_trim. ("ideally" means that it ignores page restrictions etc.) Because these fields are ints, but internal bookkeeping may be kept as longs, the reported values may wrap around zero and thus be inaccurate. */ struct mallinfo dlmallinfo(void); #endif /* NO_MALLINFO */ /* independent_calloc(size_t n_elements, size_t element_size, void* chunks[]); independent_calloc is similar to calloc, but instead of returning a single cleared space, it returns an array of pointers to n_elements independent elements that can hold contents of size elem_size, each of which starts out cleared, and can be independently freed, realloc'ed etc. The elements are guaranteed to be adjacently allocated (this is not guaranteed to occur with multiple callocs or mallocs), which may also improve cache locality in some applications. The "chunks" argument is optional (i.e., may be null, which is probably the most typical usage). If it is null, the returned array is itself dynamically allocated and should also be freed when it is no longer needed. Otherwise, the chunks array must be of at least n_elements in length. It is filled in with the pointers to the chunks. In either case, independent_calloc returns this pointer array, or null if the allocation failed. If n_elements is zero and "chunks" is null, it returns a chunk representing an array with zero elements (which should be freed if not wanted). Each element must be individually freed when it is no longer needed. If you'd like to instead be able to free all at once, you should instead use regular calloc and assign pointers into this space to represent elements. (In this case though, you cannot independently free elements.) independent_calloc simplifies and speeds up implementations of many kinds of pools. It may also be useful when constructing large data structures that initially have a fixed number of fixed-sized nodes, but the number is not known at compile time, and some of the nodes may later need to be freed. For example: struct Node { int item; struct Node* next; }; struct Node* build_list() { struct Node** pool; int n = read_number_of_nodes_needed(); if (n <= 0) return 0; pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0); if (pool == 0) die(); // organize into a linked list... struct Node* first = pool[0]; for (i = 0; i < n-1; ++i) pool[i]->next = pool[i+1]; free(pool); // Can now free the array (or not, if it is needed later) return first; } */ void **dlindependent_calloc(size_t, size_t, void **); /* independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]); independent_comalloc allocates, all at once, a set of n_elements chunks with sizes indicated in the "sizes" array. It returns an array of pointers to these elements, each of which can be independently freed, realloc'ed etc. The elements are guaranteed to be adjacently allocated (this is not guaranteed to occur with multiple callocs or mallocs), which may also improve cache locality in some applications. The "chunks" argument is optional (i.e., may be null). If it is null the returned array is itself dynamically allocated and should also be freed when it is no longer needed. Otherwise, the chunks array must be of at least n_elements in length. It is filled in with the pointers to the chunks. In either case, independent_comalloc returns this pointer array, or null if the allocation failed. If n_elements is zero and chunks is null, it returns a chunk representing an array with zero elements (which should be freed if not wanted). Each element must be individually freed when it is no longer needed. If you'd like to instead be able to free all at once, you should instead use a single regular malloc, and assign pointers at particular offsets in the aggregate space. (In this case though, you cannot independently free elements.) independent_comallac differs from independent_calloc in that each element may have a different size, and also that it does not automatically clear elements. independent_comalloc can be used to speed up allocation in cases where several structs or objects must always be allocated at the same time. For example: struct Head { ... } struct Foot { ... } void send_message(char* msg) { int msglen = strlen(msg); size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) }; void* chunks[3]; if (independent_comalloc(3, sizes, chunks) == 0) die(); struct Head* head = (struct Head*)(chunks[0]); char* body = (char*)(chunks[1]); struct Foot* foot = (struct Foot*)(chunks[2]); // ... } In general though, independent_comalloc is worth using only for larger values of n_elements. For small values, you probably won't detect enough difference from series of malloc calls to bother. Overuse of independent_comalloc can increase overall memory usage, since it cannot reuse existing noncontiguous small chunks that might be available for some of the elements. */ void **dlindependent_comalloc(size_t, size_t *, void **); /* pvalloc(size_t n); Equivalent to valloc(minimum-page-that-holds(n)), that is, round up n to nearest pagesize. */ void *dlpvalloc(size_t); /* malloc_trim(size_t pad); If possible, gives memory back to the system (via negative arguments to sbrk) if there is unused memory at the `high' end of the malloc pool or in unused MMAP segments. You can call this after freeing large blocks of memory to potentially reduce the system-level memory requirements of a program. However, it cannot guarantee to reduce memory. Under some allocation patterns, some large free blocks of memory will be locked between two used chunks, so they cannot be given back to the system. The `pad' argument to malloc_trim represents the amount of free trailing space to leave untrimmed. If this argument is zero, only the minimum amount of memory to maintain internal data structures will be left. Non-zero arguments can be supplied to maintain enough trailing space to service future expected allocations without having to re-obtain memory from the system. Malloc_trim returns 1 if it actually released any memory, else 0. */ int dlmalloc_trim(size_t); /* malloc_usable_size(void* p); Returns the number of bytes you can actually use in an allocated chunk, which may be more than you requested (although often not) due to alignment and minimum size constraints. You can use this many bytes without worrying about overwriting other allocated objects. This is not a particularly great programming practice. malloc_usable_size can be more useful in debugging and assertions, for example: p = malloc(n); assert(malloc_usable_size(p) >= 256); */ size_t dlmalloc_usable_size(void *); /* malloc_stats(); Prints on stderr the amount of space obtained from the system (both via sbrk and mmap), the maximum amount (which may be more than current if malloc_trim and/or munmap got called), and the current number of bytes allocated via malloc (or realloc, etc) but not yet freed. Note that this is the number of bytes allocated, not the number requested. It will be larger than the number requested because of alignment and bookkeeping overhead. Because it includes alignment wastage as being in use, this figure may be greater than zero even when no user-level chunks are allocated. The reported current and maximum system memory can be inaccurate if a program makes other calls to system memory allocation functions (normally sbrk) outside of malloc. malloc_stats prints only the most commonly interesting statistics. More information can be obtained by calling mallinfo. */ void dlmalloc_stats(void); #endif /* ONLY_MSPACES */ #if MSPACES /* mspace is an opaque type representing an independent region of space that supports mspace_malloc, etc. */ typedef void *mspace; /* create_mspace creates and returns a new independent space with the given initial capacity, or, if 0, the default granularity size. It returns null if there is no system memory available to create the space. If argument locked is non-zero, the space uses a separate lock to control access. The capacity of the space will grow dynamically as needed to service mspace_malloc requests. You can control the sizes of incremental increases of this space by compiling with a different DEFAULT_GRANULARITY or dynamically setting with mallopt(M_GRANULARITY, value). */ mspace create_mspace(size_t capacity, int locked); /* destroy_mspace destroys the given space, and attempts to return all of its memory back to the system, returning the total number of bytes freed. After destruction, the results of access to all memory used by the space become undefined. */ size_t destroy_mspace(mspace msp); /* create_mspace_with_base uses the memory supplied as the initial base of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this space is used for bookkeeping, so the capacity must be at least this large. (Otherwise 0 is returned.) When this initial space is exhausted, additional memory will be obtained from the system. Destroying this space will deallocate all additionally allocated space (if possible) but not the initial base. */ mspace create_mspace_with_base(void *base, size_t capacity, int locked); /* mspace_malloc behaves as malloc, but operates within the given space. */ void *mspace_malloc(mspace msp, size_t bytes); /* mspace_free behaves as free, but operates within the given space. If compiled with FOOTERS==1, mspace_free is not actually needed. free may be called instead of mspace_free because freed chunks from any space are handled by their originating spaces. */ void mspace_free(mspace msp, void *mem); /* mspace_realloc behaves as realloc, but operates within the given space. If compiled with FOOTERS==1, mspace_realloc is not actually needed. realloc may be called instead of mspace_realloc because realloced chunks from any space are handled by their originating spaces. */ void *mspace_realloc(mspace msp, void *mem, size_t newsize); /* mspace_calloc behaves as calloc, but operates within the given space. */ void *mspace_calloc(mspace msp, size_t n_elements, size_t elem_size); /* mspace_memalign behaves as memalign, but operates within the given space. */ void *mspace_memalign(mspace msp, size_t alignment, size_t bytes); /* mspace_independent_calloc behaves as independent_calloc, but operates within the given space. */ void **mspace_independent_calloc(mspace msp, size_t n_elements, size_t elem_size, void *chunks[]); /* mspace_independent_comalloc behaves as independent_comalloc, but operates within the given space. */ void **mspace_independent_comalloc(mspace msp, size_t n_elements, size_t sizes[], void *chunks[]); /* mspace_footprint() returns the number of bytes obtained from the system for this space. */ size_t mspace_footprint(mspace msp); /* mspace_max_footprint() returns the peak number of bytes obtained from the system for this space. */ size_t mspace_max_footprint(mspace msp); #if !NO_MALLINFO /* mspace_mallinfo behaves as mallinfo, but reports properties of the given space. */ struct mallinfo mspace_mallinfo(mspace msp); #endif /* NO_MALLINFO */ /* mspace_malloc_stats behaves as malloc_stats, but reports properties of the given space. */ void mspace_malloc_stats(mspace msp); /* mspace_trim behaves as malloc_trim, but operates within the given space. */ int mspace_trim(mspace msp, size_t pad); /* An alias for mallopt. */ int mspace_mallopt(int, int); #endif /* MSPACES */ #ifdef __cplusplus }; /* end of extern "C" */ #endif /* __cplusplus */ /* ======================================================================== To make a fully customizable malloc.h header file, cut everything above this line, put into file malloc.h, edit to suit, and #include it on the next line, as well as in programs that use this malloc. ======================================================================== */ /* #include "malloc.h" */ /*------------------------------ internal #includes ---------------------- */ #ifdef _MSC_VER #pragma warning( disable : 4146 ) /* no "unsigned" warnings */ #endif /* _MSC_VER */ #ifndef LACKS_STDIO_H #include <stdio.h> /* for printing in malloc_stats */ #endif #ifndef LACKS_ERRNO_H #include <errno.h> /* for MALLOC_FAILURE_ACTION */ #endif /* LACKS_ERRNO_H */ #if FOOTERS #include <time.h> /* for magic initialization */ #endif /* FOOTERS */ #ifndef LACKS_STDLIB_H #include <stdlib.h> /* for abort() */ #endif /* LACKS_STDLIB_H */ #ifdef DEBUG #if ABORT_ON_ASSERT_FAILURE #define assert(x) if(!(x)) ABORT #else /* ABORT_ON_ASSERT_FAILURE */ #include <assert.h> #endif /* ABORT_ON_ASSERT_FAILURE */ #else /* DEBUG */ #define assert(x) #endif /* DEBUG */ #ifndef LACKS_STRING_H #include <string.h> /* for memset etc */ #endif /* LACKS_STRING_H */ #if USE_BUILTIN_FFS #ifndef LACKS_STRINGS_H #include <strings.h> /* for ffs */ #endif /* LACKS_STRINGS_H */ #endif /* USE_BUILTIN_FFS */ #if HAVE_MMAP #ifndef LACKS_SYS_MMAN_H #include <sys/mman.h> /* for mmap */ #endif /* LACKS_SYS_MMAN_H */ #ifndef LACKS_FCNTL_H #include <fcntl.h> #endif /* LACKS_FCNTL_H */ #endif /* HAVE_MMAP */ #if HAVE_MORECORE #ifndef LACKS_UNISTD_H #include <unistd.h> /* for sbrk */ #else /* LACKS_UNISTD_H */ #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) extern void *sbrk(ptrdiff_t); #endif /* FreeBSD etc */ #endif /* LACKS_UNISTD_H */ #endif /* HAVE_MMAP */ #ifndef WIN32 #ifndef malloc_getpagesize # ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ # ifndef _SC_PAGE_SIZE # define _SC_PAGE_SIZE _SC_PAGESIZE # endif # endif # ifdef _SC_PAGE_SIZE # define malloc_getpagesize sysconf(_SC_PAGE_SIZE) # else # if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) extern size_t getpagesize(); # define malloc_getpagesize getpagesize() # else # ifdef WIN32 /* use supplied emulation of getpagesize */ # define malloc_getpagesize getpagesize() # else # ifndef LACKS_SYS_PARAM_H # include <sys/param.h> # endif # ifdef EXEC_PAGESIZE # define malloc_getpagesize EXEC_PAGESIZE # else # ifdef NBPG # ifndef CLSIZE # define malloc_getpagesize NBPG # else # define malloc_getpagesize (NBPG * CLSIZE) # endif # else # ifdef NBPC # define malloc_getpagesize NBPC # else # ifdef PAGESIZE # define malloc_getpagesize PAGESIZE # else /* just guess */ # define malloc_getpagesize ((size_t)4096U) # endif # endif # endif # endif # endif # endif # endif #endif #endif /* ------------------- size_t and alignment properties -------------------- */ /* The byte and bit size of a size_t */ #define SIZE_T_SIZE (sizeof(size_t)) #define SIZE_T_BITSIZE (sizeof(size_t) << 3) /* Some constants coerced to size_t */ /* Annoying but necessary to avoid errors on some plaftorms */ #define SIZE_T_ZERO ((size_t)0) #define SIZE_T_ONE ((size_t)1) #define SIZE_T_TWO ((size_t)2) #define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) #define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) #define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) #define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U) /* The bit mask value corresponding to MALLOC_ALIGNMENT */ #define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) /* True if address a has acceptable alignment */ #define is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0) /* the number of bytes to offset an address to align it */ #define align_offset(A)\ ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\ ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK)) /* -------------------------- MMAP preliminaries ------------------------- */ /* If HAVE_MORECORE or HAVE_MMAP are false, we just define calls and checks to fail so compiler optimizer can delete code rather than using so many "#if"s. */ /* MORECORE and MMAP must return MFAIL on failure */ #define MFAIL ((void*)(MAX_SIZE_T)) #define CMFAIL ((char*)(MFAIL)) /* defined for convenience */ #if !HAVE_MMAP #define IS_MMAPPED_BIT (SIZE_T_ZERO) #define USE_MMAP_BIT (SIZE_T_ZERO) #define CALL_MMAP(s) MFAIL #define CALL_MUNMAP(a, s) (-1) #define DIRECT_MMAP(s) MFAIL #else /* HAVE_MMAP */ #define IS_MMAPPED_BIT (SIZE_T_ONE) #define USE_MMAP_BIT (SIZE_T_ONE) #if !defined(WIN32) && !defined (__OS2__) #define CALL_MUNMAP(a, s) munmap((a), (s)) #define MMAP_PROT (PROT_READ|PROT_WRITE) #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) #define MAP_ANONYMOUS MAP_ANON #endif /* MAP_ANON */ #ifdef MAP_ANONYMOUS #define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) #define CALL_MMAP(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0) #else /* MAP_ANONYMOUS */ /* Nearly all versions of mmap support MAP_ANONYMOUS, so the following is unlikely to be needed, but is supplied just in case. */ #define MMAP_FLAGS (MAP_PRIVATE) static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ #define CALL_MMAP(s) ((dev_zero_fd < 0) ? \ (dev_zero_fd = open("/dev/zero", O_RDWR), \ mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \ mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) #endif /* MAP_ANONYMOUS */ #define DIRECT_MMAP(s) CALL_MMAP(s) #elif defined(__OS2__) /* OS/2 MMAP via DosAllocMem */ static void* os2mmap(size_t size) { void* ptr; if (DosAllocMem(&ptr, size, OBJ_ANY|PAG_COMMIT|PAG_READ|PAG_WRITE) && DosAllocMem(&ptr, size, PAG_COMMIT|PAG_READ|PAG_WRITE)) return MFAIL; return ptr; } #define os2direct_mmap(n) os2mmap(n) /* This function supports releasing coalesed segments */ static int os2munmap(void* ptr, size_t size) { while (size) { ULONG ulSize = size; ULONG ulFlags = 0; if (DosQueryMem(ptr, &ulSize, &ulFlags) != 0) return -1; if ((ulFlags & PAG_BASE) == 0 ||(ulFlags & PAG_COMMIT) == 0 || ulSize > size) return -1; if (DosFreeMem(ptr) != 0) return -1; ptr = ( void * ) ( ( char * ) ptr + ulSize ); size -= ulSize; } return 0; } #define CALL_MMAP(s) os2mmap(s) #define CALL_MUNMAP(a, s) os2munmap((a), (s)) #define DIRECT_MMAP(s) os2direct_mmap(s) #else /* WIN32 */ /* Win32 MMAP via VirtualAlloc */ static void * win32mmap(size_t size) { void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); return (ptr != 0) ? ptr : MFAIL; } /* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ static void * win32direct_mmap(size_t size) { void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE); return (ptr != 0) ? ptr : MFAIL; } /* This function supports releasing coalesed segments */ static int win32munmap(void *ptr, size_t size) { MEMORY_BASIC_INFORMATION minfo; char *cptr = ptr; while (size) { if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) return -1; if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || minfo.State != MEM_COMMIT || minfo.RegionSize > size) return -1; if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) return -1; cptr += minfo.RegionSize; size -= minfo.RegionSize; } return 0; } #define CALL_MMAP(s) win32mmap(s) #define CALL_MUNMAP(a, s) win32munmap((a), (s)) #define DIRECT_MMAP(s) win32direct_mmap(s) #endif /* WIN32 */ #endif /* HAVE_MMAP */ #if HAVE_MMAP && HAVE_MREMAP #define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) #else /* HAVE_MMAP && HAVE_MREMAP */ #define CALL_MREMAP(addr, osz, nsz, mv) MFAIL #endif /* HAVE_MMAP && HAVE_MREMAP */ #if HAVE_MORECORE #define CALL_MORECORE(S) MORECORE(S) #else /* HAVE_MORECORE */ #define CALL_MORECORE(S) MFAIL #endif /* HAVE_MORECORE */ /* mstate bit set if continguous morecore disabled or failed */ #define USE_NONCONTIGUOUS_BIT (4U) /* segment bit set in create_mspace_with_base */ #define EXTERN_BIT (8U) /* --------------------------- Lock preliminaries ------------------------ */ #if USE_LOCKS /* When locks are defined, there are up to two global locks: * If HAVE_MORECORE, morecore_mutex protects sequences of calls to MORECORE. In many cases sys_alloc requires two calls, that should not be interleaved with calls by other threads. This does not protect against direct calls to MORECORE by other threads not using this lock, so there is still code to cope the best we can on interference. * magic_init_mutex ensures that mparams.magic and other unique mparams values are initialized only once. */ #if !defined(WIN32) && !defined(__OS2__) /* By default use posix locks */ #ifdef __ALIOS__ #include <posix/pthread.h> #else #include <pthread.h> #endif #define MLOCK_T pthread_mutex_t #define INITIAL_LOCK(l) pthread_mutex_init(l, NULL) #define ACQUIRE_LOCK(l) pthread_mutex_lock(l) #define RELEASE_LOCK(l) pthread_mutex_unlock(l) #if HAVE_MORECORE static MLOCK_T morecore_mutex = PTHREAD_MUTEX_INITIALIZER; #endif /* HAVE_MORECORE */ static MLOCK_T magic_init_mutex = PTHREAD_MUTEX_INITIALIZER; #elif defined(__OS2__) #define MLOCK_T HMTX #define INITIAL_LOCK(l) DosCreateMutexSem(0, l, 0, FALSE) #define ACQUIRE_LOCK(l) DosRequestMutexSem(*l, SEM_INDEFINITE_WAIT) #define RELEASE_LOCK(l) DosReleaseMutexSem(*l) #if HAVE_MORECORE static MLOCK_T morecore_mutex; #endif /* HAVE_MORECORE */ static MLOCK_T magic_init_mutex; #else /* WIN32 */ /* Because lock-protected regions have bounded times, and there are no recursive lock calls, we can use simple spinlocks. */ #define MLOCK_T long static int win32_acquire_lock(MLOCK_T * sl) { for (;;) { #ifdef InterlockedCompareExchangePointer if (!InterlockedCompareExchange(sl, 1, 0)) return 0; #else /* Use older void* version */ if (!InterlockedCompareExchange((void **) sl, (void *) 1, (void *) 0)) return 0; #endif /* InterlockedCompareExchangePointer */ Sleep(0); } } static void win32_release_lock(MLOCK_T * sl) { InterlockedExchange(sl, 0); } #define INITIAL_LOCK(l) *(l)=0 #define ACQUIRE_LOCK(l) win32_acquire_lock(l) #define RELEASE_LOCK(l) win32_release_lock(l) #if HAVE_MORECORE static MLOCK_T morecore_mutex; #endif /* HAVE_MORECORE */ static MLOCK_T magic_init_mutex; #endif /* WIN32 */ #define USE_LOCK_BIT (2U) #else /* USE_LOCKS */ #define USE_LOCK_BIT (0U) #define INITIAL_LOCK(l) #endif /* USE_LOCKS */ #if USE_LOCKS && HAVE_MORECORE #define ACQUIRE_MORECORE_LOCK() ACQUIRE_LOCK(&morecore_mutex); #define RELEASE_MORECORE_LOCK() RELEASE_LOCK(&morecore_mutex); #else /* USE_LOCKS && HAVE_MORECORE */ #define ACQUIRE_MORECORE_LOCK() #define RELEASE_MORECORE_LOCK() #endif /* USE_LOCKS && HAVE_MORECORE */ #if USE_LOCKS #define ACQUIRE_MAGIC_INIT_LOCK() ACQUIRE_LOCK(&magic_init_mutex); #define RELEASE_MAGIC_INIT_LOCK() RELEASE_LOCK(&magic_init_mutex); #else /* USE_LOCKS */ #define ACQUIRE_MAGIC_INIT_LOCK() #define RELEASE_MAGIC_INIT_LOCK() #endif /* USE_LOCKS */ /* ----------------------- Chunk representations ------------------------ */ /* (The following includes lightly edited explanations by Colin Plumb.) The malloc_chunk declaration below is misleading (but accurate and necessary). It declares a "view" into memory allowing access to necessary fields at known offsets from a given base. Chunks of memory are maintained using a `boundary tag' method as originally described by Knuth. (See the paper by Paul Wilson ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such techniques.) Sizes of free chunks are stored both in the front of each chunk and at the end. This makes consolidating fragmented chunks into bigger chunks fast. The head fields also hold bits representing whether chunks are free or in use. Here are some pictures to make it clearer. They are "exploded" to show that the state of a chunk can be thought of as extending from the high 31 bits of the head field of its header through the prev_foot and PINUSE_BIT bit of the following chunk header. A chunk that's in use looks like: chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of previous chunk (if P = 1) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| | Size of this chunk 1| +-+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | +- -+ | | +- -+ | : +- size - sizeof(size_t) available payload bytes -+ : | chunk-> +- -+ | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1| | Size of next chunk (may or may not be in use) | +-+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ And if it's free, it looks like this: chunk-> +- -+ | User payload (must be in use, or we would have merged!) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| | Size of this chunk 0| +-+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Next pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Prev pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | : +- size - sizeof(struct chunk) unused bytes -+ : | chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of this chunk | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0| | Size of next chunk (must be in use, or we would have merged)| +-+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | : +- User payload -+ : | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0| +-+ Note that since we always merge adjacent free chunks, the chunks adjacent to a free chunk must be in use. Given a pointer to a chunk (which can be derived trivially from the payload pointer) we can, in O(1) time, find out whether the adjacent chunks are free, and if so, unlink them from the lists that they are on and merge them with the current chunk. Chunks always begin on even word boundaries, so the mem portion (which is returned to the user) is also on an even word boundary, and thus at least double-word aligned. The P (PINUSE_BIT) bit, stored in the unused low-order bit of the chunk size (which is always a multiple of two words), is an in-use bit for the *previous* chunk. If that bit is *clear*, then the word before the current chunk size contains the previous chunk size, and can be used to find the front of the previous chunk. The very first chunk allocated always has this bit set, preventing access to non-existent (or non-owned) memory. If pinuse is set for any given chunk, then you CANNOT determine the size of the previous chunk, and might even get a memory addressing fault when trying to do so. The C (CINUSE_BIT) bit, stored in the unused second-lowest bit of the chunk size redundantly records whether the current chunk is inuse. This redundancy enables usage checks within free and realloc, and reduces indirection when freeing and consolidating chunks. Each freshly allocated chunk must have both cinuse and pinuse set. That is, each allocated chunk borders either a previously allocated and still in-use chunk, or the base of its memory arena. This is ensured by making all allocations from the the `lowest' part of any found chunk. Further, no free chunk physically borders another one, so each free chunk is known to be preceded and followed by either inuse chunks or the ends of memory. Note that the `foot' of the current chunk is actually represented as the prev_foot of the NEXT chunk. This makes it easier to deal with alignments etc but can be very confusing when trying to extend or adapt this code. The exceptions to all this are 1. The special chunk `top' is the top-most available chunk (i.e., the one bordering the end of available memory). It is treated specially. Top is never included in any bin, is used only if no other chunk is available, and is released back to the system if it is very large (see M_TRIM_THRESHOLD). In effect, the top chunk is treated as larger (and thus less well fitting) than any other available chunk. The top chunk doesn't update its trailing size field since there is no next contiguous chunk that would have to index off it. However, space is still allocated for it (TOP_FOOT_SIZE) to enable separation or merging when space is extended. 3. Chunks allocated via mmap, which have the lowest-order bit (IS_MMAPPED_BIT) set in their prev_foot fields, and do not set PINUSE_BIT in their head fields. Because they are allocated one-by-one, each must carry its own prev_foot field, which is also used to hold the offset this chunk has within its mmapped region, which is needed to preserve alignment. Each mmapped chunk is trailed by the first two fields of a fake next-chunk for sake of usage checks. */ struct malloc_chunk { size_t prev_foot; /* Size of previous chunk (if free). */ size_t head; /* Size and inuse bits. */ struct malloc_chunk *fd; /* double links -- used only if free. */ struct malloc_chunk *bk; }; typedef struct malloc_chunk mchunk; typedef struct malloc_chunk *mchunkptr; typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */ typedef size_t bindex_t; /* Described below */ typedef unsigned int binmap_t; /* Described below */ typedef unsigned int flag_t; /* The type of various bit flag sets */ /* ------------------- Chunks sizes and alignments ----------------------- */ #define MCHUNK_SIZE (sizeof(mchunk)) #if FOOTERS #define CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) #else /* FOOTERS */ #define CHUNK_OVERHEAD (SIZE_T_SIZE) #endif /* FOOTERS */ /* MMapped chunks need a second word of overhead ... */ #define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) /* ... and additional padding for fake next-chunk at foot */ #define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES) /* The smallest size we can malloc is an aligned minimal chunk */ #define MIN_CHUNK_SIZE\ ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) /* conversion from malloc headers to user pointers, and back */ #define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES)) #define mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES)) /* chunk associated with aligned address A */ #define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) /* Bounds on request (not chunk) sizes. */ #define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2) #define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) /* pad request bytes into a usable size */ #define pad_request(req) \ (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) /* pad request, checking for minimum (but not maximum) */ #define request2size(req) \ (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) /* ------------------ Operations on head and foot fields ----------------- */ /* The head field of a chunk is or'ed with PINUSE_BIT when previous adjacent chunk in use, and or'ed with CINUSE_BIT if this chunk is in use. If the chunk was obtained with mmap, the prev_foot field has IS_MMAPPED_BIT set, otherwise holding the offset of the base of the mmapped region to the base of the chunk. */ #define PINUSE_BIT (SIZE_T_ONE) #define CINUSE_BIT (SIZE_T_TWO) #define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) /* Head value for fenceposts */ #define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) /* extraction of fields from head words */ #define cinuse(p) ((p)->head & CINUSE_BIT) #define pinuse(p) ((p)->head & PINUSE_BIT) #define chunksize(p) ((p)->head & ~(INUSE_BITS)) #define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) #define clear_cinuse(p) ((p)->head &= ~CINUSE_BIT) /* Treat space at ptr +/- offset as a chunk */ #define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) #define chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s))) /* Ptr to next or previous physical malloc_chunk. */ #define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~INUSE_BITS))) #define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) )) /* extract next chunk's pinuse bit */ #define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) /* Get/set size at footer */ #define get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot) #define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s)) /* Set size, pinuse bit, and foot */ #define set_size_and_pinuse_of_free_chunk(p, s)\ ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) /* Set size, pinuse bit, foot, and clear next pinuse */ #define set_free_with_pinuse(p, s, n)\ (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) #define is_mmapped(p)\ (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT)) /* Get the internal overhead associated with chunk p */ #define overhead_for(p)\ (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD) /* Return true if malloced space is not necessarily cleared */ #if MMAP_CLEARS #define calloc_must_clear(p) (!is_mmapped(p)) #else /* MMAP_CLEARS */ #define calloc_must_clear(p) (1) #endif /* MMAP_CLEARS */ /* ---------------------- Overlaid data structures ----------------------- */ /* When chunks are not in use, they are treated as nodes of either lists or trees. "Small" chunks are stored in circular doubly-linked lists, and look like this: chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of previous chunk | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `head:' | Size of chunk, in bytes |P| mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Forward pointer to next chunk in list | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Back pointer to previous chunk in list | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Unused space (may be 0 bytes long) . . . . | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `foot:' | Size of chunk, in bytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Larger chunks are kept in a form of bitwise digital trees (aka tries) keyed on chunksizes. Because malloc_tree_chunks are only for free chunks greater than 256 bytes, their size doesn't impose any constraints on user chunk sizes. Each node looks like: chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of previous chunk | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `head:' | Size of chunk, in bytes |P| mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Forward pointer to next chunk of same size | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Back pointer to previous chunk of same size | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Pointer to left child (child[0]) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Pointer to right child (child[1]) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Pointer to parent | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | bin index of this chunk | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Unused space . . | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `foot:' | Size of chunk, in bytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Each tree holding treenodes is a tree of unique chunk sizes. Chunks of the same size are arranged in a circularly-linked list, with only the oldest chunk (the next to be used, in our FIFO ordering) actually in the tree. (Tree members are distinguished by a non-null parent pointer.) If a chunk with the same size an an existing node is inserted, it is linked off the existing node using pointers that work in the same way as fd/bk pointers of small chunks. Each tree contains a power of 2 sized range of chunk sizes (the smallest is 0x100 <= x < 0x180), which is is divided in half at each tree level, with the chunks in the smaller half of the range (0x100 <= x < 0x140 for the top nose) in the left subtree and the larger half (0x140 <= x < 0x180) in the right subtree. This is, of course, done by inspecting individual bits. Using these rules, each node's left subtree contains all smaller sizes than its right subtree. However, the node at the root of each subtree has no particular ordering relationship to either. (The dividing line between the subtree sizes is based on trie relation.) If we remove the last chunk of a given size from the interior of the tree, we need to replace it with a leaf node. The tree ordering rules permit a node to be replaced by any leaf below it. The smallest chunk in a tree (a common operation in a best-fit allocator) can be found by walking a path to the leftmost leaf in the tree. Unlike a usual binary tree, where we follow left child pointers until we reach a null, here we follow the right child pointer any time the left one is null, until we reach a leaf with both child pointers null. The smallest chunk in the tree will be somewhere along that path. The worst case number of steps to add, find, or remove a node is bounded by the number of bits differentiating chunks within bins. Under current bin calculations, this ranges from 6 up to 21 (for 32 bit sizes) or up to 53 (for 64 bit sizes). The typical case is of course much better. */ struct malloc_tree_chunk { /* The first four fields must be compatible with malloc_chunk */ size_t prev_foot; size_t head; struct malloc_tree_chunk *fd; struct malloc_tree_chunk *bk; struct malloc_tree_chunk *child[2]; struct malloc_tree_chunk *parent; bindex_t index; }; typedef struct malloc_tree_chunk tchunk; typedef struct malloc_tree_chunk *tchunkptr; typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */ /* A little helper macro for trees */ #define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) /* ----------------------------- Segments -------------------------------- */ /* Each malloc space may include non-contiguous segments, held in a list headed by an embedded malloc_segment record representing the top-most space. Segments also include flags holding properties of the space. Large chunks that are directly allocated by mmap are not included in this list. They are instead independently created and destroyed without otherwise keeping track of them. Segment management mainly comes into play for spaces allocated by MMAP. Any call to MMAP might or might not return memory that is adjacent to an existing segment. MORECORE normally contiguously extends the current space, so this space is almost always adjacent, which is simpler and faster to deal with. (This is why MORECORE is used preferentially to MMAP when both are available -- see sys_alloc.) When allocating using MMAP, we don't use any of the hinting mechanisms (inconsistently) supported in various implementations of unix mmap, or distinguish reserving from committing memory. Instead, we just ask for space, and exploit contiguity when we get it. It is probably possible to do better than this on some systems, but no general scheme seems to be significantly better. Management entails a simpler variant of the consolidation scheme used for chunks to reduce fragmentation -- new adjacent memory is normally prepended or appended to an existing segment. However, there are limitations compared to chunk consolidation that mostly reflect the fact that segment processing is relatively infrequent (occurring only when getting memory from system) and that we don't expect to have huge numbers of segments: * Segments are not indexed, so traversal requires linear scans. (It would be possible to index these, but is not worth the extra overhead and complexity for most programs on most platforms.) * New segments are only appended to old ones when holding top-most memory; if they cannot be prepended to others, they are held in different segments. Except for the top-most segment of an mstate, each segment record is kept at the tail of its segment. Segments are added by pushing segment records onto the list headed by &mstate.seg for the containing mstate. Segment flags control allocation/merge/deallocation policies: * If EXTERN_BIT set, then we did not allocate this segment, and so should not try to deallocate or merge with others. (This currently holds only for the initial segment passed into create_mspace_with_base.) * If IS_MMAPPED_BIT set, the segment may be merged with other surrounding mmapped segments and trimmed/de-allocated using munmap. * If neither bit is set, then the segment was obtained using MORECORE so can be merged with surrounding MORECORE'd segments and deallocated/trimmed using MORECORE with negative arguments. */ struct malloc_segment { char *base; /* base address */ size_t size; /* allocated size */ struct malloc_segment *next; /* ptr to next segment */ flag_t sflags; /* mmap and extern flag */ }; #define is_mmapped_segment(S) ((S)->sflags & IS_MMAPPED_BIT) #define is_extern_segment(S) ((S)->sflags & EXTERN_BIT) typedef struct malloc_segment msegment; typedef struct malloc_segment *msegmentptr; /* ---------------------------- malloc_state ----------------------------- */ /* A malloc_state holds all of the bookkeeping for a space. The main fields are: Top The topmost chunk of the currently active segment. Its size is cached in topsize. The actual size of topmost space is topsize+TOP_FOOT_SIZE, which includes space reserved for adding fenceposts and segment records if necessary when getting more space from the system. The size at which to autotrim top is cached from mparams in trim_check, except that it is disabled if an autotrim fails. Designated victim (dv) This is the preferred chunk for servicing small requests that don't have exact fits. It is normally the chunk split off most recently to service another small request. Its size is cached in dvsize. The link fields of this chunk are not maintained since it is not kept in a bin. SmallBins An array of bin headers for free chunks. These bins hold chunks with sizes less than MIN_LARGE_SIZE bytes. Each bin contains chunks of all the same size, spaced 8 bytes apart. To simplify use in double-linked lists, each bin header acts as a malloc_chunk pointing to the real first node, if it exists (else pointing to itself). This avoids special-casing for headers. But to avoid waste, we allocate only the fd/bk pointers of bins, and then use repositioning tricks to treat these as the fields of a chunk. TreeBins Treebins are pointers to the roots of trees holding a range of sizes. There are 2 equally spaced treebins for each power of two from TREE_SHIFT to TREE_SHIFT+16. The last bin holds anything larger. Bin maps There is one bit map for small bins ("smallmap") and one for treebins ("treemap). Each bin sets its bit when non-empty, and clears the bit when empty. Bit operations are then used to avoid bin-by-bin searching -- nearly all "search" is done without ever looking at bins that won't be selected. The bit maps conservatively use 32 bits per map word, even if on 64bit system. For a good description of some of the bit-based techniques used here, see Henry S. Warren Jr's book "Hacker's Delight" (and supplement at http://hackersdelight.org/). Many of these are intended to reduce the branchiness of paths through malloc etc, as well as to reduce the number of memory locations read or written. Segments A list of segments headed by an embedded malloc_segment record representing the initial space. Address check support The least_addr field is the least address ever obtained from MORECORE or MMAP. Attempted frees and reallocs of any address less than this are trapped (unless INSECURE is defined). Magic tag A cross-check field that should always hold same value as mparams.magic. Flags Bits recording whether to use MMAP, locks, or contiguous MORECORE Statistics Each space keeps track of current and maximum system memory obtained via MORECORE or MMAP. Locking If USE_LOCKS is defined, the "mutex" lock is acquired and released around every public call using this mspace. */ /* Bin types, widths and sizes */ #define NSMALLBINS (32U) #define NTREEBINS (32U) #define SMALLBIN_SHIFT (3U) #define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) #define TREEBIN_SHIFT (8U) #define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) #define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) #define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) struct malloc_state { binmap_t smallmap; binmap_t treemap; size_t dvsize; size_t topsize; char *least_addr; mchunkptr dv; mchunkptr top; size_t trim_check; size_t magic; mchunkptr smallbins[(NSMALLBINS + 1) * 2]; tbinptr treebins[NTREEBINS]; size_t footprint; size_t max_footprint; flag_t mflags; #if USE_LOCKS MLOCK_T mutex; /* locate lock among fields that rarely change */ #endif /* USE_LOCKS */ msegment seg; }; typedef struct malloc_state *mstate; /* ------------- Global malloc_state and malloc_params ------------------- */ /* malloc_params holds global properties, including those that can be dynamically set using mallopt. There is a single instance, mparams, initialized in init_mparams. */ struct malloc_params { size_t magic; size_t page_size; size_t granularity; size_t mmap_threshold; size_t trim_threshold; flag_t default_mflags; }; static struct malloc_params mparams; /* The global malloc_state used for all non-"mspace" calls */ static struct malloc_state _gm_; #define gm (&_gm_) #define is_global(M) ((M) == &_gm_) #define is_initialized(M) ((M)->top != 0) /* -------------------------- system alloc setup ------------------------- */ /* Operations on mflags */ #define use_lock(M) ((M)->mflags & USE_LOCK_BIT) #define enable_lock(M) ((M)->mflags |= USE_LOCK_BIT) #define disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT) #define use_mmap(M) ((M)->mflags & USE_MMAP_BIT) #define enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT) #define disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT) #define use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT) #define disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT) #define set_lock(M,L)\ ((M)->mflags = (L)?\ ((M)->mflags | USE_LOCK_BIT) :\ ((M)->mflags & ~USE_LOCK_BIT)) /* page-align a size */ #define page_align(S)\ (((S) + (mparams.page_size)) & ~(mparams.page_size - SIZE_T_ONE)) /* granularity-align a size */ #define granularity_align(S)\ (((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE)) #define is_page_aligned(S)\ (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0) #define is_granularity_aligned(S)\ (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0) /* True if segment S holds address A */ #define segment_holds(S, A)\ ((char*)(A) >= S->base && (char*)(A) < S->base + S->size) /* Return segment holding given address */ static msegmentptr segment_holding(mstate m, char *addr) { msegmentptr sp = &m->seg; for (;;) { if (addr >= sp->base && addr < sp->base + sp->size) return sp; if ((sp = sp->next) == 0) return 0; } } /* Return true if segment contains a segment link */ static int has_segment_link(mstate m, msegmentptr ss) { msegmentptr sp = &m->seg; for (;;) { if ((char *) sp >= ss->base && (char *) sp < ss->base + ss->size) return 1; if ((sp = sp->next) == 0) return 0; } } #ifndef MORECORE_CANNOT_TRIM #define should_trim(M,s) ((s) > (M)->trim_check) #else /* MORECORE_CANNOT_TRIM */ #define should_trim(M,s) (0) #endif /* MORECORE_CANNOT_TRIM */ /* TOP_FOOT_SIZE is padding at the end of a segment, including space that may be needed to place segment records and fenceposts when new noncontiguous segments are added. */ #define TOP_FOOT_SIZE\ (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) /* ------------------------------- Hooks -------------------------------- */ /* PREACTION should be defined to return 0 on success, and nonzero on failure. If you are not using locking, you can redefine these to do anything you like. */ #if USE_LOCKS /* Ensure locks are initialized */ #define GLOBALLY_INITIALIZE() (mparams.page_size == 0 && init_mparams()) #define PREACTION(M) ((GLOBALLY_INITIALIZE() || use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0) #define POSTACTION(M) { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); } #else /* USE_LOCKS */ #ifndef PREACTION #define PREACTION(M) (0) #endif /* PREACTION */ #ifndef POSTACTION #define POSTACTION(M) #endif /* POSTACTION */ #endif /* USE_LOCKS */ /* CORRUPTION_ERROR_ACTION is triggered upon detected bad addresses. USAGE_ERROR_ACTION is triggered on detected bad frees and reallocs. The argument p is an address that might have triggered the fault. It is ignored by the two predefined actions, but might be useful in custom actions that try to help diagnose errors. */ #if PROCEED_ON_ERROR /* A count of the number of corruption errors causing resets */ int malloc_corruption_error_count; /* default corruption action */ static void reset_on_error(mstate m); #define CORRUPTION_ERROR_ACTION(m) reset_on_error(m) #define USAGE_ERROR_ACTION(m, p) #else /* PROCEED_ON_ERROR */ #ifndef CORRUPTION_ERROR_ACTION #define CORRUPTION_ERROR_ACTION(m) ABORT #endif /* CORRUPTION_ERROR_ACTION */ #ifndef USAGE_ERROR_ACTION #define USAGE_ERROR_ACTION(m,p) ABORT #endif /* USAGE_ERROR_ACTION */ #endif /* PROCEED_ON_ERROR */ /* -------------------------- Debugging setup ---------------------------- */ #if ! DEBUG #define check_free_chunk(M,P) #define check_inuse_chunk(M,P) #define check_malloced_chunk(M,P,N) #define check_mmapped_chunk(M,P) #define check_malloc_state(M) #define check_top_chunk(M,P) #else /* DEBUG */ #define check_free_chunk(M,P) do_check_free_chunk(M,P) #define check_inuse_chunk(M,P) do_check_inuse_chunk(M,P) #define check_top_chunk(M,P) do_check_top_chunk(M,P) #define check_malloced_chunk(M,P,N) do_check_malloced_chunk(M,P,N) #define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P) #define check_malloc_state(M) do_check_malloc_state(M) static void do_check_any_chunk(mstate m, mchunkptr p); static void do_check_top_chunk(mstate m, mchunkptr p); static void do_check_mmapped_chunk(mstate m, mchunkptr p); static void do_check_inuse_chunk(mstate m, mchunkptr p); static void do_check_free_chunk(mstate m, mchunkptr p); static void do_check_malloced_chunk(mstate m, void *mem, size_t s); static void do_check_tree(mstate m, tchunkptr t); static void do_check_treebin(mstate m, bindex_t i); static void do_check_smallbin(mstate m, bindex_t i); static void do_check_malloc_state(mstate m); static int bin_find(mstate m, mchunkptr x); static size_t traverse_and_check(mstate m); #endif /* DEBUG */ /* ---------------------------- Indexing Bins ---------------------------- */ #define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) #define small_index(s) ((s) >> SMALLBIN_SHIFT) #define small_index2size(i) ((i) << SMALLBIN_SHIFT) #define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) /* addressing by index. See above about smallbin repositioning */ #define smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1]))) #define treebin_at(M,i) (&((M)->treebins[i])) /* assign tree index for size S to variable I */ #if defined(__GNUC__) && defined(i386) #define compute_tree_index(S, I)\ {\ size_t X = S >> TREEBIN_SHIFT;\ if (X == 0)\ I = 0;\ else if (X > 0xFFFF)\ I = NTREEBINS-1;\ else {\ unsigned int K;\ __asm__("bsrl %1,%0\n\t" : "=r" (K) : "rm" (X));\ I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ }\ } #else /* GNUC */ #define compute_tree_index(S, I)\ {\ size_t X = S >> TREEBIN_SHIFT;\ if (X == 0)\ I = 0;\ else if (X > 0xFFFF)\ I = NTREEBINS-1;\ else {\ unsigned int Y = (unsigned int)X;\ unsigned int N = ((Y - 0x100) >> 16) & 8;\ unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\ N += K;\ N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\ K = 14 - N + ((Y <<= K) >> 15);\ I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\ }\ } #endif /* GNUC */ /* Bit representing maximum resolved size in a treebin at i */ #define bit_for_tree_index(i) \ (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) /* Shift placing maximum resolved bit in a treebin at i as sign bit */ #define leftshift_for_tree_index(i) \ ((i == NTREEBINS-1)? 0 : \ ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2))) /* The size of the smallest chunk held in bin with index i */ #define minsize_for_tree_index(i) \ ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \ (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1))) /* ------------------------ Operations on bin maps ----------------------- */ /* bit corresponding to given index */ #define idx2bit(i) ((binmap_t)(1) << (i)) /* Mark/Clear bits with given index */ #define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i)) #define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i)) #define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i)) #define mark_treemap(M,i) ((M)->treemap |= idx2bit(i)) #define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i)) #define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i)) /* index corresponding to given bit */ #if defined(__GNUC__) && defined(i386) #define compute_bit2idx(X, I)\ {\ unsigned int J;\ __asm__("bsfl %1,%0\n\t" : "=r" (J) : "rm" (X));\ I = (bindex_t)J;\ } #else /* GNUC */ #if USE_BUILTIN_FFS #define compute_bit2idx(X, I) I = ffs(X)-1 #else /* USE_BUILTIN_FFS */ #define compute_bit2idx(X, I)\ {\ unsigned int Y = X - 1;\ unsigned int K = Y >> (16-4) & 16;\ unsigned int N = K; Y >>= K;\ N += K = Y >> (8-3) & 8; Y >>= K;\ N += K = Y >> (4-2) & 4; Y >>= K;\ N += K = Y >> (2-1) & 2; Y >>= K;\ N += K = Y >> (1-0) & 1; Y >>= K;\ I = (bindex_t)(N + Y);\ } #endif /* USE_BUILTIN_FFS */ #endif /* GNUC */ /* isolate the least set bit of a bitmap */ #define least_bit(x) ((x) & -(x)) /* mask with all bits to left of least bit of x on */ #define left_bits(x) ((x<<1) | -(x<<1)) /* mask with all bits to left of or equal to least bit of x on */ #define same_or_left_bits(x) ((x) | -(x)) /* ----------------------- Runtime Check Support ------------------------- */ /* For security, the main invariant is that malloc/free/etc never writes to a static address other than malloc_state, unless static malloc_state itself has been corrupted, which cannot occur via malloc (because of these checks). In essence this means that we believe all pointers, sizes, maps etc held in malloc_state, but check all of those linked or offsetted from other embedded data structures. These checks are interspersed with main code in a way that tends to minimize their run-time cost. When FOOTERS is defined, in addition to range checking, we also verify footer fields of inuse chunks, which can be used guarantee that the mstate controlling malloc/free is intact. This is a streamlined version of the approach described by William Robertson et al in "Run-time Detection of Heap-based Overflows" LISA'03 http://www.usenix.org/events/lisa03/tech/robertson.html The footer of an inuse chunk holds the xor of its mstate and a random seed, that is checked upon calls to free() and realloc(). This is (probablistically) unguessable from outside the program, but can be computed by any code successfully malloc'ing any chunk, so does not itself provide protection against code that has already broken security through some other means. Unlike Robertson et al, we always dynamically check addresses of all offset chunks (previous, next, etc). This turns out to be cheaper than relying on hashes. */ #if !INSECURE /* Check if address a is at least as high as any from MORECORE or MMAP */ #define ok_address(M, a) ((char*)(a) >= (M)->least_addr) /* Check if address of next chunk n is higher than base chunk p */ #define ok_next(p, n) ((char*)(p) < (char*)(n)) /* Check if p has its cinuse bit on */ #define ok_cinuse(p) cinuse(p) /* Check if p has its pinuse bit on */ #define ok_pinuse(p) pinuse(p) #else /* !INSECURE */ #define ok_address(M, a) (1) #define ok_next(b, n) (1) #define ok_cinuse(p) (1) #define ok_pinuse(p) (1) #endif /* !INSECURE */ #if (FOOTERS && !INSECURE) /* Check if (alleged) mstate m has expected magic field */ #define ok_magic(M) ((M)->magic == mparams.magic) #else /* (FOOTERS && !INSECURE) */ #define ok_magic(M) (1) #endif /* (FOOTERS && !INSECURE) */ /* In gcc, use __builtin_expect to minimize impact of checks */ #if !INSECURE #if defined(__GNUC__) && __GNUC__ >= 3 #define RTCHECK(e) __builtin_expect(e, 1) #else /* GNUC */ #define RTCHECK(e) (e) #endif /* GNUC */ #else /* !INSECURE */ #define RTCHECK(e) (1) #endif /* !INSECURE */ /* macros to set up inuse chunks with or without footers */ #if !FOOTERS #define mark_inuse_foot(M,p,s) /* Set cinuse bit and pinuse bit of next chunk */ #define set_inuse(M,p,s)\ ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) /* Set cinuse and pinuse of this chunk and pinuse of next chunk */ #define set_inuse_and_pinuse(M,p,s)\ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) /* Set size, cinuse and pinuse bit of this chunk */ #define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) #else /* FOOTERS */ /* Set foot of inuse chunk to be xor of mstate and seed */ #define mark_inuse_foot(M,p,s)\ (((mchunkptr)((char*)(p) + (s)))->prev_foot = ((size_t)(M) ^ mparams.magic)) #define get_mstate_for(p)\ ((mstate)(((mchunkptr)((char*)(p) +\ (chunksize(p))))->prev_foot ^ mparams.magic)) #define set_inuse(M,p,s)\ ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT), \ mark_inuse_foot(M,p,s)) #define set_inuse_and_pinuse(M,p,s)\ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT),\ mark_inuse_foot(M,p,s)) #define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ mark_inuse_foot(M, p, s)) #endif /* !FOOTERS */ /* ---------------------------- setting mparams -------------------------- */ /* Initialize mparams */ static int init_mparams(void) { if (mparams.page_size == 0) { size_t s; mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; #if MORECORE_CONTIGUOUS mparams.default_mflags = USE_LOCK_BIT | USE_MMAP_BIT; #else /* MORECORE_CONTIGUOUS */ mparams.default_mflags = USE_LOCK_BIT | USE_MMAP_BIT | USE_NONCONTIGUOUS_BIT; #endif /* MORECORE_CONTIGUOUS */ #if (FOOTERS && !INSECURE) { #if USE_DEV_RANDOM int fd; unsigned char buf[sizeof(size_t)]; /* Try to use /dev/urandom, else fall back on using time */ if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 && read(fd, buf, sizeof(buf)) == sizeof(buf)) { s = *((size_t *) buf); close(fd); } else #endif /* USE_DEV_RANDOM */ s = (size_t) (time(0) ^ (size_t) 0x55555555U); s |= (size_t) 8U; /* ensure nonzero */ s &= ~(size_t) 7U; /* improve chances of fault for bad values */ } #else /* (FOOTERS && !INSECURE) */ s = (size_t) 0x58585858U; #endif /* (FOOTERS && !INSECURE) */ ACQUIRE_MAGIC_INIT_LOCK(); if (mparams.magic == 0) { mparams.magic = s; /* Set up lock for main malloc area */ INITIAL_LOCK(&gm->mutex); gm->mflags = mparams.default_mflags; } RELEASE_MAGIC_INIT_LOCK(); #if !defined(WIN32) && !defined(__OS2__) mparams.page_size = malloc_getpagesize; mparams.granularity = ((DEFAULT_GRANULARITY != 0) ? DEFAULT_GRANULARITY : mparams.page_size); #elif defined (__OS2__) /* if low-memory is used, os2munmap() would break if it were anything other than 64k */ mparams.page_size = 4096u; mparams.granularity = 65536u; #else /* WIN32 */ { SYSTEM_INFO system_info; GetSystemInfo(&system_info); mparams.page_size = system_info.dwPageSize; mparams.granularity = system_info.dwAllocationGranularity; } #endif /* WIN32 */ /* Sanity-check configuration: size_t must be unsigned and as wide as pointer type. ints must be at least 4 bytes. alignment must be at least 8. Alignment, min chunk size, and page size must all be powers of 2. */ if ((sizeof(size_t) != sizeof(char *)) || (MAX_SIZE_T < MIN_CHUNK_SIZE) || (sizeof(int) < 4) || (MALLOC_ALIGNMENT < (size_t) 8U) || ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT - SIZE_T_ONE)) != 0) || ((MCHUNK_SIZE & (MCHUNK_SIZE - SIZE_T_ONE)) != 0) || ((mparams.granularity & (mparams.granularity - SIZE_T_ONE)) != 0) || ((mparams.page_size & (mparams.page_size - SIZE_T_ONE)) != 0)) ABORT; } return 0; } /* support for mallopt */ static int change_mparam(int param_number, int value) { size_t val = (size_t) value; init_mparams(); switch (param_number) { case M_TRIM_THRESHOLD: mparams.trim_threshold = val; return 1; case M_GRANULARITY: if (val >= mparams.page_size && ((val & (val - 1)) == 0)) { mparams.granularity = val; return 1; } else return 0; case M_MMAP_THRESHOLD: mparams.mmap_threshold = val; return 1; default: return 0; } } #if DEBUG /* ------------------------- Debugging Support --------------------------- */ /* Check properties of any chunk, whether free, inuse, mmapped etc */ static void do_check_any_chunk(mstate m, mchunkptr p) { assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); assert(ok_address(m, p)); } /* Check properties of top chunk */ static void do_check_top_chunk(mstate m, mchunkptr p) { msegmentptr sp = segment_holding(m, (char *) p); size_t sz = chunksize(p); assert(sp != 0); assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); assert(ok_address(m, p)); assert(sz == m->topsize); assert(sz > 0); assert(sz == ((sp->base + sp->size) - (char *) p) - TOP_FOOT_SIZE); assert(pinuse(p)); assert(!next_pinuse(p)); } /* Check properties of (inuse) mmapped chunks */ static void do_check_mmapped_chunk(mstate m, mchunkptr p) { size_t sz = chunksize(p); size_t len = (sz + (p->prev_foot & ~IS_MMAPPED_BIT) + MMAP_FOOT_PAD); assert(is_mmapped(p)); assert(use_mmap(m)); assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); assert(ok_address(m, p)); assert(!is_small(sz)); assert((len & (mparams.page_size - SIZE_T_ONE)) == 0); assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD); assert(chunk_plus_offset(p, sz + SIZE_T_SIZE)->head == 0); } /* Check properties of inuse chunks */ static void do_check_inuse_chunk(mstate m, mchunkptr p) { do_check_any_chunk(m, p); assert(cinuse(p)); assert(next_pinuse(p)); /* If not pinuse and not mmapped, previous chunk has OK offset */ assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p); if (is_mmapped(p)) do_check_mmapped_chunk(m, p); } /* Check properties of free chunks */ static void do_check_free_chunk(mstate m, mchunkptr p) { size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT); mchunkptr next = chunk_plus_offset(p, sz); do_check_any_chunk(m, p); assert(!cinuse(p)); assert(!next_pinuse(p)); assert(!is_mmapped(p)); if (p != m->dv && p != m->top) { if (sz >= MIN_CHUNK_SIZE) { assert((sz & CHUNK_ALIGN_MASK) == 0); assert(is_aligned(chunk2mem(p))); assert(next->prev_foot == sz); assert(pinuse(p)); assert(next == m->top || cinuse(next)); assert(p->fd->bk == p); assert(p->bk->fd == p); } else /* markers are always of size SIZE_T_SIZE */ assert(sz == SIZE_T_SIZE); } } /* Check properties of malloced chunks at the point they are malloced */ static void do_check_malloced_chunk(mstate m, void *mem, size_t s) { if (mem != 0) { mchunkptr p = mem2chunk(mem); size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT); do_check_inuse_chunk(m, p); assert((sz & CHUNK_ALIGN_MASK) == 0); assert(sz >= MIN_CHUNK_SIZE); assert(sz >= s); /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */ assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE)); } } /* Check a tree and its subtrees. */ static void do_check_tree(mstate m, tchunkptr t) { tchunkptr head = 0; tchunkptr u = t; bindex_t tindex = t->index; size_t tsize = chunksize(t); bindex_t idx; compute_tree_index(tsize, idx); assert(tindex == idx); assert(tsize >= MIN_LARGE_SIZE); assert(tsize >= minsize_for_tree_index(idx)); assert((idx == NTREEBINS - 1) || (tsize < minsize_for_tree_index((idx + 1)))); do { /* traverse through chain of same-sized nodes */ do_check_any_chunk(m, ((mchunkptr) u)); assert(u->index == tindex); assert(chunksize(u) == tsize); assert(!cinuse(u)); assert(!next_pinuse(u)); assert(u->fd->bk == u); assert(u->bk->fd == u); if (u->parent == 0) { assert(u->child[0] == 0); assert(u->child[1] == 0); } else { assert(head == 0); /* only one node on chain has parent */ head = u; assert(u->parent != u); assert(u->parent->child[0] == u || u->parent->child[1] == u || *((tbinptr *) (u->parent)) == u); if (u->child[0] != 0) { assert(u->child[0]->parent == u); assert(u->child[0] != u); do_check_tree(m, u->child[0]); } if (u->child[1] != 0) { assert(u->child[1]->parent == u); assert(u->child[1] != u); do_check_tree(m, u->child[1]); } if (u->child[0] != 0 && u->child[1] != 0) { assert(chunksize(u->child[0]) < chunksize(u->child[1])); } } u = u->fd; } while (u != t); assert(head != 0); } /* Check all the chunks in a treebin. */ static void do_check_treebin(mstate m, bindex_t i) { tbinptr *tb = treebin_at(m, i); tchunkptr t = *tb; int empty = (m->treemap & (1U << i)) == 0; if (t == 0) assert(empty); if (!empty) do_check_tree(m, t); } /* Check all the chunks in a smallbin. */ static void do_check_smallbin(mstate m, bindex_t i) { sbinptr b = smallbin_at(m, i); mchunkptr p = b->bk; unsigned int empty = (m->smallmap & (1U << i)) == 0; if (p == b) assert(empty); if (!empty) { for (; p != b; p = p->bk) { size_t size = chunksize(p); mchunkptr q; /* each chunk claims to be free */ do_check_free_chunk(m, p); /* chunk belongs in bin */ assert(small_index(size) == i); assert(p->bk == b || chunksize(p->bk) == chunksize(p)); /* chunk is followed by an inuse chunk */ q = next_chunk(p); if (q->head != FENCEPOST_HEAD) do_check_inuse_chunk(m, q); } } } /* Find x in a bin. Used in other check functions. */ static int bin_find(mstate m, mchunkptr x) { size_t size = chunksize(x); if (is_small(size)) { bindex_t sidx = small_index(size); sbinptr b = smallbin_at(m, sidx); if (smallmap_is_marked(m, sidx)) { mchunkptr p = b; do { if (p == x) return 1; } while ((p = p->fd) != b); } } else { bindex_t tidx; compute_tree_index(size, tidx); if (treemap_is_marked(m, tidx)) { tchunkptr t = *treebin_at(m, tidx); size_t sizebits = size << leftshift_for_tree_index(tidx); while (t != 0 && chunksize(t) != size) { t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1]; sizebits <<= 1; } if (t != 0) { tchunkptr u = t; do { if (u == (tchunkptr) x) return 1; } while ((u = u->fd) != t); } } } return 0; } /* Traverse each chunk and check it; return total */ static size_t traverse_and_check(mstate m) { size_t sum = 0; if (is_initialized(m)) { msegmentptr s = &m->seg; sum += m->topsize + TOP_FOOT_SIZE; while (s != 0) { mchunkptr q = align_as_chunk(s->base); mchunkptr lastq = 0; assert(pinuse(q)); while (segment_holds(s, q) && q != m->top && q->head != FENCEPOST_HEAD) { sum += chunksize(q); if (cinuse(q)) { assert(!bin_find(m, q)); do_check_inuse_chunk(m, q); } else { assert(q == m->dv || bin_find(m, q)); assert(lastq == 0 || cinuse(lastq)); /* Not 2 consecutive free */ do_check_free_chunk(m, q); } lastq = q; q = next_chunk(q); } s = s->next; } } return sum; } /* Check all properties of malloc_state. */ static void do_check_malloc_state(mstate m) { bindex_t i; size_t total; /* check bins */ for (i = 0; i < NSMALLBINS; ++i) do_check_smallbin(m, i); for (i = 0; i < NTREEBINS; ++i) do_check_treebin(m, i); if (m->dvsize != 0) { /* check dv chunk */ do_check_any_chunk(m, m->dv); assert(m->dvsize == chunksize(m->dv)); assert(m->dvsize >= MIN_CHUNK_SIZE); assert(bin_find(m, m->dv) == 0); } if (m->top != 0) { /* check top chunk */ do_check_top_chunk(m, m->top); assert(m->topsize == chunksize(m->top)); assert(m->topsize > 0); assert(bin_find(m, m->top) == 0); } total = traverse_and_check(m); assert(total <= m->footprint); assert(m->footprint <= m->max_footprint); } #endif /* DEBUG */ /* ----------------------------- statistics ------------------------------ */ #if !NO_MALLINFO static struct mallinfo internal_mallinfo(mstate m) { struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; if (!PREACTION(m)) { check_malloc_state(m); if (is_initialized(m)) { size_t nfree = SIZE_T_ONE; /* top always free */ size_t mfree = m->topsize + TOP_FOOT_SIZE; size_t sum = mfree; msegmentptr s = &m->seg; while (s != 0) { mchunkptr q = align_as_chunk(s->base); while (segment_holds(s, q) && q != m->top && q->head != FENCEPOST_HEAD) { size_t sz = chunksize(q); sum += sz; if (!cinuse(q)) { mfree += sz; ++nfree; } q = next_chunk(q); } s = s->next; } nm.arena = sum; nm.ordblks = nfree; nm.hblkhd = m->footprint - sum; nm.usmblks = m->max_footprint; nm.uordblks = m->footprint - mfree; nm.fordblks = mfree; nm.keepcost = m->topsize; } POSTACTION(m); } return nm; } #endif /* !NO_MALLINFO */ static void internal_malloc_stats(mstate m) { if (!PREACTION(m)) { #ifndef LACKS_STDIO_H size_t maxfp = 0; #endif size_t fp = 0; size_t used = 0; check_malloc_state(m); if (is_initialized(m)) { msegmentptr s = &m->seg; #ifndef LACKS_STDIO_H maxfp = m->max_footprint; #endif fp = m->footprint; used = fp - (m->topsize + TOP_FOOT_SIZE); while (s != 0) { mchunkptr q = align_as_chunk(s->base); while (segment_holds(s, q) && q != m->top && q->head != FENCEPOST_HEAD) { if (!cinuse(q)) used -= chunksize(q); q = next_chunk(q); } s = s->next; } } #ifndef LACKS_STDIO_H fprintf(stderr, "max system bytes = %10lu\n", (unsigned long) (maxfp)); fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp)); fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used)); #endif POSTACTION(m); } } /* ----------------------- Operations on smallbins ----------------------- */ /* Various forms of linking and unlinking are defined as macros. Even the ones for trees, which are very long but have very short typical paths. This is ugly but reduces reliance on inlining support of compilers. */ /* Link a free chunk into a smallbin */ #define insert_small_chunk(M, P, S) {\ bindex_t I = small_index(S);\ mchunkptr B = smallbin_at(M, I);\ mchunkptr F = B;\ assert(S >= MIN_CHUNK_SIZE);\ if (!smallmap_is_marked(M, I))\ mark_smallmap(M, I);\ else if (RTCHECK(ok_address(M, B->fd)))\ F = B->fd;\ else {\ CORRUPTION_ERROR_ACTION(M);\ }\ B->fd = P;\ F->bk = P;\ P->fd = F;\ P->bk = B;\ } /* Unlink a chunk from a smallbin */ #define unlink_small_chunk(M, P, S) {\ mchunkptr F = P->fd;\ mchunkptr B = P->bk;\ bindex_t I = small_index(S);\ assert(P != B);\ assert(P != F);\ assert(chunksize(P) == small_index2size(I));\ if (F == B)\ clear_smallmap(M, I);\ else if (RTCHECK((F == smallbin_at(M,I) || ok_address(M, F)) &&\ (B == smallbin_at(M,I) || ok_address(M, B)))) {\ F->bk = B;\ B->fd = F;\ }\ else {\ CORRUPTION_ERROR_ACTION(M);\ }\ } /* Unlink the first chunk from a smallbin */ #define unlink_first_small_chunk(M, B, P, I) {\ mchunkptr F = P->fd;\ assert(P != B);\ assert(P != F);\ assert(chunksize(P) == small_index2size(I));\ if (B == F)\ clear_smallmap(M, I);\ else if (RTCHECK(ok_address(M, F))) {\ B->fd = F;\ F->bk = B;\ }\ else {\ CORRUPTION_ERROR_ACTION(M);\ }\ } /* Replace dv node, binning the old one */ /* Used only when dvsize known to be small */ #define replace_dv(M, P, S) {\ size_t DVS = M->dvsize;\ if (DVS != 0) {\ mchunkptr DV = M->dv;\ assert(is_small(DVS));\ insert_small_chunk(M, DV, DVS);\ }\ M->dvsize = S;\ M->dv = P;\ } /* ------------------------- Operations on trees ------------------------- */ /* Insert chunk into tree */ #define insert_large_chunk(M, X, S) {\ tbinptr* H;\ bindex_t I;\ compute_tree_index(S, I);\ H = treebin_at(M, I);\ X->index = I;\ X->child[0] = X->child[1] = 0;\ if (!treemap_is_marked(M, I)) {\ mark_treemap(M, I);\ *H = X;\ X->parent = (tchunkptr)H;\ X->fd = X->bk = X;\ }\ else {\ tchunkptr T = *H;\ size_t K = S << leftshift_for_tree_index(I);\ for (;;) {\ if (chunksize(T) != S) {\ tchunkptr* C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\ K <<= 1;\ if (*C != 0)\ T = *C;\ else if (RTCHECK(ok_address(M, C))) {\ *C = X;\ X->parent = T;\ X->fd = X->bk = X;\ break;\ }\ else {\ CORRUPTION_ERROR_ACTION(M);\ break;\ }\ }\ else {\ tchunkptr F = T->fd;\ if (RTCHECK(ok_address(M, T) && ok_address(M, F))) {\ T->fd = F->bk = X;\ X->fd = F;\ X->bk = T;\ X->parent = 0;\ break;\ }\ else {\ CORRUPTION_ERROR_ACTION(M);\ break;\ }\ }\ }\ }\ } /* Unlink steps: 1. If x is a chained node, unlink it from its same-sized fd/bk links and choose its bk node as its replacement. 2. If x was the last node of its size, but not a leaf node, it must be replaced with a leaf node (not merely one with an open left or right), to make sure that lefts and rights of descendents correspond properly to bit masks. We use the rightmost descendent of x. We could use any other leaf, but this is easy to locate and tends to counteract removal of leftmosts elsewhere, and so keeps paths shorter than minimally guaranteed. This doesn't loop much because on average a node in a tree is near the bottom. 3. If x is the base of a chain (i.e., has parent links) relink x's parent and children to x's replacement (or null if none). */ #define unlink_large_chunk(M, X) {\ tchunkptr XP = X->parent;\ tchunkptr R;\ if (X->bk != X) {\ tchunkptr F = X->fd;\ R = X->bk;\ if (RTCHECK(ok_address(M, F))) {\ F->bk = R;\ R->fd = F;\ }\ else {\ CORRUPTION_ERROR_ACTION(M);\ }\ }\ else {\ tchunkptr* RP;\ if (((R = *(RP = &(X->child[1]))) != 0) ||\ ((R = *(RP = &(X->child[0]))) != 0)) {\ tchunkptr* CP;\ while ((*(CP = &(R->child[1])) != 0) ||\ (*(CP = &(R->child[0])) != 0)) {\ R = *(RP = CP);\ }\ if (RTCHECK(ok_address(M, RP)))\ *RP = 0;\ else {\ CORRUPTION_ERROR_ACTION(M);\ }\ }\ }\ if (XP != 0) {\ tbinptr* H = treebin_at(M, X->index);\ if (X == *H) {\ if ((*H = R) == 0) \ clear_treemap(M, X->index);\ }\ else if (RTCHECK(ok_address(M, XP))) {\ if (XP->child[0] == X) \ XP->child[0] = R;\ else \ XP->child[1] = R;\ }\ else\ CORRUPTION_ERROR_ACTION(M);\ if (R != 0) {\ if (RTCHECK(ok_address(M, R))) {\ tchunkptr C0, C1;\ R->parent = XP;\ if ((C0 = X->child[0]) != 0) {\ if (RTCHECK(ok_address(M, C0))) {\ R->child[0] = C0;\ C0->parent = R;\ }\ else\ CORRUPTION_ERROR_ACTION(M);\ }\ if ((C1 = X->child[1]) != 0) {\ if (RTCHECK(ok_address(M, C1))) {\ R->child[1] = C1;\ C1->parent = R;\ }\ else\ CORRUPTION_ERROR_ACTION(M);\ }\ }\ else\ CORRUPTION_ERROR_ACTION(M);\ }\ }\ } /* Relays to large vs small bin operations */ #define insert_chunk(M, P, S)\ if (is_small(S)) insert_small_chunk(M, P, S)\ else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); } #define unlink_chunk(M, P, S)\ if (is_small(S)) unlink_small_chunk(M, P, S)\ else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); } /* Relays to internal calls to malloc/free from realloc, memalign etc */ #if ONLY_MSPACES #define internal_malloc(m, b) mspace_malloc(m, b) #define internal_free(m, mem) mspace_free(m,mem); #else /* ONLY_MSPACES */ #if MSPACES #define internal_malloc(m, b)\ (m == gm)? dlmalloc(b) : mspace_malloc(m, b) #define internal_free(m, mem)\ if (m == gm) dlfree(mem); else mspace_free(m,mem); #else /* MSPACES */ #define internal_malloc(m, b) dlmalloc(b) #define internal_free(m, mem) dlfree(mem) #endif /* MSPACES */ #endif /* ONLY_MSPACES */ /* ----------------------- Direct-mmapping chunks ----------------------- */ /* Directly mmapped chunks are set up with an offset to the start of the mmapped region stored in the prev_foot field of the chunk. This allows reconstruction of the required argument to MUNMAP when freed, and also allows adjustment of the returned chunk to meet alignment requirements (especially in memalign). There is also enough space allocated to hold a fake next chunk of size SIZE_T_SIZE to maintain the PINUSE bit so frees can be checked. */ /* Malloc using mmap */ static void * mmap_alloc(mstate m, size_t nb) { size_t mmsize = granularity_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); if (mmsize > nb) { /* Check for wrap around 0 */ char *mm = (char *) (DIRECT_MMAP(mmsize)); if (mm != CMFAIL) { size_t offset = align_offset(chunk2mem(mm)); size_t psize = mmsize - offset - MMAP_FOOT_PAD; mchunkptr p = (mchunkptr) (mm + offset); p->prev_foot = offset | IS_MMAPPED_BIT; (p)->head = (psize | CINUSE_BIT); mark_inuse_foot(m, p, psize); chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; chunk_plus_offset(p, psize + SIZE_T_SIZE)->head = 0; if (mm < m->least_addr) m->least_addr = mm; if ((m->footprint += mmsize) > m->max_footprint) m->max_footprint = m->footprint; assert(is_aligned(chunk2mem(p))); check_mmapped_chunk(m, p); return chunk2mem(p); } } return 0; } /* Realloc using mmap */ static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb) { size_t oldsize = chunksize(oldp); if (is_small(nb)) /* Can't shrink mmap regions below small size */ return 0; /* Keep old chunk if big enough but not too big */ if (oldsize >= nb + SIZE_T_SIZE && (oldsize - nb) <= (mparams.granularity << 1)) return oldp; else { size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT; size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD; size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); char *cp = (char *) CALL_MREMAP((char *) oldp - offset, oldmmsize, newmmsize, 1); if (cp != CMFAIL) { mchunkptr newp = (mchunkptr) (cp + offset); size_t psize = newmmsize - offset - MMAP_FOOT_PAD; newp->head = (psize | CINUSE_BIT); mark_inuse_foot(m, newp, psize); chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; chunk_plus_offset(newp, psize + SIZE_T_SIZE)->head = 0; if (cp < m->least_addr) m->least_addr = cp; if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint) m->max_footprint = m->footprint; check_mmapped_chunk(m, newp); return newp; } } return 0; } /* -------------------------- mspace management -------------------------- */ /* Initialize top chunk and its size */ static void init_top(mstate m, mchunkptr p, size_t psize) { /* Ensure alignment */ size_t offset = align_offset(chunk2mem(p)); p = (mchunkptr) ((char *) p + offset); psize -= offset; m->top = p; m->topsize = psize; p->head = psize | PINUSE_BIT; /* set size of fake trailing chunk holding overhead space only once */ chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; m->trim_check = mparams.trim_threshold; /* reset on each update */ } /* Initialize bins for a new mstate that is otherwise zeroed out */ static void init_bins(mstate m) { /* Establish circular links for smallbins */ bindex_t i; for (i = 0; i < NSMALLBINS; ++i) { sbinptr bin = smallbin_at(m, i); bin->fd = bin->bk = bin; } } #if PROCEED_ON_ERROR /* default corruption action */ static void reset_on_error(mstate m) { int i; ++malloc_corruption_error_count; /* Reinitialize fields to forget about all memory */ m->smallbins = m->treebins = 0; m->dvsize = m->topsize = 0; m->seg.base = 0; m->seg.size = 0; m->seg.next = 0; m->top = m->dv = 0; for (i = 0; i < NTREEBINS; ++i) *treebin_at(m, i) = 0; init_bins(m); } #endif /* PROCEED_ON_ERROR */ /* Allocate chunk and prepend remainder with chunk in successor base. */ static void * prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb) { mchunkptr p = align_as_chunk(newbase); mchunkptr oldfirst = align_as_chunk(oldbase); size_t psize = (char *) oldfirst - (char *) p; mchunkptr q = chunk_plus_offset(p, nb); size_t qsize = psize - nb; set_size_and_pinuse_of_inuse_chunk(m, p, nb); assert((char *) oldfirst > (char *) q); assert(pinuse(oldfirst)); assert(qsize >= MIN_CHUNK_SIZE); /* consolidate remainder with first chunk of old base */ if (oldfirst == m->top) { size_t tsize = m->topsize += qsize; m->top = q; q->head = tsize | PINUSE_BIT; check_top_chunk(m, q); } else if (oldfirst == m->dv) { size_t dsize = m->dvsize += qsize; m->dv = q; set_size_and_pinuse_of_free_chunk(q, dsize); } else { if (!cinuse(oldfirst)) { size_t nsize = chunksize(oldfirst); unlink_chunk(m, oldfirst, nsize); oldfirst = chunk_plus_offset(oldfirst, nsize); qsize += nsize; } set_free_with_pinuse(q, qsize, oldfirst); insert_chunk(m, q, qsize); check_free_chunk(m, q); } check_malloced_chunk(m, chunk2mem(p), nb); return chunk2mem(p); } /* Add a segment to hold a new noncontiguous region */ static void add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped) { /* Determine locations and sizes of segment, fenceposts, old top */ char *old_top = (char *) m->top; msegmentptr oldsp = segment_holding(m, old_top); char *old_end = oldsp->base + oldsp->size; size_t ssize = pad_request(sizeof(struct malloc_segment)); char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); size_t offset = align_offset(chunk2mem(rawsp)); char *asp = rawsp + offset; char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp; mchunkptr sp = (mchunkptr) csp; msegmentptr ss = (msegmentptr) (chunk2mem(sp)); mchunkptr tnext = chunk_plus_offset(sp, ssize); mchunkptr p = tnext; int nfences = 0; /* reset top to new space */ init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE); /* Set up segment record */ assert(is_aligned(ss)); set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); *ss = m->seg; /* Push current record */ m->seg.base = tbase; m->seg.size = tsize; m->seg.sflags = mmapped; m->seg.next = ss; /* Insert trailing fenceposts */ for (;;) { mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); p->head = FENCEPOST_HEAD; ++nfences; if ((char *) (&(nextp->head)) < old_end) p = nextp; else break; } assert(nfences >= 2); /* Insert the rest of old top into a bin as an ordinary free chunk */ if (csp != old_top) { mchunkptr q = (mchunkptr) old_top; size_t psize = csp - old_top; mchunkptr tn = chunk_plus_offset(q, psize); set_free_with_pinuse(q, psize, tn); insert_chunk(m, q, psize); } check_top_chunk(m, m->top); } /* -------------------------- System allocation -------------------------- */ /* Get memory from system using MORECORE or MMAP */ static void * sys_alloc(mstate m, size_t nb) { char *tbase = CMFAIL; size_t tsize = 0; flag_t mmap_flag = 0; init_mparams(); /* Directly map large chunks */ if (use_mmap(m) && nb >= mparams.mmap_threshold) { void *mem = mmap_alloc(m, nb); if (mem != 0) return mem; } /* Try getting memory in any of three ways (in most-preferred to least-preferred order): 1. A call to MORECORE that can normally contiguously extend memory. (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or or main space is mmapped or a previous contiguous call failed) 2. A call to MMAP new space (disabled if not HAVE_MMAP). Note that under the default settings, if MORECORE is unable to fulfill a request, and HAVE_MMAP is true, then mmap is used as a noncontiguous system allocator. This is a useful backup strategy for systems with holes in address spaces -- in this case sbrk cannot contiguously expand the heap, but mmap may be able to find space. 3. A call to MORECORE that cannot usually contiguously extend memory. (disabled if not HAVE_MORECORE) */ if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) { char *br = CMFAIL; msegmentptr ss = (m->top == 0) ? 0 : segment_holding(m, (char *) m->top); size_t asize = 0; ACQUIRE_MORECORE_LOCK(); if (ss == 0) { /* First time through or recovery */ char *base = (char *) CALL_MORECORE(0); if (base != CMFAIL) { asize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE); /* Adjust to end on a page boundary */ if (!is_page_aligned(base)) asize += (page_align((size_t) base) - (size_t) base); /* Can't call MORECORE if size is negative when treated as signed */ if (asize < HALF_MAX_SIZE_T && (br = (char *) (CALL_MORECORE(asize))) == base) { tbase = base; tsize = asize; } } } else { /* Subtract out existing available top space from MORECORE request. */ asize = granularity_align(nb - m->topsize + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE); /* Use mem here only if it did continuously extend old space */ if (asize < HALF_MAX_SIZE_T && (br = (char *) (CALL_MORECORE(asize))) == ss->base + ss->size) { tbase = br; tsize = asize; } } if (tbase == CMFAIL) { /* Cope with partial failure */ if (br != CMFAIL) { /* Try to use/extend the space we did get */ if (asize < HALF_MAX_SIZE_T && asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) { size_t esize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE - asize); if (esize < HALF_MAX_SIZE_T) { char *end = (char *) CALL_MORECORE(esize); if (end != CMFAIL) asize += esize; else { /* Can't use; try to release */ end = (char *) CALL_MORECORE(-asize); br = CMFAIL; } } } } if (br != CMFAIL) { /* Use the space we did get */ tbase = br; tsize = asize; } else disable_contiguous(m); /* Don't try contiguous path in the future */ } RELEASE_MORECORE_LOCK(); } if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */ size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE; size_t rsize = granularity_align(req); if (rsize > nb) { /* Fail if wraps around zero */ char *mp = (char *) (CALL_MMAP(rsize)); if (mp != CMFAIL) { tbase = mp; tsize = rsize; mmap_flag = IS_MMAPPED_BIT; } } } if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */ size_t asize = granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE); if (asize < HALF_MAX_SIZE_T) { char *br = CMFAIL; char *end = CMFAIL; ACQUIRE_MORECORE_LOCK(); br = (char *) (CALL_MORECORE(asize)); end = (char *) (CALL_MORECORE(0)); RELEASE_MORECORE_LOCK(); if (br != CMFAIL && end != CMFAIL && br < end) { size_t ssize = end - br; if (ssize > nb + TOP_FOOT_SIZE) { tbase = br; tsize = ssize; } } } } if (tbase != CMFAIL) { if ((m->footprint += tsize) > m->max_footprint) m->max_footprint = m->footprint; if (!is_initialized(m)) { /* first-time initialization */ m->seg.base = m->least_addr = tbase; m->seg.size = tsize; m->seg.sflags = mmap_flag; m->magic = mparams.magic; init_bins(m); if (is_global(m)) init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE); else { /* Offset top by embedded malloc_state */ mchunkptr mn = next_chunk(mem2chunk(m)); init_top(m, mn, (size_t) ((tbase + tsize) - (char *) mn) - TOP_FOOT_SIZE); } } else { /* Try to merge with an existing segment */ msegmentptr sp = &m->seg; while (sp != 0 && tbase != sp->base + sp->size) sp = sp->next; if (sp != 0 && !is_extern_segment(sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && segment_holds(sp, m->top)) { /* append */ sp->size += tsize; init_top(m, m->top, m->topsize + tsize); } else { if (tbase < m->least_addr) m->least_addr = tbase; sp = &m->seg; while (sp != 0 && sp->base != tbase + tsize) sp = sp->next; if (sp != 0 && !is_extern_segment(sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) { char *oldbase = sp->base; sp->base = tbase; sp->size += tsize; return prepend_alloc(m, tbase, oldbase, nb); } else add_segment(m, tbase, tsize, mmap_flag); } } if (nb < m->topsize) { /* Allocate from new or extended top space */ size_t rsize = m->topsize -= nb; mchunkptr p = m->top; mchunkptr r = m->top = chunk_plus_offset(p, nb); r->head = rsize | PINUSE_BIT; set_size_and_pinuse_of_inuse_chunk(m, p, nb); check_top_chunk(m, m->top); check_malloced_chunk(m, chunk2mem(p), nb); return chunk2mem(p); } } MALLOC_FAILURE_ACTION; return 0; } /* ----------------------- system deallocation -------------------------- */ /* Unmap and unlink any mmapped segments that don't contain used chunks */ static size_t release_unused_segments(mstate m) { size_t released = 0; msegmentptr pred = &m->seg; msegmentptr sp = pred->next; while (sp != 0) { char *base = sp->base; size_t size = sp->size; msegmentptr next = sp->next; if (is_mmapped_segment(sp) && !is_extern_segment(sp)) { mchunkptr p = align_as_chunk(base); size_t psize = chunksize(p); /* Can unmap if first chunk holds entire segment and not pinned */ if (!cinuse(p) && (char *) p + psize >= base + size - TOP_FOOT_SIZE) { tchunkptr tp = (tchunkptr) p; assert(segment_holds(sp, (char *) sp)); if (p == m->dv) { m->dv = 0; m->dvsize = 0; } else { unlink_large_chunk(m, tp); } if (CALL_MUNMAP(base, size) == 0) { released += size; m->footprint -= size; /* unlink obsoleted record */ sp = pred; sp->next = next; } else { /* back out if cannot unmap */ insert_large_chunk(m, tp, psize); } } } pred = sp; sp = next; } return released; } static int sys_trim(mstate m, size_t pad) { size_t released = 0; if (pad < MAX_REQUEST && is_initialized(m)) { pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ if (m->topsize > pad) { /* Shrink top space in granularity-size units, keeping at least one */ size_t unit = mparams.granularity; size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - SIZE_T_ONE) * unit; msegmentptr sp = segment_holding(m, (char *) m->top); if (!is_extern_segment(sp)) { if (is_mmapped_segment(sp)) { if (HAVE_MMAP && sp->size >= extra && !has_segment_link(m, sp)) { /* can't shrink if pinned */ size_t newsize = sp->size - extra; /* Prefer mremap, fall back to munmap */ if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != MFAIL) || (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { released = extra; } } } else if (HAVE_MORECORE) { if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */ extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit; ACQUIRE_MORECORE_LOCK(); { /* Make sure end of memory is where we last set it. */ char *old_br = (char *) (CALL_MORECORE(0)); if (old_br == sp->base + sp->size) { char *rel_br = (char *) (CALL_MORECORE(-extra)); char *new_br = (char *) (CALL_MORECORE(0)); if (rel_br != CMFAIL && new_br < old_br) released = old_br - new_br; } } RELEASE_MORECORE_LOCK(); } } if (released != 0) { sp->size -= released; m->footprint -= released; init_top(m, m->top, m->topsize - released); check_top_chunk(m, m->top); } } /* Unmap any unused mmapped segments */ if (HAVE_MMAP) released += release_unused_segments(m); /* On failure, disable autotrim to avoid repeated failed future calls */ if (released == 0) m->trim_check = MAX_SIZE_T; } return (released != 0) ? 1 : 0; } /* ---------------------------- malloc support --------------------------- */ /* allocate a large request from the best fitting chunk in a treebin */ static void * tmalloc_large(mstate m, size_t nb) { tchunkptr v = 0; size_t rsize = -nb; /* Unsigned negation */ tchunkptr t; bindex_t idx; compute_tree_index(nb, idx); if ((t = *treebin_at(m, idx)) != 0) { /* Traverse tree for this bin looking for node with size == nb */ size_t sizebits = nb << leftshift_for_tree_index(idx); tchunkptr rst = 0; /* The deepest untaken right subtree */ for (;;) { tchunkptr rt; size_t trem = chunksize(t) - nb; if (trem < rsize) { v = t; if ((rsize = trem) == 0) break; } rt = t->child[1]; t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1]; if (rt != 0 && rt != t) rst = rt; if (t == 0) { t = rst; /* set t to least subtree holding sizes > nb */ break; } sizebits <<= 1; } } if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; if (leftbits != 0) { bindex_t i; binmap_t leastbit = least_bit(leftbits); compute_bit2idx(leastbit, i); t = *treebin_at(m, i); } } while (t != 0) { /* find smallest of tree or subtree */ size_t trem = chunksize(t) - nb; if (trem < rsize) { rsize = trem; v = t; } t = leftmost_child(t); } /* If dv is a better fit, return 0 so malloc will use it */ if (v != 0 && rsize < (size_t) (m->dvsize - nb)) { if (RTCHECK(ok_address(m, v))) { /* split */ mchunkptr r = chunk_plus_offset(v, nb); assert(chunksize(v) == rsize + nb); if (RTCHECK(ok_next(v, r))) { unlink_large_chunk(m, v); if (rsize < MIN_CHUNK_SIZE) set_inuse_and_pinuse(m, v, (rsize + nb)); else { set_size_and_pinuse_of_inuse_chunk(m, v, nb); set_size_and_pinuse_of_free_chunk(r, rsize); insert_chunk(m, r, rsize); } return chunk2mem(v); } } CORRUPTION_ERROR_ACTION(m); } return 0; } /* allocate a small request from the best fitting chunk in a treebin */ static void * tmalloc_small(mstate m, size_t nb) { tchunkptr t, v; size_t rsize; bindex_t i; binmap_t leastbit = least_bit(m->treemap); compute_bit2idx(leastbit, i); v = t = *treebin_at(m, i); rsize = chunksize(t) - nb; while ((t = leftmost_child(t)) != 0) { size_t trem = chunksize(t) - nb; if (trem < rsize) { rsize = trem; v = t; } } if (RTCHECK(ok_address(m, v))) { mchunkptr r = chunk_plus_offset(v, nb); assert(chunksize(v) == rsize + nb); if (RTCHECK(ok_next(v, r))) { unlink_large_chunk(m, v); if (rsize < MIN_CHUNK_SIZE) set_inuse_and_pinuse(m, v, (rsize + nb)); else { set_size_and_pinuse_of_inuse_chunk(m, v, nb); set_size_and_pinuse_of_free_chunk(r, rsize); replace_dv(m, r, rsize); } return chunk2mem(v); } } CORRUPTION_ERROR_ACTION(m); return 0; } /* --------------------------- realloc support --------------------------- */ static void * internal_realloc(mstate m, void *oldmem, size_t bytes) { if (bytes >= MAX_REQUEST) { MALLOC_FAILURE_ACTION; return 0; } if (!PREACTION(m)) { mchunkptr oldp = mem2chunk(oldmem); size_t oldsize = chunksize(oldp); mchunkptr next = chunk_plus_offset(oldp, oldsize); mchunkptr newp = 0; void *extra = 0; /* Try to either shrink or extend into top. Else malloc-copy-free */ if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) && ok_next(oldp, next) && ok_pinuse(next))) { size_t nb = request2size(bytes); if (is_mmapped(oldp)) newp = mmap_resize(m, oldp, nb); else if (oldsize >= nb) { /* already big enough */ size_t rsize = oldsize - nb; newp = oldp; if (rsize >= MIN_CHUNK_SIZE) { mchunkptr remainder = chunk_plus_offset(newp, nb); set_inuse(m, newp, nb); set_inuse(m, remainder, rsize); extra = chunk2mem(remainder); } } else if (next == m->top && oldsize + m->topsize > nb) { /* Expand into top */ size_t newsize = oldsize + m->topsize; size_t newtopsize = newsize - nb; mchunkptr newtop = chunk_plus_offset(oldp, nb); set_inuse(m, oldp, nb); newtop->head = newtopsize | PINUSE_BIT; m->top = newtop; m->topsize = newtopsize; newp = oldp; } } else { USAGE_ERROR_ACTION(m, oldmem); POSTACTION(m); return 0; } POSTACTION(m); if (newp != 0) { if (extra != 0) { internal_free(m, extra); } check_inuse_chunk(m, newp); return chunk2mem(newp); } else { void *newmem = internal_malloc(m, bytes); if (newmem != 0) { size_t oc = oldsize - overhead_for(oldp); memcpy(newmem, oldmem, (oc < bytes) ? oc : bytes); internal_free(m, oldmem); } return newmem; } } return 0; } /* --------------------------- memalign support -------------------------- */ static void * internal_memalign(mstate m, size_t alignment, size_t bytes) { if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */ return internal_malloc(m, bytes); if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ alignment = MIN_CHUNK_SIZE; if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */ size_t a = MALLOC_ALIGNMENT << 1; while (a < alignment) a <<= 1; alignment = a; } if (bytes >= MAX_REQUEST - alignment) { if (m != 0) { /* Test isn't needed but avoids compiler warning */ MALLOC_FAILURE_ACTION; } } else { size_t nb = request2size(bytes); size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD; char *mem = (char *) internal_malloc(m, req); if (mem != 0) { void *leader = 0; void *trailer = 0; mchunkptr p = mem2chunk(mem); if (PREACTION(m)) return 0; if ((((size_t) (mem)) % alignment) != 0) { /* misaligned */ /* Find an aligned spot inside chunk. Since we need to give back leading space in a chunk of at least MIN_CHUNK_SIZE, if the first calculation places us at a spot with less than MIN_CHUNK_SIZE leader, we can move to the next aligned spot. We've allocated enough total room so that this is always possible. */ char *br = (char *) mem2chunk((size_t) (((size_t) (mem + alignment - SIZE_T_ONE)) & -alignment)); char *pos = ((size_t) (br - (char *) (p)) >= MIN_CHUNK_SIZE) ? br : br + alignment; mchunkptr newp = (mchunkptr) pos; size_t leadsize = pos - (char *) (p); size_t newsize = chunksize(p) - leadsize; if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */ newp->prev_foot = p->prev_foot + leadsize; newp->head = (newsize | CINUSE_BIT); } else { /* Otherwise, give back leader, use the rest */ set_inuse(m, newp, newsize); set_inuse(m, p, leadsize); leader = chunk2mem(p); } p = newp; } /* Give back spare room at the end */ if (!is_mmapped(p)) { size_t size = chunksize(p); if (size > nb + MIN_CHUNK_SIZE) { size_t remainder_size = size - nb; mchunkptr remainder = chunk_plus_offset(p, nb); set_inuse(m, p, nb); set_inuse(m, remainder, remainder_size); trailer = chunk2mem(remainder); } } assert(chunksize(p) >= nb); assert((((size_t) (chunk2mem(p))) % alignment) == 0); check_inuse_chunk(m, p); POSTACTION(m); if (leader != 0) { internal_free(m, leader); } if (trailer != 0) { internal_free(m, trailer); } return chunk2mem(p); } } return 0; } /* ------------------------ comalloc/coalloc support --------------------- */ static void ** ialloc(mstate m, size_t n_elements, size_t * sizes, int opts, void *chunks[]) { /* This provides common support for independent_X routines, handling all of the combinations that can result. The opts arg has: bit 0 set if all elements are same size (using sizes[0]) bit 1 set if elements should be zeroed */ size_t element_size; /* chunksize of each element, if all same */ size_t contents_size; /* total size of elements */ size_t array_size; /* request size of pointer array */ void *mem; /* malloced aggregate space */ mchunkptr p; /* corresponding chunk */ size_t remainder_size; /* remaining bytes while splitting */ void **marray; /* either "chunks" or malloced ptr array */ mchunkptr array_chunk; /* chunk for malloced ptr array */ flag_t was_enabled; /* to disable mmap */ size_t size; size_t i; /* compute array length, if needed */ if (chunks != 0) { if (n_elements == 0) return chunks; /* nothing to do */ marray = chunks; array_size = 0; } else { /* if empty req, must still return chunk representing empty array */ if (n_elements == 0) return (void **) internal_malloc(m, 0); marray = 0; array_size = request2size(n_elements * (sizeof(void *))); } /* compute total element size */ if (opts & 0x1) { /* all-same-size */ element_size = request2size(*sizes); contents_size = n_elements * element_size; } else { /* add up all the sizes */ element_size = 0; contents_size = 0; for (i = 0; i != n_elements; ++i) contents_size += request2size(sizes[i]); } size = contents_size + array_size; /* Allocate the aggregate chunk. First disable direct-mmapping so malloc won't use it, since we would not be able to later free/realloc space internal to a segregated mmap region. */ was_enabled = use_mmap(m); disable_mmap(m); mem = internal_malloc(m, size - CHUNK_OVERHEAD); if (was_enabled) enable_mmap(m); if (mem == 0) return 0; if (PREACTION(m)) return 0; p = mem2chunk(mem); remainder_size = chunksize(p); assert(!is_mmapped(p)); if (opts & 0x2) { /* optionally clear the elements */ memset((size_t *) mem, 0, remainder_size - SIZE_T_SIZE - array_size); } /* If not provided, allocate the pointer array as final part of chunk */ if (marray == 0) { size_t array_chunk_size; array_chunk = chunk_plus_offset(p, contents_size); array_chunk_size = remainder_size - contents_size; marray = (void **) (chunk2mem(array_chunk)); set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size); remainder_size = contents_size; } /* split out elements */ for (i = 0;; ++i) { marray[i] = chunk2mem(p); if (i != n_elements - 1) { if (element_size != 0) size = element_size; else size = request2size(sizes[i]); remainder_size -= size; set_size_and_pinuse_of_inuse_chunk(m, p, size); p = chunk_plus_offset(p, size); } else { /* the final element absorbs any overallocation slop */ set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size); break; } } #if DEBUG if (marray != chunks) { /* final element must have exactly exhausted chunk */ if (element_size != 0) { assert(remainder_size == element_size); } else { assert(remainder_size == request2size(sizes[i])); } check_inuse_chunk(m, mem2chunk(marray)); } for (i = 0; i != n_elements; ++i) check_inuse_chunk(m, mem2chunk(marray[i])); #endif /* DEBUG */ POSTACTION(m); return marray; } /* -------------------------- public routines ---------------------------- */ #if !ONLY_MSPACES void * dlmalloc(size_t bytes) { /* Basic algorithm: If a small request (< 256 bytes minus per-chunk overhead): 1. If one exists, use a remainderless chunk in associated smallbin. (Remainderless means that there are too few excess bytes to represent as a chunk.) 2. If it is big enough, use the dv chunk, which is normally the chunk adjacent to the one used for the most recent small request. 3. If one exists, split the smallest available chunk in a bin, saving remainder in dv. 4. If it is big enough, use the top chunk. 5. If available, get memory from system and use it Otherwise, for a large request: 1. Find the smallest available binned chunk that fits, and use it if it is better fitting than dv chunk, splitting if necessary. 2. If better fitting than any binned chunk, use the dv chunk. 3. If it is big enough, use the top chunk. 4. If request size >= mmap threshold, try to directly mmap this chunk. 5. If available, get memory from system and use it The ugly goto's here ensure that postaction occurs along all paths. */ if (!PREACTION(gm)) { void *mem; size_t nb; if (bytes <= MAX_SMALL_REQUEST) { bindex_t idx; binmap_t smallbits; nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes); idx = small_index(nb); smallbits = gm->smallmap >> idx; if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ mchunkptr b, p; idx += ~smallbits & 1; /* Uses next bin if idx empty */ b = smallbin_at(gm, idx); p = b->fd; assert(chunksize(p) == small_index2size(idx)); unlink_first_small_chunk(gm, b, p, idx); set_inuse_and_pinuse(gm, p, small_index2size(idx)); mem = chunk2mem(p); check_malloced_chunk(gm, mem, nb); goto postaction; } else if (nb > gm->dvsize) { if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ mchunkptr b, p, r; size_t rsize; bindex_t i; binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); binmap_t leastbit = least_bit(leftbits); compute_bit2idx(leastbit, i); b = smallbin_at(gm, i); p = b->fd; assert(chunksize(p) == small_index2size(i)); unlink_first_small_chunk(gm, b, p, i); rsize = small_index2size(i) - nb; /* Fit here cannot be remainderless if 4byte sizes */ if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) set_inuse_and_pinuse(gm, p, small_index2size(i)); else { set_size_and_pinuse_of_inuse_chunk(gm, p, nb); r = chunk_plus_offset(p, nb); set_size_and_pinuse_of_free_chunk(r, rsize); replace_dv(gm, r, rsize); } mem = chunk2mem(p); check_malloced_chunk(gm, mem, nb); goto postaction; } else if (gm->treemap != 0 && (mem = tmalloc_small(gm, nb)) != 0) { check_malloced_chunk(gm, mem, nb); goto postaction; } } } else if (bytes >= MAX_REQUEST) nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ else { nb = pad_request(bytes); if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) { check_malloced_chunk(gm, mem, nb); goto postaction; } } if (nb <= gm->dvsize) { size_t rsize = gm->dvsize - nb; mchunkptr p = gm->dv; if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ mchunkptr r = gm->dv = chunk_plus_offset(p, nb); gm->dvsize = rsize; set_size_and_pinuse_of_free_chunk(r, rsize); set_size_and_pinuse_of_inuse_chunk(gm, p, nb); } else { /* exhaust dv */ size_t dvs = gm->dvsize; gm->dvsize = 0; gm->dv = 0; set_inuse_and_pinuse(gm, p, dvs); } mem = chunk2mem(p); check_malloced_chunk(gm, mem, nb); goto postaction; } else if (nb < gm->topsize) { /* Split top */ size_t rsize = gm->topsize -= nb; mchunkptr p = gm->top; mchunkptr r = gm->top = chunk_plus_offset(p, nb); r->head = rsize | PINUSE_BIT; set_size_and_pinuse_of_inuse_chunk(gm, p, nb); mem = chunk2mem(p); check_top_chunk(gm, gm->top); check_malloced_chunk(gm, mem, nb); goto postaction; } mem = sys_alloc(gm, nb); postaction: POSTACTION(gm); return mem; } return 0; } void dlfree(void *mem) { /* Consolidate freed chunks with preceeding or succeeding bordering free chunks, if they exist, and then place in a bin. Intermixed with special cases for top, dv, mmapped chunks, and usage errors. */ if (mem != 0) { mchunkptr p = mem2chunk(mem); #if FOOTERS mstate fm = get_mstate_for(p); if (!ok_magic(fm)) { USAGE_ERROR_ACTION(fm, p); return; } #else /* FOOTERS */ #define fm gm #endif /* FOOTERS */ if (!PREACTION(fm)) { check_inuse_chunk(fm, p); if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { size_t psize = chunksize(p); mchunkptr next = chunk_plus_offset(p, psize); if (!pinuse(p)) { size_t prevsize = p->prev_foot; if ((prevsize & IS_MMAPPED_BIT) != 0) { prevsize &= ~IS_MMAPPED_BIT; psize += prevsize + MMAP_FOOT_PAD; if (CALL_MUNMAP((char *) p - prevsize, psize) == 0) fm->footprint -= psize; goto postaction; } else { mchunkptr prev = chunk_minus_offset(p, prevsize); psize += prevsize; p = prev; if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ if (p != fm->dv) { unlink_chunk(fm, p, prevsize); } else if ((next->head & INUSE_BITS) == INUSE_BITS) { fm->dvsize = psize; set_free_with_pinuse(p, psize, next); goto postaction; } } else goto erroraction; } } if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { if (!cinuse(next)) { /* consolidate forward */ if (next == fm->top) { size_t tsize = fm->topsize += psize; fm->top = p; p->head = tsize | PINUSE_BIT; if (p == fm->dv) { fm->dv = 0; fm->dvsize = 0; } if (should_trim(fm, tsize)) sys_trim(fm, 0); goto postaction; } else if (next == fm->dv) { size_t dsize = fm->dvsize += psize; fm->dv = p; set_size_and_pinuse_of_free_chunk(p, dsize); goto postaction; } else { size_t nsize = chunksize(next); psize += nsize; unlink_chunk(fm, next, nsize); set_size_and_pinuse_of_free_chunk(p, psize); if (p == fm->dv) { fm->dvsize = psize; goto postaction; } } } else set_free_with_pinuse(p, psize, next); insert_chunk(fm, p, psize); check_free_chunk(fm, p); goto postaction; } } erroraction: USAGE_ERROR_ACTION(fm, p); postaction: POSTACTION(fm); } } #if !FOOTERS #undef fm #endif /* FOOTERS */ } void * dlcalloc(size_t n_elements, size_t elem_size) { void *mem; size_t req = 0; if (n_elements != 0) { req = n_elements * elem_size; if (((n_elements | elem_size) & ~(size_t) 0xffff) && (req / n_elements != elem_size)) req = MAX_SIZE_T; /* force downstream failure on overflow */ } mem = dlmalloc(req); if (mem != 0 && calloc_must_clear(mem2chunk(mem))) memset(mem, 0, req); return mem; } void * dlrealloc(void *oldmem, size_t bytes) { if (oldmem == 0) return dlmalloc(bytes); #ifdef REALLOC_ZERO_BYTES_FREES if (bytes == 0) { dlfree(oldmem); return 0; } #endif /* REALLOC_ZERO_BYTES_FREES */ else { #if ! FOOTERS mstate m = gm; #else /* FOOTERS */ mstate m = get_mstate_for(mem2chunk(oldmem)); if (!ok_magic(m)) { USAGE_ERROR_ACTION(m, oldmem); return 0; } #endif /* FOOTERS */ return internal_realloc(m, oldmem, bytes); } } void * dlmemalign(size_t alignment, size_t bytes) { return internal_memalign(gm, alignment, bytes); } void ** dlindependent_calloc(size_t n_elements, size_t elem_size, void *chunks[]) { size_t sz = elem_size; /* serves as 1-element array */ return ialloc(gm, n_elements, &sz, 3, chunks); } void ** dlindependent_comalloc(size_t n_elements, size_t sizes[], void *chunks[]) { return ialloc(gm, n_elements, sizes, 0, chunks); } void * dlvalloc(size_t bytes) { size_t pagesz; init_mparams(); pagesz = mparams.page_size; return dlmemalign(pagesz, bytes); } void * dlpvalloc(size_t bytes) { size_t pagesz; init_mparams(); pagesz = mparams.page_size; return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); } int dlmalloc_trim(size_t pad) { int result = 0; if (!PREACTION(gm)) { result = sys_trim(gm, pad); POSTACTION(gm); } return result; } size_t dlmalloc_footprint(void) { return gm->footprint; } size_t dlmalloc_max_footprint(void) { return gm->max_footprint; } #if !NO_MALLINFO struct mallinfo dlmallinfo(void) { return internal_mallinfo(gm); } #endif /* NO_MALLINFO */ void dlmalloc_stats() { internal_malloc_stats(gm); } size_t dlmalloc_usable_size(void *mem) { if (mem != 0) { mchunkptr p = mem2chunk(mem); if (cinuse(p)) return chunksize(p) - overhead_for(p); } return 0; } int dlmallopt(int param_number, int value) { return change_mparam(param_number, value); } #endif /* !ONLY_MSPACES */ /* ----------------------------- user mspaces ---------------------------- */ #if MSPACES static mstate init_user_mstate(char *tbase, size_t tsize) { size_t msize = pad_request(sizeof(struct malloc_state)); mchunkptr mn; mchunkptr msp = align_as_chunk(tbase); mstate m = (mstate) (chunk2mem(msp)); memset(m, 0, msize); INITIAL_LOCK(&m->mutex); msp->head = (msize | PINUSE_BIT | CINUSE_BIT); m->seg.base = m->least_addr = tbase; m->seg.size = m->footprint = m->max_footprint = tsize; m->magic = mparams.magic; m->mflags = mparams.default_mflags; disable_contiguous(m); init_bins(m); mn = next_chunk(mem2chunk(m)); init_top(m, mn, (size_t) ((tbase + tsize) - (char *) mn) - TOP_FOOT_SIZE); check_top_chunk(m, m->top); return m; } mspace create_mspace(size_t capacity, int locked) { mstate m = 0; size_t msize = pad_request(sizeof(struct malloc_state)); init_mparams(); /* Ensure pagesize etc initialized */ if (capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) { size_t rs = ((capacity == 0) ? mparams.granularity : (capacity + TOP_FOOT_SIZE + msize)); size_t tsize = granularity_align(rs); char *tbase = (char *) (CALL_MMAP(tsize)); if (tbase != CMFAIL) { m = init_user_mstate(tbase, tsize); m->seg.sflags = IS_MMAPPED_BIT; set_lock(m, locked); } } return (mspace) m; } mspace create_mspace_with_base(void *base, size_t capacity, int locked) { mstate m = 0; size_t msize = pad_request(sizeof(struct malloc_state)); init_mparams(); /* Ensure pagesize etc initialized */ if (capacity > msize + TOP_FOOT_SIZE && capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) { m = init_user_mstate((char *) base, capacity); m->seg.sflags = EXTERN_BIT; set_lock(m, locked); } return (mspace) m; } size_t destroy_mspace(mspace msp) { size_t freed = 0; mstate ms = (mstate) msp; if (ok_magic(ms)) { msegmentptr sp = &ms->seg; while (sp != 0) { char *base = sp->base; size_t size = sp->size; flag_t flag = sp->sflags; sp = sp->next; if ((flag & IS_MMAPPED_BIT) && !(flag & EXTERN_BIT) && CALL_MUNMAP(base, size) == 0) freed += size; } } else { USAGE_ERROR_ACTION(ms, ms); } return freed; } /* mspace versions of routines are near-clones of the global versions. This is not so nice but better than the alternatives. */ void * mspace_malloc(mspace msp, size_t bytes) { mstate ms = (mstate) msp; if (!ok_magic(ms)) { USAGE_ERROR_ACTION(ms, ms); return 0; } if (!PREACTION(ms)) { void *mem; size_t nb; if (bytes <= MAX_SMALL_REQUEST) { bindex_t idx; binmap_t smallbits; nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes); idx = small_index(nb); smallbits = ms->smallmap >> idx; if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ mchunkptr b, p; idx += ~smallbits & 1; /* Uses next bin if idx empty */ b = smallbin_at(ms, idx); p = b->fd; assert(chunksize(p) == small_index2size(idx)); unlink_first_small_chunk(ms, b, p, idx); set_inuse_and_pinuse(ms, p, small_index2size(idx)); mem = chunk2mem(p); check_malloced_chunk(ms, mem, nb); goto postaction; } else if (nb > ms->dvsize) { if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ mchunkptr b, p, r; size_t rsize; bindex_t i; binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); binmap_t leastbit = least_bit(leftbits); compute_bit2idx(leastbit, i); b = smallbin_at(ms, i); p = b->fd; assert(chunksize(p) == small_index2size(i)); unlink_first_small_chunk(ms, b, p, i); rsize = small_index2size(i) - nb; /* Fit here cannot be remainderless if 4byte sizes */ if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) set_inuse_and_pinuse(ms, p, small_index2size(i)); else { set_size_and_pinuse_of_inuse_chunk(ms, p, nb); r = chunk_plus_offset(p, nb); set_size_and_pinuse_of_free_chunk(r, rsize); replace_dv(ms, r, rsize); } mem = chunk2mem(p); check_malloced_chunk(ms, mem, nb); goto postaction; } else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) { check_malloced_chunk(ms, mem, nb); goto postaction; } } } else if (bytes >= MAX_REQUEST) nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ else { nb = pad_request(bytes); if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { check_malloced_chunk(ms, mem, nb); goto postaction; } } if (nb <= ms->dvsize) { size_t rsize = ms->dvsize - nb; mchunkptr p = ms->dv; if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ mchunkptr r = ms->dv = chunk_plus_offset(p, nb); ms->dvsize = rsize; set_size_and_pinuse_of_free_chunk(r, rsize); set_size_and_pinuse_of_inuse_chunk(ms, p, nb); } else { /* exhaust dv */ size_t dvs = ms->dvsize; ms->dvsize = 0; ms->dv = 0; set_inuse_and_pinuse(ms, p, dvs); } mem = chunk2mem(p); check_malloced_chunk(ms, mem, nb); goto postaction; } else if (nb < ms->topsize) { /* Split top */ size_t rsize = ms->topsize -= nb; mchunkptr p = ms->top; mchunkptr r = ms->top = chunk_plus_offset(p, nb); r->head = rsize | PINUSE_BIT; set_size_and_pinuse_of_inuse_chunk(ms, p, nb); mem = chunk2mem(p); check_top_chunk(ms, ms->top); check_malloced_chunk(ms, mem, nb); goto postaction; } mem = sys_alloc(ms, nb); postaction: POSTACTION(ms); return mem; } return 0; } void mspace_free(mspace msp, void *mem) { if (mem != 0) { mchunkptr p = mem2chunk(mem); #if FOOTERS mstate fm = get_mstate_for(p); #else /* FOOTERS */ mstate fm = (mstate) msp; #endif /* FOOTERS */ if (!ok_magic(fm)) { USAGE_ERROR_ACTION(fm, p); return; } if (!PREACTION(fm)) { check_inuse_chunk(fm, p); if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { size_t psize = chunksize(p); mchunkptr next = chunk_plus_offset(p, psize); if (!pinuse(p)) { size_t prevsize = p->prev_foot; if ((prevsize & IS_MMAPPED_BIT) != 0) { prevsize &= ~IS_MMAPPED_BIT; psize += prevsize + MMAP_FOOT_PAD; if (CALL_MUNMAP((char *) p - prevsize, psize) == 0) fm->footprint -= psize; goto postaction; } else { mchunkptr prev = chunk_minus_offset(p, prevsize); psize += prevsize; p = prev; if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ if (p != fm->dv) { unlink_chunk(fm, p, prevsize); } else if ((next->head & INUSE_BITS) == INUSE_BITS) { fm->dvsize = psize; set_free_with_pinuse(p, psize, next); goto postaction; } } else goto erroraction; } } if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { if (!cinuse(next)) { /* consolidate forward */ if (next == fm->top) { size_t tsize = fm->topsize += psize; fm->top = p; p->head = tsize | PINUSE_BIT; if (p == fm->dv) { fm->dv = 0; fm->dvsize = 0; } if (should_trim(fm, tsize)) sys_trim(fm, 0); goto postaction; } else if (next == fm->dv) { size_t dsize = fm->dvsize += psize; fm->dv = p; set_size_and_pinuse_of_free_chunk(p, dsize); goto postaction; } else { size_t nsize = chunksize(next); psize += nsize; unlink_chunk(fm, next, nsize); set_size_and_pinuse_of_free_chunk(p, psize); if (p == fm->dv) { fm->dvsize = psize; goto postaction; } } } else set_free_with_pinuse(p, psize, next); insert_chunk(fm, p, psize); check_free_chunk(fm, p); goto postaction; } } erroraction: USAGE_ERROR_ACTION(fm, p); postaction: POSTACTION(fm); } } } void * mspace_calloc(mspace msp, size_t n_elements, size_t elem_size) { void *mem; size_t req = 0; mstate ms = (mstate) msp; if (!ok_magic(ms)) { USAGE_ERROR_ACTION(ms, ms); return 0; } if (n_elements != 0) { req = n_elements * elem_size; if (((n_elements | elem_size) & ~(size_t) 0xffff) && (req / n_elements != elem_size)) req = MAX_SIZE_T; /* force downstream failure on overflow */ } mem = internal_malloc(ms, req); if (mem != 0 && calloc_must_clear(mem2chunk(mem))) memset(mem, 0, req); return mem; } void * mspace_realloc(mspace msp, void *oldmem, size_t bytes) { if (oldmem == 0) return mspace_malloc(msp, bytes); #ifdef REALLOC_ZERO_BYTES_FREES if (bytes == 0) { mspace_free(msp, oldmem); return 0; } #endif /* REALLOC_ZERO_BYTES_FREES */ else { #if FOOTERS mchunkptr p = mem2chunk(oldmem); mstate ms = get_mstate_for(p); #else /* FOOTERS */ mstate ms = (mstate) msp; #endif /* FOOTERS */ if (!ok_magic(ms)) { USAGE_ERROR_ACTION(ms, ms); return 0; } return internal_realloc(ms, oldmem, bytes); } } void * mspace_memalign(mspace msp, size_t alignment, size_t bytes) { mstate ms = (mstate) msp; if (!ok_magic(ms)) { USAGE_ERROR_ACTION(ms, ms); return 0; } return internal_memalign(ms, alignment, bytes); } void ** mspace_independent_calloc(mspace msp, size_t n_elements, size_t elem_size, void *chunks[]) { size_t sz = elem_size; /* serves as 1-element array */ mstate ms = (mstate) msp; if (!ok_magic(ms)) { USAGE_ERROR_ACTION(ms, ms); return 0; } return ialloc(ms, n_elements, &sz, 3, chunks); } void ** mspace_independent_comalloc(mspace msp, size_t n_elements, size_t sizes[], void *chunks[]) { mstate ms = (mstate) msp; if (!ok_magic(ms)) { USAGE_ERROR_ACTION(ms, ms); return 0; } return ialloc(ms, n_elements, sizes, 0, chunks); } int mspace_trim(mspace msp, size_t pad) { int result = 0; mstate ms = (mstate) msp; if (ok_magic(ms)) { if (!PREACTION(ms)) { result = sys_trim(ms, pad); POSTACTION(ms); } } else { USAGE_ERROR_ACTION(ms, ms); } return result; } void mspace_malloc_stats(mspace msp) { mstate ms = (mstate) msp; if (ok_magic(ms)) { internal_malloc_stats(ms); } else { USAGE_ERROR_ACTION(ms, ms); } } size_t mspace_footprint(mspace msp) { size_t result; mstate ms = (mstate) msp; if (ok_magic(ms)) { result = ms->footprint; } USAGE_ERROR_ACTION(ms, ms); return result; } size_t mspace_max_footprint(mspace msp) { size_t result; mstate ms = (mstate) msp; if (ok_magic(ms)) { result = ms->max_footprint; } USAGE_ERROR_ACTION(ms, ms); return result; } #if !NO_MALLINFO struct mallinfo mspace_mallinfo(mspace msp) { mstate ms = (mstate) msp; if (!ok_magic(ms)) { USAGE_ERROR_ACTION(ms, ms); } return internal_mallinfo(ms); } #endif /* NO_MALLINFO */ int mspace_mallopt(int param_number, int value) { return change_mparam(param_number, value); } #endif /* MSPACES */ /* -------------------- Alternative MORECORE functions ------------------- */ /* Guidelines for creating a custom version of MORECORE: * For best performance, MORECORE should allocate in multiples of pagesize. * MORECORE may allocate more memory than requested. (Or even less, but this will usually result in a malloc failure.) * MORECORE must not allocate memory when given argument zero, but instead return one past the end address of memory from previous nonzero call. * For best performance, consecutive calls to MORECORE with positive arguments should return increasing addresses, indicating that space has been contiguously extended. * Even though consecutive calls to MORECORE need not return contiguous addresses, it must be OK for malloc'ed chunks to span multiple regions in those cases where they do happen to be contiguous. * MORECORE need not handle negative arguments -- it may instead just return MFAIL when given negative arguments. Negative arguments are always multiples of pagesize. MORECORE must not misinterpret negative args as large positive unsigned args. You can suppress all such calls from even occurring by defining MORECORE_CANNOT_TRIM, As an example alternative MORECORE, here is a custom allocator kindly contributed for pre-OSX macOS. It uses virtually but not necessarily physically contiguous non-paged memory (locked in, present and won't get swapped out). You can use it by uncommenting this section, adding some #includes, and setting up the appropriate defines above: #define MORECORE osMoreCore There is also a shutdown routine that should somehow be called for cleanup upon program exit. #define MAX_POOL_ENTRIES 100 #define MINIMUM_MORECORE_SIZE (64 * 1024U) static int next_os_pool; void *our_os_pools[MAX_POOL_ENTRIES]; void *osMoreCore(int size) { void *ptr = 0; static void *sbrk_top = 0; if (size > 0) { if (size < MINIMUM_MORECORE_SIZE) size = MINIMUM_MORECORE_SIZE; if (CurrentExecutionLevel() == kTaskLevel) ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0); if (ptr == 0) { return (void *) MFAIL; } // save ptrs so they can be freed during cleanup our_os_pools[next_os_pool] = ptr; next_os_pool++; ptr = (void *) ((((size_t) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK); sbrk_top = (char *) ptr + size; return ptr; } else if (size < 0) { // we don't currently support shrink behavior return (void *) MFAIL; } else { return sbrk_top; } } // cleanup any allocated memory pools // called as last thing before shutting down driver void osCleanupMem(void) { void **ptr; for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++) if (*ptr) { PoolDeallocate(*ptr); *ptr = 0; } } */ /* ----------------------------------------------------------------------- History: V2.8.3 Thu Sep 22 11:16:32 2005 Doug Lea (dl at gee) * Add max_footprint functions * Ensure all appropriate literals are size_t * Fix conditional compilation problem for some #define settings * Avoid concatenating segments with the one provided in create_mspace_with_base * Rename some variables to avoid compiler shadowing warnings * Use explicit lock initialization. * Better handling of sbrk interference. * Simplify and fix segment insertion, trimming and mspace_destroy * Reinstate REALLOC_ZERO_BYTES_FREES option from 2.7.x * Thanks especially to Dennis Flanagan for help on these. V2.8.2 Sun Jun 12 16:01:10 2005 Doug Lea (dl at gee) * Fix memalign brace error. V2.8.1 Wed Jun 8 16:11:46 2005 Doug Lea (dl at gee) * Fix improper #endif nesting in C++ * Add explicit casts needed for C++ V2.8.0 Mon May 30 14:09:02 2005 Doug Lea (dl at gee) * Use trees for large bins * Support mspaces * Use segments to unify sbrk-based and mmap-based system allocation, removing need for emulation on most platforms without sbrk. * Default safety checks * Optional footer checks. Thanks to William Robertson for the idea. * Internal code refactoring * Incorporate suggestions and platform-specific changes. Thanks to Dennis Flanagan, Colin Plumb, Niall Douglas, Aaron Bachmann, Emery Berger, and others. * Speed up non-fastbin processing enough to remove fastbins. * Remove useless cfree() to avoid conflicts with other apps. * Remove internal memcpy, memset. Compilers handle builtins better. * Remove some options that no one ever used and rename others. V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee) * Fix malloc_state bitmap array misdeclaration V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee) * Allow tuning of FIRST_SORTED_BIN_SIZE * Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte. * Better detection and support for non-contiguousness of MORECORE. Thanks to Andreas Mueller, Conal Walsh, and Wolfram Gloger * Bypass most of malloc if no frees. Thanks To Emery Berger. * Fix freeing of old top non-contiguous chunk im sysmalloc. * Raised default trim and map thresholds to 256K. * Fix mmap-related #defines. Thanks to Lubos Lunak. * Fix copy macros; added LACKS_FCNTL_H. Thanks to Neal Walfield. * Branch-free bin calculation * Default trim and mmap thresholds now 256K. V2.7.0 Sun Mar 11 14:14:06 2001 Doug Lea (dl at gee) * Introduce independent_comalloc and independent_calloc. Thanks to Michael Pachos for motivation and help. * Make optional .h file available * Allow > 2GB requests on 32bit systems. * new WIN32 sbrk, mmap, munmap, lock code from <Walter@GeNeSys-e.de>. Thanks also to Andreas Mueller <a.mueller at paradatec.de>, and Anonymous. * Allow override of MALLOC_ALIGNMENT (Thanks to Ruud Waij for helping test this.) * memalign: check alignment arg * realloc: don't try to shift chunks backwards, since this leads to more fragmentation in some programs and doesn't seem to help in any others. * Collect all cases in malloc requiring system memory into sysmalloc * Use mmap as backup to sbrk * Place all internal state in malloc_state * Introduce fastbins (although similar to 2.5.1) * Many minor tunings and cosmetic improvements * Introduce USE_PUBLIC_MALLOC_WRAPPERS, USE_MALLOC_LOCK * Introduce MALLOC_FAILURE_ACTION, MORECORE_CONTIGUOUS Thanks to Tony E. Bennett <tbennett@nvidia.com> and others. * Include errno.h to support default failure action. V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee) * return null for negative arguments * Added Several WIN32 cleanups from Martin C. Fong <mcfong at yahoo.com> * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' (e.g. WIN32 platforms) * Cleanup header file inclusion for WIN32 platforms * Cleanup code to avoid Microsoft Visual C++ compiler complaints * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing memory allocation routines * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to usage of 'assert' in non-WIN32 code * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to avoid infinite loop * Always call 'fREe()' rather than 'free()' V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee) * Fixed ordering problem with boundary-stamping V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee) * Added pvalloc, as recommended by H.J. Liu * Added 64bit pointer support mainly from Wolfram Gloger * Added anonymously donated WIN32 sbrk emulation * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen * malloc_extend_top: fix mask error that caused wastage after foreign sbrks * Add linux mremap support code from HJ Liu V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) * Integrated most documentation with the code. * Add support for mmap, with help from Wolfram Gloger (Gloger@lrz.uni-muenchen.de). * Use last_remainder in more cases. * Pack bins using idea from colin@nyx10.cs.du.edu * Use ordered bins instead of best-fit threshhold * Eliminate block-local decls to simplify tracing and debugging. * Support another case of realloc via move into top * Fix error occuring when initial sbrk_base not word-aligned. * Rely on page size for units instead of SBRK_UNIT to avoid surprises about sbrk alignment conventions. * Add mallinfo, mallopt. Thanks to Raymond Nijssen (raymond@es.ele.tue.nl) for the suggestion. * Add `pad' argument to malloc_trim and top_pad mallopt parameter. * More precautions for cases where other routines call sbrk, courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). * Added macros etc., allowing use in linux libc from H.J. Lu (hjl@gnu.ai.mit.edu) * Inverted this history list V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) * Re-tuned and fixed to behave more nicely with V2.6.0 changes. * Removed all preallocation code since under current scheme the work required to undo bad preallocations exceeds the work saved in good cases for most test programs. * No longer use return list or unconsolidated bins since no scheme using them consistently outperforms those that don't given above changes. * Use best fit for very large chunks to prevent some worst-cases. * Added some support for debugging V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) * Removed footers when chunks are in use. Thanks to Paul Wilson (wilson@cs.texas.edu) for the suggestion. V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) * Added malloc_trim, with help from Wolfram Gloger (wmglo@Dent.MED.Uni-Muenchen.DE). V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g) * realloc: try to expand in both directions * malloc: swap order of clean-bin strategy; * realloc: only conditionally expand backwards * Try not to scavenge used bins * Use bin counts as a guide to preallocation * Occasionally bin return list chunks in first scan * Add a few optimizations from colin@nyx10.cs.du.edu V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) * faster bin computation & slightly different binning * merged all consolidations to one part of malloc proper (eliminating old malloc_find_space & malloc_clean_bin) * Scan 2 returns chunks (not just 1) * Propagate failure in realloc if malloc returns 0 * Add stuff to allow compilation on non-ANSI compilers from kpv@research.att.com V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) * removed potential for odd address access in prev_chunk * removed dependency on getpagesize.h * misc cosmetics and a bit more internal documentation * anticosmetics: mangled names in macros to evade debugger strangeness * tested on sparc, hp-700, dec-mips, rs6000 with gcc & native cc (hp, dec only) allowing Detlefs & Zorn comparison study (in SIGPLAN Notices.) Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) * Based loosely on libg++-1.2X malloc. (It retains some of the overall structure of old version, but most details differ.) */ #endif /* !HAVE_MALLOC */ #ifdef HAVE_MALLOC #define real_malloc malloc #define real_calloc calloc #define real_realloc realloc #define real_free free #else #define real_malloc dlmalloc #define real_calloc dlcalloc #define real_realloc dlrealloc #define real_free dlfree #endif /* Memory functions used by SDL that can be replaced by the application */ static struct { SDL_malloc_func malloc_func; SDL_calloc_func calloc_func; SDL_realloc_func realloc_func; SDL_free_func free_func; SDL_atomic_t num_allocations; } s_mem = { real_malloc, real_calloc, real_realloc, real_free, { 0 } }; void SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func) { if (malloc_func) { *malloc_func = s_mem.malloc_func; } if (calloc_func) { *calloc_func = s_mem.calloc_func; } if (realloc_func) { *realloc_func = s_mem.realloc_func; } if (free_func) { *free_func = s_mem.free_func; } } int SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func) { if (!malloc_func) { return SDL_InvalidParamError("malloc_func"); } if (!calloc_func) { return SDL_InvalidParamError("calloc_func"); } if (!realloc_func) { return SDL_InvalidParamError("realloc_func"); } if (!free_func) { return SDL_InvalidParamError("free_func"); } s_mem.malloc_func = malloc_func; s_mem.calloc_func = calloc_func; s_mem.realloc_func = realloc_func; s_mem.free_func = free_func; return 0; } int SDL_GetNumAllocations(void) { return SDL_AtomicGet(&s_mem.num_allocations); } void *SDL_malloc(size_t size) { void *mem; if (!size) { size = 1; } mem = s_mem.malloc_func(size); if (mem) { SDL_AtomicIncRef(&s_mem.num_allocations); } return mem; } void *SDL_calloc(size_t nmemb, size_t size) { void *mem; if (!nmemb || !size) { nmemb = 1; size = 1; } mem = s_mem.calloc_func(nmemb, size); if (mem) { SDL_AtomicIncRef(&s_mem.num_allocations); } return mem; } void *SDL_realloc(void *ptr, size_t size) { void *mem; if (!ptr && !size) { size = 1; } mem = s_mem.realloc_func(ptr, size); if (mem && !ptr) { SDL_AtomicIncRef(&s_mem.num_allocations); } return mem; } void SDL_free(void *ptr) { if (!ptr) { return; } s_mem.free_func(ptr); (void)SDL_AtomicDecRef(&s_mem.num_allocations); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/stdlib/SDL_malloc.c
C
apache-2.0
196,668
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) #define SDL_DISABLE_ANALYZE_MACROS 1 #endif #include "../SDL_internal.h" #include "SDL_stdinc.h" #include "SDL_assert.h" #if defined(HAVE_QSORT) void SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *)) { qsort(base, nmemb, size, compare); } #else #ifdef assert #undef assert #endif #define assert SDL_assert #ifdef malloc #undef malloc #endif #define malloc SDL_malloc #ifdef free #undef free #endif #define free SDL_free #ifdef memcpy #undef memcpy #endif #define memcpy SDL_memcpy #ifdef memmove #undef memmove #endif #define memmove SDL_memmove #ifdef qsortG #undef qsortG #endif #define qsortG SDL_qsort /* This code came from Gareth McCaughan, under the zlib license. Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.15 Everything below this comment until the HAVE_QSORT #endif was from Gareth (any minor changes will be noted inline). Thank you to Gareth for relicensing this code under the zlib license for our benefit! --ryan. */ /* This is a drop-in replacement for the C library's |qsort()| routine. * * It is intended for use where you know or suspect that your * platform's qsort is bad. If that isn't the case, then you * should probably use the qsort your system gives you in preference * to mine -- it will likely have been tested and tuned better. * * Features: * - Median-of-three pivoting (and more) * - Truncation and final polishing by a single insertion sort * - Early truncation when no swaps needed in pivoting step * - Explicit recursion, guaranteed not to overflow * - A few little wrinkles stolen from the GNU |qsort()|. * (For the avoidance of doubt, no code was stolen, only * broad ideas.) * - separate code for non-aligned / aligned / word-size objects * * Earlier releases of this code used an idiosyncratic licence * I wrote myself, because I'm an idiot. The code is now released * under the "zlib/libpng licence"; you will find the actual * terms in the next comment. I request (but do not require) * that if you make any changes beyond the name of the exported * routine and reasonable tweaks to the TRUNC_* and * PIVOT_THRESHOLD values, you modify the _ID string so as * to make it clear that you have changed the code. * * If you find problems with this code, or find ways of * making it significantly faster, please let me know! * My e-mail address, valid as of early 2016 and for the * foreseeable future, is * gareth.mccaughan@pobox.com * Thanks! * * Gareth McCaughan */ /* Copyright (c) 1998-2016 Gareth McCaughan * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any * damages arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; * you must not claim that you wrote the original software. * If you use this software in a product, an acknowledgment * in the product documentation would be appreciated but * is not required. * * 2. Altered source versions must be plainly marked as such, * and must not be misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source * distribution. */ /* Revision history since release: * 1998-03-19 v1.12 First release I have any records of. * 2007-09-02 v1.13 Fix bug kindly reported by Dan Bodoh * (premature termination of recursion). * Add a few clarifying comments. * Minor improvements to debug output. * 2016-02-21 v1.14 Replace licence with 2-clause BSD, * and clarify a couple of things in * comments. No code changes. * 2016-03-10 v1.15 Fix bug kindly reported by Ryan Gordon * (pre-insertion-sort messed up). * Disable DEBUG_QSORT by default. * Tweak comments very slightly. */ /* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */ #if 0 #include <assert.h> #include <stdlib.h> #include <string.h> #undef DEBUG_QSORT static char _ID[]="<qsort.c gjm 1.15 2016-03-10>"; #endif /* END SDL CHANGE ... commented this out with an #if 0 block. --ryan. */ /* How many bytes are there per word? (Must be a power of 2, * and must in fact equal sizeof(int).) */ #define WORD_BYTES sizeof(int) /* How big does our stack need to be? Answer: one entry per * bit in a |size_t|. */ #define STACK_SIZE (8*sizeof(size_t)) /* Different situations have slightly different requirements, * and we make life epsilon easier by using different truncation * points for the three different cases. * So far, I have tuned TRUNC_words and guessed that the same * value might work well for the other two cases. Of course * what works well on my machine might work badly on yours. */ #define TRUNC_nonaligned 12 #define TRUNC_aligned 12 #define TRUNC_words 12*WORD_BYTES /* nb different meaning */ /* We use a simple pivoting algorithm for shortish sub-arrays * and a more complicated one for larger ones. The threshold * is PIVOT_THRESHOLD. */ #define PIVOT_THRESHOLD 40 typedef struct { char * first; char * last; } stack_entry; #define pushLeft {stack[stacktop].first=ffirst;stack[stacktop++].last=last;} #define pushRight {stack[stacktop].first=first;stack[stacktop++].last=llast;} #define doLeft {first=ffirst;llast=last;continue;} #define doRight {ffirst=first;last=llast;continue;} #define pop {if (--stacktop<0) break;\ first=ffirst=stack[stacktop].first;\ last=llast=stack[stacktop].last;\ continue;} /* Some comments on the implementation. * 1. When we finish partitioning the array into "low" * and "high", we forget entirely about short subarrays, * because they'll be done later by insertion sort. * Doing lots of little insertion sorts might be a win * on large datasets for locality-of-reference reasons, * but it makes the code much nastier and increases * bookkeeping overhead. * 2. We always save the shorter and get to work on the * longer. This guarantees that every time we push * an item onto the stack its size is <= 1/2 of that * of its parent; so the stack can't need more than * log_2(max-array-size) entries. * 3. We choose a pivot by looking at the first, last * and middle elements. We arrange them into order * because it's easy to do that in conjunction with * choosing the pivot, and it makes things a little * easier in the partitioning step. Anyway, the pivot * is the middle of these three. It's still possible * to construct datasets where the algorithm takes * time of order n^2, but it simply never happens in * practice. * 3' Newsflash: On further investigation I find that * it's easy to construct datasets where median-of-3 * simply isn't good enough. So on large-ish subarrays * we do a more sophisticated pivoting: we take three * sets of 3 elements, find their medians, and then * take the median of those. * 4. We copy the pivot element to a separate place * because that way we can always do our comparisons * directly against a pointer to that separate place, * and don't have to wonder "did we move the pivot * element?". This makes the inner loop better. * 5. It's possible to make the pivoting even more * reliable by looking at more candidates when n * is larger. (Taking this to its logical conclusion * results in a variant of quicksort that doesn't * have that n^2 worst case.) However, the overhead * from the extra bookkeeping means that it's just * not worth while. * 6. This is pretty clean and portable code. Here are * all the potential portability pitfalls and problems * I know of: * - In one place (the insertion sort) I construct * a pointer that points just past the end of the * supplied array, and assume that (a) it won't * compare equal to any pointer within the array, * and (b) it will compare equal to a pointer * obtained by stepping off the end of the array. * These might fail on some segmented architectures. * - I assume that there are 8 bits in a |char| when * computing the size of stack needed. This would * fail on machines with 9-bit or 16-bit bytes. * - I assume that if |((int)base&(sizeof(int)-1))==0| * and |(size&(sizeof(int)-1))==0| then it's safe to * get at array elements via |int*|s, and that if * actually |size==sizeof(int)| as well then it's * safe to treat the elements as |int|s. This might * fail on systems that convert pointers to integers * in non-standard ways. * - I assume that |8*sizeof(size_t)<=INT_MAX|. This * would be false on a machine with 8-bit |char|s, * 16-bit |int|s and 4096-bit |size_t|s. :-) */ /* The recursion logic is the same in each case. * We keep chopping up until we reach subarrays of size * strictly less than Trunc; we leave these unsorted. */ #define Recurse(Trunc) \ { size_t l=last-ffirst,r=llast-first; \ if (l<Trunc) { \ if (r>=Trunc) doRight \ else pop \ } \ else if (l<=r) { pushLeft; doRight } \ else if (r>=Trunc) { pushRight; doLeft }\ else doLeft \ } /* and so is the pivoting logic (note: last is inclusive): */ #define Pivot(swapper,sz) \ if ((size_t)(last-first)>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\ else { \ if (compare(first,mid)<0) { \ if (compare(mid,last)>0) { \ swapper(mid,last); \ if (compare(first,mid)>0) swapper(first,mid);\ } \ } \ else { \ if (compare(mid,last)>0) swapper(first,last)\ else { \ swapper(first,mid); \ if (compare(mid,last)>0) swapper(mid,last);\ } \ } \ first+=sz; last-=sz; \ } #ifdef DEBUG_QSORT #include <stdio.h> #endif /* and so is the partitioning logic: */ #define Partition(swapper,sz) { \ do { \ while (compare(first,pivot)<0) first+=sz; \ while (compare(pivot,last)<0) last-=sz; \ if (first<last) { \ swapper(first,last); \ first+=sz; last-=sz; } \ else if (first==last) { first+=sz; last-=sz; break; }\ } while (first<=last); \ } /* and so is the pre-insertion-sort operation of putting * the smallest element into place as a sentinel. * Doing this makes the inner loop nicer. I got this * idea from the GNU implementation of qsort(). * We find the smallest element from the first |nmemb|, * or the first |limit|, whichever is smaller; * therefore we must have ensured that the globally smallest * element is in the first |limit| (because our * quicksort recursion bottoms out only once we * reach subarrays smaller than |limit|). */ #define PreInsertion(swapper,limit,sz) \ first=base; \ last=first + ((nmemb>limit ? limit : nmemb)-1)*sz;\ while (last!=base) { \ if (compare(first,last)>0) first=last; \ last-=sz; } \ if (first!=base) swapper(first,(char*)base); /* and so is the insertion sort, in the first two cases: */ #define Insertion(swapper) \ last=((char*)base)+nmemb*size; \ for (first=((char*)base)+size;first!=last;first+=size) { \ char *test; \ /* Find the right place for |first|. \ * My apologies for var reuse. */ \ for (test=first-size;compare(test,first)>0;test-=size) ; \ test+=size; \ if (test!=first) { \ /* Shift everything in [test,first) \ * up by one, and place |first| \ * where |test| is. */ \ memcpy(pivot,first,size); \ memmove(test+size,test,first-test); \ memcpy(test,pivot,size); \ } \ } #define SWAP_nonaligned(a,b) { \ register char *aa=(a),*bb=(b); \ register size_t sz=size; \ do { register char t=*aa; *aa++=*bb; *bb++=t; } while (--sz); } #define SWAP_aligned(a,b) { \ register int *aa=(int*)(a),*bb=(int*)(b); \ register size_t sz=size; \ do { register int t=*aa;*aa++=*bb; *bb++=t; } while (sz-=WORD_BYTES); } #define SWAP_words(a,b) { \ register int t=*((int*)a); *((int*)a)=*((int*)b); *((int*)b)=t; } /* ---------------------------------------------------------------------- */ static char * pivot_big(char *first, char *mid, char *last, size_t size, int compare(const void *, const void *)) { size_t d=(((last-first)/size)>>3)*size; #ifdef DEBUG_QSORT fprintf(stderr, "pivot_big: first=%p last=%p size=%lu n=%lu\n", first, (unsigned long)last, size, (unsigned long)((last-first+1)/size)); #endif char *m1,*m2,*m3; { char *a=first, *b=first+d, *c=first+2*d; #ifdef DEBUG_QSORT fprintf(stderr,"< %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c); #endif m1 = compare(a,b)<0 ? (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b)); } { char *a=mid-d, *b=mid, *c=mid+d; #ifdef DEBUG_QSORT fprintf(stderr,". %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c); #endif m2 = compare(a,b)<0 ? (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b)); } { char *a=last-2*d, *b=last-d, *c=last; #ifdef DEBUG_QSORT fprintf(stderr,"> %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c); #endif m3 = compare(a,b)<0 ? (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a)) : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b)); } #ifdef DEBUG_QSORT fprintf(stderr,"-> %d %d %d @ %p %p %p\n",*(int*)m1,*(int*)m2,*(int*)m3, m1,m2,m3); #endif return compare(m1,m2)<0 ? (compare(m2,m3)<0 ? m2 : (compare(m1,m3)<0 ? m3 : m1)) : (compare(m1,m3)<0 ? m1 : (compare(m2,m3)<0 ? m3 : m2)); } /* ---------------------------------------------------------------------- */ static void qsort_nonaligned(void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *)) { stack_entry stack[STACK_SIZE]; int stacktop=0; char *first,*last; char *pivot=malloc(size); size_t trunc=TRUNC_nonaligned*size; assert(pivot!=0); first=(char*)base; last=first+(nmemb-1)*size; if ((size_t)(last-first)>=trunc) { char *ffirst=first, *llast=last; while (1) { /* Select pivot */ { char * mid=first+size*((last-first)/size >> 1); Pivot(SWAP_nonaligned,size); memcpy(pivot,mid,size); } /* Partition. */ Partition(SWAP_nonaligned,size); /* Prepare to recurse/iterate. */ Recurse(trunc) } } PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size); Insertion(SWAP_nonaligned); free(pivot); } static void qsort_aligned(void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *)) { stack_entry stack[STACK_SIZE]; int stacktop=0; char *first,*last; char *pivot=malloc(size); size_t trunc=TRUNC_aligned*size; assert(pivot!=0); first=(char*)base; last=first+(nmemb-1)*size; if ((size_t)(last-first)>=trunc) { char *ffirst=first,*llast=last; while (1) { /* Select pivot */ { char * mid=first+size*((last-first)/size >> 1); Pivot(SWAP_aligned,size); memcpy(pivot,mid,size); } /* Partition. */ Partition(SWAP_aligned,size); /* Prepare to recurse/iterate. */ Recurse(trunc) } } PreInsertion(SWAP_aligned,TRUNC_aligned,size); Insertion(SWAP_aligned); free(pivot); } static void qsort_words(void *base, size_t nmemb, int (*compare)(const void *, const void *)) { stack_entry stack[STACK_SIZE]; int stacktop=0; char *first,*last; char *pivot=malloc(WORD_BYTES); assert(pivot!=0); first=(char*)base; last=first+(nmemb-1)*WORD_BYTES; if (last-first>=TRUNC_words) { char *ffirst=first, *llast=last; while (1) { #ifdef DEBUG_QSORT fprintf(stderr,"Doing %d:%d: ", (first-(char*)base)/WORD_BYTES, (last-(char*)base)/WORD_BYTES); #endif /* Select pivot */ { char * mid=first+WORD_BYTES*((last-first) / (2*WORD_BYTES)); Pivot(SWAP_words,WORD_BYTES); *(int*)pivot=*(int*)mid; #ifdef DEBUG_QSORT fprintf(stderr,"pivot = %p = #%lu = %d\n", mid, (unsigned long)(((int*)mid)-((int*)base)), *(int*)mid); #endif } /* Partition. */ Partition(SWAP_words,WORD_BYTES); #ifdef DEBUG_QSORT fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)/4lu, (last-(char*)base)/4lu); #endif /* Prepare to recurse/iterate. */ Recurse(TRUNC_words) } } PreInsertion(SWAP_words,TRUNC_words/WORD_BYTES,WORD_BYTES); /* Now do insertion sort. */ last=((char*)base)+nmemb*WORD_BYTES; for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) { /* Find the right place for |first|. My apologies for var reuse */ int *pl=(int*)(first-WORD_BYTES),*pr=(int*)first; *(int*)pivot=*(int*)first; for (;compare(pl,pivot)>0;pr=pl,--pl) { *pr=*pl; } if (pr!=(int*)first) *pr=*(int*)pivot; } free(pivot); } /* ---------------------------------------------------------------------- */ extern void qsortG(void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *)) { if (nmemb<=1) return; if (((size_t)base|size)&(WORD_BYTES-1)) qsort_nonaligned(base,nmemb,size,compare); else if (size!=WORD_BYTES) qsort_aligned(base,nmemb,size,compare); else qsort_words(base,nmemb,compare); } #endif /* HAVE_QSORT */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/stdlib/SDL_qsort.c
C
apache-2.0
18,876
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) #define SDL_DISABLE_ANALYZE_MACROS 1 #endif #include "../SDL_internal.h" /* This file contains portable stdlib functions for SDL */ #include "SDL_stdinc.h" #include "../libm/math_libm.h" double SDL_atan(double x) { #if defined(HAVE_ATAN) return atan(x); #else return SDL_uclibc_atan(x); #endif } float SDL_atanf(float x) { #if defined(HAVE_ATANF) return atanf(x); #else return (float)SDL_atan((double)x); #endif } double SDL_atan2(double x, double y) { #if defined(HAVE_ATAN2) return atan2(x, y); #else return SDL_uclibc_atan2(x, y); #endif } float SDL_atan2f(float x, float y) { #if defined(HAVE_ATAN2F) return atan2f(x, y); #else return (float)SDL_atan2((double)x, (double)y); #endif } double SDL_acos(double val) { #if defined(HAVE_ACOS) return acos(val); #else double result; if (val == -1.0) { result = M_PI; } else { result = SDL_atan(SDL_sqrt(1.0 - val * val) / val); if (result < 0.0) { result += M_PI; } } return result; #endif } float SDL_acosf(float val) { #if defined(HAVE_ACOSF) return acosf(val); #else return (float)SDL_acos((double)val); #endif } double SDL_asin(double val) { #if defined(HAVE_ASIN) return asin(val); #else double result; if (val == -1.0) { result = -(M_PI / 2.0); } else { result = (M_PI / 2.0) - SDL_acos(val); } return result; #endif } float SDL_asinf(float val) { #if defined(HAVE_ASINF) return asinf(val); #else return (float)SDL_asin((double)val); #endif } double SDL_ceil(double x) { #if defined(HAVE_CEIL) return ceil(x); #else double integer = SDL_floor(x); double fraction = x - integer; if (fraction > 0.0) { integer += 1.0; } return integer; #endif /* HAVE_CEIL */ } float SDL_ceilf(float x) { #if defined(HAVE_CEILF) return ceilf(x); #else return (float)SDL_ceil((float)x); #endif } double SDL_copysign(double x, double y) { #if defined(HAVE_COPYSIGN) return copysign(x, y); #elif defined(HAVE__COPYSIGN) return _copysign(x, y); #elif defined(__WATCOMC__) && defined(__386__) /* this is nasty as hell, but it works.. */ unsigned int *xi = (unsigned int *) &x, *yi = (unsigned int *) &y; xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff); return x; #else return SDL_uclibc_copysign(x, y); #endif /* HAVE_COPYSIGN */ } float SDL_copysignf(float x, float y) { #if defined(HAVE_COPYSIGNF) return copysignf(x, y); #else return (float)SDL_copysign((double)x, (double)y); #endif } double SDL_cos(double x) { #if defined(HAVE_COS) return cos(x); #else return SDL_uclibc_cos(x); #endif } float SDL_cosf(float x) { #if defined(HAVE_COSF) return cosf(x); #else return (float)SDL_cos((double)x); #endif } double SDL_exp(double x) { #if defined(HAVE_EXP) return exp(x); #else return SDL_uclibc_exp(x); #endif } float SDL_expf(float x) { #if defined(HAVE_EXPF) return expf(x); #else return (float)SDL_exp((double)x); #endif } double SDL_fabs(double x) { #if defined(HAVE_FABS) return fabs(x); #else return SDL_uclibc_fabs(x); #endif } float SDL_fabsf(float x) { #if defined(HAVE_FABSF) return fabsf(x); #else return (float)SDL_fabs((double)x); #endif } double SDL_floor(double x) { #if defined(HAVE_FLOOR) return floor(x); #else return SDL_uclibc_floor(x); #endif } float SDL_floorf(float x) { #if defined(HAVE_FLOORF) return floorf(x); #else return (float)SDL_floor((double)x); #endif } double SDL_trunc(double x) { #if defined(HAVE_TRUNC) return trunc(x); #else if (x >= 0.0f) { return SDL_floor(x); } else { return SDL_ceil(x); } #endif } float SDL_truncf(float x) { #if defined(HAVE_TRUNCF) return truncf(x); #else return (float)SDL_trunc((double)x); #endif } double SDL_fmod(double x, double y) { #if defined(HAVE_FMOD) return fmod(x, y); #else return SDL_uclibc_fmod(x, y); #endif } float SDL_fmodf(float x, float y) { #if defined(HAVE_FMODF) return fmodf(x, y); #else return (float)SDL_fmod((double)x, (double)y); #endif } double SDL_log(double x) { #if defined(HAVE_LOG) return log(x); #else return SDL_uclibc_log(x); #endif } float SDL_logf(float x) { #if defined(HAVE_LOGF) return logf(x); #else return (float)SDL_log((double)x); #endif } double SDL_log10(double x) { #if defined(HAVE_LOG10) return log10(x); #else return SDL_uclibc_log10(x); #endif } float SDL_log10f(float x) { #if defined(HAVE_LOG10F) return log10f(x); #else return (float)SDL_log10((double)x); #endif } double SDL_pow(double x, double y) { #if defined(HAVE_POW) return pow(x, y); #else return SDL_uclibc_pow(x, y); #endif } float SDL_powf(float x, float y) { #if defined(HAVE_POWF) return powf(x, y); #else return (float)SDL_pow((double)x, (double)y); #endif } double SDL_scalbn(double x, int n) { #if defined(HAVE_SCALBN) return scalbn(x, n); #elif defined(HAVE__SCALB) return _scalb(x, n); #elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2) /* from scalbn(3): If FLT_RADIX equals 2 (which is * usual), then scalbn() is equivalent to ldexp(3). */ return ldexp(x, n); #else return SDL_uclibc_scalbn(x, n); #endif } float SDL_scalbnf(float x, int n) { #if defined(HAVE_SCALBNF) return scalbnf(x, n); #else return (float)SDL_scalbn((double)x, n); #endif } double SDL_sin(double x) { #if defined(HAVE_SIN) return sin(x); #else return SDL_uclibc_sin(x); #endif } float SDL_sinf(float x) { #if defined(HAVE_SINF) return sinf(x); #else return (float)SDL_sin((double)x); #endif } double SDL_sqrt(double x) { #if defined(HAVE_SQRT) return sqrt(x); #else return SDL_uclibc_sqrt(x); #endif } float SDL_sqrtf(float x) { #if defined(HAVE_SQRTF) return sqrtf(x); #else return (float)SDL_sqrt((double)x); #endif } double SDL_tan(double x) { #if defined(HAVE_TAN) return tan(x); #else return SDL_uclibc_tan(x); #endif } float SDL_tanf(float x) { #if defined(HAVE_TANF) return tanf(x); #else return (float)SDL_tan((double)x); #endif } int SDL_abs(int x) { #if defined(HAVE_ABS) return abs(x); #else return ((x) < 0 ? -(x) : (x)); #endif } #if defined(HAVE_CTYPE_H) int SDL_isdigit(int x) { return isdigit(x); } int SDL_isspace(int x) { return isspace(x); } int SDL_isupper(int x) { return isupper(x); } int SDL_islower(int x) { return islower(x); } int SDL_toupper(int x) { return toupper(x); } int SDL_tolower(int x) { return tolower(x); } #else int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); } int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); } int SDL_isupper(int x) { return ((x) >= 'A') && ((x) <= 'Z'); } int SDL_islower(int x) { return ((x) >= 'a') && ((x) <= 'z'); } int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); } int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); } #endif #ifndef HAVE_LIBC /* These are some C runtime intrinsics that need to be defined */ #if defined(_MSC_VER) #ifndef __FLTUSED__ #define __FLTUSED__ __declspec(selectany) int _fltused = 1; #endif /* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls */ #if _MSC_VER >= 1400 #pragma function(memcpy) void * memcpy(void *dst, const void *src, size_t len) { return SDL_memcpy(dst, src, len); } #pragma function(memset) void * memset(void *dst, int c, size_t len) { return SDL_memset(dst, c, len); } #endif #ifdef _M_IX86 /* Float to long */ void __declspec(naked) _ftol() { /* *INDENT-OFF* */ __asm { push ebp mov ebp,esp sub esp,20h and esp,0FFFFFFF0h fld st(0) fst dword ptr [esp+18h] fistp qword ptr [esp+10h] fild qword ptr [esp+10h] mov edx,dword ptr [esp+18h] mov eax,dword ptr [esp+10h] test eax,eax je integer_QnaN_or_zero arg_is_not_integer_QnaN: fsubp st(1),st test edx,edx jns positive fstp dword ptr [esp] mov ecx,dword ptr [esp] xor ecx,80000000h add ecx,7FFFFFFFh adc eax,0 mov edx,dword ptr [esp+14h] adc edx,0 jmp localexit positive: fstp dword ptr [esp] mov ecx,dword ptr [esp] add ecx,7FFFFFFFh sbb eax,0 mov edx,dword ptr [esp+14h] sbb edx,0 jmp localexit integer_QnaN_or_zero: mov edx,dword ptr [esp+14h] test edx,7FFFFFFFh jne arg_is_not_integer_QnaN fstp dword ptr [esp+18h] fstp dword ptr [esp+18h] localexit: leave ret } /* *INDENT-ON* */ } void _ftol2_sse() { _ftol(); } /* 64-bit math operators for 32-bit systems */ void __declspec(naked) _allmul() { /* *INDENT-OFF* */ __asm { mov eax, dword ptr[esp+8] mov ecx, dword ptr[esp+10h] or ecx, eax mov ecx, dword ptr[esp+0Ch] jne hard mov eax, dword ptr[esp+4] mul ecx ret 10h hard: push ebx mul ecx mov ebx, eax mov eax, dword ptr[esp+8] mul dword ptr[esp+14h] add ebx, eax mov eax, dword ptr[esp+8] mul ecx add edx, ebx pop ebx ret 10h } /* *INDENT-ON* */ } void __declspec(naked) _alldiv() { /* *INDENT-OFF* */ __asm { push edi push esi push ebx xor edi,edi mov eax,dword ptr [esp+14h] or eax,eax jge L1 inc edi mov edx,dword ptr [esp+10h] neg eax neg edx sbb eax,0 mov dword ptr [esp+14h],eax mov dword ptr [esp+10h],edx L1: mov eax,dword ptr [esp+1Ch] or eax,eax jge L2 inc edi mov edx,dword ptr [esp+18h] neg eax neg edx sbb eax,0 mov dword ptr [esp+1Ch],eax mov dword ptr [esp+18h],edx L2: or eax,eax jne L3 mov ecx,dword ptr [esp+18h] mov eax,dword ptr [esp+14h] xor edx,edx div ecx mov ebx,eax mov eax,dword ptr [esp+10h] div ecx mov edx,ebx jmp L4 L3: mov ebx,eax mov ecx,dword ptr [esp+18h] mov edx,dword ptr [esp+14h] mov eax,dword ptr [esp+10h] L5: shr ebx,1 rcr ecx,1 shr edx,1 rcr eax,1 or ebx,ebx jne L5 div ecx mov esi,eax mul dword ptr [esp+1Ch] mov ecx,eax mov eax,dword ptr [esp+18h] mul esi add edx,ecx jb L6 cmp edx,dword ptr [esp+14h] ja L6 jb L7 cmp eax,dword ptr [esp+10h] jbe L7 L6: dec esi L7: xor edx,edx mov eax,esi L4: dec edi jne L8 neg edx neg eax sbb edx,0 L8: pop ebx pop esi pop edi ret 10h } /* *INDENT-ON* */ } void __declspec(naked) _aulldiv() { /* *INDENT-OFF* */ __asm { push ebx push esi mov eax,dword ptr [esp+18h] or eax,eax jne L1 mov ecx,dword ptr [esp+14h] mov eax,dword ptr [esp+10h] xor edx,edx div ecx mov ebx,eax mov eax,dword ptr [esp+0Ch] div ecx mov edx,ebx jmp L2 L1: mov ecx,eax mov ebx,dword ptr [esp+14h] mov edx,dword ptr [esp+10h] mov eax,dword ptr [esp+0Ch] L3: shr ecx,1 rcr ebx,1 shr edx,1 rcr eax,1 or ecx,ecx jne L3 div ebx mov esi,eax mul dword ptr [esp+18h] mov ecx,eax mov eax,dword ptr [esp+14h] mul esi add edx,ecx jb L4 cmp edx,dword ptr [esp+10h] ja L4 jb L5 cmp eax,dword ptr [esp+0Ch] jbe L5 L4: dec esi L5: xor edx,edx mov eax,esi L2: pop esi pop ebx ret 10h } /* *INDENT-ON* */ } void __declspec(naked) _allrem() { /* *INDENT-OFF* */ __asm { push ebx push edi xor edi,edi mov eax,dword ptr [esp+10h] or eax,eax jge L1 inc edi mov edx,dword ptr [esp+0Ch] neg eax neg edx sbb eax,0 mov dword ptr [esp+10h],eax mov dword ptr [esp+0Ch],edx L1: mov eax,dword ptr [esp+18h] or eax,eax jge L2 mov edx,dword ptr [esp+14h] neg eax neg edx sbb eax,0 mov dword ptr [esp+18h],eax mov dword ptr [esp+14h],edx L2: or eax,eax jne L3 mov ecx,dword ptr [esp+14h] mov eax,dword ptr [esp+10h] xor edx,edx div ecx mov eax,dword ptr [esp+0Ch] div ecx mov eax,edx xor edx,edx dec edi jns L4 jmp L8 L3: mov ebx,eax mov ecx,dword ptr [esp+14h] mov edx,dword ptr [esp+10h] mov eax,dword ptr [esp+0Ch] L5: shr ebx,1 rcr ecx,1 shr edx,1 rcr eax,1 or ebx,ebx jne L5 div ecx mov ecx,eax mul dword ptr [esp+18h] xchg eax,ecx mul dword ptr [esp+14h] add edx,ecx jb L6 cmp edx,dword ptr [esp+10h] ja L6 jb L7 cmp eax,dword ptr [esp+0Ch] jbe L7 L6: sub eax,dword ptr [esp+14h] sbb edx,dword ptr [esp+18h] L7: sub eax,dword ptr [esp+0Ch] sbb edx,dword ptr [esp+10h] dec edi jns L8 L4: neg edx neg eax sbb edx,0 L8: pop edi pop ebx ret 10h } /* *INDENT-ON* */ } void __declspec(naked) _aullrem() { /* *INDENT-OFF* */ __asm { push ebx mov eax,dword ptr [esp+14h] or eax,eax jne L1 mov ecx,dword ptr [esp+10h] mov eax,dword ptr [esp+0Ch] xor edx,edx div ecx mov eax,dword ptr [esp+8] div ecx mov eax,edx xor edx,edx jmp L2 L1: mov ecx,eax mov ebx,dword ptr [esp+10h] mov edx,dword ptr [esp+0Ch] mov eax,dword ptr [esp+8] L3: shr ecx,1 rcr ebx,1 shr edx,1 rcr eax,1 or ecx,ecx jne L3 div ebx mov ecx,eax mul dword ptr [esp+14h] xchg eax,ecx mul dword ptr [esp+10h] add edx,ecx jb L4 cmp edx,dword ptr [esp+0Ch] ja L4 jb L5 cmp eax,dword ptr [esp+8] jbe L5 L4: sub eax,dword ptr [esp+10h] sbb edx,dword ptr [esp+14h] L5: sub eax,dword ptr [esp+8] sbb edx,dword ptr [esp+0Ch] neg edx neg eax sbb edx,0 L2: pop ebx ret 10h } /* *INDENT-ON* */ } void __declspec(naked) _alldvrm() { /* *INDENT-OFF* */ __asm { push edi push esi push ebp xor edi,edi xor ebp,ebp mov eax,dword ptr [esp+14h] or eax,eax jge L1 inc edi inc ebp mov edx,dword ptr [esp+10h] neg eax neg edx sbb eax,0 mov dword ptr [esp+14h],eax mov dword ptr [esp+10h],edx L1: mov eax,dword ptr [esp+1Ch] or eax,eax jge L2 inc edi mov edx,dword ptr [esp+18h] neg eax neg edx sbb eax,0 mov dword ptr [esp+1Ch],eax mov dword ptr [esp+18h],edx L2: or eax,eax jne L3 mov ecx,dword ptr [esp+18h] mov eax,dword ptr [esp+14h] xor edx,edx div ecx mov ebx,eax mov eax,dword ptr [esp+10h] div ecx mov esi,eax mov eax,ebx mul dword ptr [esp+18h] mov ecx,eax mov eax,esi mul dword ptr [esp+18h] add edx,ecx jmp L4 L3: mov ebx,eax mov ecx,dword ptr [esp+18h] mov edx,dword ptr [esp+14h] mov eax,dword ptr [esp+10h] L5: shr ebx,1 rcr ecx,1 shr edx,1 rcr eax,1 or ebx,ebx jne L5 div ecx mov esi,eax mul dword ptr [esp+1Ch] mov ecx,eax mov eax,dword ptr [esp+18h] mul esi add edx,ecx jb L6 cmp edx,dword ptr [esp+14h] ja L6 jb L7 cmp eax,dword ptr [esp+10h] jbe L7 L6: dec esi sub eax,dword ptr [esp+18h] sbb edx,dword ptr [esp+1Ch] L7: xor ebx,ebx L4: sub eax,dword ptr [esp+10h] sbb edx,dword ptr [esp+14h] dec ebp jns L9 neg edx neg eax sbb edx,0 L9: mov ecx,edx mov edx,ebx mov ebx,ecx mov ecx,eax mov eax,esi dec edi jne L8 neg edx neg eax sbb edx,0 L8: pop ebp pop esi pop edi ret 10h } /* *INDENT-ON* */ } void __declspec(naked) _aulldvrm() { /* *INDENT-OFF* */ __asm { push esi mov eax,dword ptr [esp+14h] or eax,eax jne L1 mov ecx,dword ptr [esp+10h] mov eax,dword ptr [esp+0Ch] xor edx,edx div ecx mov ebx,eax mov eax,dword ptr [esp+8] div ecx mov esi,eax mov eax,ebx mul dword ptr [esp+10h] mov ecx,eax mov eax,esi mul dword ptr [esp+10h] add edx,ecx jmp L2 L1: mov ecx,eax mov ebx,dword ptr [esp+10h] mov edx,dword ptr [esp+0Ch] mov eax,dword ptr [esp+8] L3: shr ecx,1 rcr ebx,1 shr edx,1 rcr eax,1 or ecx,ecx jne L3 div ebx mov esi,eax mul dword ptr [esp+14h] mov ecx,eax mov eax,dword ptr [esp+10h] mul esi add edx,ecx jb L4 cmp edx,dword ptr [esp+0Ch] ja L4 jb L5 cmp eax,dword ptr [esp+8] jbe L5 L4: dec esi sub eax,dword ptr [esp+10h] sbb edx,dword ptr [esp+14h] L5: xor ebx,ebx L2: sub eax,dword ptr [esp+8] sbb edx,dword ptr [esp+0Ch] neg edx neg eax sbb edx,0 mov ecx,edx mov edx,ebx mov ebx,ecx mov ecx,eax mov eax,esi pop esi ret 10h } /* *INDENT-ON* */ } void __declspec(naked) _allshl() { /* *INDENT-OFF* */ __asm { cmp cl,40h jae RETZERO cmp cl,20h jae MORE32 shld edx,eax,cl shl eax,cl ret MORE32: mov edx,eax xor eax,eax and cl,1Fh shl edx,cl ret RETZERO: xor eax,eax xor edx,edx ret } /* *INDENT-ON* */ } void __declspec(naked) _allshr() { /* *INDENT-OFF* */ __asm { cmp cl,3Fh jae RETSIGN cmp cl,20h jae MORE32 shrd eax,edx,cl sar edx,cl ret MORE32: mov eax,edx sar edx,1Fh and cl,1Fh sar eax,cl ret RETSIGN: sar edx,1Fh mov eax,edx ret } /* *INDENT-ON* */ } void __declspec(naked) _aullshr() { /* *INDENT-OFF* */ __asm { cmp cl,40h jae RETZERO cmp cl,20h jae MORE32 shrd eax,edx,cl shr edx,cl ret MORE32: mov eax,edx xor edx,edx and cl,1Fh shr eax,cl ret RETZERO: xor eax,eax xor edx,edx ret } /* *INDENT-ON* */ } #endif /* _M_IX86 */ #endif /* MSC_VER */ #endif /* !HAVE_LIBC */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/stdlib/SDL_stdlib.c
C
apache-2.0
24,703
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #if defined(__clang_analyzer__) #define SDL_DISABLE_ANALYZE_MACROS 1 #endif #include "../SDL_internal.h" /* This file contains portable string manipulation functions for SDL */ #include "SDL_stdinc.h" #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL) || !defined(HAVE_STRTOD) #define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F')) #define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f')) #endif #define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4) #define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF) static int UTF8_TrailingBytes(unsigned char c) { if (c >= 0xC0 && c <= 0xDF) return 1; else if (c >= 0xE0 && c <= 0xEF) return 2; else if (c >= 0xF0 && c <= 0xF4) return 3; else return 0; } #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) static size_t SDL_ScanLong(const char *text, int radix, long *valuep) { const char *textstart = text; long value = 0; SDL_bool negative = SDL_FALSE; if (*text == '-') { negative = SDL_TRUE; ++text; } if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { text += 2; } for (;;) { int v; if (SDL_isdigit((unsigned char) *text)) { v = *text - '0'; } else if (radix == 16 && SDL_isupperhex(*text)) { v = 10 + (*text - 'A'); } else if (radix == 16 && SDL_islowerhex(*text)) { v = 10 + (*text - 'a'); } else { break; } value *= radix; value += v; ++text; } if (valuep && text > textstart) { if (negative && value) { *valuep = -value; } else { *valuep = value; } } return (text - textstart); } #endif #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep) { const char *textstart = text; unsigned long value = 0; if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { text += 2; } for (;;) { int v; if (SDL_isdigit((unsigned char) *text)) { v = *text - '0'; } else if (radix == 16 && SDL_isupperhex(*text)) { v = 10 + (*text - 'A'); } else if (radix == 16 && SDL_islowerhex(*text)) { v = 10 + (*text - 'a'); } else { break; } value *= radix; value += v; ++text; } if (valuep && text > textstart) { *valuep = value; } return (text - textstart); } #endif #ifndef HAVE_VSSCANF static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep) { const char *textstart = text; uintptr_t value = 0; if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { text += 2; } for (;;) { int v; if (SDL_isdigit((unsigned char) *text)) { v = *text - '0'; } else if (radix == 16 && SDL_isupperhex(*text)) { v = 10 + (*text - 'A'); } else if (radix == 16 && SDL_islowerhex(*text)) { v = 10 + (*text - 'a'); } else { break; } value *= radix; value += v; ++text; } if (valuep && text > textstart) { *valuep = value; } return (text - textstart); } #endif #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL) static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep) { const char *textstart = text; Sint64 value = 0; SDL_bool negative = SDL_FALSE; if (*text == '-') { negative = SDL_TRUE; ++text; } if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { text += 2; } for (;;) { int v; if (SDL_isdigit((unsigned char) *text)) { v = *text - '0'; } else if (radix == 16 && SDL_isupperhex(*text)) { v = 10 + (*text - 'A'); } else if (radix == 16 && SDL_islowerhex(*text)) { v = 10 + (*text - 'a'); } else { break; } value *= radix; value += v; ++text; } if (valuep && text > textstart) { if (negative && value) { *valuep = -value; } else { *valuep = value; } } return (text - textstart); } #endif #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOULL) static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep) { const char *textstart = text; Uint64 value = 0; if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) { text += 2; } for (;;) { int v; if (SDL_isdigit((unsigned char) *text)) { v = *text - '0'; } else if (radix == 16 && SDL_isupperhex(*text)) { v = 10 + (*text - 'A'); } else if (radix == 16 && SDL_islowerhex(*text)) { v = 10 + (*text - 'a'); } else { break; } value *= radix; value += v; ++text; } if (valuep && text > textstart) { *valuep = value; } return (text - textstart); } #endif #if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOD) static size_t SDL_ScanFloat(const char *text, double *valuep) { const char *textstart = text; unsigned long lvalue = 0; double value = 0.0; SDL_bool negative = SDL_FALSE; if (*text == '-') { negative = SDL_TRUE; ++text; } text += SDL_ScanUnsignedLong(text, 10, &lvalue); value += lvalue; if (*text == '.') { int mult = 10; ++text; while (SDL_isdigit((unsigned char) *text)) { lvalue = *text - '0'; value += (double) lvalue / mult; mult *= 10; ++text; } } if (valuep && text > textstart) { if (negative && value) { *valuep = -value; } else { *valuep = value; } } return (text - textstart); } #endif void * SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len) { #if defined(HAVE_MEMSET) return memset(dst, c, len); #else size_t left; Uint32 *dstp4; Uint8 *dstp1 = (Uint8 *) dst; Uint8 value1; Uint32 value4; /* The value used in memset() is a byte, passed as an int */ c &= 0xff; /* The destination pointer needs to be aligned on a 4-byte boundary to * execute a 32-bit set. Set first bytes manually if needed until it is * aligned. */ value1 = (Uint8)c; while ((intptr_t)dstp1 & 0x3) { if (len--) { *dstp1++ = value1; } else { return dst; } } value4 = (c | (c << 8) | (c << 16) | (c << 24)); dstp4 = (Uint32 *) dstp1; left = (len % 4); len /= 4; while (len--) { *dstp4++ = value4; } dstp1 = (Uint8 *) dstp4; switch (left) { case 3: *dstp1++ = value1; case 2: *dstp1++ = value1; case 1: *dstp1++ = value1; } return dst; #endif /* HAVE_MEMSET */ } void * SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len) { #ifdef __GNUC__ /* Presumably this is well tuned for speed. On my machine this is twice as fast as the C code below. */ return __builtin_memcpy(dst, src, len); #elif defined(HAVE_MEMCPY) return memcpy(dst, src, len); #elif defined(HAVE_BCOPY) bcopy(src, dst, len); return dst; #else /* GCC 4.9.0 with -O3 will generate movaps instructions with the loop using Uint32* pointers, so we need to make sure the pointers are aligned before we loop using them. */ if (((intptr_t)src & 0x3) || ((intptr_t)dst & 0x3)) { /* Do an unaligned byte copy */ Uint8 *srcp1 = (Uint8 *)src; Uint8 *dstp1 = (Uint8 *)dst; while (len--) { *dstp1++ = *srcp1++; } } else { size_t left = (len % 4); Uint32 *srcp4, *dstp4; Uint8 *srcp1, *dstp1; srcp4 = (Uint32 *) src; dstp4 = (Uint32 *) dst; len /= 4; while (len--) { *dstp4++ = *srcp4++; } srcp1 = (Uint8 *) srcp4; dstp1 = (Uint8 *) dstp4; switch (left) { case 3: *dstp1++ = *srcp1++; case 2: *dstp1++ = *srcp1++; case 1: *dstp1++ = *srcp1++; } } return dst; #endif /* __GNUC__ */ } void * SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len) { #if defined(HAVE_MEMMOVE) return memmove(dst, src, len); #else char *srcp = (char *) src; char *dstp = (char *) dst; if (src < dst) { srcp += len - 1; dstp += len - 1; while (len--) { *dstp-- = *srcp--; } } else { while (len--) { *dstp++ = *srcp++; } } return dst; #endif /* HAVE_MEMMOVE */ } int SDL_memcmp(const void *s1, const void *s2, size_t len) { #if defined(HAVE_MEMCMP) return memcmp(s1, s2, len); #else char *s1p = (char *) s1; char *s2p = (char *) s2; while (len--) { if (*s1p != *s2p) { return (*s1p - *s2p); } ++s1p; ++s2p; } return 0; #endif /* HAVE_MEMCMP */ } size_t SDL_strlen(const char *string) { #if defined(HAVE_STRLEN) return strlen(string); #else size_t len = 0; while (*string++) { ++len; } return len; #endif /* HAVE_STRLEN */ } size_t SDL_wcslen(const wchar_t * string) { #if defined(HAVE_WCSLEN) return wcslen(string); #else size_t len = 0; while (*string++) { ++len; } return len; #endif /* HAVE_WCSLEN */ } size_t SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen) { #if defined(HAVE_WCSLCPY) return wcslcpy(dst, src, maxlen); #else size_t srclen = SDL_wcslen(src); if (maxlen > 0) { size_t len = SDL_min(srclen, maxlen - 1); SDL_memcpy(dst, src, len * sizeof(wchar_t)); dst[len] = '\0'; } return srclen; #endif /* HAVE_WCSLCPY */ } size_t SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen) { #if defined(HAVE_WCSLCAT) return wcslcat(dst, src, maxlen); #else size_t dstlen = SDL_wcslen(dst); size_t srclen = SDL_wcslen(src); if (dstlen < maxlen) { SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen); } return dstlen + srclen; #endif /* HAVE_WCSLCAT */ } wchar_t * SDL_wcsdup(const wchar_t *string) { size_t len = ((SDL_wcslen(string) + 1) * sizeof(wchar_t)); wchar_t *newstr = (wchar_t *)SDL_malloc(len); if (newstr) { SDL_memcpy(newstr, string, len); } return newstr; } wchar_t * SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle) { #if defined(HAVE_WCSSTR) return SDL_const_cast(wchar_t*,wcsstr(haystack, needle)); #else size_t length = SDL_wcslen(needle); while (*haystack) { if (SDL_wcsncmp(haystack, needle, length) == 0) { return (wchar_t *)haystack; } ++haystack; } return NULL; #endif /* HAVE_WCSSTR */ } int SDL_wcscmp(const wchar_t *str1, const wchar_t *str2) { #if defined(HAVE_WCSCMP) return wcscmp(str1, str2); #else while (*str1 && *str2) { if (*str1 != *str2) break; ++str1; ++str2; } return (int)(*str1 - *str2); #endif /* HAVE_WCSCMP */ } int SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen) { #if defined(HAVE_WCSNCMP) return wcsncmp(str1, str2, maxlen); #else while (*str1 && *str2) { if (*str1 != *str2) break; ++str1; ++str2; } return (int)(*str1 - *str2); #endif /* HAVE_WCSNCMP */ } size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen) { #if defined(HAVE_STRLCPY) return strlcpy(dst, src, maxlen); #else size_t srclen = SDL_strlen(src); if (maxlen > 0) { size_t len = SDL_min(srclen, maxlen - 1); SDL_memcpy(dst, src, len); dst[len] = '\0'; } return srclen; #endif /* HAVE_STRLCPY */ } size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes) { size_t src_bytes = SDL_strlen(src); size_t bytes = SDL_min(src_bytes, dst_bytes - 1); size_t i = 0; char trailing_bytes = 0; if (bytes) { unsigned char c = (unsigned char)src[bytes - 1]; if (UTF8_IsLeadByte(c)) --bytes; else if (UTF8_IsTrailingByte(c)) { for (i = bytes - 1; i != 0; --i) { c = (unsigned char)src[i]; trailing_bytes = UTF8_TrailingBytes(c); if (trailing_bytes) { if (bytes - i != trailing_bytes + 1) bytes = i; break; } } } SDL_memcpy(dst, src, bytes); } dst[bytes] = '\0'; return bytes; } size_t SDL_utf8strlen(const char *str) { size_t retval = 0; const char *p = str; char ch; while ((ch = *(p++)) != 0) { /* if top two bits are 1 and 0, it's a continuation byte. */ if ((ch & 0xc0) != 0x80) { retval++; } } return retval; } size_t SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen) { #if defined(HAVE_STRLCAT) return strlcat(dst, src, maxlen); #else size_t dstlen = SDL_strlen(dst); size_t srclen = SDL_strlen(src); if (dstlen < maxlen) { SDL_strlcpy(dst + dstlen, src, maxlen - dstlen); } return dstlen + srclen; #endif /* HAVE_STRLCAT */ } char * SDL_strdup(const char *string) { size_t len = SDL_strlen(string) + 1; char *newstr = (char *)SDL_malloc(len); if (newstr) { SDL_memcpy(newstr, string, len); } return newstr; } char * SDL_strrev(char *string) { #if defined(HAVE__STRREV) return _strrev(string); #else size_t len = SDL_strlen(string); char *a = &string[0]; char *b = &string[len - 1]; len /= 2; while (len--) { char c = *a; *a++ = *b; *b-- = c; } return string; #endif /* HAVE__STRREV */ } char * SDL_strupr(char *string) { #if defined(HAVE__STRUPR) return _strupr(string); #else char *bufp = string; while (*bufp) { *bufp = SDL_toupper((unsigned char) *bufp); ++bufp; } return string; #endif /* HAVE__STRUPR */ } char * SDL_strlwr(char *string) { #if defined(HAVE__STRLWR) return _strlwr(string); #else char *bufp = string; while (*bufp) { *bufp = SDL_tolower((unsigned char) *bufp); ++bufp; } return string; #endif /* HAVE__STRLWR */ } char * SDL_strchr(const char *string, int c) { #ifdef HAVE_STRCHR return SDL_const_cast(char*,strchr(string, c)); #elif defined(HAVE_INDEX) return SDL_const_cast(char*,index(string, c)); #else while (*string) { if (*string == c) { return (char *) string; } ++string; } return NULL; #endif /* HAVE_STRCHR */ } char * SDL_strrchr(const char *string, int c) { #ifdef HAVE_STRRCHR return SDL_const_cast(char*,strrchr(string, c)); #elif defined(HAVE_RINDEX) return SDL_const_cast(char*,rindex(string, c)); #else const char *bufp = string + SDL_strlen(string) - 1; while (bufp >= string) { if (*bufp == c) { return (char *) bufp; } --bufp; } return NULL; #endif /* HAVE_STRRCHR */ } char * SDL_strstr(const char *haystack, const char *needle) { #if defined(HAVE_STRSTR) return SDL_const_cast(char*,strstr(haystack, needle)); #else size_t length = SDL_strlen(needle); while (*haystack) { if (SDL_strncmp(haystack, needle, length) == 0) { return (char *) haystack; } ++haystack; } return NULL; #endif /* HAVE_STRSTR */ } #if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \ !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA) static const char ntoa_table[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; #endif /* ntoa() conversion table */ char * SDL_itoa(int value, char *string, int radix) { #ifdef HAVE_ITOA return itoa(value, string, radix); #else return SDL_ltoa((long)value, string, radix); #endif /* HAVE_ITOA */ } char * SDL_uitoa(unsigned int value, char *string, int radix) { #ifdef HAVE__UITOA return _uitoa(value, string, radix); #else return SDL_ultoa((unsigned long)value, string, radix); #endif /* HAVE__UITOA */ } char * SDL_ltoa(long value, char *string, int radix) { #if defined(HAVE__LTOA) return _ltoa(value, string, radix); #else char *bufp = string; if (value < 0) { *bufp++ = '-'; SDL_ultoa(-value, bufp, radix); } else { SDL_ultoa(value, bufp, radix); } return string; #endif /* HAVE__LTOA */ } char * SDL_ultoa(unsigned long value, char *string, int radix) { #if defined(HAVE__ULTOA) return _ultoa(value, string, radix); #else char *bufp = string; if (value) { while (value > 0) { *bufp++ = ntoa_table[value % radix]; value /= radix; } } else { *bufp++ = '0'; } *bufp = '\0'; /* The numbers went into the string backwards. :) */ SDL_strrev(string); return string; #endif /* HAVE__ULTOA */ } char * SDL_lltoa(Sint64 value, char *string, int radix) { #if defined(HAVE__I64TOA) return _i64toa(value, string, radix); #else char *bufp = string; if (value < 0) { *bufp++ = '-'; SDL_ulltoa(-value, bufp, radix); } else { SDL_ulltoa(value, bufp, radix); } return string; #endif /* HAVE__I64TOA */ } char * SDL_ulltoa(Uint64 value, char *string, int radix) { #if defined(HAVE__UI64TOA) return _ui64toa(value, string, radix); #else char *bufp = string; if (value) { while (value > 0) { *bufp++ = ntoa_table[value % radix]; value /= radix; } } else { *bufp++ = '0'; } *bufp = '\0'; /* The numbers went into the string backwards. :) */ SDL_strrev(string); return string; #endif /* HAVE__UI64TOA */ } int SDL_atoi(const char *string) { #ifdef HAVE_ATOI return atoi(string); #else return SDL_strtol(string, NULL, 0); #endif /* HAVE_ATOI */ } double SDL_atof(const char *string) { #ifdef HAVE_ATOF return atof(string); #else return SDL_strtod(string, NULL); #endif /* HAVE_ATOF */ } long SDL_strtol(const char *string, char **endp, int base) { #if defined(HAVE_STRTOL) return strtol(string, endp, base); #else size_t len; long value = 0; if (!base) { if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { base = 16; } else { base = 10; } } len = SDL_ScanLong(string, base, &value); if (endp) { *endp = (char *) string + len; } return value; #endif /* HAVE_STRTOL */ } unsigned long SDL_strtoul(const char *string, char **endp, int base) { #if defined(HAVE_STRTOUL) return strtoul(string, endp, base); #else size_t len; unsigned long value = 0; if (!base) { if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { base = 16; } else { base = 10; } } len = SDL_ScanUnsignedLong(string, base, &value); if (endp) { *endp = (char *) string + len; } return value; #endif /* HAVE_STRTOUL */ } Sint64 SDL_strtoll(const char *string, char **endp, int base) { #if defined(HAVE_STRTOLL) return strtoll(string, endp, base); #else size_t len; Sint64 value = 0; if (!base) { if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { base = 16; } else { base = 10; } } len = SDL_ScanLongLong(string, base, &value); if (endp) { *endp = (char *) string + len; } return value; #endif /* HAVE_STRTOLL */ } Uint64 SDL_strtoull(const char *string, char **endp, int base) { #if defined(HAVE_STRTOULL) return strtoull(string, endp, base); #else size_t len; Uint64 value = 0; if (!base) { if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) { base = 16; } else { base = 10; } } len = SDL_ScanUnsignedLongLong(string, base, &value); if (endp) { *endp = (char *) string + len; } return value; #endif /* HAVE_STRTOULL */ } double SDL_strtod(const char *string, char **endp) { #if defined(HAVE_STRTOD) return strtod(string, endp); #else size_t len; double value = 0.0; len = SDL_ScanFloat(string, &value); if (endp) { *endp = (char *) string + len; } return value; #endif /* HAVE_STRTOD */ } int SDL_strcmp(const char *str1, const char *str2) { #if defined(HAVE_STRCMP) return strcmp(str1, str2); #else while (*str1 && *str2) { if (*str1 != *str2) break; ++str1; ++str2; } return (int)((unsigned char) *str1 - (unsigned char) *str2); #endif /* HAVE_STRCMP */ } int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { #if defined(HAVE_STRNCMP) return strncmp(str1, str2, maxlen); #else while (*str1 && *str2 && maxlen) { if (*str1 != *str2) break; ++str1; ++str2; --maxlen; } if (!maxlen) { return 0; } return (int) ((unsigned char) *str1 - (unsigned char) *str2); #endif /* HAVE_STRNCMP */ } int SDL_strcasecmp(const char *str1, const char *str2) { #ifdef HAVE_STRCASECMP return strcasecmp(str1, str2); #elif defined(HAVE__STRICMP) return _stricmp(str1, str2); #else char a = 0; char b = 0; while (*str1 && *str2) { a = SDL_toupper((unsigned char) *str1); b = SDL_toupper((unsigned char) *str2); if (a != b) break; ++str1; ++str2; } a = SDL_toupper(*str1); b = SDL_toupper(*str2); return (int) ((unsigned char) a - (unsigned char) b); #endif /* HAVE_STRCASECMP */ } int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { #ifdef HAVE_STRNCASECMP return strncasecmp(str1, str2, maxlen); #elif defined(HAVE__STRNICMP) return _strnicmp(str1, str2, maxlen); #else char a = 0; char b = 0; while (*str1 && *str2 && maxlen) { a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); if (a != b) break; ++str1; ++str2; --maxlen; } if (maxlen == 0) { return 0; } else { a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); return (int) ((unsigned char) a - (unsigned char) b); } #endif /* HAVE_STRNCASECMP */ } int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) { int rc; va_list ap; va_start(ap, fmt); rc = SDL_vsscanf(text, fmt, ap); va_end(ap); return rc; } #ifdef HAVE_VSSCANF int SDL_vsscanf(const char *text, const char *fmt, va_list ap) { return vsscanf(text, fmt, ap); } #else int SDL_vsscanf(const char *text, const char *fmt, va_list ap) { int retval = 0; if (!text || !*text) { return -1; } while (*fmt) { if (*fmt == ' ') { while (SDL_isspace((unsigned char) *text)) { ++text; } ++fmt; continue; } if (*fmt == '%') { SDL_bool done = SDL_FALSE; long count = 0; int radix = 10; enum { DO_SHORT, DO_INT, DO_LONG, DO_LONGLONG } inttype = DO_INT; size_t advance; SDL_bool suppress = SDL_FALSE; ++fmt; if (*fmt == '%') { if (*text == '%') { ++text; ++fmt; continue; } break; } if (*fmt == '*') { suppress = SDL_TRUE; ++fmt; } fmt += SDL_ScanLong(fmt, 10, &count); if (*fmt == 'c') { if (!count) { count = 1; } if (suppress) { while (count--) { ++text; } } else { char *valuep = va_arg(ap, char *); while (count--) { *valuep++ = *text++; } ++retval; } continue; } while (SDL_isspace((unsigned char) *text)) { ++text; } /* FIXME: implement more of the format specifiers */ while (!done) { switch (*fmt) { case '*': suppress = SDL_TRUE; break; case 'h': if (inttype > DO_SHORT) { ++inttype; } break; case 'l': if (inttype < DO_LONGLONG) { ++inttype; } break; case 'I': if (SDL_strncmp(fmt, "I64", 3) == 0) { fmt += 2; inttype = DO_LONGLONG; } break; case 'i': { int index = 0; if (text[index] == '-') { ++index; } if (text[index] == '0') { if (SDL_tolower((unsigned char) text[index + 1]) == 'x') { radix = 16; } else { radix = 8; } } } /* Fall through to %d handling */ case 'd': if (inttype == DO_LONGLONG) { Sint64 value; advance = SDL_ScanLongLong(text, radix, &value); text += advance; if (advance && !suppress) { Sint64 *valuep = va_arg(ap, Sint64 *); *valuep = value; ++retval; } } else { long value; advance = SDL_ScanLong(text, radix, &value); text += advance; if (advance && !suppress) { switch (inttype) { case DO_SHORT: { short *valuep = va_arg(ap, short *); *valuep = (short) value; } break; case DO_INT: { int *valuep = va_arg(ap, int *); *valuep = (int) value; } break; case DO_LONG: { long *valuep = va_arg(ap, long *); *valuep = value; } break; case DO_LONGLONG: /* Handled above */ break; } ++retval; } } done = SDL_TRUE; break; case 'o': if (radix == 10) { radix = 8; } /* Fall through to unsigned handling */ case 'x': case 'X': if (radix == 10) { radix = 16; } /* Fall through to unsigned handling */ case 'u': if (inttype == DO_LONGLONG) { Uint64 value = 0; advance = SDL_ScanUnsignedLongLong(text, radix, &value); text += advance; if (advance && !suppress) { Uint64 *valuep = va_arg(ap, Uint64 *); *valuep = value; ++retval; } } else { unsigned long value = 0; advance = SDL_ScanUnsignedLong(text, radix, &value); text += advance; if (advance && !suppress) { switch (inttype) { case DO_SHORT: { short *valuep = va_arg(ap, short *); *valuep = (short) value; } break; case DO_INT: { int *valuep = va_arg(ap, int *); *valuep = (int) value; } break; case DO_LONG: { long *valuep = va_arg(ap, long *); *valuep = value; } break; case DO_LONGLONG: /* Handled above */ break; } ++retval; } } done = SDL_TRUE; break; case 'p': { uintptr_t value = 0; advance = SDL_ScanUintPtrT(text, 16, &value); text += advance; if (advance && !suppress) { void **valuep = va_arg(ap, void **); *valuep = (void *) value; ++retval; } } done = SDL_TRUE; break; case 'f': { double value; advance = SDL_ScanFloat(text, &value); text += advance; if (advance && !suppress) { float *valuep = va_arg(ap, float *); *valuep = (float) value; ++retval; } } done = SDL_TRUE; break; case 's': if (suppress) { while (!SDL_isspace((unsigned char) *text)) { ++text; if (count) { if (--count == 0) { break; } } } } else { char *valuep = va_arg(ap, char *); while (!SDL_isspace((unsigned char) *text)) { *valuep++ = *text++; if (count) { if (--count == 0) { break; } } } *valuep = '\0'; ++retval; } done = SDL_TRUE; break; default: done = SDL_TRUE; break; } ++fmt; } continue; } if (*text == *fmt) { ++text; ++fmt; continue; } /* Text didn't match format specifier */ break; } return retval; } #endif /* HAVE_VSSCANF */ int SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { va_list ap; int retval; va_start(ap, fmt); retval = SDL_vsnprintf(text, maxlen, fmt, ap); va_end(ap); return retval; } #if defined(HAVE_LIBC) && defined(__WATCOMC__) /* _vsnprintf() doesn't ensure nul termination */ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap) { int retval; if (!fmt) fmt = ""; retval = _vsnprintf(text, maxlen, fmt, ap); if (maxlen > 0) text[maxlen-1] = '\0'; if (retval < 0) retval = (int) maxlen; return retval; } #elif defined(HAVE_VSNPRINTF) int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap) { if (!fmt) { fmt = ""; } return vsnprintf(text, maxlen, fmt, ap); } #else /* FIXME: implement more of the format specifiers */ typedef enum { SDL_CASE_NOCHANGE, SDL_CASE_LOWER, SDL_CASE_UPPER } SDL_letter_case; typedef struct { SDL_bool left_justify; /* for now: ignored. */ SDL_bool force_sign; SDL_bool force_type; /* for now: used only by float printer, ignored otherwise. */ SDL_bool pad_zeroes; SDL_letter_case force_case; int width; int radix; int precision; } SDL_FormatInfo; static size_t SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string) { size_t length = 0; size_t slen, sz; if (string == NULL) { string = "(null)"; } sz = SDL_strlen(string); if (info && info->width > 0 && (size_t)info->width > sz) { const char fill = info->pad_zeroes ? '0' : ' '; size_t width = info->width - sz; size_t filllen; if (info->precision >= 0 && (size_t)info->precision < sz) width += sz - (size_t)info->precision; filllen = SDL_min(width, maxlen); SDL_memset(text, fill, filllen); text += filllen; length += filllen; maxlen -= filllen; } slen = SDL_strlcpy(text, string, maxlen); length += SDL_min(slen, maxlen); if (info) { if (info->precision >= 0 && (size_t)info->precision < sz) { slen = (size_t)info->precision; if (slen < maxlen) { text[slen] = 0; length -= (sz - slen); } } if (info->force_case == SDL_CASE_LOWER) { SDL_strlwr(text); } else if (info->force_case == SDL_CASE_UPPER) { SDL_strupr(text); } } return length; } static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info) {/* left-pad num with zeroes. */ size_t sz, pad, have_sign; if (!info) return; have_sign = 0; if (*num == '-' || *num == '+') { have_sign = 1; ++num; --maxlen; } sz = SDL_strlen(num); if (info->precision > 0 && sz < (size_t)info->precision) { pad = (size_t)info->precision - sz; if (pad + sz + 1 <= maxlen) { /* otherwise ignore the precision */ SDL_memmove(num + pad, num, sz + 1); SDL_memset(num, '0', pad); } } info->precision = -1;/* so that SDL_PrintString() doesn't make a mess. */ if (info->pad_zeroes && info->width > 0 && (size_t)info->width > sz + have_sign) { /* handle here: spaces are added before the sign but zeroes must be placed _after_ the sign. */ /* sz hasn't changed: we ignore pad_zeroes if a precision is given. */ pad = (size_t)info->width - sz - have_sign; if (pad + sz + 1 <= maxlen) { SDL_memmove(num + pad, num, sz + 1); SDL_memset(num, '0', pad); } info->width = 0; /* so that SDL_PrintString() doesn't make a mess. */ } } static size_t SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value) { char num[130], *p = num; if (info->force_sign && value >= 0L) { *p++ = '+'; } SDL_ltoa(value, p, info ? info->radix : 10); SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } static size_t SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value) { char num[130]; SDL_ultoa(value, num, info ? info->radix : 10); SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } static size_t SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value) { char num[130], *p = num; if (info->force_sign && value >= (Sint64)0) { *p++ = '+'; } SDL_lltoa(value, p, info ? info->radix : 10); SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } static size_t SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint64 value) { char num[130]; SDL_ulltoa(value, num, info ? info->radix : 10); SDL_IntPrecisionAdjust(num, maxlen, info); return SDL_PrintString(text, maxlen, info, num); } static size_t SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg) { int width; size_t len; size_t left = maxlen; char *textstart = text; if (arg) { /* This isn't especially accurate, but hey, it's easy. :) */ unsigned long value; if (arg < 0) { if (left > 1) { *text = '-'; --left; } ++text; arg = -arg; } else if (info->force_sign) { if (left > 1) { *text = '+'; --left; } ++text; } value = (unsigned long) arg; len = SDL_PrintUnsignedLong(text, left, NULL, value); if (len >= left) { text += (left > 1) ? left - 1 : 0; left = SDL_min(left, 1); } else { text += len; left -= len; } arg -= value; if (info->precision < 0) { info->precision = 6; } if (info->force_type || info->precision > 0) { int mult = 10; if (left > 1) { *text = '.'; --left; } ++text; while (info->precision-- > 0) { value = (unsigned long) (arg * mult); len = SDL_PrintUnsignedLong(text, left, NULL, value); if (len >= left) { text += (left > 1) ? left - 1 : 0; left = SDL_min(left, 1); } else { text += len; left -= len; } arg -= (double) value / mult; mult *= 10; } } } else { if (left > 1) { *text = '0'; --left; } ++text; if (info->force_type) { if (left > 1) { *text = '.'; --left; } ++text; } } width = info->width - (int)(text - textstart); if (width > 0) { const char fill = info->pad_zeroes ? '0' : ' '; char *end = text+left-1; len = (text - textstart); for (len = (text - textstart); len--; ) { if ((textstart+len+width) < end) { *(textstart+len+width) = *(textstart+len); } } len = (size_t)width; if (len >= left) { text += (left > 1) ? left - 1 : 0; left = SDL_min(left, 1); } else { text += len; left -= len; } if (end != textstart) { const size_t filllen = SDL_min(len, ((size_t) (end - textstart)) - 1); SDL_memset(textstart, fill, filllen); } } return (text - textstart); } int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap) { size_t left = maxlen; char *textstart = text; if (!fmt) { fmt = ""; } while (*fmt && left > 1) { if (*fmt == '%') { SDL_bool done = SDL_FALSE; size_t len = 0; SDL_bool check_flag; SDL_FormatInfo info; enum { DO_INT, DO_LONG, DO_LONGLONG } inttype = DO_INT; SDL_zero(info); info.radix = 10; info.precision = -1; check_flag = SDL_TRUE; while (check_flag) { ++fmt; switch (*fmt) { case '-': info.left_justify = SDL_TRUE; break; case '+': info.force_sign = SDL_TRUE; break; case '#': info.force_type = SDL_TRUE; break; case '0': info.pad_zeroes = SDL_TRUE; break; default: check_flag = SDL_FALSE; break; } } if (*fmt >= '0' && *fmt <= '9') { info.width = SDL_strtol(fmt, (char **)&fmt, 0); } else if (*fmt == '*') { ++fmt; info.width = va_arg(ap, int); } if (*fmt == '.') { ++fmt; if (*fmt >= '0' && *fmt <= '9') { info.precision = SDL_strtol(fmt, (char **)&fmt, 0); } else if (*fmt == '*') { ++fmt; info.precision = va_arg(ap, int); } else { info.precision = 0; } if (info.precision < 0) { info.precision = 0; } } while (!done) { switch (*fmt) { case '%': if (left > 1) { *text = '%'; } len = 1; done = SDL_TRUE; break; case 'c': /* char is promoted to int when passed through (...) */ if (left > 1) { *text = (char) va_arg(ap, int); } len = 1; done = SDL_TRUE; break; case 'h': /* short is promoted to int when passed through (...) */ break; case 'l': if (inttype < DO_LONGLONG) { ++inttype; } break; case 'I': if (SDL_strncmp(fmt, "I64", 3) == 0) { fmt += 2; inttype = DO_LONGLONG; } break; case 'i': case 'd': if (info.precision >= 0) { info.pad_zeroes = SDL_FALSE; } switch (inttype) { case DO_INT: len = SDL_PrintLong(text, left, &info, (long) va_arg(ap, int)); break; case DO_LONG: len = SDL_PrintLong(text, left, &info, va_arg(ap, long)); break; case DO_LONGLONG: len = SDL_PrintLongLong(text, left, &info, va_arg(ap, Sint64)); break; } done = SDL_TRUE; break; case 'p': case 'x': info.force_case = SDL_CASE_LOWER; /* Fall through to 'X' handling */ case 'X': if (info.force_case == SDL_CASE_NOCHANGE) { info.force_case = SDL_CASE_UPPER; } if (info.radix == 10) { info.radix = 16; } if (*fmt == 'p') { inttype = DO_LONG; } /* Fall through to unsigned handling */ case 'o': if (info.radix == 10) { info.radix = 8; } /* Fall through to unsigned handling */ case 'u': info.force_sign = SDL_FALSE; if (info.precision >= 0) { info.pad_zeroes = SDL_FALSE; } switch (inttype) { case DO_INT: len = SDL_PrintUnsignedLong(text, left, &info, (unsigned long) va_arg(ap, unsigned int)); break; case DO_LONG: len = SDL_PrintUnsignedLong(text, left, &info, va_arg(ap, unsigned long)); break; case DO_LONGLONG: len = SDL_PrintUnsignedLongLong(text, left, &info, va_arg(ap, Uint64)); break; } done = SDL_TRUE; break; case 'f': len = SDL_PrintFloat(text, left, &info, va_arg(ap, double)); done = SDL_TRUE; break; case 'S': { /* In practice this is used on Windows for WCHAR strings */ wchar_t *wide_arg = va_arg(ap, wchar_t *); char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg)); info.pad_zeroes = SDL_FALSE; len = SDL_PrintString(text, left, &info, arg); SDL_free(arg); done = SDL_TRUE; } break; case 's': info.pad_zeroes = SDL_FALSE; len = SDL_PrintString(text, left, &info, va_arg(ap, char *)); done = SDL_TRUE; break; default: done = SDL_TRUE; break; } ++fmt; } if (len >= left) { text += (left > 1) ? left - 1 : 0; left = SDL_min(left, 1); } else { text += len; left -= len; } } else { *text++ = *fmt++; --left; } } if (left > 0) { *text = '\0'; } return (int)(text - textstart); } #endif /* HAVE_VSNPRINTF */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/stdlib/SDL_string.c
C
apache-2.0
49,375
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #if defined(__clang_analyzer__) #define SDL_DISABLE_ANALYZE_MACROS 1 #endif #include "../SDL_internal.h" #include "SDL_stdinc.h" char *SDL_strtokr(char *s1, const char *s2, char **ptr) { #if defined(HAVE_STRTOK_R) return strtok_r(s1, s2, ptr); #elif defined(_MSC_VER) && defined(HAVE_STRTOK_S) return strtok_s(s1, s2, ptr); #else /* SDL implementation */ /* * Adapted from _PDCLIB_strtok() of PDClib library at * https://github.com/DevSolar/pdclib.git * * The code was under CC0 license: * https://creativecommons.org/publicdomain/zero/1.0/legalcode : * * No Copyright * * The person who associated a work with this deed has dedicated the * work to the public domain by waiving all of his or her rights to * the work worldwide under copyright law, including all related and * neighboring rights, to the extent allowed by law. * * You can copy, modify, distribute and perform the work, even for * commercial purposes, all without asking permission. See Other * Information below. */ const char *p = s2; if (!s2 || !ptr || (!s1 && !*ptr)) return NULL; if (s1 != NULL) { /* new string */ *ptr = s1; } else { /* old string continued */ if (*ptr == NULL) { /* No old string, no new string, nothing to do */ return NULL; } s1 = *ptr; } /* skip leading s2 characters */ while (*p && *s1) { if (*s1 == *p) { /* found separator; skip and start over */ ++s1; p = s2; continue; } ++p; } if (! *s1) { /* no more to parse */ *ptr = s1; return NULL; } /* skipping non-s2 characters */ *ptr = s1; while (**ptr) { p = s2; while (*p) { if (**ptr == *p++) { /* found separator; overwrite with '\0', position *ptr, return */ *((*ptr)++) = '\0'; return s1; } } ++(*ptr); } /* parsed to end of string */ return s1; #endif }
YifuLiu/AliOS-Things
components/SDL2/src/stdlib/SDL_strtokr.c
C
apache-2.0
3,002
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Used by the test framework and test cases. */ #include "SDL_config.h" #include "SDL_test.h" /* Assert check message format */ #define SDLTEST_ASSERT_CHECK_FORMAT "Assert '%s': %s" /* Assert summary message format */ #define SDLTEST_ASSERT_SUMMARY_FORMAT "Assert Summary: Total=%d Passed=%d Failed=%d" /* ! \brief counts the failed asserts */ static int SDLTest_AssertsFailed = 0; /* ! \brief counts the passed asserts */ static int SDLTest_AssertsPassed = 0; /* * Assert that logs and break execution flow on failures (i.e. for harness errors). */ void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) { va_list list; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; /* Print assert description into a buffer */ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH); va_start(list, assertDescription); SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list); va_end(list); /* Log, then assert and break on failure */ SDL_assert((SDLTest_AssertCheck(assertCondition, "%s", logMessage))); } /* * Assert that logs but does not break execution flow on failures (i.e. for test cases). */ int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) { va_list list; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; /* Print assert description into a buffer */ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH); va_start(list, assertDescription); SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list); va_end(list); /* Log pass or fail message */ if (assertCondition == ASSERT_FAIL) { SDLTest_AssertsFailed++; SDLTest_LogError(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Failed"); } else { SDLTest_AssertsPassed++; SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Passed"); } return assertCondition; } /* * Explicitly passing Assert that logs (i.e. for test cases). */ void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) { va_list list; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; /* Print assert description into a buffer */ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH); va_start(list, assertDescription); SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list); va_end(list); /* Log pass message */ SDLTest_AssertsPassed++; SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Pass"); } /* * Resets the assert summary counters to zero. */ void SDLTest_ResetAssertSummary() { SDLTest_AssertsPassed = 0; SDLTest_AssertsFailed = 0; } /* * Logs summary of all assertions (total, pass, fail) since last reset * as INFO (failed==0) or ERROR (failed > 0). */ void SDLTest_LogAssertSummary() { int totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed; if (SDLTest_AssertsFailed == 0) { SDLTest_Log(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed); } else { SDLTest_LogError(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed); } } /* * Converts the current assert state into a test result */ int SDLTest_AssertSummaryToTestResult() { if (SDLTest_AssertsFailed > 0) { return TEST_RESULT_FAILED; } else { if (SDLTest_AssertsPassed > 0) { return TEST_RESULT_PASSED; } else { return TEST_RESULT_NO_ASSERT; } } } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_assert.c
C
apache-2.0
4,637
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Ported from original test/common.c file. */ #include "SDL_config.h" #include "SDL_test.h" #include <stdio.h> static const char *video_usage[] = { "[--video driver]", "[--renderer driver]", "[--gldebug]", "[--info all|video|modes|render|event]", "[--log all|error|system|audio|video|render|input]", "[--display N]", "[--fullscreen | --fullscreen-desktop | --windows N]", "[--title title]", "[--icon icon.bmp]", "[--center | --position X,Y]", "[--geometry WxH]", "[--min-geometry WxH]", "[--max-geometry WxH]", "[--logical WxH]", "[--scale N]", "[--depth N]", "[--refresh R]", "[--vsync]", "[--noframe]", "[--resize]", "[--minimize]", "[--maximize]", "[--grab]", "[--allow-highdpi]", "[--usable-bounds]" }; static const char *audio_usage[] = { "[--rate N]", "[--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE]", "[--channels N]", "[--samples N]" }; static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... ) { size_t length = SDL_strlen(text); va_list ap; va_start(ap, fmt); text += length; maxlen -= length; SDL_vsnprintf(text, maxlen, fmt, ap); va_end(ap); } SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags) { int i; SDLTest_CommonState *state; /* Do this first so we catch all allocations */ for (i = 1; argv[i]; ++i) { if (SDL_strcasecmp(argv[i], "--trackmem") == 0) { SDLTest_TrackAllocations(); break; } } state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state)); if (!state) { SDL_OutOfMemory(); return NULL; } /* Initialize some defaults */ state->argv = argv; state->flags = flags; state->window_title = argv[0]; state->window_flags = 0; state->window_x = SDL_WINDOWPOS_UNDEFINED; state->window_y = SDL_WINDOWPOS_UNDEFINED; state->window_w = DEFAULT_WINDOW_WIDTH; state->window_h = DEFAULT_WINDOW_HEIGHT; state->num_windows = 1; state->audiospec.freq = 22050; state->audiospec.format = AUDIO_S16; state->audiospec.channels = 2; state->audiospec.samples = 2048; /* Set some very sane GL defaults */ state->gl_red_size = 3; state->gl_green_size = 3; state->gl_blue_size = 2; state->gl_alpha_size = 0; state->gl_buffer_size = 0; state->gl_depth_size = 16; state->gl_stencil_size = 0; state->gl_double_buffer = 1; state->gl_accum_red_size = 0; state->gl_accum_green_size = 0; state->gl_accum_blue_size = 0; state->gl_accum_alpha_size = 0; state->gl_stereo = 0; state->gl_multisamplebuffers = 0; state->gl_multisamplesamples = 0; state->gl_retained_backing = 1; state->gl_accelerated = -1; state->gl_debug = 0; return state; } int SDLTest_CommonArg(SDLTest_CommonState * state, int index) { char **argv = state->argv; if (SDL_strcasecmp(argv[index], "--video") == 0) { ++index; if (!argv[index]) { return -1; } state->videodriver = argv[index]; return 2; } if (SDL_strcasecmp(argv[index], "--renderer") == 0) { ++index; if (!argv[index]) { return -1; } state->renderdriver = argv[index]; return 2; } if (SDL_strcasecmp(argv[index], "--gldebug") == 0) { state->gl_debug = 1; return 1; } if (SDL_strcasecmp(argv[index], "--info") == 0) { ++index; if (!argv[index]) { return -1; } if (SDL_strcasecmp(argv[index], "all") == 0) { state->verbose |= (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER | VERBOSE_EVENT); return 2; } if (SDL_strcasecmp(argv[index], "video") == 0) { state->verbose |= VERBOSE_VIDEO; return 2; } if (SDL_strcasecmp(argv[index], "modes") == 0) { state->verbose |= VERBOSE_MODES; return 2; } if (SDL_strcasecmp(argv[index], "render") == 0) { state->verbose |= VERBOSE_RENDER; return 2; } if (SDL_strcasecmp(argv[index], "event") == 0) { state->verbose |= VERBOSE_EVENT; return 2; } return -1; } if (SDL_strcasecmp(argv[index], "--log") == 0) { ++index; if (!argv[index]) { return -1; } if (SDL_strcasecmp(argv[index], "all") == 0) { SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); return 2; } if (SDL_strcasecmp(argv[index], "error") == 0) { SDL_LogSetPriority(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_VERBOSE); return 2; } if (SDL_strcasecmp(argv[index], "system") == 0) { SDL_LogSetPriority(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE); return 2; } if (SDL_strcasecmp(argv[index], "audio") == 0) { SDL_LogSetPriority(SDL_LOG_CATEGORY_AUDIO, SDL_LOG_PRIORITY_VERBOSE); return 2; } if (SDL_strcasecmp(argv[index], "video") == 0) { SDL_LogSetPriority(SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE); return 2; } if (SDL_strcasecmp(argv[index], "render") == 0) { SDL_LogSetPriority(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_VERBOSE); return 2; } if (SDL_strcasecmp(argv[index], "input") == 0) { SDL_LogSetPriority(SDL_LOG_CATEGORY_INPUT, SDL_LOG_PRIORITY_VERBOSE); return 2; } return -1; } if (SDL_strcasecmp(argv[index], "--display") == 0) { ++index; if (!argv[index]) { return -1; } state->display = SDL_atoi(argv[index]); if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) { state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display); state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display); } if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) { state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display); state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display); } return 2; } if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) { state->window_flags |= SDL_WINDOW_FULLSCREEN; state->num_windows = 1; return 1; } if (SDL_strcasecmp(argv[index], "--fullscreen-desktop") == 0) { state->window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; state->num_windows = 1; return 1; } if (SDL_strcasecmp(argv[index], "--allow-highdpi") == 0) { state->window_flags |= SDL_WINDOW_ALLOW_HIGHDPI; return 1; } if (SDL_strcasecmp(argv[index], "--windows") == 0) { ++index; if (!argv[index] || !SDL_isdigit(*argv[index])) { return -1; } if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) { state->num_windows = SDL_atoi(argv[index]); } return 2; } if (SDL_strcasecmp(argv[index], "--title") == 0) { ++index; if (!argv[index]) { return -1; } state->window_title = argv[index]; return 2; } if (SDL_strcasecmp(argv[index], "--icon") == 0) { ++index; if (!argv[index]) { return -1; } state->window_icon = argv[index]; return 2; } if (SDL_strcasecmp(argv[index], "--center") == 0) { state->window_x = SDL_WINDOWPOS_CENTERED; state->window_y = SDL_WINDOWPOS_CENTERED; return 1; } if (SDL_strcasecmp(argv[index], "--position") == 0) { char *x, *y; ++index; if (!argv[index]) { return -1; } x = argv[index]; y = argv[index]; while (*y && *y != ',') { ++y; } if (!*y) { return -1; } *y++ = '\0'; state->window_x = SDL_atoi(x); state->window_y = SDL_atoi(y); return 2; } if (SDL_strcasecmp(argv[index], "--usable-bounds") == 0) { /* !!! FIXME: this is a bit of a hack, but I don't want to add a !!! FIXME: flag to the public structure in 2.0.x */ state->window_x = -1; state->window_y = -1; state->window_w = -1; state->window_h = -1; return 1; } if (SDL_strcasecmp(argv[index], "--geometry") == 0) { char *w, *h; ++index; if (!argv[index]) { return -1; } w = argv[index]; h = argv[index]; while (*h && *h != 'x') { ++h; } if (!*h) { return -1; } *h++ = '\0'; state->window_w = SDL_atoi(w); state->window_h = SDL_atoi(h); return 2; } if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) { char *w, *h; ++index; if (!argv[index]) { return -1; } w = argv[index]; h = argv[index]; while (*h && *h != 'x') { ++h; } if (!*h) { return -1; } *h++ = '\0'; state->window_minW = SDL_atoi(w); state->window_minH = SDL_atoi(h); return 2; } if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) { char *w, *h; ++index; if (!argv[index]) { return -1; } w = argv[index]; h = argv[index]; while (*h && *h != 'x') { ++h; } if (!*h) { return -1; } *h++ = '\0'; state->window_maxW = SDL_atoi(w); state->window_maxH = SDL_atoi(h); return 2; } if (SDL_strcasecmp(argv[index], "--logical") == 0) { char *w, *h; ++index; if (!argv[index]) { return -1; } w = argv[index]; h = argv[index]; while (*h && *h != 'x') { ++h; } if (!*h) { return -1; } *h++ = '\0'; state->logical_w = SDL_atoi(w); state->logical_h = SDL_atoi(h); return 2; } if (SDL_strcasecmp(argv[index], "--scale") == 0) { ++index; if (!argv[index]) { return -1; } state->scale = (float)SDL_atof(argv[index]); return 2; } if (SDL_strcasecmp(argv[index], "--depth") == 0) { ++index; if (!argv[index]) { return -1; } state->depth = SDL_atoi(argv[index]); return 2; } if (SDL_strcasecmp(argv[index], "--refresh") == 0) { ++index; if (!argv[index]) { return -1; } state->refresh_rate = SDL_atoi(argv[index]); return 2; } if (SDL_strcasecmp(argv[index], "--vsync") == 0) { state->render_flags |= SDL_RENDERER_PRESENTVSYNC; return 1; } if (SDL_strcasecmp(argv[index], "--noframe") == 0) { state->window_flags |= SDL_WINDOW_BORDERLESS; return 1; } if (SDL_strcasecmp(argv[index], "--resize") == 0) { state->window_flags |= SDL_WINDOW_RESIZABLE; return 1; } if (SDL_strcasecmp(argv[index], "--minimize") == 0) { state->window_flags |= SDL_WINDOW_MINIMIZED; return 1; } if (SDL_strcasecmp(argv[index], "--maximize") == 0) { state->window_flags |= SDL_WINDOW_MAXIMIZED; return 1; } if (SDL_strcasecmp(argv[index], "--grab") == 0) { state->window_flags |= SDL_WINDOW_INPUT_GRABBED; return 1; } if (SDL_strcasecmp(argv[index], "--rate") == 0) { ++index; if (!argv[index]) { return -1; } state->audiospec.freq = SDL_atoi(argv[index]); return 2; } if (SDL_strcasecmp(argv[index], "--format") == 0) { ++index; if (!argv[index]) { return -1; } if (SDL_strcasecmp(argv[index], "U8") == 0) { state->audiospec.format = AUDIO_U8; return 2; } if (SDL_strcasecmp(argv[index], "S8") == 0) { state->audiospec.format = AUDIO_S8; return 2; } if (SDL_strcasecmp(argv[index], "U16") == 0) { state->audiospec.format = AUDIO_U16; return 2; } if (SDL_strcasecmp(argv[index], "U16LE") == 0) { state->audiospec.format = AUDIO_U16LSB; return 2; } if (SDL_strcasecmp(argv[index], "U16BE") == 0) { state->audiospec.format = AUDIO_U16MSB; return 2; } if (SDL_strcasecmp(argv[index], "S16") == 0) { state->audiospec.format = AUDIO_S16; return 2; } if (SDL_strcasecmp(argv[index], "S16LE") == 0) { state->audiospec.format = AUDIO_S16LSB; return 2; } if (SDL_strcasecmp(argv[index], "S16BE") == 0) { state->audiospec.format = AUDIO_S16MSB; return 2; } return -1; } if (SDL_strcasecmp(argv[index], "--channels") == 0) { ++index; if (!argv[index]) { return -1; } state->audiospec.channels = (Uint8) SDL_atoi(argv[index]); return 2; } if (SDL_strcasecmp(argv[index], "--samples") == 0) { ++index; if (!argv[index]) { return -1; } state->audiospec.samples = (Uint16) SDL_atoi(argv[index]); return 2; } if (SDL_strcasecmp(argv[index], "--trackmem") == 0) { /* Already handled in SDLTest_CommonCreateState() */ return 1; } if ((SDL_strcasecmp(argv[index], "-h") == 0) || (SDL_strcasecmp(argv[index], "--help") == 0)) { /* Print the usage message */ return -1; } if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) { /* Debug flag sent by Xcode */ return 2; } return 0; } void SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options) { int i; SDL_Log("USAGE: %s", argv0); SDL_Log(" %s", "[--trackmem]"); if (state->flags & SDL_INIT_VIDEO) { for (i = 0; i < SDL_arraysize(video_usage); i++) { SDL_Log(" %s", video_usage[i]); } } if (state->flags & SDL_INIT_AUDIO) { for (i = 0; i < SDL_arraysize(audio_usage); i++) { SDL_Log(" %s", audio_usage[i]); } } if (options) { for (i = 0; options[i] != NULL; i++) { SDL_Log(" %s", options[i]); } } } static const char * BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, const char **strlist2, const int numitems2) { char *str = *pstr; if (!str) { size_t len = SDL_strlen("[--trackmem]") + 2; int i; for (i = 0; i < numitems; i++) { len += SDL_strlen(strlist[i]) + 1; } if (strlist2) { for (i = 0; i < numitems2; i++) { len += SDL_strlen(strlist2[i]) + 1; } } str = (char *) SDL_calloc(1, len); if (!str) { return ""; /* oh well. */ } SDL_strlcat(str, "[--trackmem] ", len); for (i = 0; i < numitems-1; i++) { SDL_strlcat(str, strlist[i], len); SDL_strlcat(str, " ", len); } SDL_strlcat(str, strlist[i], len); if (strlist2) { SDL_strlcat(str, " ", len); for (i = 0; i < numitems2-1; i++) { SDL_strlcat(str, strlist2[i], len); SDL_strlcat(str, " ", len); } SDL_strlcat(str, strlist2[i], len); } *pstr = str; } return str; } static char *common_usage_video = NULL; static char *common_usage_audio = NULL; static char *common_usage_videoaudio = NULL; const char * SDLTest_CommonUsage(SDLTest_CommonState * state) { switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { case SDL_INIT_VIDEO: return BuildCommonUsageString(&common_usage_video, video_usage, SDL_arraysize(video_usage), NULL, 0); case SDL_INIT_AUDIO: return BuildCommonUsageString(&common_usage_audio, audio_usage, SDL_arraysize(audio_usage), NULL, 0); case (SDL_INIT_VIDEO | SDL_INIT_AUDIO): return BuildCommonUsageString(&common_usage_videoaudio, video_usage, SDL_arraysize(video_usage), audio_usage, SDL_arraysize(audio_usage)); default: return "[--trackmem]"; } } SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **argv) { int i = 1; while (i < argc) { const int consumed = SDLTest_CommonArg(state, i); if (consumed == 0) { SDLTest_CommonLogUsage(state, argv[0], NULL); return SDL_FALSE; } i += consumed; } return SDL_TRUE; } static void SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag) { switch (flag) { case SDL_RENDERER_SOFTWARE: SDL_snprintfcat(text, maxlen, "Software"); break; case SDL_RENDERER_ACCELERATED: SDL_snprintfcat(text, maxlen, "Accelerated"); break; case SDL_RENDERER_PRESENTVSYNC: SDL_snprintfcat(text, maxlen, "PresentVSync"); break; case SDL_RENDERER_TARGETTEXTURE: SDL_snprintfcat(text, maxlen, "TargetTexturesSupported"); break; default: SDL_snprintfcat(text, maxlen, "0x%8.8x", flag); break; } } static void SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format) { switch (format) { case SDL_PIXELFORMAT_UNKNOWN: SDL_snprintfcat(text, maxlen, "Unknown"); break; case SDL_PIXELFORMAT_INDEX1LSB: SDL_snprintfcat(text, maxlen, "Index1LSB"); break; case SDL_PIXELFORMAT_INDEX1MSB: SDL_snprintfcat(text, maxlen, "Index1MSB"); break; case SDL_PIXELFORMAT_INDEX4LSB: SDL_snprintfcat(text, maxlen, "Index4LSB"); break; case SDL_PIXELFORMAT_INDEX4MSB: SDL_snprintfcat(text, maxlen, "Index4MSB"); break; case SDL_PIXELFORMAT_INDEX8: SDL_snprintfcat(text, maxlen, "Index8"); break; case SDL_PIXELFORMAT_RGB332: SDL_snprintfcat(text, maxlen, "RGB332"); break; case SDL_PIXELFORMAT_RGB444: SDL_snprintfcat(text, maxlen, "RGB444"); break; case SDL_PIXELFORMAT_BGR444: SDL_snprintfcat(text, maxlen, "BGR444"); break; case SDL_PIXELFORMAT_RGB555: SDL_snprintfcat(text, maxlen, "RGB555"); break; case SDL_PIXELFORMAT_BGR555: SDL_snprintfcat(text, maxlen, "BGR555"); break; case SDL_PIXELFORMAT_ARGB4444: SDL_snprintfcat(text, maxlen, "ARGB4444"); break; case SDL_PIXELFORMAT_ABGR4444: SDL_snprintfcat(text, maxlen, "ABGR4444"); break; case SDL_PIXELFORMAT_ARGB1555: SDL_snprintfcat(text, maxlen, "ARGB1555"); break; case SDL_PIXELFORMAT_ABGR1555: SDL_snprintfcat(text, maxlen, "ABGR1555"); break; case SDL_PIXELFORMAT_RGB565: SDL_snprintfcat(text, maxlen, "RGB565"); break; case SDL_PIXELFORMAT_BGR565: SDL_snprintfcat(text, maxlen, "BGR565"); break; case SDL_PIXELFORMAT_RGB24: SDL_snprintfcat(text, maxlen, "RGB24"); break; case SDL_PIXELFORMAT_BGR24: SDL_snprintfcat(text, maxlen, "BGR24"); break; case SDL_PIXELFORMAT_RGB888: SDL_snprintfcat(text, maxlen, "RGB888"); break; case SDL_PIXELFORMAT_BGR888: SDL_snprintfcat(text, maxlen, "BGR888"); break; case SDL_PIXELFORMAT_ARGB8888: SDL_snprintfcat(text, maxlen, "ARGB8888"); break; case SDL_PIXELFORMAT_RGBA8888: SDL_snprintfcat(text, maxlen, "RGBA8888"); break; case SDL_PIXELFORMAT_ABGR8888: SDL_snprintfcat(text, maxlen, "ABGR8888"); break; case SDL_PIXELFORMAT_BGRA8888: SDL_snprintfcat(text, maxlen, "BGRA8888"); break; case SDL_PIXELFORMAT_ARGB2101010: SDL_snprintfcat(text, maxlen, "ARGB2101010"); break; case SDL_PIXELFORMAT_YV12: SDL_snprintfcat(text, maxlen, "YV12"); break; case SDL_PIXELFORMAT_IYUV: SDL_snprintfcat(text, maxlen, "IYUV"); break; case SDL_PIXELFORMAT_YUY2: SDL_snprintfcat(text, maxlen, "YUY2"); break; case SDL_PIXELFORMAT_UYVY: SDL_snprintfcat(text, maxlen, "UYVY"); break; case SDL_PIXELFORMAT_YVYU: SDL_snprintfcat(text, maxlen, "YVYU"); break; case SDL_PIXELFORMAT_NV12: SDL_snprintfcat(text, maxlen, "NV12"); break; case SDL_PIXELFORMAT_NV21: SDL_snprintfcat(text, maxlen, "NV21"); break; default: SDL_snprintfcat(text, maxlen, "0x%8.8x", format); break; } } static void SDLTest_PrintRenderer(SDL_RendererInfo * info) { int i, count; char text[1024]; SDL_Log(" Renderer %s:\n", info->name); SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8X", info->flags); SDL_snprintfcat(text, sizeof(text), " ("); count = 0; for (i = 0; i < sizeof(info->flags) * 8; ++i) { Uint32 flag = (1 << i); if (info->flags & flag) { if (count > 0) { SDL_snprintfcat(text, sizeof(text), " | "); } SDLTest_PrintRendererFlag(text, sizeof(text), flag); ++count; } } SDL_snprintfcat(text, sizeof(text), ")"); SDL_Log("%s\n", text); SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info->num_texture_formats); for (i = 0; i < (int) info->num_texture_formats; ++i) { if (i > 0) { SDL_snprintfcat(text, sizeof(text), ", "); } SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]); } SDL_Log("%s\n", text); if (info->max_texture_width || info->max_texture_height) { SDL_Log(" Max Texture Size: %dx%d\n", info->max_texture_width, info->max_texture_height); } } static SDL_Surface * SDLTest_LoadIcon(const char *file) { SDL_Surface *icon; /* Load the icon surface */ icon = SDL_LoadBMP(file); if (icon == NULL) { SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError()); return (NULL); } if (icon->format->palette) { /* Set the colorkey */ SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels)); } return (icon); } static SDL_HitTestResult SDLCALL SDLTest_ExampleHitTestCallback(SDL_Window *win, const SDL_Point *area, void *data) { int w, h; const int RESIZE_BORDER = 8; const int DRAGGABLE_TITLE = 32; /*SDL_Log("Hit test point %d,%d\n", area->x, area->y);*/ SDL_GetWindowSize(win, &w, &h); if (area->x < RESIZE_BORDER) { if (area->y < RESIZE_BORDER) { SDL_Log("SDL_HITTEST_RESIZE_TOPLEFT\n"); return SDL_HITTEST_RESIZE_TOPLEFT; } else if (area->y >= (h-RESIZE_BORDER)) { SDL_Log("SDL_HITTEST_RESIZE_BOTTOMLEFT\n"); return SDL_HITTEST_RESIZE_BOTTOMLEFT; } else { SDL_Log("SDL_HITTEST_RESIZE_LEFT\n"); return SDL_HITTEST_RESIZE_LEFT; } } else if (area->x >= (w-RESIZE_BORDER)) { if (area->y < RESIZE_BORDER) { SDL_Log("SDL_HITTEST_RESIZE_TOPRIGHT\n"); return SDL_HITTEST_RESIZE_TOPRIGHT; } else if (area->y >= (h-RESIZE_BORDER)) { SDL_Log("SDL_HITTEST_RESIZE_BOTTOMRIGHT\n"); return SDL_HITTEST_RESIZE_BOTTOMRIGHT; } else { SDL_Log("SDL_HITTEST_RESIZE_RIGHT\n"); return SDL_HITTEST_RESIZE_RIGHT; } } else if (area->y >= (h-RESIZE_BORDER)) { SDL_Log("SDL_HITTEST_RESIZE_BOTTOM\n"); return SDL_HITTEST_RESIZE_BOTTOM; } else if (area->y < RESIZE_BORDER) { SDL_Log("SDL_HITTEST_RESIZE_TOP\n"); return SDL_HITTEST_RESIZE_TOP; } else if (area->y < DRAGGABLE_TITLE) { SDL_Log("SDL_HITTEST_DRAGGABLE\n"); return SDL_HITTEST_DRAGGABLE; } return SDL_HITTEST_NORMAL; } SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state) { int i, j, m, n, w, h; SDL_DisplayMode fullscreen_mode; char text[1024]; if (state->flags & SDL_INIT_VIDEO) { if (state->verbose & VERBOSE_VIDEO) { n = SDL_GetNumVideoDrivers(); if (n == 0) { SDL_Log("No built-in video drivers\n"); } else { SDL_snprintf(text, sizeof(text), "Built-in video drivers:"); for (i = 0; i < n; ++i) { if (i > 0) { SDL_snprintfcat(text, sizeof(text), ","); } SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i)); } SDL_Log("%s\n", text); } } if (SDL_VideoInit(state->videodriver) < 0) { SDL_Log("Couldn't initialize video driver: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->verbose & VERBOSE_VIDEO) { SDL_Log("Video driver: %s\n", SDL_GetCurrentVideoDriver()); } /* Upload GL settings */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size); SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples); if (state->gl_accelerated >= 0) { SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, state->gl_accelerated); } SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing); if (state->gl_major_version) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version); } if (state->gl_debug) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); } if (state->gl_profile_mask) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, state->gl_profile_mask); } if (state->verbose & VERBOSE_MODES) { SDL_Rect bounds, usablebounds; float hdpi = 0; float vdpi = 0; SDL_DisplayMode mode; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; #if SDL_VIDEO_DRIVER_WINDOWS int adapterIndex = 0; int outputIndex = 0; #endif n = SDL_GetNumVideoDisplays(); SDL_Log("Number of displays: %d\n", n); for (i = 0; i < n; ++i) { SDL_Log("Display %d: %s\n", i, SDL_GetDisplayName(i)); SDL_zero(bounds); SDL_GetDisplayBounds(i, &bounds); SDL_zero(usablebounds); SDL_GetDisplayUsableBounds(i, &usablebounds); SDL_GetDisplayDPI(i, NULL, &hdpi, &vdpi); SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y); SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y); SDL_Log("DPI: %fx%f\n", hdpi, vdpi); SDL_GetDesktopDisplayMode(i, &mode); SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); SDL_Log(" Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n", mode.w, mode.h, mode.refresh_rate, bpp, SDL_GetPixelFormatName(mode.format)); if (Rmask || Gmask || Bmask) { SDL_Log(" Red Mask = 0x%.8x\n", Rmask); SDL_Log(" Green Mask = 0x%.8x\n", Gmask); SDL_Log(" Blue Mask = 0x%.8x\n", Bmask); if (Amask) SDL_Log(" Alpha Mask = 0x%.8x\n", Amask); } /* Print available fullscreen video modes */ m = SDL_GetNumDisplayModes(i); if (m == 0) { SDL_Log("No available fullscreen video modes\n"); } else { SDL_Log(" Fullscreen video modes:\n"); for (j = 0; j < m; ++j) { SDL_GetDisplayMode(i, j, &mode); SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); SDL_Log(" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n", j, mode.w, mode.h, mode.refresh_rate, bpp, SDL_GetPixelFormatName(mode.format)); if (Rmask || Gmask || Bmask) { SDL_Log(" Red Mask = 0x%.8x\n", Rmask); SDL_Log(" Green Mask = 0x%.8x\n", Gmask); SDL_Log(" Blue Mask = 0x%.8x\n", Bmask); if (Amask) SDL_Log(" Alpha Mask = 0x%.8x\n", Amask); } } } #if SDL_VIDEO_DRIVER_WINDOWS /* Print the D3D9 adapter index */ adapterIndex = SDL_Direct3D9GetAdapterIndex( i ); SDL_Log("D3D9 Adapter Index: %d", adapterIndex); /* Print the DXGI adapter and output indices */ SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex); SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex); #endif } } if (state->verbose & VERBOSE_RENDER) { SDL_RendererInfo info; n = SDL_GetNumRenderDrivers(); if (n == 0) { SDL_Log("No built-in render drivers\n"); } else { SDL_Log("Built-in render drivers:\n"); for (i = 0; i < n; ++i) { SDL_GetRenderDriverInfo(i, &info); SDLTest_PrintRenderer(&info); } } } SDL_zero(fullscreen_mode); switch (state->depth) { case 8: fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8; break; case 15: fullscreen_mode.format = SDL_PIXELFORMAT_RGB555; break; case 16: fullscreen_mode.format = SDL_PIXELFORMAT_RGB565; break; case 24: fullscreen_mode.format = SDL_PIXELFORMAT_RGB24; break; default: fullscreen_mode.format = SDL_PIXELFORMAT_RGB888; break; } fullscreen_mode.refresh_rate = state->refresh_rate; state->windows = (SDL_Window **) SDL_calloc(state->num_windows, sizeof(*state->windows)); state->renderers = (SDL_Renderer **) SDL_calloc(state->num_windows, sizeof(*state->renderers)); state->targets = (SDL_Texture **) SDL_calloc(state->num_windows, sizeof(*state->targets)); if (!state->windows || !state->renderers) { SDL_Log("Out of memory!\n"); return SDL_FALSE; } for (i = 0; i < state->num_windows; ++i) { char title[1024]; SDL_Rect r; r.x = state->window_x; r.y = state->window_y; r.w = state->window_w; r.h = state->window_h; /* !!! FIXME: hack to make --usable-bounds work for now. */ if ((r.x == -1) && (r.y == -1) && (r.w == -1) && (r.h == -1)) { SDL_GetDisplayUsableBounds(state->display, &r); } if (state->num_windows > 1) { SDL_snprintf(title, SDL_arraysize(title), "%s %d", state->window_title, i + 1); } else { SDL_strlcpy(title, state->window_title, SDL_arraysize(title)); } state->windows[i] = SDL_CreateWindow(title, r.x, r.y, r.w, r.h, state->window_flags); if (!state->windows[i]) { SDL_Log("Couldn't create window: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->window_minW || state->window_minH) { SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH); } if (state->window_maxW || state->window_maxH) { SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH); } SDL_GetWindowSize(state->windows[i], &w, &h); if (!(state->window_flags & SDL_WINDOW_RESIZABLE) && (w != state->window_w || h != state->window_h)) { printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h); state->window_w = w; state->window_h = h; } if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) { SDL_Log("Can't set up fullscreen display mode: %s\n", SDL_GetError()); return SDL_FALSE; } /* Add resize/drag areas for windows that are borderless and resizable */ if ((state->window_flags & (SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) == (SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) { SDL_SetWindowHitTest(state->windows[i], SDLTest_ExampleHitTestCallback, NULL); } if (state->window_icon) { SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon); if (icon) { SDL_SetWindowIcon(state->windows[i], icon); SDL_FreeSurface(icon); } } SDL_ShowWindow(state->windows[i]); if (!state->skip_renderer && (state->renderdriver || !(state->window_flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_VULKAN)))) { m = -1; if (state->renderdriver) { SDL_RendererInfo info; n = SDL_GetNumRenderDrivers(); for (j = 0; j < n; ++j) { SDL_GetRenderDriverInfo(j, &info); if (SDL_strcasecmp(info.name, state->renderdriver) == 0) { m = j; break; } } if (m == -1) { SDL_Log("Couldn't find render driver named %s", state->renderdriver); return SDL_FALSE; } } state->renderers[i] = SDL_CreateRenderer(state->windows[i], m, state->render_flags); if (!state->renderers[i]) { SDL_Log("Couldn't create renderer: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->logical_w && state->logical_h) { SDL_RenderSetLogicalSize(state->renderers[i], state->logical_w, state->logical_h); } else if (state->scale != 0.) { SDL_RenderSetScale(state->renderers[i], state->scale, state->scale); } if (state->verbose & VERBOSE_RENDER) { SDL_RendererInfo info; SDL_Log("Current renderer:\n"); SDL_GetRendererInfo(state->renderers[i], &info); SDLTest_PrintRenderer(&info); } } } } if (state->flags & SDL_INIT_AUDIO) { if (state->verbose & VERBOSE_AUDIO) { n = SDL_GetNumAudioDrivers(); if (n == 0) { SDL_Log("No built-in audio drivers\n"); } else { SDL_snprintf(text, sizeof(text), "Built-in audio drivers:"); for (i = 0; i < n; ++i) { if (i > 0) { SDL_snprintfcat(text, sizeof(text), ","); } SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i)); } SDL_Log("%s\n", text); } } if (SDL_AudioInit(state->audiodriver) < 0) { SDL_Log("Couldn't initialize audio driver: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->verbose & VERBOSE_AUDIO) { SDL_Log("Audio driver: %s\n", SDL_GetCurrentAudioDriver()); } if (SDL_OpenAudio(&state->audiospec, NULL) < 0) { SDL_Log("Couldn't open audio: %s\n", SDL_GetError()); return SDL_FALSE; } } return SDL_TRUE; } static const char * DisplayOrientationName(int orientation) { switch (orientation) { #define CASE(X) case SDL_ORIENTATION_##X: return #X CASE(UNKNOWN); CASE(LANDSCAPE); CASE(LANDSCAPE_FLIPPED); CASE(PORTRAIT); CASE(PORTRAIT_FLIPPED); #undef CASE default: return "???"; } } static const char * ControllerAxisName(const SDL_GameControllerAxis axis) { switch (axis) { #define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax AXIS_CASE(INVALID); AXIS_CASE(LEFTX); AXIS_CASE(LEFTY); AXIS_CASE(RIGHTX); AXIS_CASE(RIGHTY); AXIS_CASE(TRIGGERLEFT); AXIS_CASE(TRIGGERRIGHT); #undef AXIS_CASE default: return "???"; } } static const char * ControllerButtonName(const SDL_GameControllerButton button) { switch (button) { #define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn BUTTON_CASE(INVALID); BUTTON_CASE(A); BUTTON_CASE(B); BUTTON_CASE(X); BUTTON_CASE(Y); BUTTON_CASE(BACK); BUTTON_CASE(GUIDE); BUTTON_CASE(START); BUTTON_CASE(LEFTSTICK); BUTTON_CASE(RIGHTSTICK); BUTTON_CASE(LEFTSHOULDER); BUTTON_CASE(RIGHTSHOULDER); BUTTON_CASE(DPAD_UP); BUTTON_CASE(DPAD_DOWN); BUTTON_CASE(DPAD_LEFT); BUTTON_CASE(DPAD_RIGHT); #undef BUTTON_CASE default: return "???"; } } static void SDLTest_PrintEvent(SDL_Event * event) { if ((event->type == SDL_MOUSEMOTION) || (event->type == SDL_FINGERMOTION)) { /* Mouse and finger motion are really spammy */ return; } switch (event->type) { case SDL_DISPLAYEVENT: switch (event->display.event) { case SDL_DISPLAYEVENT_ORIENTATION: SDL_Log("SDL EVENT: Display %d changed orientation to %s", event->display.display, DisplayOrientationName(event->display.data1)); break; default: SDL_Log("SDL EVENT: Display %d got unknown event 0x%4.4x", event->display.display, event->display.event); break; } break; case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_SHOWN: SDL_Log("SDL EVENT: Window %d shown", event->window.windowID); break; case SDL_WINDOWEVENT_HIDDEN: SDL_Log("SDL EVENT: Window %d hidden", event->window.windowID); break; case SDL_WINDOWEVENT_EXPOSED: SDL_Log("SDL EVENT: Window %d exposed", event->window.windowID); break; case SDL_WINDOWEVENT_MOVED: SDL_Log("SDL EVENT: Window %d moved to %d,%d", event->window.windowID, event->window.data1, event->window.data2); break; case SDL_WINDOWEVENT_RESIZED: SDL_Log("SDL EVENT: Window %d resized to %dx%d", event->window.windowID, event->window.data1, event->window.data2); break; case SDL_WINDOWEVENT_SIZE_CHANGED: SDL_Log("SDL EVENT: Window %d changed size to %dx%d", event->window.windowID, event->window.data1, event->window.data2); break; case SDL_WINDOWEVENT_MINIMIZED: SDL_Log("SDL EVENT: Window %d minimized", event->window.windowID); break; case SDL_WINDOWEVENT_MAXIMIZED: SDL_Log("SDL EVENT: Window %d maximized", event->window.windowID); break; case SDL_WINDOWEVENT_RESTORED: SDL_Log("SDL EVENT: Window %d restored", event->window.windowID); break; case SDL_WINDOWEVENT_ENTER: SDL_Log("SDL EVENT: Mouse entered window %d", event->window.windowID); break; case SDL_WINDOWEVENT_LEAVE: SDL_Log("SDL EVENT: Mouse left window %d", event->window.windowID); break; case SDL_WINDOWEVENT_FOCUS_GAINED: SDL_Log("SDL EVENT: Window %d gained keyboard focus", event->window.windowID); break; case SDL_WINDOWEVENT_FOCUS_LOST: SDL_Log("SDL EVENT: Window %d lost keyboard focus", event->window.windowID); break; case SDL_WINDOWEVENT_CLOSE: SDL_Log("SDL EVENT: Window %d closed", event->window.windowID); break; case SDL_WINDOWEVENT_TAKE_FOCUS: SDL_Log("SDL EVENT: Window %d take focus", event->window.windowID); break; case SDL_WINDOWEVENT_HIT_TEST: SDL_Log("SDL EVENT: Window %d hit test", event->window.windowID); break; default: SDL_Log("SDL EVENT: Window %d got unknown event 0x%4.4x", event->window.windowID, event->window.event); break; } break; case SDL_KEYDOWN: SDL_Log("SDL EVENT: Keyboard: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s", event->key.windowID, event->key.keysym.scancode, SDL_GetScancodeName(event->key.keysym.scancode), event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); break; case SDL_KEYUP: SDL_Log("SDL EVENT: Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s", event->key.windowID, event->key.keysym.scancode, SDL_GetScancodeName(event->key.keysym.scancode), event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); break; case SDL_TEXTEDITING: SDL_Log("SDL EVENT: Keyboard: text editing \"%s\" in window %d", event->edit.text, event->edit.windowID); break; case SDL_TEXTINPUT: SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %d", event->text.text, event->text.windowID); break; case SDL_KEYMAPCHANGED: SDL_Log("SDL EVENT: Keymap changed"); break; case SDL_MOUSEMOTION: SDL_Log("SDL EVENT: Mouse: moved to %d,%d (%d,%d) in window %d", event->motion.x, event->motion.y, event->motion.xrel, event->motion.yrel, event->motion.windowID); break; case SDL_MOUSEBUTTONDOWN: SDL_Log("SDL EVENT: Mouse: button %d pressed at %d,%d with click count %d in window %d", event->button.button, event->button.x, event->button.y, event->button.clicks, event->button.windowID); break; case SDL_MOUSEBUTTONUP: SDL_Log("SDL EVENT: Mouse: button %d released at %d,%d with click count %d in window %d", event->button.button, event->button.x, event->button.y, event->button.clicks, event->button.windowID); break; case SDL_MOUSEWHEEL: SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y (reversed: %d) in window %d", event->wheel.x, event->wheel.y, event->wheel.direction, event->wheel.windowID); break; case SDL_JOYDEVICEADDED: SDL_Log("SDL EVENT: Joystick index %d attached", event->jdevice.which); break; case SDL_JOYDEVICEREMOVED: SDL_Log("SDL EVENT: Joystick %d removed", event->jdevice.which); break; case SDL_JOYBALLMOTION: SDL_Log("SDL EVENT: Joystick %d: ball %d moved by %d,%d", event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel); break; case SDL_JOYHATMOTION: { const char *position = "UNKNOWN"; switch (event->jhat.value) { case SDL_HAT_CENTERED: position = "CENTER"; break; case SDL_HAT_UP: position = "UP"; break; case SDL_HAT_RIGHTUP: position = "RIGHTUP"; break; case SDL_HAT_RIGHT: position = "RIGHT"; break; case SDL_HAT_RIGHTDOWN: position = "RIGHTDOWN"; break; case SDL_HAT_DOWN: position = "DOWN"; break; case SDL_HAT_LEFTDOWN: position = "LEFTDOWN"; break; case SDL_HAT_LEFT: position = "LEFT"; break; case SDL_HAT_LEFTUP: position = "LEFTUP"; break; } SDL_Log("SDL EVENT: Joystick %d: hat %d moved to %s", event->jhat.which, event->jhat.hat, position); } break; case SDL_JOYBUTTONDOWN: SDL_Log("SDL EVENT: Joystick %d: button %d pressed", event->jbutton.which, event->jbutton.button); break; case SDL_JOYBUTTONUP: SDL_Log("SDL EVENT: Joystick %d: button %d released", event->jbutton.which, event->jbutton.button); break; case SDL_CONTROLLERDEVICEADDED: SDL_Log("SDL EVENT: Controller index %d attached", event->cdevice.which); break; case SDL_CONTROLLERDEVICEREMOVED: SDL_Log("SDL EVENT: Controller %d removed", event->cdevice.which); break; case SDL_CONTROLLERAXISMOTION: SDL_Log("SDL EVENT: Controller %d axis %d ('%s') value: %d", event->caxis.which, event->caxis.axis, ControllerAxisName((SDL_GameControllerAxis)event->caxis.axis), event->caxis.value); break; case SDL_CONTROLLERBUTTONDOWN: SDL_Log("SDL EVENT: Controller %d button %d ('%s') down", event->cbutton.which, event->cbutton.button, ControllerButtonName((SDL_GameControllerButton)event->cbutton.button)); break; case SDL_CONTROLLERBUTTONUP: SDL_Log("SDL EVENT: Controller %d button %d ('%s') up", event->cbutton.which, event->cbutton.button, ControllerButtonName((SDL_GameControllerButton)event->cbutton.button)); break; case SDL_CLIPBOARDUPDATE: SDL_Log("SDL EVENT: Clipboard updated"); break; case SDL_FINGERMOTION: SDL_Log("SDL EVENT: Finger: motion touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f", (long) event->tfinger.touchId, (long) event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure); break; case SDL_FINGERDOWN: case SDL_FINGERUP: SDL_Log("SDL EVENT: Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f", (event->type == SDL_FINGERDOWN) ? "down" : "up", (long) event->tfinger.touchId, (long) event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure); break; case SDL_DOLLARGESTURE: SDL_Log("SDL_EVENT: Dollar gesture detect: %ld", (long) event->dgesture.gestureId); break; case SDL_DOLLARRECORD: SDL_Log("SDL_EVENT: Dollar gesture record: %ld", (long) event->dgesture.gestureId); break; case SDL_MULTIGESTURE: SDL_Log("SDL_EVENT: Multi gesture fingers: %d", event->mgesture.numFingers); break; case SDL_RENDER_DEVICE_RESET: SDL_Log("SDL EVENT: render device reset"); break; case SDL_RENDER_TARGETS_RESET: SDL_Log("SDL EVENT: render targets reset"); break; case SDL_APP_TERMINATING: SDL_Log("SDL EVENT: App terminating"); break; case SDL_APP_LOWMEMORY: SDL_Log("SDL EVENT: App running low on memory"); break; case SDL_APP_WILLENTERBACKGROUND: SDL_Log("SDL EVENT: App will enter the background"); break; case SDL_APP_DIDENTERBACKGROUND: SDL_Log("SDL EVENT: App entered the background"); break; case SDL_APP_WILLENTERFOREGROUND: SDL_Log("SDL EVENT: App will enter the foreground"); break; case SDL_APP_DIDENTERFOREGROUND: SDL_Log("SDL EVENT: App entered the foreground"); break; case SDL_DROPBEGIN: SDL_Log("SDL EVENT: Drag and drop beginning"); break; case SDL_DROPFILE: SDL_Log("SDL EVENT: Drag and drop file: '%s'", event->drop.file); break; case SDL_DROPTEXT: SDL_Log("SDL EVENT: Drag and drop text: '%s'", event->drop.file); break; case SDL_DROPCOMPLETE: SDL_Log("SDL EVENT: Drag and drop ending"); break; case SDL_QUIT: SDL_Log("SDL EVENT: Quit requested"); break; case SDL_USEREVENT: SDL_Log("SDL EVENT: User event %d", event->user.code); break; default: SDL_Log("Unknown event 0x%4.4x", event->type); break; } } static void SDLTest_ScreenShot(SDL_Renderer *renderer) { SDL_Rect viewport; SDL_Surface *surface; if (!renderer) { return; } SDL_RenderGetViewport(renderer, &viewport); surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24, #if SDL_BYTEORDER == SDL_LIL_ENDIAN 0x00FF0000, 0x0000FF00, 0x000000FF, #else 0x000000FF, 0x0000FF00, 0x00FF0000, #endif 0x00000000); if (!surface) { SDL_Log("Couldn't create surface: %s\n", SDL_GetError()); return; } if (SDL_RenderReadPixels(renderer, NULL, surface->format->format, surface->pixels, surface->pitch) < 0) { SDL_Log("Couldn't read screen: %s\n", SDL_GetError()); SDL_free(surface); return; } if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) { SDL_Log("Couldn't save screenshot.bmp: %s\n", SDL_GetError()); SDL_free(surface); return; } } static void FullscreenTo(int index, int windowId) { Uint32 flags; struct SDL_Rect rect = { 0, 0, 0, 0 }; SDL_Window *window = SDL_GetWindowFromID(windowId); if (!window) { return; } SDL_GetDisplayBounds( index, &rect ); flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_FULLSCREEN) { SDL_SetWindowFullscreen( window, SDL_FALSE ); SDL_Delay( 15 ); } SDL_SetWindowPosition( window, rect.x, rect.y ); SDL_SetWindowFullscreen( window, SDL_TRUE ); } void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done) { int i; static SDL_MouseMotionEvent lastEvent; if (state->verbose & VERBOSE_EVENT) { SDLTest_PrintEvent(event); } switch (event->type) { case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_CLOSE: { SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); if (window) { for (i = 0; i < state->num_windows; ++i) { if (window == state->windows[i]) { if (state->targets[i]) { SDL_DestroyTexture(state->targets[i]); state->targets[i] = NULL; } if (state->renderers[i]) { SDL_DestroyRenderer(state->renderers[i]); state->renderers[i] = NULL; } SDL_DestroyWindow(state->windows[i]); state->windows[i] = NULL; break; } } } } break; } break; case SDL_KEYDOWN: { SDL_bool withControl = !!(event->key.keysym.mod & KMOD_CTRL); SDL_bool withShift = !!(event->key.keysym.mod & KMOD_SHIFT); SDL_bool withAlt = !!(event->key.keysym.mod & KMOD_ALT); switch (event->key.keysym.sym) { /* Add hotkeys here */ case SDLK_PRINTSCREEN: { SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { for (i = 0; i < state->num_windows; ++i) { if (window == state->windows[i]) { SDLTest_ScreenShot(state->renderers[i]); } } } } break; case SDLK_EQUALS: if (withControl) { /* Ctrl-+ double the size of the window */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); SDL_SetWindowSize(window, w*2, h*2); } } break; case SDLK_MINUS: if (withControl) { /* Ctrl-- half the size of the window */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); SDL_SetWindowSize(window, w/2, h/2); } } break; case SDLK_UP: case SDLK_DOWN: case SDLK_LEFT: case SDLK_RIGHT: if (withAlt) { /* Alt-Up/Down/Left/Right switches between displays */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { int currentIndex = SDL_GetWindowDisplayIndex(window); int numDisplays = SDL_GetNumVideoDisplays(); if (currentIndex >= 0 && numDisplays >= 1) { int dest; if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) { dest = (currentIndex + numDisplays - 1) % numDisplays; } else { dest = (currentIndex + numDisplays + 1) % numDisplays; } SDL_Log("Centering on display %d\n", dest); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED_DISPLAY(dest), SDL_WINDOWPOS_CENTERED_DISPLAY(dest)); } } } if (withShift) { /* Shift-Up/Down/Left/Right shift the window by 100px */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { const int delta = 100; int x, y; SDL_GetWindowPosition(window, &x, &y); if (event->key.keysym.sym == SDLK_UP) y -= delta; if (event->key.keysym.sym == SDLK_DOWN) y += delta; if (event->key.keysym.sym == SDLK_LEFT) x -= delta; if (event->key.keysym.sym == SDLK_RIGHT) x += delta; SDL_Log("Setting position to (%d, %d)\n", x, y); SDL_SetWindowPosition(window, x, y); } } break; case SDLK_o: if (withControl) { /* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { float opacity; if (SDL_GetWindowOpacity(window, &opacity) == 0) { if (withShift) { opacity += 0.20f; } else { opacity -= 0.20f; } SDL_SetWindowOpacity(window, opacity); } } } break; case SDLK_c: if (withControl) { /* Ctrl-C copy awesome text! */ SDL_SetClipboardText("SDL rocks!\nYou know it!"); printf("Copied text to clipboard\n"); } if (withAlt) { /* Alt-C toggle a render clip rectangle */ for (i = 0; i < state->num_windows; ++i) { int w, h; if (state->renderers[i]) { SDL_Rect clip; SDL_GetWindowSize(state->windows[i], &w, &h); SDL_RenderGetClipRect(state->renderers[i], &clip); if (SDL_RectEmpty(&clip)) { clip.x = w/4; clip.y = h/4; clip.w = w/2; clip.h = h/2; SDL_RenderSetClipRect(state->renderers[i], &clip); } else { SDL_RenderSetClipRect(state->renderers[i], NULL); } } } } if (withShift) { SDL_Window *current_win = SDL_GetKeyboardFocus(); if (current_win) { const SDL_bool shouldCapture = (SDL_GetWindowFlags(current_win) & SDL_WINDOW_MOUSE_CAPTURE) == 0; const int rc = SDL_CaptureMouse(shouldCapture); SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed"); } } break; case SDLK_v: if (withControl) { /* Ctrl-V paste awesome text! */ char *text = SDL_GetClipboardText(); if (*text) { printf("Clipboard: %s\n", text); } else { printf("Clipboard is empty\n"); } SDL_free(text); } break; case SDLK_g: if (withControl) { /* Ctrl-G toggle grab */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE); } } break; case SDLK_m: if (withControl) { /* Ctrl-M maximize */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_MAXIMIZED) { SDL_RestoreWindow(window); } else { SDL_MaximizeWindow(window); } } } break; case SDLK_r: if (withControl) { /* Ctrl-R toggle mouse relative mode */ SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE); } break; case SDLK_z: if (withControl) { /* Ctrl-Z minimize */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { SDL_MinimizeWindow(window); } } break; case SDLK_RETURN: if (withControl) { /* Ctrl-Enter toggle fullscreen */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_FULLSCREEN) { SDL_SetWindowFullscreen(window, SDL_FALSE); } else { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); } } } else if (withAlt) { /* Alt-Enter toggle fullscreen desktop */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_FULLSCREEN) { SDL_SetWindowFullscreen(window, SDL_FALSE); } else { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } } } else if (withShift) { /* Shift-Enter toggle fullscreen desktop / fullscreen */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); } else { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } } } break; case SDLK_b: if (withControl) { /* Ctrl-B toggle window border */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { const Uint32 flags = SDL_GetWindowFlags(window); const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE; SDL_SetWindowBordered(window, b); } } break; case SDLK_a: if (withControl) { /* Ctrl-A reports absolute mouse position. */ int x, y; const Uint32 mask = SDL_GetGlobalMouseState(&x, &y); SDL_Log("ABSOLUTE MOUSE: (%d, %d)%s%s%s%s%s\n", x, y, (mask & SDL_BUTTON_LMASK) ? " [LBUTTON]" : "", (mask & SDL_BUTTON_MMASK) ? " [MBUTTON]" : "", (mask & SDL_BUTTON_RMASK) ? " [RBUTTON]" : "", (mask & SDL_BUTTON_X1MASK) ? " [X2BUTTON]" : "", (mask & SDL_BUTTON_X2MASK) ? " [X2BUTTON]" : ""); } break; case SDLK_0: if (withControl) { SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window); } break; case SDLK_1: if (withControl) { FullscreenTo(0, event->key.windowID); } break; case SDLK_2: if (withControl) { FullscreenTo(1, event->key.windowID); } break; case SDLK_ESCAPE: *done = 1; break; case SDLK_SPACE: { char message[256]; SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window); break; } default: break; } break; } case SDL_QUIT: *done = 1; break; case SDL_MOUSEMOTION: lastEvent = event->motion; break; case SDL_DROPFILE: case SDL_DROPTEXT: SDL_free(event->drop.file); break; } } void SDLTest_CommonQuit(SDLTest_CommonState * state) { int i; SDL_free(common_usage_video); SDL_free(common_usage_audio); SDL_free(common_usage_videoaudio); common_usage_video = NULL; common_usage_audio = NULL; common_usage_videoaudio = NULL; SDL_free(state->windows); if (state->targets) { for (i = 0; i < state->num_windows; ++i) { if (state->targets[i]) { SDL_DestroyTexture(state->targets[i]); } } SDL_free(state->targets); } if (state->renderers) { for (i = 0; i < state->num_windows; ++i) { if (state->renderers[i]) { SDL_DestroyRenderer(state->renderers[i]); } } SDL_free(state->renderers); } if (state->flags & SDL_INIT_VIDEO) { SDL_VideoQuit(); } if (state->flags & SDL_INIT_AUDIO) { SDL_AudioQuit(); } SDL_free(state); SDL_Quit(); SDLTest_LogAllocations(); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_common.c
C
apache-2.0
68,421
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Based on automated SDL_Surface tests originally written by Edgar Simo 'bobbens'. Rewritten for test lib by Andreas Schiffler. */ #include "SDL_config.h" #include "SDL_test.h" /* Counter for _CompareSurface calls; used for filename creation when comparisons fail */ static int _CompareSurfaceCount = 0; /* Compare surfaces */ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error) { int ret; int i,j; int bpp, bpp_reference; Uint8 *p, *p_reference; int dist; int sampleErrorX = 0, sampleErrorY = 0, sampleDist = 0; Uint8 R, G, B, A; Uint8 Rd, Gd, Bd, Ad; char imageFilename[128]; char referenceFilename[128]; /* Validate input surfaces */ if (surface == NULL || referenceSurface == NULL) { return -1; } /* Make sure surface size is the same. */ if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) { return -2; } /* Sanitize input value */ if (allowable_error<0) { allowable_error = 0; } SDL_LockSurface( surface ); SDL_LockSurface( referenceSurface ); ret = 0; bpp = surface->format->BytesPerPixel; bpp_reference = referenceSurface->format->BytesPerPixel; /* Compare image - should be same format. */ for (j=0; j<surface->h; j++) { for (i=0; i<surface->w; i++) { p = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp; p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference; SDL_GetRGBA(*(Uint32*)p, surface->format, &R, &G, &B, &A); SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad); dist = 0; dist += (R-Rd)*(R-Rd); dist += (G-Gd)*(G-Gd); dist += (B-Bd)*(B-Bd); /* Allow some difference in blending accuracy */ if (dist > allowable_error) { ret++; if (ret == 1) { sampleErrorX = i; sampleErrorY = j; sampleDist = dist; } } } } SDL_UnlockSurface( surface ); SDL_UnlockSurface( referenceSurface ); /* Save test image and reference for analysis on failures */ _CompareSurfaceCount++; if (ret != 0) { SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret); SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist); SDL_snprintf(imageFilename, 127, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount); SDL_SaveBMP(surface, imageFilename); SDL_snprintf(referenceFilename, 127, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount); SDL_SaveBMP(referenceSurface, referenceFilename); SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename); } return ret; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_compare.c
C
apache-2.0
3,962
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Used by the test execution component. Original source code contributed by A. Schiffler for GSOC project. */ #include "SDL_config.h" #include "SDL_test.h" int SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext) { int i,j; CrcUint32 c; /* Sanity check context pointer */ if (crcContext==NULL) { return -1; } /* * Build auxiliary table for parallel byte-at-a-time CRC-32 */ #ifdef ORIGINAL_METHOD for (i = 0; i < 256; ++i) { for (c = i << 24, j = 8; j > 0; --j) { c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1); } crcContext->crc32_table[i] = c; } #else for (i=0; i<256; i++) { c = i; for (j=8; j>0; j--) { if (c & 1) { c = (c >> 1) ^ CRC32_POLY; } else { c >>= 1; } } crcContext->crc32_table[i] = c; } #endif return 0; } /* Complete CRC32 calculation on a memory block */ int SDLTest_Crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32) { if (SDLTest_Crc32CalcStart(crcContext,crc32)) { return -1; } if (SDLTest_Crc32CalcBuffer(crcContext, inBuf, inLen, crc32)) { return -1; } if (SDLTest_Crc32CalcEnd(crcContext, crc32)) { return -1; } return 0; } /* Start crc calculation */ int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32) { /* Sanity check pointers */ if (crcContext==NULL) { *crc32=0; return -1; } /* * Preload shift register, per CRC-32 spec */ *crc32 = 0xffffffff; return 0; } /* Finish crc calculation */ int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32) { /* Sanity check pointers */ if (crcContext==NULL) { *crc32=0; return -1; } /* * Return complement, per CRC-32 spec */ *crc32 = (~(*crc32)); return 0; } /* Include memory block in crc */ int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32) { CrcUint8 *p; register CrcUint32 crc; if (crcContext==NULL) { *crc32=0; return -1; } if (inBuf==NULL) { return -1; } /* * Calculate CRC from data */ crc = *crc32; for (p = inBuf; inLen > 0; ++p, --inLen) { #ifdef ORIGINAL_METHOD crc = (crc << 8) ^ crcContext->crc32_table[(crc >> 24) ^ *p]; #else crc = ((crc >> 8) & 0x00FFFFFF) ^ crcContext->crc32_table[ (crc ^ *p) & 0xFF ]; #endif } *crc32 = crc; return 0; } int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext) { if (crcContext==NULL) { return -1; } return 0; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_crc32.c
C
apache-2.0
3,523
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Data generators for fuzzing test data in a reproducible way. */ #include "SDL_config.h" #include <limits.h> /* Visual Studio 2008 doesn't have stdint.h */ #if defined(_MSC_VER) && _MSC_VER <= 1500 #define UINT8_MAX _UI8_MAX #define UINT16_MAX _UI16_MAX #define UINT32_MAX _UI32_MAX #define INT64_MIN _I64_MIN #define INT64_MAX _I64_MAX #define UINT64_MAX _UI64_MAX #else #include <stdint.h> #endif #include <stdio.h> #include <stdlib.h> #include <float.h> #include "SDL_test.h" /** * Counter for fuzzer invocations */ static int fuzzerInvocationCounter = 0; /** * Context for shared random number generator */ static SDLTest_RandomContext rndContext; /* * Note: doxygen documentation markup for functions is in the header file. */ void SDLTest_FuzzerInit(Uint64 execKey) { Uint32 a = (execKey >> 32) & 0x00000000FFFFFFFF; Uint32 b = execKey & 0x00000000FFFFFFFF; SDL_memset((void *)&rndContext, 0, sizeof(SDLTest_RandomContext)); SDLTest_RandomInit(&rndContext, a, b); fuzzerInvocationCounter = 0; } int SDLTest_GetFuzzerInvocationCount() { return fuzzerInvocationCounter; } Uint8 SDLTest_RandomUint8() { fuzzerInvocationCounter++; return (Uint8) SDLTest_RandomInt(&rndContext) & 0x000000FF; } Sint8 SDLTest_RandomSint8() { fuzzerInvocationCounter++; return (Sint8) SDLTest_RandomInt(&rndContext) & 0x000000FF; } Uint16 SDLTest_RandomUint16() { fuzzerInvocationCounter++; return (Uint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF; } Sint16 SDLTest_RandomSint16() { fuzzerInvocationCounter++; return (Sint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF; } Sint32 SDLTest_RandomSint32() { fuzzerInvocationCounter++; return (Sint32) SDLTest_RandomInt(&rndContext); } Uint32 SDLTest_RandomUint32() { fuzzerInvocationCounter++; return (Uint32) SDLTest_RandomInt(&rndContext); } Uint64 SDLTest_RandomUint64() { union { Uint64 v64; Uint32 v32[2]; } value; value.v64 = 0; fuzzerInvocationCounter++; value.v32[0] = SDLTest_RandomSint32(); value.v32[1] = SDLTest_RandomSint32(); return value.v64; } Sint64 SDLTest_RandomSint64() { union { Uint64 v64; Uint32 v32[2]; } value; value.v64 = 0; fuzzerInvocationCounter++; value.v32[0] = SDLTest_RandomSint32(); value.v32[1] = SDLTest_RandomSint32(); return (Sint64)value.v64; } Sint32 SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax) { Sint64 min = pMin; Sint64 max = pMax; Sint64 temp; Sint64 number; if(pMin > pMax) { temp = min; min = max; max = temp; } else if(pMin == pMax) { return (Sint32)min; } number = SDLTest_RandomUint32(); /* invocation count increment in preceeding call */ return (Sint32)((number % ((max + 1) - min)) + min); } /* ! * Generates a unsigned boundary value between the given boundaries. * Boundary values are inclusive. See the examples below. * If boundary2 < boundary1, the values are swapped. * If boundary1 == boundary2, value of boundary1 will be returned * * Generating boundary values for Uint8: * BoundaryValues(UINT8_MAX, 10, 20, True) -> [10,11,19,20] * BoundaryValues(UINT8_MAX, 10, 20, False) -> [9,21] * BoundaryValues(UINT8_MAX, 0, 15, True) -> [0, 1, 14, 15] * BoundaryValues(UINT8_MAX, 0, 15, False) -> [16] * BoundaryValues(UINT8_MAX, 0, 0xFF, False) -> [0], error set * * Generator works the same for other types of unsigned integers. * * \param maxValue The biggest value that is acceptable for this data type. * For instance, for Uint8 -> 255, Uint16 -> 65536 etc. * \param boundary1 defines lower boundary * \param boundary2 defines upper boundary * \param validDomain Generate only for valid domain (for the data type) * * \returns Returns a random boundary value for the domain or 0 in case of error */ static Uint64 SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain) { Uint64 b1, b2; Uint64 delta; Uint64 tempBuf[4]; Uint8 index; /* Maybe swap */ if (boundary1 > boundary2) { b1 = boundary2; b2 = boundary1; } else { b1 = boundary1; b2 = boundary2; } index = 0; if (validDomain == SDL_TRUE) { if (b1 == b2) { return b1; } /* Generate up to 4 values within bounds */ delta = b2 - b1; if (delta < 4) { do { tempBuf[index] = b1 + index; index++; } while (index < delta); } else { tempBuf[index] = b1; index++; tempBuf[index] = b1 + 1; index++; tempBuf[index] = b2 - 1; index++; tempBuf[index] = b2; index++; } } else { /* Generate up to 2 values outside of bounds */ if (b1 > 0) { tempBuf[index] = b1 - 1; index++; } if (b2 < maxValue) { tempBuf[index] = b2 + 1; index++; } } if (index == 0) { /* There are no valid boundaries */ SDL_Unsupported(); return 0; } return tempBuf[SDLTest_RandomUint8() % index]; } Uint8 SDLTest_RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain) { /* max value for Uint8 */ const Uint64 maxValue = UCHAR_MAX; return (Uint8)SDLTest_GenerateUnsignedBoundaryValues(maxValue, (Uint64) boundary1, (Uint64) boundary2, validDomain); } Uint16 SDLTest_RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain) { /* max value for Uint16 */ const Uint64 maxValue = USHRT_MAX; return (Uint16)SDLTest_GenerateUnsignedBoundaryValues(maxValue, (Uint64) boundary1, (Uint64) boundary2, validDomain); } Uint32 SDLTest_RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain) { /* max value for Uint32 */ #if ((ULONG_MAX) == (UINT_MAX)) const Uint64 maxValue = ULONG_MAX; #else const Uint64 maxValue = UINT_MAX; #endif return (Uint32)SDLTest_GenerateUnsignedBoundaryValues(maxValue, (Uint64) boundary1, (Uint64) boundary2, validDomain); } Uint64 SDLTest_RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain) { /* max value for Uint64 */ const Uint64 maxValue = UINT64_MAX; return SDLTest_GenerateUnsignedBoundaryValues(maxValue, boundary1, boundary2, validDomain); } /* ! * Generates a signed boundary value between the given boundaries. * Boundary values are inclusive. See the examples below. * If boundary2 < boundary1, the values are swapped. * If boundary1 == boundary2, value of boundary1 will be returned * * Generating boundary values for Sint8: * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -10, 20, True) -> [-10,-9,19,20] * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -10, 20, False) -> [-11,21] * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -30, -15, True) -> [-30, -29, -16, -15] * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -127, 15, False) -> [16] * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -127, 127, False) -> [0], error set * * Generator works the same for other types of signed integers. * * \param minValue The smallest value that is acceptable for this data type. * For instance, for Uint8 -> -127, etc. * \param maxValue The biggest value that is acceptable for this data type. * For instance, for Uint8 -> 127, etc. * \param boundary1 defines lower boundary * \param boundary2 defines upper boundary * \param validDomain Generate only for valid domain (for the data type) * * \returns Returns a random boundary value for the domain or 0 in case of error */ static Sint64 SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain) { Sint64 b1, b2; Sint64 delta; Sint64 tempBuf[4]; Uint8 index; /* Maybe swap */ if (boundary1 > boundary2) { b1 = boundary2; b2 = boundary1; } else { b1 = boundary1; b2 = boundary2; } index = 0; if (validDomain == SDL_TRUE) { if (b1 == b2) { return b1; } /* Generate up to 4 values within bounds */ delta = b2 - b1; if (delta < 4) { do { tempBuf[index] = b1 + index; index++; } while (index < delta); } else { tempBuf[index] = b1; index++; tempBuf[index] = b1 + 1; index++; tempBuf[index] = b2 - 1; index++; tempBuf[index] = b2; index++; } } else { /* Generate up to 2 values outside of bounds */ if (b1 > minValue) { tempBuf[index] = b1 - 1; index++; } if (b2 < maxValue) { tempBuf[index] = b2 + 1; index++; } } if (index == 0) { /* There are no valid boundaries */ SDL_Unsupported(); return minValue; } return tempBuf[SDLTest_RandomUint8() % index]; } Sint8 SDLTest_RandomSint8BoundaryValue(Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain) { /* min & max values for Sint8 */ const Sint64 maxValue = SCHAR_MAX; const Sint64 minValue = SCHAR_MIN; return (Sint8)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue, (Sint64) boundary1, (Sint64) boundary2, validDomain); } Sint16 SDLTest_RandomSint16BoundaryValue(Sint16 boundary1, Sint16 boundary2, SDL_bool validDomain) { /* min & max values for Sint16 */ const Sint64 maxValue = SHRT_MAX; const Sint64 minValue = SHRT_MIN; return (Sint16)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue, (Sint64) boundary1, (Sint64) boundary2, validDomain); } Sint32 SDLTest_RandomSint32BoundaryValue(Sint32 boundary1, Sint32 boundary2, SDL_bool validDomain) { /* min & max values for Sint32 */ #if ((ULONG_MAX) == (UINT_MAX)) const Sint64 maxValue = LONG_MAX; const Sint64 minValue = LONG_MIN; #else const Sint64 maxValue = INT_MAX; const Sint64 minValue = INT_MIN; #endif return (Sint32)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue, (Sint64) boundary1, (Sint64) boundary2, validDomain); } Sint64 SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain) { /* min & max values for Sint64 */ const Sint64 maxValue = INT64_MAX; const Sint64 minValue = INT64_MIN; return SDLTest_GenerateSignedBoundaryValues(minValue, maxValue, boundary1, boundary2, validDomain); } float SDLTest_RandomUnitFloat() { return SDLTest_RandomUint32() / (float) UINT_MAX; } float SDLTest_RandomFloat() { return (float) (SDLTest_RandomUnitDouble() * 2.0 * (double)FLT_MAX - (double)(FLT_MAX)); } double SDLTest_RandomUnitDouble() { return (double) (SDLTest_RandomUint64() >> 11) * (1.0/9007199254740992.0); } double SDLTest_RandomDouble() { double r = 0.0; double s = 1.0; do { s /= UINT_MAX + 1.0; r += (double)SDLTest_RandomInt(&rndContext) * s; } while (s > DBL_EPSILON); fuzzerInvocationCounter++; return r; } char * SDLTest_RandomAsciiString() { return SDLTest_RandomAsciiStringWithMaximumLength(255); } char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength) { int size; if(maxLength < 1) { SDL_InvalidParamError("maxLength"); return NULL; } size = (SDLTest_RandomUint32() % (maxLength + 1)); return SDLTest_RandomAsciiStringOfSize(size); } char * SDLTest_RandomAsciiStringOfSize(int size) { char *string; int counter; if(size < 1) { SDL_InvalidParamError("size"); return NULL; } string = (char *)SDL_malloc((size + 1) * sizeof(char)); if (string==NULL) { return NULL; } for(counter = 0; counter < size; ++counter) { string[counter] = (char)SDLTest_RandomIntegerInRange(32, 126); } string[counter] = '\0'; fuzzerInvocationCounter++; return string; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_fuzzer.c
C
apache-2.0
13,629
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include "SDL_test.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> /* Invalid test name/description message format */ #define SDLTEST_INVALID_NAME_FORMAT "(Invalid)" /* Log summary message format */ #define SDLTEST_LOG_SUMMARY_FORMAT "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d" /* Final result message format */ #define SDLTEST_FINAL_RESULT_FORMAT ">>> %s '%s': %s\n" /* ! \brief Timeout for single test case execution */ static Uint32 SDLTest_TestCaseTimeout = 3600; /** * Generates a random run seed string for the harness. The generated seed * will contain alphanumeric characters (0-9A-Z). * * Note: The returned string needs to be deallocated by the caller. * * \param length The length of the seed string to generate * * \returns The generated seed string */ char * SDLTest_GenerateRunSeed(const int length) { char *seed = NULL; SDLTest_RandomContext randomContext; int counter; /* Sanity check input */ if (length <= 0) { SDLTest_LogError("The length of the harness seed must be >0."); return NULL; } /* Allocate output buffer */ seed = (char *)SDL_malloc((length + 1) * sizeof(char)); if (seed == NULL) { SDLTest_LogError("SDL_malloc for run seed output buffer failed."); SDL_Error(SDL_ENOMEM); return NULL; } /* Generate a random string of alphanumeric characters */ SDLTest_RandomInitTime(&randomContext); for (counter = 0; counter < length; counter++) { unsigned int number = SDLTest_Random(&randomContext); char ch = (char) (number % (91 - 48)) + 48; if (ch >= 58 && ch <= 64) { ch = 65; } seed[counter] = ch; } seed[length] = '\0'; return seed; } /** * Generates an execution key for the fuzzer. * * \param runSeed The run seed to use * \param suiteName The name of the test suite * \param testName The name of the test * \param iteration The iteration count * * \returns The generated execution key to initialize the fuzzer with. * */ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, char *suiteName, char *testName, int iteration) { SDLTest_Md5Context md5Context; Uint64 *keys; char iterationString[16]; size_t runSeedLength; size_t suiteNameLength; size_t testNameLength; size_t iterationStringLength; size_t entireStringLength; char *buffer; if (runSeed == NULL || runSeed[0] == '\0') { SDLTest_LogError("Invalid runSeed string."); return -1; } if (suiteName == NULL || suiteName[0] == '\0') { SDLTest_LogError("Invalid suiteName string."); return -1; } if (testName == NULL || testName[0] == '\0') { SDLTest_LogError("Invalid testName string."); return -1; } if (iteration <= 0) { SDLTest_LogError("Invalid iteration count."); return -1; } /* Convert iteration number into a string */ SDL_memset(iterationString, 0, sizeof(iterationString)); SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration); /* Combine the parameters into single string */ runSeedLength = SDL_strlen(runSeed); suiteNameLength = SDL_strlen(suiteName); testNameLength = SDL_strlen(testName); iterationStringLength = SDL_strlen(iterationString); entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1; buffer = (char *)SDL_malloc(entireStringLength); if (buffer == NULL) { SDLTest_LogError("Failed to allocate buffer for execKey generation."); SDL_Error(SDL_ENOMEM); return 0; } SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration); /* Hash string and use half of the digest as 64bit exec key */ SDLTest_Md5Init(&md5Context); SDLTest_Md5Update(&md5Context, (unsigned char *)buffer, (unsigned int) entireStringLength); SDLTest_Md5Final(&md5Context); SDL_free(buffer); keys = (Uint64 *)md5Context.digest; return keys[0]; } /** * \brief Set timeout handler for test. * * Note: SDL_Init(SDL_INIT_TIMER) will be called if it wasn't done so before. * * \param timeout Timeout interval in seconds. * \param callback Function that will be called after timeout has elapsed. * * \return Timer id or -1 on failure. */ static SDL_TimerID SDLTest_SetTestTimeout(int timeout, void (*callback)(void)) { Uint32 timeoutInMilliseconds; SDL_TimerID timerID; if (callback == NULL) { SDLTest_LogError("Timeout callback can't be NULL"); return -1; } if (timeout < 0) { SDLTest_LogError("Timeout value must be bigger than zero."); return -1; } /* Init SDL timer if not initialized before */ if (SDL_WasInit(SDL_INIT_TIMER) == 0) { if (SDL_InitSubSystem(SDL_INIT_TIMER)) { SDLTest_LogError("Failed to init timer subsystem: %s", SDL_GetError()); return -1; } } /* Set timer */ timeoutInMilliseconds = timeout * 1000; timerID = SDL_AddTimer(timeoutInMilliseconds, (SDL_TimerCallback)callback, 0x0); if (timerID == 0) { SDLTest_LogError("Creation of SDL timer failed: %s", SDL_GetError()); return -1; } return timerID; } /** * \brief Timeout handler. Aborts test run and exits harness process. */ #if defined(__WATCOMC__) #pragma aux SDLTest_BailOut aborts; #endif static SDL_NORETURN void SDLTest_BailOut(void) { SDLTest_LogError("TestCaseTimeout timer expired. Aborting test run."); exit(TEST_ABORTED); /* bail out from the test */ } /** * \brief Execute a test using the given execution key. * * \param testSuite Suite containing the test case. * \param testCase Case to execute. * \param execKey Execution key for the fuzzer. * \param forceTestRun Force test to run even if test was disabled in suite. * * \returns Test case result. */ static int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseReference *testCase, Uint64 execKey, SDL_bool forceTestRun) { SDL_TimerID timer = 0; int testCaseResult = 0; int testResult = 0; int fuzzerCount; if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL) { SDLTest_LogError("Setup failure: testSuite or testCase references NULL"); return TEST_RESULT_SETUP_FAILURE; } if (!testCase->enabled && forceTestRun == SDL_FALSE) { SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Skipped (Disabled)"); return TEST_RESULT_SKIPPED; } /* Initialize fuzzer */ SDLTest_FuzzerInit(execKey); /* Reset assert tracker */ SDLTest_ResetAssertSummary(); /* Set timeout timer */ timer = SDLTest_SetTestTimeout(SDLTest_TestCaseTimeout, SDLTest_BailOut); /* Maybe run suite initalizer function */ if (testSuite->testSetUp) { testSuite->testSetUp(0x0); if (SDLTest_AssertSummaryToTestResult() == TEST_RESULT_FAILED) { SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite Setup", testSuite->name, "Failed"); return TEST_RESULT_SETUP_FAILURE; } } /* Run test case function */ testCaseResult = testCase->testCase(0x0); /* Convert test execution result into harness result */ if (testCaseResult == TEST_SKIPPED) { /* Test was programatically skipped */ testResult = TEST_RESULT_SKIPPED; } else if (testCaseResult == TEST_STARTED) { /* Test did not return a TEST_COMPLETED value; assume it failed */ testResult = TEST_RESULT_FAILED; } else if (testCaseResult == TEST_ABORTED) { /* Test was aborted early; assume it failed */ testResult = TEST_RESULT_FAILED; } else { /* Perform failure analysis based on asserts */ testResult = SDLTest_AssertSummaryToTestResult(); } /* Maybe run suite cleanup function (ignore failed asserts) */ if (testSuite->testTearDown) { testSuite->testTearDown(0x0); } /* Cancel timeout timer */ if (timer) { SDL_RemoveTimer(timer); } /* Report on asserts and fuzzer usage */ fuzzerCount = SDLTest_GetFuzzerInvocationCount(); if (fuzzerCount > 0) { SDLTest_Log("Fuzzer invocations: %d", fuzzerCount); } /* Final log based on test execution result */ if (testCaseResult == TEST_SKIPPED) { /* Test was programatically skipped */ SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Skipped (Programmatically)"); } else if (testCaseResult == TEST_STARTED) { /* Test did not return a TEST_COMPLETED value; assume it failed */ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Failed (test started, but did not return TEST_COMPLETED)"); } else if (testCaseResult == TEST_ABORTED) { /* Test was aborted early; assume it failed */ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Failed (Aborted)"); } else { SDLTest_LogAssertSummary(); } return testResult; } /* Prints summary of all suites/tests contained in the given reference */ #if 0 static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites) { int suiteCounter; int testCounter; SDLTest_TestSuiteReference *testSuite; SDLTest_TestCaseReference *testCase; /* Loop over all suites */ suiteCounter = 0; while(&testSuites[suiteCounter]) { testSuite=&testSuites[suiteCounter]; suiteCounter++; SDLTest_Log("Test Suite %i - %s\n", suiteCounter, (testSuite->name) ? testSuite->name : SDLTEST_INVALID_NAME_FORMAT); /* Loop over all test cases */ testCounter = 0; while(testSuite->testCases[testCounter]) { testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter]; testCounter++; SDLTest_Log(" Test Case %i - %s: %s", testCounter, (testCase->name) ? testCase->name : SDLTEST_INVALID_NAME_FORMAT, (testCase->description) ? testCase->description : SDLTEST_INVALID_NAME_FORMAT); } } } #endif /* Gets a timer value in seconds */ static float GetClock() { float currentClock = clock() / (float) CLOCKS_PER_SEC; return currentClock; } /** * \brief Execute a test suite using the given run seed and execution key. * * The filter string is matched to the suite name (full comparison) to select a single suite, * or if no suite matches, it is matched to the test names (full comparison) to select a single test. * * \param testSuites Suites containing the test case. * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one. * \param userExecKey Custom execution key provided by user, or 0 to autogenerate one. * \param filter Filter specification. NULL disables. Case sensitive. * \param testIterations Number of iterations to run each test case. * * \returns Test run result; 0 when all tests passed, 1 if any tests failed. */ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations) { int totalNumberOfTests = 0; int failedNumberOfTests = 0; int suiteCounter; int testCounter; int iterationCounter; SDLTest_TestSuiteReference *testSuite; const SDLTest_TestCaseReference *testCase; const char *runSeed = NULL; char *currentSuiteName; char *currentTestName; Uint64 execKey; float runStartSeconds; float suiteStartSeconds; float testStartSeconds; float runEndSeconds; float suiteEndSeconds; float testEndSeconds; float runtime; int suiteFilter = 0; char *suiteFilterName = NULL; int testFilter = 0; char *testFilterName = NULL; SDL_bool forceTestRun = SDL_FALSE; int testResult = 0; int runResult = 0; int totalTestFailedCount = 0; int totalTestPassedCount = 0; int totalTestSkippedCount = 0; int testFailedCount = 0; int testPassedCount = 0; int testSkippedCount = 0; int countSum = 0; const SDLTest_TestCaseReference **failedTests; /* Sanitize test iterations */ if (testIterations < 1) { testIterations = 1; } /* Generate run see if we don't have one already */ if (userRunSeed == NULL || userRunSeed[0] == '\0') { runSeed = SDLTest_GenerateRunSeed(16); if (runSeed == NULL) { SDLTest_LogError("Generating a random seed failed"); return 2; } } else { runSeed = userRunSeed; } /* Reset per-run counters */ totalTestFailedCount = 0; totalTestPassedCount = 0; totalTestSkippedCount = 0; /* Take time - run start */ runStartSeconds = GetClock(); /* Log run with fuzzer parameters */ SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed); /* Count the total number of tests */ suiteCounter = 0; while (testSuites[suiteCounter]) { testSuite = testSuites[suiteCounter]; suiteCounter++; testCounter = 0; while (testSuite->testCases[testCounter]) { testCounter++; totalNumberOfTests++; } } /* Pre-allocate an array for tracking failed tests (potentially all test cases) */ failedTests = (const SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *)); if (failedTests == NULL) { SDLTest_LogError("Unable to allocate cache for failed tests"); SDL_Error(SDL_ENOMEM); return -1; } /* Initialize filtering */ if (filter != NULL && filter[0] != '\0') { /* Loop over all suites to check if we have a filter match */ suiteCounter = 0; while (testSuites[suiteCounter] && suiteFilter == 0) { testSuite = testSuites[suiteCounter]; suiteCounter++; if (testSuite->name != NULL && SDL_strcmp(filter, testSuite->name) == 0) { /* Matched a suite name */ suiteFilter = 1; suiteFilterName = testSuite->name; SDLTest_Log("Filtering: running only suite '%s'", suiteFilterName); break; } /* Within each suite, loop over all test cases to check if we have a filter match */ testCounter = 0; while (testSuite->testCases[testCounter] && testFilter == 0) { testCase = testSuite->testCases[testCounter]; testCounter++; if (testCase->name != NULL && SDL_strcmp(filter, testCase->name) == 0) { /* Matched a test name */ suiteFilter = 1; suiteFilterName = testSuite->name; testFilter = 1; testFilterName = testCase->name; SDLTest_Log("Filtering: running only test '%s' in suite '%s'", testFilterName, suiteFilterName); break; } } } if (suiteFilter == 0 && testFilter == 0) { SDLTest_LogError("Filter '%s' did not match any test suite/case.", filter); SDLTest_Log("Exit code: 2"); SDL_free((void *) failedTests); return 2; } } /* Loop over all suites */ suiteCounter = 0; while(testSuites[suiteCounter]) { testSuite = testSuites[suiteCounter]; currentSuiteName = (testSuite->name ? testSuite->name : SDLTEST_INVALID_NAME_FORMAT); suiteCounter++; /* Filter suite if flag set and we have a name */ if (suiteFilter == 1 && suiteFilterName != NULL && testSuite->name != NULL && SDL_strcmp(suiteFilterName, testSuite->name) != 0) { /* Skip suite */ SDLTest_Log("===== Test Suite %i: '%s' skipped\n", suiteCounter, currentSuiteName); } else { /* Reset per-suite counters */ testFailedCount = 0; testPassedCount = 0; testSkippedCount = 0; /* Take time - suite start */ suiteStartSeconds = GetClock(); /* Log suite started */ SDLTest_Log("===== Test Suite %i: '%s' started\n", suiteCounter, currentSuiteName); /* Loop over all test cases */ testCounter = 0; while(testSuite->testCases[testCounter]) { testCase = testSuite->testCases[testCounter]; currentTestName = (testCase->name ? testCase->name : SDLTEST_INVALID_NAME_FORMAT); testCounter++; /* Filter tests if flag set and we have a name */ if (testFilter == 1 && testFilterName != NULL && testCase->name != NULL && SDL_strcmp(testFilterName, testCase->name) != 0) { /* Skip test */ SDLTest_Log("===== Test Case %i.%i: '%s' skipped\n", suiteCounter, testCounter, currentTestName); } else { /* Override 'disabled' flag if we specified a test filter (i.e. force run for debugging) */ if (testFilter == 1 && !testCase->enabled) { SDLTest_Log("Force run of disabled test since test filter was set"); forceTestRun = SDL_TRUE; } /* Take time - test start */ testStartSeconds = GetClock(); /* Log test started */ SDLTest_Log("----- Test Case %i.%i: '%s' started", suiteCounter, testCounter, currentTestName); if (testCase->description != NULL && testCase->description[0] != '\0') { SDLTest_Log("Test Description: '%s'", (testCase->description) ? testCase->description : SDLTEST_INVALID_NAME_FORMAT); } /* Loop over all iterations */ iterationCounter = 0; while(iterationCounter < testIterations) { iterationCounter++; if (userExecKey != 0) { execKey = userExecKey; } else { execKey = SDLTest_GenerateExecKey(runSeed, testSuite->name, testCase->name, iterationCounter); } SDLTest_Log("Test Iteration %i: execKey %" SDL_PRIu64, iterationCounter, execKey); testResult = SDLTest_RunTest(testSuite, testCase, execKey, forceTestRun); if (testResult == TEST_RESULT_PASSED) { testPassedCount++; totalTestPassedCount++; } else if (testResult == TEST_RESULT_SKIPPED) { testSkippedCount++; totalTestSkippedCount++; } else { testFailedCount++; totalTestFailedCount++; } } /* Take time - test end */ testEndSeconds = GetClock(); runtime = testEndSeconds - testStartSeconds; if (runtime < 0.0f) runtime = 0.0f; if (testIterations > 1) { /* Log test runtime */ SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, runtime); SDLTest_Log("Average Test runtime: %.5f sec", runtime / (float)testIterations); } else { /* Log test runtime */ SDLTest_Log("Total Test runtime: %.1f sec", runtime); } /* Log final test result */ switch (testResult) { case TEST_RESULT_PASSED: SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Passed"); break; case TEST_RESULT_FAILED: SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Failed"); break; case TEST_RESULT_NO_ASSERT: SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT,"Test", currentTestName, "No Asserts"); break; } /* Collect failed test case references for repro-step display */ if (testResult == TEST_RESULT_FAILED) { failedTests[failedNumberOfTests] = testCase; failedNumberOfTests++; } } } /* Take time - suite end */ suiteEndSeconds = GetClock(); runtime = suiteEndSeconds - suiteStartSeconds; if (runtime < 0.0f) runtime = 0.0f; /* Log suite runtime */ SDLTest_Log("Total Suite runtime: %.1f sec", runtime); /* Log summary and final Suite result */ countSum = testPassedCount + testFailedCount + testSkippedCount; if (testFailedCount == 0) { SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Passed"); } else { SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Failed"); } } } /* Take time - run end */ runEndSeconds = GetClock(); runtime = runEndSeconds - runStartSeconds; if (runtime < 0.0f) runtime = 0.0f; /* Log total runtime */ SDLTest_Log("Total Run runtime: %.1f sec", runtime); /* Log summary and final run result */ countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount; if (totalTestFailedCount == 0) { runResult = 0; SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount); SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Passed"); } else { runResult = 1; SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount); SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Failed"); } /* Print repro steps for failed tests */ if (failedNumberOfTests > 0) { SDLTest_Log("Harness input to repro failures:"); for (testCounter = 0; testCounter < failedNumberOfTests; testCounter++) { SDLTest_Log(" --seed %s --filter %s", runSeed, failedTests[testCounter]->name); } } SDL_free((void *) failedTests); SDLTest_Log("Exit code: %d", runResult); return runResult; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_harness.c
C
apache-2.0
24,449
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include "SDL_test.h" /* GIMP RGB C-Source image dump (blit.c) */ static const SDLTest_SurfaceImage_t SDLTest_imageBlit = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377" "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0" "\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0" "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0" "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0" "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0" "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0" "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0" "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0" "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0" "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377" "\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377" "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377" "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377" "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377" "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377" "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377" "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0" "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0" "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0" "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0" "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0" "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0" "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377" "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0" "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377" "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377" "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0" "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0" "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0", }; /** * \brief Returns the Blit test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlit() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlit.pixel_data, SDLTest_imageBlit.width, SDLTest_imageBlit.height, SDLTest_imageBlit.bytes_per_pixel * 8, SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } static const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\0\0\24\0\0\0\0\0\0" "\0\0(\0\0(\0\0\0\0\0\0\0\0<\0\0<\0\0\0\0\0\0\0\0P\0\0P\0\0\0\0\0\0\0\0d\0" "\0d\0\0\0\0\0\0\0\0x\0\0x\0\0\0\0\0\0\0\0\214\0\0\214\0\0\0\0\0\0\0\0\240" "\0\0\240\0\0\0\0\0\0\0\0\264\0\0\264\0\0\0\0\0\0\0\0\310\0\0\310\0\0\0\0" "\0\0\0\0\334\0\0\334\0\0\0\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360" "\0\0\360\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\0\0\24\0\0\24\0\0\0\0\0(\0\0" "(\0\0(\0\0\0\0\0<\0\0<\0\0<\0\0\0\0\0P\0\0P\0\0P\0\0\0\0\0d\0\0d\0\0d\0\0" "\0\0\0x\0\0x\0\0x\0\0\0\0\0\214\0\0\214\0\0\214\0\0\0\0\0\240\0\0\240\0\0" "\240\0\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\310\0\0\310\0\0\310\0\0\0\0" "\0\334\0\0\334\0\0\334\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0" "\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\0\0\24\0\0\24\0\0\0" "\0\0(\0\0(\0\0(\0\0\0\0\0<\0\0<\0\0<\0\0\0\0\0P\0\0P\0\0P\0\0\0\0\0d\0\0" "d\0\0d\0\0\0\0\0x\0\0x\0\0x\0\0\0\0\0\214\0\0\214\0\0\214\0\0\0\0\0\240\0" "\0\240\0\0\240\0\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\310\0\0\310\0\0\310" "\0\0\0\0\0\334\0\0\334\0\0\334\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0" "\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0" "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0\0\0\0\0\0\0$\24\0" "$\24\0\0\0\0\0\0\0$(\0$(\0\0\0\0\0\0\0$<\0$<\0\0\0\0\0\0\0$P\0$P\0\0\0\0" "\0\0\0$d\0$d\0\0\0\0\0\0\0$x\0$x\0\0\0\0\0\0\0$\214\0$\214\0\0\0\0\0\0\0" "$\240\0$\240\0\0\0\0\0\0\0$\264\0$\264\0\0\0\0\0\0\0$\310\0$\310\0\0\0\0" "\0\0\0$\334\0$\334\0\0\0\0\0\0\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360" "\0$\360\0$\360\0\0\0\0\0\0\0\0\360\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0$\0\0$\0\0$\0\0\0\0\0$\24\0$\24\0$\24\0\0\0\0$(\0$(\0$(\0\0\0\0" "$<\0$<\0$<\0\0\0\0$P\0$P\0$P\0\0\0\0$d\0$d\0$d\0\0\0\0$x\0$x\0$x\0\0\0\0" "$\214\0$\214\0$\214\0\0\0\0$\240\0$\240\0$\240\0\0\0\0$\264\0$\264\0$\264" "\0\0\0\0$\310\0$\310\0$\310\0\0\0\0$\334\0$\334\0$\334\0\0\0\0$\360\0$\360" "\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0" "\0\0\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0$\0\0\0\0\0$\24\0" "$\24\0$\24\0\0\0\0$(\0$(\0$(\0\0\0\0$<\0$<\0$<\0\0\0\0$P\0$P\0$P\0\0\0\0" "$d\0$d\0$d\0\0\0\0$x\0$x\0$x\0\0\0\0$\214\0$\214\0$\214\0\0\0\0$\240\0$\240" "\0$\240\0\0\0\0$\264\0$\264\0$\264\0\0\0\0$\310\0$\310\0$\310\0\0\0\0$\334" "\0$\334\0$\334\0\0\0\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$" "\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0\0\0\0\0\360\0\0\360\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0$\0\0$\0\0$\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0$\360\0$\360\0$\360\0$\360\0\0\0\0\0\360\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0$\0\0\0\0" "\0\0\0\0H\0\0H\0\0\0\0\0\0\0\0H\24\0H\24\0\0\0\0\0\0\0H(\0H(\0\0\0\0\0\0" "\0H<\0H<\0\0\0\0\0\0\0HP\0HP\0\0\0\0\0\0\0Hd\0Hd\0\0\0\0\0\0\0Hx\0Hx\0\0" "\0\0\0\0\0H\214\0H\214\0\0\0\0\0\0\0H\240\0H\240\0\0\0\0\0\0\0H\264\0H\264" "\0\0\0\0\0\0\0H\310\0H\310\0\0\0\0\0\0\0H\334\0H\334\0\0\0\0\0\0\0H\360\0" "H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0\0\0\0\0\0\0$\360\0$\360" "\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0\0\0\0H\0\0H\0\0H\0\0\0\0\0H\24\0H\24\0H\24" "\0\0\0\0H(\0H(\0H(\0\0\0\0H<\0H<\0H<\0\0\0\0HP\0HP\0HP\0\0\0\0Hd\0Hd\0Hd" "\0\0\0\0Hx\0Hx\0Hx\0\0\0\0H\214\0H\214\0H\214\0\0\0\0H\240\0H\240\0H\240" "\0\0\0\0H\264\0H\264\0H\264\0\0\0\0H\310\0H\310\0H\310\0\0\0\0H\334\0H\334" "\0H\334\0\0\0\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H" "\360\0H\360\0H\360\0H\360\0\0\0\0$\360\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0\0\0\0H\0\0" "H\0\0H\0\0\0\0\0H\24\0H\24\0H\24\0\0\0\0H(\0H(\0H(\0\0\0\0H<\0H<\0H<\0\0" "\0\0HP\0HP\0HP\0\0\0\0Hd\0Hd\0Hd\0\0\0\0Hx\0Hx\0Hx\0\0\0\0H\214\0H\214\0" "H\214\0\0\0\0H\240\0H\240\0H\240\0\0\0\0H\264\0H\264\0H\264\0\0\0\0H\310" "\0H\310\0H\310\0\0\0\0H\334\0H\334\0H\334\0\0\0\0H\360\0H\360\0H\360\0H\360" "\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0" "\0\0\0$\360\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0$\0\0\0\0\0H\0\0H\0\0H\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\360\0H\360\0H\360\0H\360\0\0\0\0$\360\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0H\0\0H\0\0H\0\0\0\0\0\0\0\0l\0\0l\0\0\0\0\0\0\0\0l\24\0l\24\0\0\0\0\0\0" "\0l(\0l(\0\0\0\0\0\0\0l<\0l<\0\0\0\0\0\0\0lP\0lP\0\0\0\0\0\0\0ld\0ld\0\0" "\0\0\0\0\0lx\0lx\0\0\0\0\0\0\0l\214\0l\214\0\0\0\0\0\0\0l\240\0l\240\0\0" "\0\0\0\0\0l\264\0l\264\0\0\0\0\0\0\0l\310\0l\310\0\0\0\0\0\0\0l\334\0l\334" "\0\0\0\0\0\0\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0\0" "\0\0\0\0\0H\360\0H\360\0H\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\0\0H\0\0\0\0\0l\0\0l\0\0l\0\0" "\0\0\0l\24\0l\24\0l\24\0\0\0\0l(\0l(\0l(\0\0\0\0l<\0l<\0l<\0\0\0\0lP\0lP" "\0lP\0\0\0\0ld\0ld\0ld\0\0\0\0lx\0lx\0lx\0\0\0\0l\214\0l\214\0l\214\0\0\0" "\0l\240\0l\240\0l\240\0\0\0\0l\264\0l\264\0l\264\0\0\0\0l\310\0l\310\0l\310" "\0\0\0\0l\334\0l\334\0l\334\0\0\0\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360" "\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0\0\0\0H\360\0H\360\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\0" "\0H\0\0\0\0\0l\0\0l\0\0l\0\0\0\0\0l\24\0l\24\0l\24\0\0\0\0l(\0l(\0l(\0\0" "\0\0l<\0l<\0l<\0\0\0\0lP\0lP\0lP\0\0\0\0ld\0ld\0ld\0\0\0\0lx\0lx\0lx\0\0" "\0\0l\214\0l\214\0l\214\0\0\0\0l\240\0l\240\0l\240\0\0\0\0l\264\0l\264\0" "l\264\0\0\0\0l\310\0l\310\0l\310\0\0\0\0l\334\0l\334\0l\334\0\0\0\0l\360" "\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0" "l\360\0l\360\0l\360\0\0\0\0H\360\0H\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\0\0\0\0\0l\0\0l\0\0l\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0l\360\0l\360\0l\360\0l\360" "\0\0\0\0H\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0l\0\0l\0\0l\0\0\0\0\0\0\0\0\220\0\0\220\0\0\0\0\0\0\0" "\0\220\24\0\220\24\0\0\0\0\0\0\0\220(\0\220(\0\0\0\0\0\0\0\220<\0\220<\0" "\0\0\0\0\0\0\220P\0\220P\0\0\0\0\0\0\0\220d\0\220d\0\0\0\0\0\0\0\220x\0\220" "x\0\0\0\0\0\0\0\220\214\0\220\214\0\0\0\0\0\0\0\220\240\0\220\240\0\0\0\0" "\0\0\0\220\264\0\220\264\0\0\0\0\0\0\0\220\310\0\220\310\0\0\0\0\0\0\0\220" "\334\0\220\334\0\0\0\0\0\0\0\220\360\0\220\360\0\220\360\0\220\360\0\220" "\360\0\220\360\0\220\360\0\220\360\0\0\0\0\0\0\0l\360\0l\360\0l\360\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0l\0\0l\0\0\0\0\0\220\0\0\220\0\0\220\0\0\0\0\0\220\24\0\220\24\0" "\220\24\0\0\0\0\220(\0\220(\0\220(\0\0\0\0\220<\0\220<\0\220<\0\0\0\0\220" "P\0\220P\0\220P\0\0\0\0\220d\0\220d\0\220d\0\0\0\0\220x\0\220x\0\220x\0\0" "\0\0\220\214\0\220\214\0\220\214\0\0\0\0\220\240\0\220\240\0\220\240\0\0" "\0\0\220\264\0\220\264\0\220\264\0\0\0\0\220\310\0\220\310\0\220\310\0\0" "\0\0\220\334\0\220\334\0\220\334\0\0\0\0\220\360\0\220\360\0\220\360\0\220" "\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360" "\0\220\360\0\0\0\0l\360\0l\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0l\0\0l\0\0\0\0\0\220\0\0\220\0\0\220" "\0\0\0\0\0\220\24\0\220\24\0\220\24\0\0\0\0\220(\0\220(\0\220(\0\0\0\0\220" "<\0\220<\0\220<\0\0\0\0\220P\0\220P\0\220P\0\0\0\0\220d\0\220d\0\220d\0\0" "\0\0\220x\0\220x\0\220x\0\0\0\0\220\214\0\220\214\0\220\214\0\0\0\0\220\240" "\0\220\240\0\220\240\0\0\0\0\220\264\0\220\264\0\220\264\0\0\0\0\220\310" "\0\220\310\0\220\310\0\0\0\0\220\334\0\220\334\0\220\334\0\0\0\0\220\360" "\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0" "\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\0\0\0l\360\0" "l\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0l\0\0\0\0\0\220\0\0\220\0\0\220\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\220\360\0\220\360\0\220\360\0\220\360\0\0\0\0l\360" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\220\0\0\220\0\0\220\0\0\0\0\0\0\0\0\264\0\0\264\0\0\0\0\0\0\0\0" "\264\24\0\264\24\0\0\0\0\0\0\0\264(\0\264(\0\0\0\0\0\0\0\264<\0\264<\0\0" "\0\0\0\0\0\264P\0\264P\0\0\0\0\0\0\0\264d\0\264d\0\0\0\0\0\0\0\264x\0\264" "x\0\0\0\0\0\0\0\264\214\0\264\214\0\0\0\0\0\0\0\264\240\0\264\240\0\0\0\0" "\0\0\0\264\264\0\264\264\0\0\0\0\0\0\0\264\310\0\264\310\0\0\0\0\0\0\0\264" "\334\0\264\334\0\0\0\0\0\0\0\264\360\0\264\360\0\264\360\0\264\360\0\264" "\360\0\264\360\0\264\360\0\264\360\0\0\0\0\0\0\0\220\360\0\220\360\0\220" "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\220\0\0\220\0\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\264" "\24\0\264\24\0\264\24\0\0\0\0\264(\0\264(\0\264(\0\0\0\0\264<\0\264<\0\264" "<\0\0\0\0\264P\0\264P\0\264P\0\0\0\0\264d\0\264d\0\264d\0\0\0\0\264x\0\264" "x\0\264x\0\0\0\0\264\214\0\264\214\0\264\214\0\0\0\0\264\240\0\264\240\0" "\264\240\0\0\0\0\264\264\0\264\264\0\264\264\0\0\0\0\264\310\0\264\310\0" "\264\310\0\0\0\0\264\334\0\264\334\0\264\334\0\0\0\0\264\360\0\264\360\0" "\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264" "\360\0\264\360\0\264\360\0\0\0\0\220\360\0\220\360\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\220\0\0\220\0" "\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\264\24\0\264\24\0\264\24\0\0\0\0\264" "(\0\264(\0\264(\0\0\0\0\264<\0\264<\0\264<\0\0\0\0\264P\0\264P\0\264P\0\0" "\0\0\264d\0\264d\0\264d\0\0\0\0\264x\0\264x\0\264x\0\0\0\0\264\214\0\264" "\214\0\264\214\0\0\0\0\264\240\0\264\240\0\264\240\0\0\0\0\264\264\0\264" "\264\0\264\264\0\0\0\0\264\310\0\264\310\0\264\310\0\0\0\0\264\334\0\264" "\334\0\264\334\0\0\0\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0" "\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264" "\360\0\264\360\0\0\0\0\220\360\0\220\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\220\0\0\0\0\0\264\0\0\264\0\0" "\264\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\360\0" "\264\360\0\264\360\0\264\360\0\0\0\0\220\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\0\0\264\0\0\264" "\0\0\0\0\0\0\0\0\330\0\0\330\0\0\0\0\0\0\0\0\330\24\0\330\24\0\0\0\0\0\0" "\0\330(\0\330(\0\0\0\0\0\0\0\330<\0\330<\0\0\0\0\0\0\0\330P\0\330P\0\0\0" "\0\0\0\0\330d\0\330d\0\0\0\0\0\0\0\330x\0\330x\0\0\0\0\0\0\0\330\214\0\330" "\214\0\0\0\0\0\0\0\330\240\0\330\240\0\0\0\0\0\0\0\330\264\0\330\264\0\0" "\0\0\0\0\0\330\310\0\330\310\0\0\0\0\0\0\0\330\334\0\330\334\0\0\0\0\0\0" "\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0" "\330\360\0\0\0\0\0\0\0\264\360\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\0\0" "\264\0\0\0\0\0\330\0\0\330\0\0\330\0\0\0\0\0\330\24\0\330\24\0\330\24\0\0" "\0\0\330(\0\330(\0\330(\0\0\0\0\330<\0\330<\0\330<\0\0\0\0\330P\0\330P\0" "\330P\0\0\0\0\330d\0\330d\0\330d\0\0\0\0\330x\0\330x\0\330x\0\0\0\0\330\214" "\0\330\214\0\330\214\0\0\0\0\330\240\0\330\240\0\330\240\0\0\0\0\330\264" "\0\330\264\0\330\264\0\0\0\0\330\310\0\330\310\0\330\310\0\0\0\0\330\334" "\0\330\334\0\330\334\0\0\0\0\330\360\0\330\360\0\330\360\0\330\360\0\330" "\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360" "\0\0\0\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\0\0\264\0\0\0\0\0\330\0\0\330\0\0" "\330\0\0\0\0\0\330\24\0\330\24\0\330\24\0\0\0\0\330(\0\330(\0\330(\0\0\0" "\0\330<\0\330<\0\330<\0\0\0\0\330P\0\330P\0\330P\0\0\0\0\330d\0\330d\0\330" "d\0\0\0\0\330x\0\330x\0\330x\0\0\0\0\330\214\0\330\214\0\330\214\0\0\0\0" "\330\240\0\330\240\0\330\240\0\0\0\0\330\264\0\330\264\0\330\264\0\0\0\0" "\330\310\0\330\310\0\330\310\0\0\0\0\330\334\0\330\334\0\330\334\0\0\0\0" "\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330" "\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\0\0\0" "\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\264\0\0\0\0\0\330\0\0\330\0\0\330\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\360\0\330\360\0\330\360\0\330" "\360\0\0\0\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\0\0\330\0\0\330\0\0\0\0\0\0\0\0\374\0\0" "\374\0\0\0\0\0\0\0\0\374\24\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0" "\0\0\374<\0\374<\0\0\0\0\0\0\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0" "\0\0\0\0\0\374x\0\374x\0\0\0\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374" "\240\0\374\240\0\0\0\0\0\0\0\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374" "\310\0\0\0\0\0\0\0\374\334\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\330" "\360\0\330\360\0\330\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\0\0\330\0\0\0\0\0\374\0\0\374" "\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0" "\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d" "\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0" "\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0" "\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0" "\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\330" "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\330\0\0\330\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0" "\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0" "\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x" "\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374" "\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374" "\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\330\360\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330" "\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0" "\374(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374" "P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0" "\374\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0" "\374\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0" "\374\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374" "\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0" "\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d" "\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0" "\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0" "\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0" "\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374" "\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374" "<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0" "\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240" "\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310" "\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360" "\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360" "\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374" "(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374" "d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374" "\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374" "\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374" "\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\374\334" "\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\374\334\0\0" "\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0" "\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374<\0\374" "<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374" "x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240\0\374" "\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310\0\374" "\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360\0\374" "\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374" "\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374" "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374" "(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0" "\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374" "\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374" "\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374" "\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0" "\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0" "\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214" "\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264" "\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334" "\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374" "(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374" "d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374" "\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374" "\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374" "\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374" "\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0" "\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d" "\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0" "\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0" "\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0" "\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374" "\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374" "<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0" "\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240" "\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310" "\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374" "\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374" "<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0" "\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240" "\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310" "\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0\0\0\0\0\0\374\24" "\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0\374<\0\0\0\0\0\0" "\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374x\0\374x\0\0\0" "\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240\0\0\0\0\0\0\0" "\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0\0\0\0\374\334" "\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0" "\0\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0" "\0\0\0\0\0\374\24\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0" "\374<\0\0\0\0\0\0\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374" "x\0\374x\0\0\0\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240" "\0\0\0\0\0\0\0\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0" "\0\0\0\374\334\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374" "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0\0\0\0\0\0\374\24\0" "\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0\374<\0\0\0\0\0\0\0" "\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374x\0\374x\0\0\0\0" "\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240\0\0\0\0\0\0\0\374" "\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0\0\0\0\374\334\0\374" "\334\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0" "\0\0\0\374(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P" "\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374" "\214\0\374\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374" "\264\0\374\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374" "\334\0\374\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0\0\0\0\0\0" "\374\24\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0\374<\0\0" "\0\0\0\0\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374x\0\374" "x\0\0\0\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240\0\0\0\0" "\0\0\0\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0\0\0\0\374" "\334\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; /** * \brief Returns the BlitColor test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlitColor() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlitColor.pixel_data, SDLTest_imageBlitColor.width, SDLTest_imageBlitColor.height, SDLTest_imageBlitColor.bytes_per_pixel * 8, SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } static const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\20\20\0" "\20\20\0""88\0""88\0**\0**\0ZZ\0ZZ\0==\0==\0yy\0yy\0II\0II\0\224\224\0\224" "\224\0NN\0NN\0\254\254\0\254\254\0MM\0MM\0\302\302\0\302\302\0HH\0HH\0\324" "\324\0\324\324\0>>\0>>\0\343\343\0\343\343\0""00\0""00\0\356\356\0\356\356" "\0\40\40\0\40\40\0\367\367\0\367\367\0\16\16\0\16\16\0\374\374\0\374\374" "\0\374\374\0\374\374\0\360\360\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\24\24\0\24\24\0\24\24\0\20\20\0""88\0""88\0""88\0**\0ff\0ff\0ff\0FF\0" "\215\215\0\215\215\0\215\215\0UU\0\255\255\0\255\255\0\255\255\0[[\0\306" "\306\0\306\306\0\306\306\0YY\0\331\331\0\331\331\0\331\331\0PP\0\350\350" "\0\350\350\0\350\350\0DD\0\362\362\0\362\362\0\362\362\0""44\0\370\370\0" "\370\370\0\370\370\0\"\"\0\374\374\0\374\374\0\374\374\0\16\16\0\376\376" "\0\376\376\0\376\376\0\376\376\0\374\374\0\374\374\0\374\374\0\374\374\0" "\360\360\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\24\24\0\20\20\0""88\0" """88\0""88\0**\0ff\0ff\0ff\0FF\0\226\226\0\226\226\0\215\215\0UU\0\271\271" "\0\271\271\0\255\255\0[[\0\323\323\0\323\323\0\306\306\0YY\0\345\345\0\345" "\345\0\331\331\0PP\0\360\360\0\360\360\0\350\350\0DD\0\370\370\0\370\370" "\0\362\362\0""44\0\374\374\0\374\374\0\370\370\0\"\"\0\376\376\0\376\376" "\0\374\374\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376" "\376\0\374\374\0\374\374\0\374\374\0\374\374\0\360\360\0\360\360\0\360\360" "\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24" "\0\24\24\0\24\24\0\20\20\0""33\0""33\0""33\0&&\0OO\0OO\0OO\0""55\0``\0``" "\0``\0::\0``\0``\0``\0""22\0WW\0WW\0WW\0''\0II\0II\0II\0\33\33\0""99\0""9" "9\0""99\0\20\20\0))\0))\0))\0\10\10\0\33\33\0\33\33\0\33\33\0\3\3\0\17\17" "\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0" "\16\16\0\16\16\0\16\16\0\16\16\0\360\360\0\360\360\0\360\360\0\360\360\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\24\24\0\16\16" "\0""33\0GG\0GG\0""00\0``\0\210\210\0\210\210\0TT\0\204\204\0\263\263\0\263" "\263\0ee\0\222\222\0\315\315\0\312\312\0gg\0\216\216\0\331\331\0\327\327" "\0cc\0\202\202\0\340\340\0\337\337\0YY\0qq\0\345\345\0\344\344\0NN\0^^\0" "\352\352\0\352\352\0@@\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364" "\364\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375" "\0\376\376\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16" "\16\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24" "\24\0\24\24\0\22\22\0\24\24\0""88\0""88\0//\0BB\0pp\0pp\0UU\0ss\0\242\242" "\0\242\242\0oo\0\230\230\0\306\306\0\306\306\0ww\0\265\265\0\335\335\0\335" "\335\0ss\0\313\313\0\353\353\0\353\353\0ii\0\333\333\0\364\364\0\364\364" "\0ZZ\0\351\351\0\371\371\0\371\371\0II\0\362\362\0\374\374\0\374\374\0""6" "6\0\370\370\0\376\376\0\376\376\0\"\"\0\374\374\0\376\376\0\376\376\0\16" "\16\0\376\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376" "\0\376\376\0\360\360\0\360\360\0\360\360\0\360\360\0\16\16\0\360\360\0\360" "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\22\22\0\"\"\0""88\0" """88\0//\0OO\0pp\0pp\0WW\0\203\203\0\242\242\0\242\242\0qq\0\256\256\0\312" "\312\0\301\301\0||\0\313\313\0\342\342\0\325\325\0yy\0\336\336\0\360\360" "\0\342\342\0mm\0\353\353\0\367\367\0\354\354\0\\\\\0\363\363\0\373\373\0" "\362\362\0JJ\0\371\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373" "\373\0\"\"\0\376\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376" "\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375" "\0\360\360\0\374\374\0\360\360\0\376\376\0\16\16\0\360\360\0\360\360\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\24\24\0\22\22\0&&\0\"\"\0""88\0//\0PP\0HH\0gg\0NN" "\0pp\0ee\0}}\0VV\0{{\0oo\0\202\202\0NN\0qq\0jj\0vv\0>>\0``\0\\\\\0cc\0,," "\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33\33\0" "\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7\0\7" "\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360\0\360" "\360\0\376\376\0\376\376\0\16\16\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22" "\0&&\0&&\0\"\"\0""66\0[[\0oo\0ee\0``\0\220\220\0\270\270\0\250\250\0xx\0" "\250\250\0\327\327\0\311\311\0zz\0\246\246\0\341\341\0\325\325\0rr\0\230" "\230\0\343\343\0\334\334\0gg\0\205\205\0\344\344\0\340\340\0[[\0rr\0\346" "\346\0\344\344\0NN\0^^\0\352\352\0\352\352\0AA\0JJ\0\357\357\0\357\357\0" """11\0""66\0\364\364\0\364\364\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16" "\0\16\16\0\375\375\0\375\375\0\376\376\0\376\376\0\362\362\0\362\362\0\376" "\376\0\376\376\0\16\16\0\16\16\0\376\376\0\376\376\0\376\376\0\16\16\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\22\22\0&&\0&&\0\37\37\0;;\0``\0``\0HH\0qq\0\237\237" "\0\237\237\0nn\0\227\227\0\306\306\0\306\306\0}}\0\254\254\0\334\334\0\334" "\334\0}}\0\275\275\0\347\347\0\347\347\0vv\0\316\316\0\357\357\0\357\357" "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II" "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\"" "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376" "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360" "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "&&\0&&\0##\0--\0``\0``\0TT\0cc\0\237\237\0\231\231\0||\0\223\223\0\306\306" "\0\301\301\0\217\217\0\267\267\0\336\336\0\322\322\0\220\220\0\317\317\0" "\352\352\0\334\334\0\202\202\0\337\337\0\362\362\0\345\345\0qq\0\353\353" "\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371\371\0\375" "\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376\376\0\376" "\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376" "\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0\376\376\0" "\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "&&\0##\0""77\0--\0``\0PP\0nn\0[[\0\222\222\0kk\0\211\211\0qq\0\231\231\0" "ff\0\210\210\0uu\0\217\217\0UU\0vv\0ll\0zz\0@@\0aa\0]]\0dd\0,,\0MM\0KK\0" "OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33\33\0\33\33\0\33" "\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7\0\7\7\0\2\2\0\2" "\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360\0\360\360\0\376" "\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0##\0""77\0""77" "\0--\0UU\0zz\0\216\216\0ww\0}}\0\254\254\0\324\324\0\264\264\0\207\207\0" "\266\266\0\345\345\0\316\316\0\177\177\0\254\254\0\346\346\0\326\326\0rr" "\0\231\231\0\344\344\0\334\334\0gg\0\206\206\0\344\344\0\340\340\0[[\0rr" "\0\346\346\0\344\344\0NN\0^^\0\352\352\0\352\352\0AA\0JJ\0\357\357\0\357" "\357\0""11\0""66\0\364\364\0\364\364\0\40\40\0\"\"\0\371\371\0\371\371\0" "\16\16\0\16\16\0\375\375\0\375\375\0\376\376\0\376\376\0\362\362\0\362\362" "\0\376\376\0\376\376\0\16\16\0\16\16\0\376\376\0\376\376\0\376\376\0\16\16" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0""77\0--\0CC\0~~\0~~\0\\\\\0||\0" "\274\274\0\274\274\0||\0\235\235\0\325\325\0\325\325\0\204\204\0\256\256" "\0\340\340\0\340\340\0\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316" "\0\360\360\0\360\360\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371" "\371\0\371\371\0II\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376" "\0\376\376\0\"\"\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376" "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0" "\360\360\0\360\360\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0&&\0""77\0""22\0--\0``\0vv\0pp\0gg\0\243\243\0\255\255" "\0\225\225\0\231\231\0\311\311\0\314\314\0\235\235\0\271\271\0\337\337\0" "\326\326\0\224\224\0\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362" "\362\0\345\345\0qq\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373" "\0\362\362\0JJ\0\371\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0" "\373\373\0\"\"\0\376\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376" "\0\376\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0" "\375\375\0\360\360\0\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376" "\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222" "\222\0kk\0\222\222\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm" "\0zz\0@@\0bb\0]]\0dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0" "))\0**\0\10\10\0\33\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0" "\0\0\7\7\0\7\7\0\7\7\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16" "\0\16\16\0\360\360\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203" "\203\0\254\254\0\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317" "\0\200\200\0\254\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334" "\0gg\0\206\206\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0" "\352\352\0\352\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364" "\364\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375" "\0\376\376\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16" "\16\0\376\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22" "\0""77\0""77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302" "\302\0||\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341" "\341\0\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360" "\360\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371" "\0II\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0" "\"\"\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376" "\0\376\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0" "\360\360\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235" "\0\234\234\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0" "\225\225\0\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345" "\345\0qq\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362" "\0JJ\0\371\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0" "\"\"\0\376\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376" "\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0" "\360\360\0\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222\222\0kk" "\0\222\222\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm\0zz\0@@" "\0bb\0]]\0dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0" "\10\10\0\33\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7" "\0\7\7\0\7\7\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16" "\0\360\360\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203\203\0" "\254\254\0\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317\0\200" "\200\0\254\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334\0gg" "\0\206\206\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0\352" "\352\0\352\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364\364" "\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375\0" "\376\376\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16" "\0\376\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0" """77\0""77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302\302" "\0||\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341\341" "\0\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360\360" "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II" "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\"" "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376" "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360" "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235\0\234\234" "\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0\225\225\0" "\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345\345\0qq" "\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371" "\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376" "\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376" "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0" "\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222\222\0kk\0\222\222" "\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm\0zz\0@@\0bb\0]]\0" "dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33" "\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7" "\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360" "\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203\203\0\254\254\0" "\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317\0\200\200\0\254" "\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334\0gg\0\206\206" "\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0\352\352\0\352" "\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364\364\0\40\40" "\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375\0\376\376" "\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16\0\376" "\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0" """77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302\302\0||" "\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341\341\0" "\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360\360" "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II" "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\"" "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376" "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360" "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235\0\234\234" "\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0\225\225\0" "\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345\345\0qq" "\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371" "\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376" "\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376" "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0" "\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222\222\0kk\0\222\222" "\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm\0zz\0@@\0bb\0]]\0" "dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33" "\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7" "\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360" "\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203\203\0\254\254\0" "\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317\0\200\200\0\254" "\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334\0gg\0\206\206" "\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0\352\352\0\352" "\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364\364\0\40\40" "\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375\0\376\376" "\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16\0\376" "\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0" """77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302\302\0||" "\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341\341\0" "\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360\360" "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II" "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\"" "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376" "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360" "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235\0\234\234" "\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0\225\225\0" "\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345\345\0qq" "\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371" "\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376" "\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376" "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0" "\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\213\213\0mm\0\237\237\0uu\0\275\275" "\0\232\232\0\306\306\0\204\204\0\331\331\0\272\272\0\336\336\0\205\205\0" "\345\345\0\320\320\0\352\352\0{{\0\355\355\0\337\337\0\362\362\0mm\0\363" "\363\0\353\353\0\370\370\0\\\\\0\367\367\0\363\363\0\373\373\0II\0\373\373" "\0\371\371\0\375\375\0""66\0\375\375\0\374\374\0\376\376\0\"\"\0\376\376" "\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376" "\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\375\375\0\375\375" "\0\360\360\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0##\0""77\0""77\0""99\0gg\0\205\205\0\205\205\0ww\0\224\224\0" "\310\310\0\310\310\0\247\247\0\240\240\0\354\354\0\354\354\0\306\306\0\227" "\227\0\372\372\0\372\372\0\325\325\0\205\205\0\375\375\0\375\375\0\342\342" "\0rr\0\376\376\0\376\376\0\354\354\0^^\0\376\376\0\376\376\0\363\363\0JJ" "\0\376\376\0\376\376\0\370\370\0""66\0\376\376\0\376\376\0\374\374\0\"\"" "\0\376\376\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376" "\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\375\375" "\0\376\376\0\376\376\0\376\376\0\362\362\0\376\376\0\376\376\0\376\376\0" "\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0""77\0""11\0>>\0~~\0~~\0bb" "\0__\0\261\261\0\261\261\0\212\212\0``\0\277\277\0\277\277\0\230\230\0SS" "\0\275\275\0\275\275\0\233\233\0@@\0\273\273\0\273\273\0\240\240\0//\0\274" "\274\0\274\274\0\252\252\0!!\0\301\301\0\301\301\0\266\266\0\25\25\0\311" "\311\0\311\311\0\303\303\0\14\14\0\324\324\0\324\324\0\322\322\0\6\6\0\342" "\342\0\342\342\0\341\341\0\1\1\0\361\361\0\361\361\0\361\361\0\15\15\0\15" "\15\0\15\15\0\15\15\0\362\362\0\362\362\0\362\362\0\360\360\0\16\16\0\16" "\16\0\16\16\0\2\2\0\376\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0&&\0""77\0""77\0\34\34\0SS\0kk\0\206\206\0BB\0\214\214\0\232\232" "\0\302\302\0YY\0\250\250\0\255\255\0\340\340\0XX\0\264\264\0\264\264\0\355" "\355\0SS\0\265\265\0\266\266\0\364\364\0JJ\0\270\270\0\272\272\0\371\371" "\0AA\0\277\277\0\300\300\0\374\374\0""66\0\310\310\0\311\311\0\375\375\0" "**\0\324\324\0\324\324\0\376\376\0\34\34\0\341\341\0\342\342\0\376\376\0" "\15\15\0\361\361\0\361\361\0\376\376\0\361\361\0\15\15\0\15\15\0\376\376" "\0\15\15\0\361\361\0\361\361\0\373\373\0\362\362\0\15\15\0\16\16\0\376\376" "\0\16\16\0\361\361\0\376\376\0\376\376\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0&&\0&&\0""77\0))\0SS\0SS\0kk\0DD\0\205\205\0}}\0\222\222\0WW\0\241\241" "\0\230\230\0\245\245\0XX\0\261\261\0\252\252\0\261\261\0SS\0\264\264\0\263" "\263\0\265\265\0JJ\0\270\270\0\271\271\0\272\272\0AA\0\276\276\0\300\300" "\0\300\300\0""66\0\310\310\0\311\311\0\311\311\0**\0\324\324\0\324\324\0" "\324\324\0\34\34\0\341\341\0\342\342\0\342\342\0\15\15\0\361\361\0\361\361" "\0\361\361\0\361\361\0\15\15\0\15\15\0\15\15\0\15\15\0\361\361\0\361\361" "\0\361\361\0\362\362\0\15\15\0\16\16\0\16\16\0\16\16\0\361\361\0\376\376" "\0\376\376\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&&\0&&\0&&\0))\0pp\0cc\0cc" "\0QQ\0\261\261\0\244\244\0\244\244\0ll\0\335\335\0\323\323\0\323\323\0ww" "\0\364\364\0\356\356\0\356\356\0ss\0\370\370\0\371\371\0\371\371\0ii\0\372" "\372\0\375\375\0\375\375\0YY\0\374\374\0\376\376\0\376\376\0HH\0\375\375" "\0\376\376\0\376\376\0""66\0\376\376\0\376\376\0\376\376\0\"\"\0\376\376" "\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376" "\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376" "\0\375\375\0\376\376\0\376\376\0\376\376\0\361\361\0\376\376\0\376\376\0" "\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0&&\0&&\0\40\40\0QQ\0pp\0pp\0KK" "\0\215\215\0\261\261\0\261\261\0pp\0\274\274\0\337\337\0\337\337\0\200\200" "\0\332\332\0\364\364\0\364\364\0}}\0\350\350\0\373\373\0\373\373\0oo\0\361" "\361\0\375\375\0\375\375\0]]\0\367\367\0\376\376\0\376\376\0JJ\0\373\373" "\0\376\376\0\376\376\0""66\0\375\375\0\376\376\0\376\376\0\"\"\0\376\376" "\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376" "\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376" "\0\375\375\0\376\376\0\376\376\0\376\376\0\361\361\0\376\376\0\376\376\0" "\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0&&\0&&\0\20\20\0""88\0WW\0pp\0" "==\0ss\0\212\212\0\252\252\0dd\0\250\250\0\264\264\0\312\312\0rr\0\313\313" "\0\315\315\0\331\331\0rr\0\340\340\0\331\331\0\340\340\0hh\0\355\355\0\341" "\341\0\345\345\0YY\0\366\366\0\350\350\0\352\352\0HH\0\372\372\0\356\356" "\0\357\357\0""66\0\375\375\0\364\364\0\364\364\0\"\"\0\376\376\0\371\371" "\0\371\371\0\16\16\0\376\376\0\375\375\0\375\375\0\376\376\0\376\376\0\361" "\361\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16\0\376\376\0\375\375\0" "\376\376\0\375\375\0\374\374\0\360\360\0\376\376\0\376\376\0\360\360\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0&&\0\40\40\0""88\0""88\0WW\0BB\0ff" "\0ZZ\0}}\0^^\0\226\226\0\201\201\0\241\241\0nn\0\301\301\0\246\246\0\277" "\277\0rr\0\333\333\0\301\301\0\321\321\0ii\0\353\353\0\323\323\0\335\335" "\0[[\0\365\365\0\341\341\0\346\346\0II\0\372\372\0\353\353\0\356\356\0""6" "6\0\375\375\0\363\363\0\364\364\0\"\"\0\376\376\0\371\371\0\371\371\0\16" "\16\0\376\376\0\375\375\0\375\375\0\376\376\0\376\376\0\361\361\0\361\361" "\0\376\376\0\376\376\0\16\16\0\16\16\0\376\376\0\374\374\0\375\375\0\374" "\374\0\374\374\0\361\361\0\376\376\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\24\24\0\24\24\0\24\24\0\40\40\0HH\0""88\0""88\0BB\0~~\0ff\0ff\0" "^^\0\256\256\0\226\226\0\226\226\0qq\0\325\325\0\277\277\0\277\277\0ss\0" "\350\350\0\331\331\0\331\331\0jj\0\363\363\0\353\353\0\353\353\0[[\0\371" "\371\0\365\365\0\365\365\0II\0\374\374\0\372\372\0\372\372\0""66\0\375\375" "\0\375\375\0\375\375\0\"\"\0\376\376\0\376\376\0\376\376\0\16\16\0\376\376" "\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0" "\376\376\0\376\376\0\376\376\0\376\376\0\374\374\0\374\374\0\374\374\0\376" "\376\0\361\361\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\24\24\0\24\24\0\24\24\0\40\40\0HH\0HH\0""88\0BB\0~~\0~~\0ff\0^^\0\263" "\263\0\263\263\0\231\231\0nn\0\330\330\0\330\330\0\274\274\0pp\0\353\353" "\0\353\353\0\324\324\0hh\0\365\365\0\365\365\0\345\345\0ZZ\0\373\373\0\373" "\373\0\361\361\0II\0\375\375\0\375\375\0\370\370\0""66\0\376\376\0\376\376" "\0\374\374\0\"\"\0\376\376\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376" "\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0" "\376\376\0\374\374\0\374\374\0\376\376\0\376\376\0\361\361\0\360\360\0\360" "\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\0\0" "\0\0\0\0((\0HH\0\40\40\0\25\25\0QQ\0\207\207\0KK\0--\0}}\0\262\262\0bb\0" """44\0\235\235\0\320\320\0ff\0""00\0\257\257\0\341\341\0cc\0))\0\272\272" "\0\354\354\0ZZ\0\37\37\0\303\303\0\363\363\0OO\0\26\26\0\314\314\0\370\370" "\0AA\0\15\15\0\326\326\0\373\373\0""22\0\6\6\0\343\343\0\375\375\0!!\0\1" "\1\0\362\362\0\376\376\0\16\16\0\16\16\0\16\16\0\375\375\0\375\375\0\375" "\375\0\376\376\0\362\362\0\360\360\0\361\361\0\376\376\0\14\14\0\0\0\0\0" "\0\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24" "\0\24\24\0\0\0\0\0\0\0((\0((\0\0\0\0\0\0\0<<\0<<\0\0\0\0\0\0\0PP\0PP\0\10" "\10\0\4\4\0dd\0dd\0\14\14\0\6\6\0xx\0xx\0\14\14\0\5\5\0\214\214\0\214\214" "\0\13\13\0\4\4\0\240\240\0\240\240\0\10\10\0\2\2\0\264\264\0\264\264\0\5" "\5\0\1\1\0\310\310\0\310\310\0\3\3\0\0\0\0\334\334\0\334\334\0\1\1\0\0\0" "\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\1\1\0\1\1\0\0\0\0\0\0\0\14" "\14\0\14\14\0\0\0\0\0\0\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\0\0\0\0\0\0((\0((\0\0\0\0\0\0" "\0<<\0<<\0\0\0\0\0\0\0XX\0XX\0\0\0\0\0\0\0pp\0pp\0\0\0\0\0\0\0\204\204\0" "\204\204\0\0\0\0\0\0\0\227\227\0\227\227\0\0\0\0\0\0\0\250\250\0\250\250" "\0\0\0\0\0\0\0\271\271\0\271\271\0\0\0\0\0\0\0\313\313\0\313\313\0\0\0\0" "\0\0\0\335\335\0\335\335\0\0\0\0\0\0\0\360\360\0\360\360\0\0\0\0\0\0\0\1" "\1\0\1\1\0\0\0\0\0\0\0\14\14\0\14\14\0\0\0\0\0\0\0\360\360\0\360\360\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0" "\24\24\0\24\24\0\0\0\0((\0((\0((\0\0\0\0<<\0HH\0HH\0\10\10\0PP\0dd\0dd\0" "\14\14\0dd\0||\0||\0\14\14\0xx\0\221\221\0\221\221\0\13\13\0\214\214\0\243" "\243\0\243\243\0\10\10\0\240\240\0\264\264\0\264\264\0\5\5\0\264\264\0\303" "\303\0\303\303\0\3\3\0\310\310\0\322\322\0\322\322\0\1\1\0\334\334\0\341" "\341\0\341\341\0\0\0\0\360\360\0\361\361\0\361\361\0\1\1\0\0\0\0\14\14\0" "\14\14\0\14\14\0\0\0\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0" "\24\24\0\20\20\0\20\20\0""88\0""88\0**\0**\0ZZ\0ZZ\0==\0==\0yy\0yy\0II\0" "II\0\224\224\0\224\224\0NN\0NN\0\254\254\0\254\254\0MM\0MM\0\302\302\0\302" "\302\0HH\0HH\0\324\324\0\324\324\0>>\0>>\0\343\343\0\343\343\0""00\0""00" "\0\356\356\0\356\356\0\40\40\0\40\40\0\367\367\0\367\367\0\16\16\0\16\16" "\0\374\374\0\374\374\0\374\374\0\374\374\0\360\360\0\360\360\0\360\360\0" "\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; /** * \brief Returns the BlitAlpha test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlitAlpha() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlitAlpha.pixel_data, SDLTest_imageBlitAlpha.width, SDLTest_imageBlitAlpha.height, SDLTest_imageBlitAlpha.bytes_per_pixel * 8, SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_imageBlit.c
C
apache-2.0
115,276
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include "SDL_test.h" /* GIMP RGB C-Source image dump (alpha.c) */ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310" "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310" "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0" "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310" "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310" "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0" "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310" "\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310\310\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310" "\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310\310" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\310\310\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd" "\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0" "\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310" "\310\0\310\310\0\310\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0" "dd\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0" "dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd" "\0\310\310\0\310\310\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310" "\310\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\310\310\0\310\310" "\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310" "\310\0\310\310\0\310\310\0\310\310\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310\310\0\310" "\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\310\310\0\310\310\0\310\310\0dd\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310" "\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\310\310\0dd\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310" "\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310" "\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310" "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310" "\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310" "\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310" "\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310" "\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\310" "\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310" "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\310\310" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\310\310\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\310\310" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\310\310\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310" "\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310\310\0\310\310\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310" "\310\0\310\310\0\310\310\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310\310\0dd\0\310\310\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0" "dd\0\310\310\0\310\310\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310\310" "\0\377\377\0\377\377\0\377\377\0\310\310\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\310\310\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\310" "\310\0\310\310\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0\310\310\0\377\377\0\310\310\0\310\310" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\377\377\0\310\310\0dd" "\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0dd\0dd\0dd\0\310\310\0\377\377\0\377\377\0\310\310\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\310\310\0\377\377\0\377\377\0\310\310\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd" "\0\0\0\0\0\0\0dd\0\377\377\0\310\310\0\310\310\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\377\377\0dd\0\0" "\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0" "\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0" "dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0" "dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0" "dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0" "\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0" "\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310" "\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310" "\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0" "\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0" "\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0\0\0\0dd\0dd\0dd\0\0\0\0dd\0\310\310\0\310" "\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310" "\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0" "dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310" "\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0" "\0\0\0dd\0dd\0dd\0\0\0\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310" "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310" "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0" "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310" "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310" "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0" "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310" "\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; /** * \brief Returns the BlitBlendAdd test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlitBlendAdd() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlitBlendAdd.pixel_data, SDLTest_imageBlitBlendAdd.width, SDLTest_imageBlitBlendAdd.height, SDLTest_imageBlitBlendAdd.bytes_per_pixel * 8, SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0<<\0<<\0\240\240\0\240\240\0aa\0aa\0\240" "\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0" "aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240" "\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0" "aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240" "\240\0\240\240\0\240\240\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0<<\0\240\240\0\240\240\0\240\240" "\0aa\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww" "\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305" "\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305\305" "\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305" "\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305" "\0\305\305\0\305\305\0\240\240\0\240\240\0\240\240\0\240\240\0dd\0dd\0dd" "\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0<<\0\240\240" "\0\240\240\0\240\240\0aa\0\305\305\0\305\305\0\305\305\0ww\0\333\333\0\333" "\333\0\305\305\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333" "\0\305\305\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333\0\305" "\305\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333\0\305\305" "\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333\0\305\305\0ww" "\0\333\333\0\333\333\0\305\305\0\305\305\0\305\305\0\305\305\0\240\240\0" "\240\240\0\240\240\0\240\240\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0dd\0dd\0dd\0<<\0aa\0aa\0aa\0::\0HH\0HH\0HH\0++\0PP\0PP\0PP\0""00\0PP" "\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP" "\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP" "\0PP\0PP\0PP\0HH\0HH\0HH\0HH\0aa\0aa\0aa\0aa\0dd\0dd\0dd\0dd\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0dd\0dd\0dd\0$$\0aa\0\305\305\0\305\305\0``\0\205\205\0\351\351\0" "\351\351\0||\0\222\222\0\321\321\0\321\321\0\177\177\0\225\225\0\324\324" "\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0\177\177\0\225\225\0" "\324\324\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0\177\177\0\225" "\225\0\324\324\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0\177\177" "\0\225\225\0\324\324\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0" "\177\177\0\225\225\0\324\324\0\321\321\0\222\222\0\222\222\0\321\321\0\314" "\314\0\351\351\0\351\351\0\254\254\0\236\236\0\305\305\0\305\305\0aa\0<<" "\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0<<\0dd\0\240\240\0\240\240\0aa\0\255\255" "\0\322\322\0\322\322\0\177\177\0\315\315\0\343\343\0\343\343\0\211\211\0" "\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346\346\0\346\346\0\211" "\211\0\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346\346\0\346\346" "\0\211\211\0\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346\346\0" "\346\346\0\211\211\0\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346" "\346\0\346\346\0\211\211\0\313\313\0\346\346\0\346\346\0\211\211\0\320\320" "\0\327\327\0\327\327\0\322\322\0\276\276\0\322\322\0\322\322\0\305\305\0" "yy\0\210\210\0\210\210\0dd\0<<\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0<<\0\210\210\0\240" "\240\0\240\240\0aa\0\266\266\0\322\322\0\322\322\0\205\205\0\327\327\0\343" "\343\0\343\343\0\215\215\0\346\346\0\357\357\0\331\331\0\222\222\0\347\347" "\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0\331\331\0\222\222\0" "\347\347\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0\331\331\0\222" "\222\0\347\347\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0\331\331" "\0\222\222\0\347\347\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0" "\331\331\0\222\222\0\357\357\0\346\346\0\320\320\0\351\351\0\327\327\0\343" "\343\0\276\276\0\333\333\0\322\322\0\266\266\0yy\0\240\240\0\210\210\0\240" "\240\0<<\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0dd\0<<\0\240\240\0\210\210\0\240\240\0aa\0ww\0nn\0\177" "\177\0MM\0SS\0OO\0SS\0""22\0WW\0TT\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0" "XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0" "XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0XX\0TT\0TT\0LL\0OO\0SS" "\0SS\0ss\0\177\177\0nn\0nn\0yy\0\210\210\0\240\240\0\240\240\0<<\0dd\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<" "\0\240\240\0\240\240\0\210\210\0HH\0\205\205\0\351\351\0\333\333\0pp\0\225" "\225\0\371\371\0\363\363\0\202\202\0\231\231\0\330\330\0\325\325\0\203\203" "\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0" "\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324" "\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331" "\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0" "\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\325\325\0\231\231\0\231" "\231\0\330\330\0\323\323\0\371\371\0\371\371\0\274\274\0\257\257\0\351\351" "\0\351\351\0\205\205\0``\0\240\240\0\240\240\0\240\240\0<<\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\240\240" "\0\240\240\0RR\0\207\207\0\304\304\0\304\304\0nn\0\275\275\0\343\343\0\343" "\343\0\205\205\0\324\324\0\352\352\0\352\352\0\214\214\0\316\316\0\352\352" "\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0\213\213\0\316\316\0" "\352\352\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0\213\213\0\316" "\316\0\352\352\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0\213\213" "\0\316\316\0\352\352\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0" "\213\213\0\316\316\0\352\352\0\352\352\0\214\214\0\324\324\0\336\336\0\336" "\336\0\331\331\0\310\310\0\343\343\0\343\343\0\325\325\0\217\217\0\254\254" "\0\254\254\0\207\207\0aa\0\240\240\0\240\240\0<<\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\240\240\0aa" "\0\225\225\0\304\304\0\304\304\0\205\205\0\276\276\0\343\343\0\340\340\0" "\222\222\0\333\333\0\352\352\0\351\351\0\226\226\0\347\347\0\362\362\0\333" "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361" "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0" "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351" "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230" "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0" "\366\366\0\336\336\0\351\351\0\304\304\0\351\351\0\343\343\0\304\304\0\217" "\217\0\333\333\0\254\254\0\266\266\0aa\0\240\240\0\240\240\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa" "\0\305\305\0\225\225\0\304\304\0ww\0\205\205\0ss\0\211\211\0RR\0VV\0PP\0" "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211" "\0ww\0||\0\217\217\0\254\254\0\266\266\0\305\305\0aa\0\240\240\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305" "\305\0\305\305\0\225\225\0UU\0\222\222\0\366\366\0\340\340\0tt\0\231\231" "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0" "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203" "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324" "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0" "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331" "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231" "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0" "\366\366\0\222\222\0mm\0\266\266\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0" "\305\305\0``\0\214\214\0\321\321\0\321\321\0rr\0\277\277\0\346\346\0\346" "\346\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353" "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0" "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316" "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213" "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0" "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337" "\337\0\331\331\0\312\312\0\346\346\0\346\346\0\330\330\0\224\224\0\271\271" "\0\271\271\0\217\217\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww" "\0\225\225\0\304\304\0\314\314\0\222\222\0\277\277\0\343\343\0\342\342\0" "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333" "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361" "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0" "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351" "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230" "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0" "\370\370\0\336\336\0\352\352\0\306\306\0\354\354\0\344\344\0\305\305\0\227" "\227\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa" "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0" "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211" "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305" "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231" "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0" "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203" "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324" "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0" "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331" "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231" "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0" "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0" "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347" "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353" "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0" "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316" "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213" "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0" "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337" "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274" "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww" "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0" "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333" "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361" "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0" "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351" "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230" "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0" "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231" "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa" "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0" "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211" "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305" "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231" "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0" "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203" "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324" "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0" "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331" "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231" "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0" "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0" "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347" "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353" "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0" "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316" "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213" "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0" "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337" "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274" "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww" "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0" "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333" "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361" "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0" "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351" "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230" "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0" "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231" "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa" "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0" "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211" "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305" "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231" "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0" "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203" "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324" "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0" "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331" "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231" "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0" "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0" "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347" "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353" "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0" "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316" "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213" "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0" "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337" "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274" "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww" "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0" "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333" "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361" "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0" "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351" "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230" "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0" "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231" "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa" "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0" "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0" "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211" "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305" "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231" "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0" "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203" "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324" "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0" "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331" "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231" "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0" "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0" "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347" "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353" "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0" "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316" "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213" "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0" "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337" "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274" "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww" "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0" "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333" "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361" "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0" "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351" "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230" "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0" "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231" "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa" "\0\333\333\0\236\236\0\304\304\0ww\0\340\340\0\300\300\0\343\343\0\210\210" "\0\354\354\0\333\333\0\352\352\0\215\215\0\361\361\0\350\350\0\362\362\0" "\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351\351\0\351\351\0\361" "\361\0\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351\351\0\351\351" "\0\361\361\0\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351\351\0" "\351\351\0\361\361\0\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351" "\351\0\351\351\0\361\361\0\223\223\0\351\351\0\362\362\0\351\351\0\351\351" "\0\323\323\0\336\336\0\351\351\0\351\351\0\304\304\0\343\343\0\305\305\0" "\317\317\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305" "\305\0\305\305\0\236\236\0\222\222\0\361\361\0\361\361\0\316\316\0\230\230" "\0\373\373\0\373\373\0\344\344\0\231\231\0\375\375\0\375\375\0\357\357\0" "\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375\375\0\375\375\0\347" "\347\0\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375\375\0\375\375" "\0\347\347\0\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375\375\0" "\375\375\0\347\347\0\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375" "\375\0\375\375\0\347\347\0\231\231\0\375\375\0\375\375\0\360\360\0\373\373" "\0\375\375\0\375\375\0\347\347\0\367\367\0\373\373\0\373\373\0\326\326\0" "\351\351\0\361\361\0\361\361\0\271\271\0\276\276\0\305\305\0\305\305\0aa" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0<<\0\305\305\0\305\305\0\236\236\0HH\0\271\271\0\271\271\0\224\224\0VV" "\0\277\277\0\277\277\0\251\251\0DD\0\252\252\0\252\252\0\235\235\0FF\0\253" "\253\0\253\253\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253" "\0\253\253\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253\0\253" "\253\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253\0\253\253" "\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253\0\253\253\0\235" "\235\0rr\0uu\0uu\0^^\0\272\272\0\277\277\0\277\277\0\230\230\0\205\205\0" "\222\222\0\222\222\0MM\0\266\266\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305" "\305\0\305\305\0RR\0\236\236\0\254\254\0\361\361\0VV\0\267\267\0\263\263" "\0\356\356\0ee\0\247\247\0\244\244\0\356\356\0^^\0\251\251\0\247\247\0\365" "\365\0bb\0\242\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365" "\0bb\0\242\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365\0bb" "\0\242\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365\0bb\0\242" "\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365\0\252\252\0ee" "\0jj\0\345\345\0tt\0\246\246\0\251\251\0\321\321\0\272\272\0ff\0\222\222" "\0\322\322\0ww\0\210\210\0\305\305\0\305\305\0\240\240\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\240\240" "\0\305\305\0``\0\236\236\0\236\236\0\254\254\0VV\0\264\264\0\254\254\0\261" "\261\0dd\0\246\246\0\240\240\0\243\243\0^^\0\251\251\0\246\246\0\246\246" "\0bb\0\242\242\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0bb" "\0\242\242\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0bb\0\242" "\242\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0bb\0\242\242" "\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0\251\251\0dd\0hh" "\0hh\0pp\0\243\243\0\240\240\0\236\236\0\264\264\0cc\0\177\177\0ww\0ww\0" "\225\225\0\305\305\0\240\240\0\240\240\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\240\240\0\240\240\0``" "\0\351\351\0\333\333\0\333\333\0||\0\366\366\0\361\361\0\361\361\0\211\211" "\0\373\373\0\371\371\0\371\371\0\221\221\0\375\375\0\374\374\0\374\374\0" "\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365\365\0\374\374\0\374" "\374\0\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365\365\0\374\374" "\0\374\374\0\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365\365\0" "\374\374\0\374\374\0\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365" "\365\0\374\374\0\374\374\0\375\375\0\356\356\0\371\371\0\371\371\0\372\372" "\0\340\340\0\361\361\0\361\361\0\364\364\0\307\307\0\333\333\0\333\333\0" "\351\351\0\225\225\0\240\240\0\240\240\0\240\240\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\240\240\0\240\240" "\0aa\0\304\304\0\351\351\0\351\351\0\205\205\0\340\340\0\366\366\0\366\366" "\0\222\222\0\355\355\0\373\373\0\373\373\0\227\227\0\364\364\0\375\375\0" "\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230\230\0\360\360\0\375" "\375\0\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230\230\0\360\360" "\0\375\375\0\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230\230\0" "\360\360\0\375\375\0\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230" "\230\0\360\360\0\375\375\0\375\375\0\373\373\0\356\356\0\373\373\0\373\373" "\0\367\367\0\340\340\0\364\364\0\364\364\0\354\354\0\304\304\0\351\351\0" "\351\351\0\322\322\0\210\210\0\240\240\0\240\240\0dd\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\240\240\0\240" "\240\0<<\0\240\240\0\305\305\0\351\351\0ww\0\320\320\0\301\301\0\324\324" "\0\211\211\0\345\345\0\316\316\0\324\324\0\217\217\0\356\356\0\323\323\0" "\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223\223\0\354\354\0\323" "\323\0\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223\223\0\354\354" "\0\323\323\0\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223\223\0" "\354\354\0\323\323\0\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223" "\223\0\354\354\0\323\323\0\326\326\0\362\362\0\344\344\0\261\261\0\272\272" "\0\364\364\0\340\340\0\225\225\0\205\205\0\340\340\0\276\276\0\351\351\0" "\266\266\0\240\240\0dd\0\240\240\0\240\240\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\240\240\0aa\0\240" "\240\0\240\240\0\305\305\0ww\0\305\305\0\240\240\0\266\266\0\205\205\0\333" "\333\0\266\266\0\304\304\0\215\215\0\352\352\0\305\305\0\314\314\0\222\222" "\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0\305\305\0\314\314\0" "\222\222\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0\305\305\0\314" "\314\0\222\222\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0\305\305" "\0\314\314\0\222\222\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0" "\305\305\0\314\314\0\361\361\0\335\335\0\242\242\0\236\236\0\333\333\0\312" "\312\0ii\0aa\0\305\305\0\255\255\0\266\266\0\240\240\0\240\240\0\210\210" "\0\240\240\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0aa\0\305\305\0\240\240\0\240\240\0ww\0\333" "\333\0\305\305\0\305\305\0\205\205\0\351\351\0\333\333\0\333\333\0\217\217" "\0\363\363\0\351\351\0\351\351\0\223\223\0\357\357\0\351\351\0\351\351\0" "\223\223\0\357\357\0\351\351\0\351\351\0\223\223\0\357\357\0\351\351\0\351" "\351\0\223\223\0\357\357\0\351\351\0\351\351\0\223\223\0\357\357\0\351\351" "\0\351\351\0\223\223\0\357\357\0\351\351\0\351\351\0\223\223\0\357\357\0" "\351\351\0\351\351\0\223\223\0\357\357\0\351\351\0\351\351\0\363\363\0\345" "\345\0\333\333\0\333\333\0\340\340\0\312\312\0\305\305\0\305\305\0\322\322" "\0\255\255\0\240\240\0\240\240\0\305\305\0\210\210\0dd\0dd\0dd\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd" "\0dd\0dd\0aa\0\305\305\0\305\305\0\240\240\0ww\0\333\333\0\333\333\0\305" "\305\0\205\205\0\355\355\0\355\355\0\336\336\0\215\215\0\364\364\0\364\364" "\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0\215\215\0\364\364\0" "\364\364\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0\215\215\0\364" "\364\0\364\364\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0\215\215" "\0\364\364\0\364\364\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0" "\215\215\0\364\364\0\364\364\0\335\335\0\351\351\0\355\355\0\355\355\0\312" "\312\0\305\305\0\322\322\0\322\322\0\255\255\0\240\240\0\305\305\0\305\305" "\0\210\210\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0\305\305\0aa" "\0""11\0\225\225\0\351\351\0\205\205\0HH\0\254\254\0\333\333\0ww\0BB\0\264" "\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0" "nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264" "\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0" "BB\0\264\264\0\340\340\0nn\0nn\0\205\205\0\314\314\0\266\266\0\304\304\0" "\351\351\0\236\236\0yy\0\210\210\0\305\305\0<<\0\0\0\0\0\0\0dd\0dd\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0" "\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14" "\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14" "\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14" "\0dd\0dd\0\25\25\0\25\25\0\0\0\0\0\0\0$$\0$$\0\0\0\0\0\0\0<<\0<<\0\0\0\0" "\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0" "\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0" "yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0" "\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0" "yy\0\0\0\0\0\0\0$$\0$$\0\0\0\0\0\0\0<<\0<<\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0\0\0\0dd\0dd\0dd\0\0\0\0dd" "\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210" "\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210" "\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25" "\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210" "\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0$$\0\0\0\0<<\0<<\0<<\0\0" "\0\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0dd\0dd\0<<\0<<\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0" "aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240" "\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240" "\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0" "aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0\240\240\0\240\240" "\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; /** * \brief Returns the BlitBlend test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlitBlend() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlitBlend.pixel_data, SDLTest_imageBlitBlend.width, SDLTest_imageBlitBlend.height, SDLTest_imageBlitBlend.bytes_per_pixel * 8, SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; /** * \brief Returns the BlitBlendMod test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlitBlendMod() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlitBlendMod.pixel_data, SDLTest_imageBlitBlendMod.width, SDLTest_imageBlitBlendMod.height, SDLTest_imageBlitBlendMod.bytes_per_pixel * 8, SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = { 80, 60, 3, "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" "\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377" "\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0" "\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\0\0\0\377\377" "\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\0\0\0\377\377\0" "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0" "\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0" "\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377" "\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377\377" "\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377" "\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0" "\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377" "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377", }; /** * \brief Returns the BlitBlendNone test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlitBlendNone() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlitBlendNone.pixel_data, SDLTest_imageBlitBlendNone.width, SDLTest_imageBlitBlendNone.height, SDLTest_imageBlitBlendNone.bytes_per_pixel * 8, SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\0\0\0\0\0" "\0\11\0\0\11\0\0\0\0\0\0\0\0\16\0\0\16\0\0\0\0\0\0\0\0\11\0\0\11\0\0\0\0" "\0\0\0\0\14\0\0\14\0\0\0\0\0\0\0\0\17\0\0\17\0\0\0\0\0\0\0\0\21\0\0\21\0" "\0\0\0\0\0\0\0K\0\0K\0\0\0\0\0\0\0\0T\0\0T\0\0\0\0\0\0\0\0^\0\0^\0\0\0\0" "\0\0\0\0g\0\0g\0\0\0\0\0\0\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317" "\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\4\0\0\0\0\0\11\0\0\11\0\0\11" "\0\0\0\0\0\16\0\0\16\0\0\16\0\0\0\0\0\22\0\0\22\0\0\11\0\0\0\0\0\14\0\0\14" "\0\0\14\0\0\0\0\0\17\0\0\17\0\0\17\0\0\0\0\0\21\0\0\21\0\0\21\0\0\0\0\0\24" "\0\0\24\0\0K\0\0\0\0\0T\0\0T\0\0T\0\0\0\0\0^\0\0^\0\0^\0\0\0\0\0g\0\0g\0" "\0g\0\0\0\0\0q\0\0q\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317" "\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\4\0\0\0\0\0\11\0\0\11\0\0\11\0\0\0\0\0" "\16\0\0\16\0\0\16\0\0\0\0\0\22\0\0\22\0\0\22\0\0\0\0\0\14\0\0\14\0\0\14\0" "\0\0\0\0\17\0\0\17\0\0\17\0\0\0\0\0\21\0\0\21\0\0\21\0\0\0\0\0\24\0\0\24" "\0\0\24\0\0\0\0\0T\0\0T\0\0T\0\0\0\0\0^\0\0^\0\0^\0\0\0\0\0g\0\0g\0\0g\0" "\0\0\0\0q\0\0q\0\0q\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317" "\0\0\317\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\4\0\0\0\0\0\10\0\0\10\0\0\10\0\0\0\0\0\15" "\0\0\15\0\0\15\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\16\0\0\16\0\0\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0J\0\0J\0\0J\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\317" "\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\1\0\0\1\0\0\1\0\0\1" "\0\0\4\0\0\4\0\0\0\0\0\0\0\0\7\0\0\7\0\0\0\0\0\0\0\0&\0\0&\0\0\32\0\0\32" "\0\0&\0\0&\0\0&\0\0&\0\0C\0\0C\0\0\0\0\0\0\0\0^\0\0^\0\0\0\0\0\0\0\17\251" "\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\0\0\0\0" "\0\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\6\2\0\6\2\0\0\1\0\0\0\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1\0\0" "\17\0\0\0\0\0\4\0\0\11\0\0\11\0\0\0\0\6+\0\6+\0\0&\0\0\32\0\0&\0\0&\0\0&" "\0\0&\0\0""5\0\0""5\0\2\210\0\0\0\0\0C\0\0|\0\0|\0\0\0\0\17\251\0\17\251" "\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251" "\0$\360\0$\360\0\0\0\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1" "\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\6\2\0\6\2\0\6\2\0\0\0\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1" "\0\0\1\0\0\0\0\0\17\0\0\17\0\0\4\0\0\0\0\6+\0\6+\0\6+\0\0\32\0\0&\0\0&\0" "\0&\0\0&\0\0""5\0\0""5\0\0""5\0\0\0\0\2\210\0\2\210\0\0C\0\0\0\0\17\251\0" "\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0" "\17\251\0\17\251\0$\360\0$\360\0$\360\0\0\0\0\0\317\0\0\317\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "$\360\0$\360\0$\360\0$\360\0\0\0\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0" "\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\14\1\0\14\1\0\14\1" "\0\14\1\0\15\1\0\15\1\0\0\0\0\0\0\0\14\2\0\14\2\0\14\2\0\14\2\0\16\2\0\16" "\2\0\0\0\0\0\0\0\14!\0\14!\0\14!\0\14!\0\17(\0\17(\0\0\0\0\0\0\0\14+\0\14" "+\0\14+\0\14+\0\20""9\0\20""9\0\0\0\0\0\0\0\36\215\0\36\215\0\36\215\0\36" "\215\0(\264\0(\264\0\0\0\0\0\0\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251" "\0\36\251\0\36\251\0\36\251\0\0\0\0\0\0\0$\360\0$\360\0$\360\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\36\3" "\0\36\3\0\14\1\0\14\1\0\15\1\0\15\1\0\15\1\0\0\0\0\14\2\0\14\2\0\14\2\0\14" "\2\0\16\2\0\16\2\0\16\2\0\0\0\0\14\3\0\14\3\0\14!\0\14!\0\17(\0\17(\0\17" "(\0\0\0\0\14+\0\14+\0\14+\0\14+\0\20""9\0\20""9\0\20""9\0\0\0\0\14""7\0\14" """7\0\36\215\0\36\215\0(\264\0(\264\0(\264\0\0\0\0\36\251\0\36\251\0\36\251" "\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0H\360\0" "H\360\0\0\0\0$\360\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\36\3\0\36\3\0\36\3\0\14\1\0\15\1\0\15\1\0\15\1" "\0\0\0\0\14\2\0\14\2\0\14\2\0\14\2\0\16\2\0\16\2\0\16\2\0\0\0\0\14\3\0\14" "\3\0\14\3\0\14!\0\17(\0\17(\0\17(\0\0\0\0\14+\0\14+\0\14+\0\14+\0\20""9\0" "\20""9\0\20""9\0\0\0\0\14""7\0\14""7\0\14""7\0\36\215\0(\264\0(\264\0(\264" "\0\0\0\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36" "\251\0\36\251\0\36\251\0\36\251\0H\360\0H\360\0H\360\0\0\0\0$\360\0$\360" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\13\1\0\13\1\0\13\1\0\13\1\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\11!\0" "\11!\0\11!\0\11!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\23n\0\23n\0\23n\0\23n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0H\360\0H\360\0H\360\0H\360\0\0\0\0$\360\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\1\0\1\1\0\0\0\0\0\0\0\0\0\0\0\0\0\25\0\0\25\0\0\25\0\0\27\0" "\0\13\0\0\13\0\0\1\0\0\11\0\0\4\0\0\4\0\0\0\0\0\0\0\0\25\3\0\25\3\0\0\0\0" "\0\0\0\25\3\0\25\3\0\25\3\0\25\3\0\3\1\0\3\1\0\2\1\0\7\5\0\7\3\0\7\3\0\0" "\0\0\0\0\0\25""4\0\25""4\0\0\0\0\0\0\0\25""4\0\25""4\0\25""4\0\25""4\0\20" "\35\0\20\35\0\11\22\0\23F\0\34""6\0\34""6\0\0\0\0\0\0\0L\317\0L\317\0L\317" "\0L\317\0L\317\0L\317\0L\317\0L\317\0\0\0\0\0\0\0""2\317\0""2\317\0""2\317" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\1\0\0\0\0\0\0\0\0\0\0\25\0\0\25" "\0\0\25\0\0\4\0\0\5\0\0\2\0\0\1\0\0\4\0\0\14\0\0\14\0\0\0\0\0\37\7\0\37\7" "\0\25\3\0\0\0\0\25\3\0\25\3\0\25\3\0\25\3\0\37\6\0\37\6\0\15\4\0\11\3\0\7" "\3\0\14\10\0\14\10\0\0\0\0\25\16\0\25\16\0\25""4\0\0\0\0\25""4\0\25""4\0" "\25""4\0\25""4\0&Q\0&Q\0&Q\0\31""5\0\34""6\0&j\0&j\0\0\0\0""5q\0""5q\0L\317" "\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0\0\0\0""2" "\317\0""2\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\1\0\0\0\0\0\0\0\25\0" "\0\25\0\0\25\0\0\31\1\0\5\0\0\5\0\0\2\0\0\4\0\0\14\0\0\14\0\0\0\0\0\37\7" "\0\37\7\0\37\7\0\0\0\0\25\3\0\25\3\0\25\3\0\25\3\0\37\6\0\37\6\0\37\6\0\11" "\3\0\16\6\0\16\6\0\7\3\0\0\0\0\25\16\0\25\16\0\25\16\0\0\0\0\25""4\0\25""4" "\0\25""4\0\25""4\0&Q\0&Q\0&Q\0\31""5\0+X\0+X\0\34""6\0\0\0\0""5q\0""5q\0" """5q\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317" "\0L\317\0\0\0\0""2\317\0""2\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0" "\0\0\0\0\25\0\0\25\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0L\317\0L\317\0L\317\0L\317" "\0\0\0\0""2\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0e\4\0e\4\0\0\0\0\0\0\0e\11\0e\11\0\0\0\0\0\0\0e\16\0e\16\0\0\0\0\0\0" "\0G\11\0G\11\0\0\0\0\0\0\0G\14\0G\14\0\0\0\0\0\0\0G\17\0G\17\0\0\0\0\0\0" "\0G\21\0G\21\0\0\0\0\0\0\0GK\0GK\0\0\0\0\0\0\0GT\0GT\0\0\0\0\0\0\0G^\0G^" "\0\0\0\0\0\0\0Gg\0Gg\0\0\0\0\0\0\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317" "\0e\317\0e\317\0\0\0\0\0\0\0L\317\0L\317\0L\317\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0e\4\0e\4\0e\4\0\0\0\0e\11\0e\11\0e\11\0\0\0" "\0e\16\0e\16\0e\16\0\0\0\0e\22\0e\22\0G\11\0\0\0\0G\14\0G\14\0G\14\0\0\0" "\0G\17\0G\17\0G\17\0\0\0\0G\21\0G\21\0G\21\0\0\0\0G\24\0G\24\0GK\0\0\0\0" "GT\0GT\0GT\0\0\0\0G^\0G^\0G^\0\0\0\0Gg\0Gg\0Gg\0\0\0\0Gq\0Gq\0e\317\0e\317" "\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0\0\0\0L\317\0L" "\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0e\4\0e\4\0e\4\0\0\0" "\0e\11\0e\11\0e\11\0\0\0\0e\16\0e\16\0e\16\0\0\0\0e\22\0e\22\0e\22\0\0\0" "\0G\14\0G\14\0G\14\0\0\0\0G\17\0G\17\0G\17\0\0\0\0G\21\0G\21\0G\21\0\0\0" "\0G\24\0G\24\0G\24\0\0\0\0GT\0GT\0GT\0\0\0\0G^\0G^\0G^\0\0\0\0Gg\0Gg\0Gg" "\0\0\0\0Gq\0Gq\0Gq\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317" "\0e\317\0e\317\0e\317\0\0\0\0L\317\0L\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0e\4\0e\4\0e\4\0\0\0\0b\10\0b\10\0b\10\0\0\0\0b\15\0b\15\0b\15\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0<\16\0<\16\0<\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0""2J\0""2J\0""2J\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0e\317\0e\317\0e\317\0e" "\317\0\0\0\0L\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0c\0\0c\0\0\0\0\0" "`\0\0c\0\0c\0\0\2\0\0c\1\0i\0\0i\0\0\0\0\0\0\0\0e\0\0e\0\0\0\0\0\0\0\0{\1" "\0{\1\0f\0\0f\0\0z\1\0z\1\0z\1\0z\1\0)\4\0)\4\0\0\0\0\0\0\0Q\7\0Q\7\0\0\0" "\0\0\0\0{&\0{&\0W\32\0W\32\0z&\0z&\0z&\0z&\0IC\0IC\0\0\0\0\0\0\0X^\0X^\0" "\0\0\0\0\0\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0" "\261\251\0\261\251\0\0\0\0\0\0\0e\317\0e\317\0e\317\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\216\1\0c\0\0`\0\0\2\0\0c\0\0c\0\0c\0\0\12\0\0k\1\0i\0\0" "\0\0\0\11\0\0i\0\0i\0\0\0\0\0\256\2\0\256\2\0{\1\0f\0\0z\1\0z\1\0z\1\0z\1" "\0\221\1\0\221\1\0\221\17\0\0\0\0)\4\0c\11\0c\11\0\0\0\0\256+\0\256+\0{&" "\0W\32\0z&\0z&\0z&\0z&\0\2415\0\2415\0\243\210\0\0\0\0IC\0{|\0{|\0\0\0\0" "\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261" "\251\0\261\251\0\261\251\0\264\360\0\264\360\0\0\0\0e\317\0e\317\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0\216\1\0`\0\0\2\0\0c\0\0c\0\0c\0\0\12\0\0" "k\1\0k\1\0\0\0\0\11\0\0i\0\0i\0\0\0\0\0\256\2\0\256\2\0\256\2\0f\0\0z\1\0" "z\1\0z\1\0z\1\0\221\1\0\221\1\0\221\1\0\0\0\0\221\17\0\221\17\0)\4\0\0\0" "\0\256+\0\256+\0\256+\0W\32\0z&\0z&\0z&\0z&\0\2415\0\2415\0\2415\0\0\0\0" "\243\210\0\243\210\0IC\0\0\0\0\261\251\0\261\251\0\261\251\0\261\251\0\261" "\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\264\360" "\0\264\360\0\264\360\0\0\0\0e\317\0e\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1" "\0\211\1\0c\0\0\2\0\0c\0\0c\0\0k\0\0\12\0\0k\1\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\360\0\264\360" "\0\264\360\0\264\360\0\0\0\0e\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\211\1\0\216\1" "\0c\0\0\2\0\0c\0\0k\0\0q\0\0\20\0\0\0\0\0\0\0\0\322\1\0\322\1\0\322\1\0\322" "\1\0\346\1\0\346\1\0\0\0\0\0\0\0\322\2\0\322\2\0\322\2\0\322\2\0\363\2\0" "\363\2\0\0\0\0\0\0\0\322!\0\322!\0\322!\0\322!\0\371(\0\371(\0\0\0\0\0\0" "\0\322+\0\322+\0\322+\0\322+\0\3719\0\3719\0\0\0\0\0\0\0\325\215\0\325\215" "\0\325\215\0\325\215\0\374\264\0\374\264\0\0\0\0\0\0\0\325\251\0\325\251" "\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\0\0\0\0\0" "\0\264\360\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\211\1\0\216" "\1\0c\0\0\2\0\0f\0\0m\0\0m\0\0\0\0\0\325\3\0\325\3\0\322\1\0\322\1\0\346" "\1\0\346\1\0\346\1\0\0\0\0\322\2\0\322\2\0\322\2\0\322\2\0\363\2\0\363\2" "\0\363\2\0\0\0\0\322\3\0\322\3\0\322!\0\322!\0\371(\0\371(\0\371(\0\0\0\0" "\322+\0\322+\0\322+\0\322+\0\3719\0\3719\0\3719\0\0\0\0\3227\0\3227\0\325" "\215\0\325\215\0\374\264\0\374\264\0\374\264\0\0\0\0\325\251\0\325\251\0" "\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325" "\251\0\330\360\0\330\360\0\0\0\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\216\1\0\216\1\0c\0\0\10\0\0m\0\0m\0\0\0\0\0\325\3\0\325\3\0\325" "\3\0\322\1\0\346\1\0\346\1\0\346\1\0\0\0\0\322\2\0\322\2\0\322\2\0\322\2" "\0\363\2\0\363\2\0\363\2\0\0\0\0\322\3\0\322\3\0\322\3\0\322!\0\371(\0\371" "(\0\371(\0\0\0\0\322+\0\322+\0\322+\0\322+\0\3719\0\3719\0\3719\0\0\0\0\322" "7\0\3227\0\3227\0\325\215\0\374\264\0\374\264\0\374\264\0\0\0\0\325\251\0" "\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325" "\251\0\325\251\0\325\251\0\330\360\0\330\360\0\330\360\0\0\0\0\264\360\0" "\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0\216\1\0i\0\0\10\0\0m\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\275\1\0\275\1\0\275\1\0" "\275\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\244!\0\244!\0\244!\0\244!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\213n\0\213n\0\213n\0\213n\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\360\0\330\360\0\330\360\0\330" "\360\0\0\0\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0\224\1\0i\0\0\10\0" "\0\0\0\0\0\0\0\325\3\0\325\3\0\325\3\0\351\3\0\365\1\0\365\1\0\14\0\0\313" "\2\0#\2\0#\2\0\0\0\0\0\0\0\371\37\0\371\37\0\0\0\0\0\0\0\371\37\0\371\37" "\0\371\37\0\371\37\0.\17\0.\17\0#\14\0\304-\0Y!\0Y!\0\0\0\0\0\0\0\371p\0" "\371p\0\0\0\0\0\0\0\371p\0\371p\0\371p\0\371p\0O>\0O>\0""3(\0\247\227\0\211" "s\0\211s\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\330\360\0\330\360\0\330\360\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\224\1\0i\0\0\0\0\0\0\0\0\325\3\0\325" "\3\0\325\3\0\17\2\0\"\2\0!\0\0\35\0\0#\2\0\342\4\0\342\4\0\0\0\0\371\37\0" "\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0\3775" "\0\374%\0\304\34\0Y!\0\373C\0\373C\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371" "p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0\247q\0\211s\0\375" "\342\0\375\342\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0" "\0\0\330\360\0\330\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\12\0\0\224\1\0\0\0" "\0\0\0\0\325\3\0\325\3\0\325\3\0\344\5\0\"\2\0\"\2\0\200\0\0#\2\0\342\4\0" "\342\4\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37" "\0\371\37\0\3775\0\3775\0\3775\0\304\34\0\3732\0\3732\0Y!\0\0\0\0\371p\0" "\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377" "\256\0\247q\0\375\274\0\375\274\0\211s\0\0\0\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\330\360\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\12\0\0\0\0\0i\0\0\0\0\0\325\3\0\325\3\0\344\5\0\344\5" "\0\"\2\0\36\1\0""4\2\0#\2\0\342\4\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0" "\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0\3775\0\3775\0\307)\0\3732\0" "\3732\0\3732\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371" "p\0\377\256\0\377\256\0\377\256\0\247q\0\375\274\0\375\274\0\375\274\0\0" "\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\0\0\0\330\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\12\0\0" "\10\0\0\0\0\0\325\3\0\344\5\0\344\5\0\344\5\0\340\4\0\367\11\0\364\3\0#\2" "\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371" "\37\0\3775\0\3775\0\3775\0\307)\0\376G\0\3732\0\3732\0\0\0\0\371p\0\371p" "\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0" "\247q\0\375\274\0\375\274\0\375\274\0\0\0\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\12\0\0\10\0\0\0\0\0\0\0\0\17\2\0\17" "\2\0\17\2\0\323\2\0\352\7\0\347\2\0\26\1\0\0\0\0\371\37\0\371\37\0\371\37" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0/\26\0\0\0\0""7\36\0""6\25\0" """6\25\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0O>\0O>\0" "O>\0\0\0\0VK\0VK\0VK\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0" "\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0" "\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\12\0" "\0\10\0\0\0\0\0\17\2\0\17\2\0\344\5\0\15\1\0\352\7\0\352\7\0\347\2\0\0\0" "\0\371\37\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\362\4\0\0\0\0/\26\0/\26\0" "\3775\0$\21\0""7\36\0""7\36\0\3672\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\0\0" "\0\0\0\0\370A\0\0\0\0O>\0O>\0\377\256\0""3(\0VK\0VK\0\372\264\0\0\0\0\374" "\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\341\271\0\0\0\0\374\360" "\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\343\350\0\0\0\0\374\360\0\374" "\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\5\0\0\10\0\0\0\0" "\0\17\2\0\17\2\0\17\2\0\15\1\0\352\7\0\352\7\0\347\2\0\0\0\0\371\37\0\371" "\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0/\26\0$\21\0""7\36" "\0""7\36\0""6\25\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0O>\0O>\0O>\0""3(\0VK\0VK\0VK\0\0\0\0\374\360\0\374\360\0\374\360\0\374" "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0" "\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\5\0\0\5\0\0\5\0\0\0\0\0\344\5\0\344\5\0\344\5\0\316\4\0\367" "\11\0\367\11\0\364\3\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371" "\37\0\371\37\0\371\37\0\3775\0\3775\0\3775\0\307)\0\376G\0\376G\0\3732\0" "\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377" "\256\0\377\256\0\247q\0\375\274\0\375\274\0\375\274\0\0\0\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5" "\0\0\5\0\0\5\0\0\17\2\0\344\5\0\344\5\0\316\4\0\345\11\0\367\11\0\364\3\0" "\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37" "\0\3775\0\3775\0\3775\0\307)\0\376G\0\376G\0\3732\0\0\0\0\371p\0\371p\0\371" "p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0\247q" "\0\375\274\0\375\274\0\375\274\0\0\0\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\5\0\0\0\0\0\17\2" "\0\344\5\0\344\5\0\15\1\0$\6\0$\6\0#\2\0\0\0\0\371\37\0\371\37\0\371\37\0" "\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0/\26\0/\26\0\307)\0\376" "G\0[/\0Y!\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0" "\377\256\0O>\0O>\0\247q\0\375\274\0\211s\0\211s\0\0\0\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0" "\5\0\0\17\2\0\17\2\0\344\5\0\316\4\0$\6\0$\6\0#\2\0\0\0\0\371\37\0\371\37" "\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0/\26\0/\26\0" "\307)\0\376G\0[/\0Y!\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371" "p\0\371p\0\377\256\0O>\0O>\0\247q\0\375\274\0\211s\0\211s\0\0\0\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\5\0\0\24\2\0\17\2\0\17\2\0\316\4\0\345\11\0$\6\0#\2\0\0\0\0\371" "\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0" "\3775\0\3775\0\307)\0\376G\0\376G\0\3732\0\0\0\0\371p\0\371p\0\371p\0\0\0" "\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0\247q\0\375\274" "\0\375\274\0\375\274\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0" "\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\24\2\0\24" "\2\0\17\2\0\316\4\0\345\11\0\342\3\0#\2\0\0\0\0\371\37\0\371\37\0\371\37" "\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0\3775\0\3775\0\307)\0" "\376G\0\3732\0\3732\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371" "p\0\371p\0\377\256\0\377\256\0\377\256\0\247q\0\375\274\0\375\274\0\375\274" "\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\17\2\0\24\2\0\5\0\0\0\0\0\27\5\0\342\3\0\313" "\1\0\0\0\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\371\37\0\0\0\0\0\0\0/\26\0" "\3775\0\371\37\0\302\30\0\3716\0Y!\0#\14\0\0\0\0\371p\0\371p\0\0\0\0\0\0" "\0\0\0\0\371p\0\0\0\0\0\0\0O>\0\377\256\0\371p\0\243I\0\371\224\0\211s\0" """3(\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374" "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0" "\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\17\2\0\17\2\0\0\0\0\0\0\0\26\1\0\26\1\0\0\0\0\0\0\0\371" "\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0\0\0\0\0\0" "\0""6\25\0""6\25\0\0\0\0\0\0\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0O>\0O>\0\0\0\0\0\0\0VK\0VK\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374" "\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\17\2\0\17\2\0\0\0\0\0\0\0\26\1\0\26\1\0\0\0\0\0\0" "\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0\0\0" "\0\0\0\0""6\25\0""6\25\0\0\0\0\0\0\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0O>\0O>\0\0\0\0\0\0\0VK\0VK\0\0\0\0\0\0\0\374\360\0\374\360" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0" "\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\17\2\0\17\2\0\16\0\0\0\0\0\26\1\0\26\1\0\26" "\1\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0" "/\26\0.\17\0\0\0\0""6\25\0""6\25\0""6\25\0\0\0\0\371p\0\371p\0\371p\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0O>\0O>\0O>\0\0\0\0VK\0VK\0VK\0\0\0\0\374\360\0" "\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360" "\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\16\0\0\16\0\0\14\0\0\14" "\0\0#\2\0#\2\0\0\0\0\0\0\0\371\37\0\371\37\0\0\0\0\0\0\0\371\37\0\371\37" "\0\371\37\0\371\37\0.\17\0.\17\0#\14\0#\14\0Y!\0Y!\0\0\0\0\0\0\0\371p\0\371" "p\0\0\0\0\0\0\0\371p\0\371p\0\371p\0\371p\0O>\0O>\0""3(\0""3(\0\211s\0\211" "s\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360" "\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; /** * \brief Returns the BlitBlendAll test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageBlitBlendAll() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageBlitBlendAll.pixel_data, SDLTest_imageBlitBlendAll.width, SDLTest_imageBlitBlendAll.height, SDLTest_imageBlitBlendAll.bytes_per_pixel * 8, SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_imageBlitBlend.c
C
apache-2.0
212,200
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include "SDL_test.h" /* GIMP RGBA C-Source image dump (face.c) */ static const SDLTest_SurfaceImage_t SDLTest_imageFace = { 32, 32, 4, "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0" "\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0" "\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\0\0\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377" "\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\0\0\0\377\0\0\0\377\377\377\377\0\0\0\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0" "\377\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0" "\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0" "\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0" "\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377" "\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0" "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377" "\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0" "\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377" "\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0" "\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0" "\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\0\0\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0" "\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377" "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0" "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0", }; /** * \brief Returns the Face test image as SDL_Surface. */ SDL_Surface *SDLTest_ImageFace() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imageFace.pixel_data, SDLTest_imageFace.width, SDLTest_imageFace.height, SDLTest_imageFace.bytes_per_pixel * 8, SDLTest_imageFace.width * SDLTest_imageFace.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_imageFace.c
C
apache-2.0
16,758
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include "SDL_test.h" /* GIMP RGB C-Source image dump (primitives.c) */ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = { 80, 60, 3, "\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15" "I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310" "\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0" "\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0" "\0\5ii\0\0\0\5ii\0\0\0\3\1\1\0\0\0\5\2\1\0\0\0\7\3\2\0\0\0\11\4\3\0\0\0\13" "\5\3\0\0\0\15\6\4\0\0\0\17\7\5\0\0\0\21\10\5\0\0\0\23\11\6\0\0\0\25\12\7" "\0\0\0\27\13\7\0\0\0\31\14\10\0\0\0\33\15\11\0\0\0\35\16\11\0\0\0\37\17\12" "\0\0\0!\20\13\0\0\0#\21\13\0\0\0%\22\14\0\0\0'\23\15\15I\310)\24\15\15I\310" "+\25\16\15I\310-\26\17\15I\310/\27\17\15I\3101\30\20\15I\3103\31\21\15I\310" "5\32\21\15I\3107\33\22\15I\3109\34\23\15I\310;\35\23\15I\310=\36\24\15I\310" "?\37\25\15I\310A\40\25\15I\310C!\26\15I\310E\"\27\15I\310G#\27\15I\310I$" "\30\15I\310K%\31\15I\310M&\31\5iiO'\32\0\0\0\0\0\0\5ii\0\0\0\10\4\2\0\0\0" "\14\6\4\0\0\0\20\10\5\0\0\0\24\12\6\0\0\0\30\14\10\0\0\0\34\16\11\0\0\0\40" "\20\12\0\0\0$\22\14\0\0\0(\24\15\0\0\0,\26\16\0\0\0""0\30\20\0\0\0""4\32" "\21\0\0\0""8\34\22\0\0\0<\36\24\0\0\0@\40\25\0\0\0D\"\26\0\0\0H$\30\0\0\0" "L&\31\0\0\0P(\32\15I\310T*\34\15I\310X,\35\15I\310\\.\36\15I\310`0\40\15" "I\310d2!\15I\310h4\"\15I\310l6$\15I\310p8%\15I\310t:&\15I\310x<(\15I\310" "|>)\15I\310\200@*\15I\310\204B,\15I\310\210D-\15I\310\214F.\15I\310\220H" "0\15I\310\224J1\15I\310\230L2\5ii\234N4\15I\310\0\0\0\0\0\0\0\0\0\5ii\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii" "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d" "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\5ii\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\5ii\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d" "\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\5ii\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310" "\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d" "\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d" "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5" "ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d" "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d" "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0" "\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0" "\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0" "\0\377\0\0\377\0\0\377\0\0\377\0\5ii\0\377\0\0\377\0\0\377\0\0\377\0\0\377" "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0""77\5\0\377\0\0\377\0\0\377\0" "\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\5ii\0\377\0\0\377\0\0\377" "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377" "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377" "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5" "ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d" "\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5i" "i\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310" "\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310" "\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\5ii\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310" "\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\5ii\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\5ii\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15" "I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d7" "7\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0" "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310" "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310" "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310" "\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5" "ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310" "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\0\0\0\0" "\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\5ii\15I\310\15I\310\15I\310\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii" "\15I\310\15I\310\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\5ii\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I" "\310\15I\310\15I\310\15I\310\15I\310\5ii", }; /** * \brief Returns the Primitives test image as SDL_Surface. */ SDL_Surface *SDLTest_ImagePrimitives() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imagePrimitives.pixel_data, SDLTest_imagePrimitives.width, SDLTest_imagePrimitives.height, SDLTest_imagePrimitives.bytes_per_pixel * 8, SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_imagePrimitives.c
C
apache-2.0
37,445
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include "SDL_test.h" /* GIMP RGB C-Source image dump (alpha.c) */ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = { 80, 60, 3, "\260e\15\222\356/\37\313\15\36\330\17K\3745D\3471\0\20\0D\3502D\3502<\321" ",\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0-\0\377\377" "\377\377\377\377\311\324\311\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\0H\0\377\377\377\377\377\377\256\307\256\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\0c\0\377\377\377\377\377\377" "\223\300\223\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\0~\0\377\377\377\377\377\377x\277x\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\0\231\0\377\377\377\377\377\377]\303]\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\0\264\0\377\377\377\377\377" "\377B\316B\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0" "\317\0\377\377\377\377\377\377'\335'\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\0\352\0\377\377\377#\262\6\260d\15\260e\15\224\357" "/&\262\6\34\300\5.\314\22\40\315\12[\3747M\332/\27\331\12\27\331\12K\374" "5K\3745K\3745D\3471D\3471D\3471D\3471D\3471D\3502D\3502D\3502D\3502D\350" "2D\3502D\3502D\3502D\3502D\3502\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377,\372\27\273\3465\327" "Q.\260d\15\213\213\40\241\3601\200\366*=\265\13?\301\25s\375<Y\316-X\320" "-!\315\13]\3749]\3749O\3321O\3321P\3342P\3342P\3342\371\377\364\371\377\364" "\371\377\364\371\377\364\371\377\364\362\375\360\362\375\360\362\375\360" "\362\375\360\362\375\360D\3471D\3471D\3471D\3502D\3502D\3502D\3502D\3502" "D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "K\3745&\262\6\213\213\40\11\2\0\260`\15\241~#m}\11\273\363AQ\247\15S\266" "\31\212\373@e\302,\4\33\2s\375<\\\3161M\260*\\\3202X\320-\366\377\354\364" "\377\352O\3321\3""5\2O\3321O\3321<\261&P\3342P\3342S\3655\377\377\377\377" "\377\377\14Z\14\377\377\377\377\377\377\234\302\231\371\377\364\362\375\360" "\367\377\365\362\375\360\362\375\360\13t\13\362\375\360\362\375\360\177\275" "~\362\375\360\362\375\360\370\377\366\362\375\360\377\377\377\14\220\14\377" "\377\377D\3502\"\267\33D\3502D\3502K\3779D\3502D\3502\3\233\2D\3502D\350" "2\34\303\26D\3502D\3502L\377:D\3502D\3502\3\264\2D\3502D\3502\25\323\22\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\14\341\14\377\377" "\377\377\377\377\40\353\40\377\377\377D\3471\34\300\5e\247\33\356\336?\277" "f)\260P\17\260i\16\356\336?\331\353C\274\363GQ\247\15\243\370Cp\270)\212" "\373@h\3021h\3042c\304+\364\377\336\\\3161\\\3161\\\3202\\\3202\\\3202\377" "\377\377\364\377\352\364\377\352\346\371\342\346\371\342O\3321O\3321P\334" "2P\3342P\3342P\3342P\3342P\3342\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\362\375\360\362\375\360\362\375\360\362\375\360\362\375" "\360\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360\362\375" "\360\362\375\360\362\375\360\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502\40" "\315\12=\265\13f\230\14\237y\15\274Y\17\327Q.\260X\14\243\177$\220\214\"" "\215\235*\274\363G\177\252+\243\370Cu\2661p\270)\367\377\324h\3021h\3021" "h\3042\364\377\336\364\377\336\335\364\323\\\3161\\\3161\\\3202\\\3202\\" "\3202\377\377\377\377\377\377\364\377\352\364\377\352\346\371\342\346\371" "\342\346\371\342\346\371\342O\3321P\3342P\3342P\3342P\3342P\3342P\3342P\334" "2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\362\375\360\362\375\360" "\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360" "\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\6\0\4[\3747?\301\25N\241\14\331\353C\243\177$\275Z\21\377\254W\260Q\17\30" "\26\7\370\343N\201\210\16|\213-\274\363G\200\2521\202\263+\243\370Cu\266" "1\12&\4\367\377\324h\3021S\241)h\3042h\3042\377\377\377\364\377\336\335\364" "\323\24M\23\\\3161\\\3202C\245(\\\3202\\\3202\377\377\377\377\377\377\377" "\377\377\30l\30\346\371\342\346\371\342\207\273\205\346\371\342\346\371\342" "\361\377\355\377\377\377P\3342\7t\4P\3342P\3342/\260\"P\3342P\3342^\377@" "\377\377\377\377\377\377\30\242\30\377\377\377\377\377\377d\306d\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\30\275\30\377\377\377" "\377\377\377K\322K\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\30\330\30\362\375\360\362\375\3601\3431\362\375\360\362\375\360\377" "\377\377\362\375\360D\3502M\332/s\375<>\265\14\177\252+\201\210\16\245\204" "*\377\314U\312\\,\224'\11\260i\17\244\210\40\232\2211\331\353J\215\2351\377" "\377\276\200\2521\200\2542\375\377\310u\2661t\2702t\2702\367\377\324\325" "\355\305h\3021h\3042h\3042\377\377\377\377\377\377\364\377\336\335\364\323" "\335\364\323\335\364\323\\\3202\\\3202\\\3202\\\3202\\\3202\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\346\371\342\346\371\342\346" "\371\342\346\371\342\346\371\342\346\371\342\346\371\342\377\377\377\377" "\377\377P\3342P\3342P\3342P\3342P\3342P\3342P\3342P\3342\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\27\331\12Y\316-h\3021\243\370Cg\230\15\230\224\"\245" "\204*\377\314U\310J\21\327Q.\260b\21\245\2041\370\343N\230\2242\331\353J" "\214\2402\377\377\276\200\2521\200\2542\375\377\310\317\344\266u\2661t\270" "2\377\377\377\367\377\324\325\355\305h\3021h\3042h\3042h\3042\377\377\377" "\377\377\377\364\377\336\335\364\323\335\364\323\335\364\323\335\364\323" "\\\3202\\\3202\\\3202\\\3202\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\346\371\342\346\371" "\342\346\371\342\346\371\342\346\371\342\346\371\342\377\377\377\377\377" "\377\377\377\377\377\377\377P\3342P\3342P\3342P\3342P\3342P\3342P\3342P\334" "2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377K\3745!\315\13d\304,p\270)\177\252+\23\13\6\232\2211\245\204" "1\347\270O\377\277Y\324<\22\265V\24\377\330Q\244\210\40#(\13\230\224\"\331" "\353Ju\211.\377\377\276\200\2521\210\273:\200\2542\375\377\310\20""3\6u\266" "1t\2702\271\307\271\367\377\324\325\355\305\341\377\321h\3021h\3042\16L\7" "h\3042\377\377\377\242\300\242\377\377\377\335\364\323\355\377\343\335\364" "\323\335\364\323\14f\7\\\3202\\\3202>\250*\\\3202\377\377\377\377\377\377" "\377\377\377\377\377\377$\231$\377\377\377\377\377\377s\303s\377\377\377" "\346\371\342\376\377\372\346\371\342\346\371\342\40\257\37\346\371\342\346" "\371\342\\\316\\\377\377\377\377\377\377\377\377\377\377\377\377P\3342\13" "\262\7P\3342P\3342*\327%P\3342P\3342o\377Q\377\377\377\377\377\377$\352$" "\377\377\377\377\377\377K\3745]\3749s\375<\212\373@\243\370C\274\363G\331" "\353J\370\343N\377\330Q\377\314U\377\277Y\377\260\\\224(\11\260|\36\245\204" "1\377\377\250\232\2211\230\224\"\215\2351\214\2402\377\377\276\312\332\250" "\200\2521\200\2542\377\377\377\317\344\266u\2661t\2702t\2702\377\377\377" "\377\377\377\325\355\305\325\355\305\325\355\305h\3042h\3042h\3042\377\377" "\377\377\377\377\377\377\377\377\377\377\335\364\323\335\364\323\335\364" "\323\335\364\323\335\364\323\\\3202\\\3202\\\3202\\\3202\\\3202\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\346\371\342\346\371\342" "\346\371\342\346\371\342\346\371\342\346\371\342\346\371\342\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377P\3342P\3342" "P\3342P\3342\377\377\377K\3745O\3321\\\3161h\3021t\2702~\254'\214\240%\377" "\377\262\370\343N\377\330Q\262x1\277l1\312`1\327R.\260X\23\377\330Q\244\210" "2\377\377\250\230\2242\377\377\262\215\2351\214\2402\377\377\377\312\332" "\250\200\2521\200\2542\377\377\377\375\377\310\317\344\266u\2661t\2702t\270" "2\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305h\3042h\304" "2h\3042h\3042\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\335\364\323\335\364\323\335\364\323\335\364\323\377\377\377\\\3202\\\320" "2\\\3202\\\3202\\\3202\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\346\371\342\346\371\342\346\371\342\346" "\371\342\346\371\342\346\371\342\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377D\3471O\3321\21\7\11c\304+\367\377\324o\2520\200\252" "1\214\2402\235\226'\377\377\250\377\330Q!\20\11\277l1\310d2\266?\33\224(" "\11\260|\36\257\217;\377\377\250\232\2211\34$\11\377\377\262\215\2351q\206" "0\377\377\377\312\332\250\217\303@\200\2542\200\25420Z0\317\344\266\317\344" "\266X\2260t\2702t\2702\377\377\377\377\377\377\325\355\305(l%\325\355\305" "\325\355\305K\2410h\3042h\3042\377\377\377\377\377\377\377\377\3770\2200" "\377\377\377\377\377\377t\274p\335\364\323\335\364\323\373\377\361\377\377" "\377\377\377\377\21\213\11\\\3202\\\3202<\274/\\\3202\377\377\377\377\377" "\377\377\377\377\377\377\3770\3060\377\377\377\377\377\377V\330V\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\3770\3410\346\371\342\346" "\371\342>\352>\346\371\342\377\377\377D\3471P\3342\364\377\352s\375<h\302" "1t\2702~\254'\377\377\276\215\2351\230\2242\244\210\40\377\377\234\262x1" "\277l1\310W\32\377\260\\\327T1\260|2\377\330Q\244\2102\377\377\250\232\221" "1\230\2242\377\377\262\215\2351\214\2402\377\377\377\377\377\276\312\332" "\250\200\2542\200\2542\377\377\377\375\377\310\317\344\266\317\344\266t\270" "2t\2702t\2702\377\377\377\377\377\377\377\377\377\325\355\305\325\355\305" "\325\355\305h\3042h\3042h\3042h\3042\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\335\364\323\335\364\323\335\364\323" "\335\364\323\335\364\323\377\377\377\377\377\377\\\3202\\\3202\\\3202\\\320" "2\\\3202\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377D\3471P\3342\364\377\352\\\3161h\3042\367" "\377\324u\2661\200\2542\214\240%\377\377\262\232\2211\244\2102\377\377\234" "\262x1\274p2\377\337\207\377\260\\\327T1\227/\14\377\377\234\245\2041\244" "\2102\307\300\213\230\2242\377\377\377\377\377\262\215\2351\214\2402\377" "\377\377\377\377\276\312\332\250\200\2542\200\2542\377\377\377\377\377\377" "\317\344\266\317\344\266\317\344\266t\2702t\2702\377\377\377\377\377\377" "\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305\377\377\377" "h\3042h\3042h\3042h\3042\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\335\364\323\335\364\323\335\364\323" "\335\364\323\377\377\377\377\377\377\377\377\377\\\3202\\\3202\\\3202\\\320" "2\\\3202\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377<\0<D\3502\371\377\364N\3221\\\3202\364\377" "\336l\3035t\2702\375\377\310\36\22\13\214\2402\377\377\262\214\2012\244\210" "2\377\377\234\274\177;\274p2\377\337\207/\24\13\324X2\227/\14\222l3\307\260" "|\244\2102\377\377\270\232\2211\230\2242<Q<\310\316\231\215\2351o\2065\377" "\377\377\377\377\276\341\377\277\200\2521\200\2542\36H\13\377\377\377\377" "\377\377\213\260}\317\344\266t\2702\221\366Ot\2702\377\377\377<\207<\377" "\377\377\377\377\377}\270v\325\355\305\325\355\305\371\377\351\377\377\377" "h\3042\30|\13h\3042\377\377\377|\306|\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377<\275<\335\364\323\335\364\323_\317]\335\364\323" "\335\364\323\377\377\377\377\377\377\377\377\377\25\260\13\\\3202\\\3202" ">\3369\\\3202\377\377\377\377\377\377\377\377\377\377\377\377D\3502\371\377" "\364O\3321\\\3202\364\377\336h\3042\367\377\324u\2661\200\2542\377\377\276" "\215\2351\230\2242\307\300\213\244\2102\377\377\234\262x1\274p2\377\337\207" "\312`1\324E\30\327T1\260|2\377\377\234\245\2041\244\2102\377\377\250\232" "\2211\230\2242\377\377\377\310\316\231\215\2351\214\2402\377\377\377\377" "\377\377\312\332\250\312\332\250\200\2542\200\2542\377\377\377\377\377\377" "\317\344\266\317\344\266\317\344\266t\2702t\2702t\2702\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\325\355\305\325\355\305\325\355" "\305\377\377\377h\3042h\3042h\3042h\3042\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\335\364\323\335\364\323\335\364\323\335\364\323\377\377\377\377\377" "\377\377\377\377\377\377\377\\\3202\\\3202\\\3202\377\377\377D\3502\371\377" "\364O\3321\377\377\377\\\3161h\3042\367\377\324t\2702\375\377\310\200\252" "1\377\377\377\215\2351\230\2242\377\377\250\244\2102\377\377\234\262x1\274" "p2\316\214_\310d2\377\310|\327T1\227/\14\377\377\377\307\260|\244\2102\377" "\377\377\307\300\213\230\2242\230\2242\377\377\377\310\316\231\214\2402\214" "\2402\377\377\377\377\377\377\312\332\250\312\332\250\200\2542\200\2542\377" "\377\377\377\377\377\377\377\377\317\344\266\317\344\266\317\344\266t\270" "2t\2702t\2702\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\325\355\305\325\355\305\325\355\305\377\377\377\377\377\377h\3042h\3042" "h\3042\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\335\364\323\335\364" "\323\335\364\323\335\364\323\377\377\377\377\377\377\377\377\377\377\377" "\377D\3502\371\377\364R\3344\364\377\352\\\3161H\22Hh\3021\377\377\377o\244" "2\200\2542\312\332\250\226\245<\377\377\262\230\2242H-/\245\2041\377\377" "\377\233i5\274p2\277l1\331sC\377\310|\324X2*\15\3\260|2\377\377\234\206s" "7\244\2102\377\377\250\340\337\244\230\2242\377\377\377Hc2\310\316\231\214" "\2402n\211:\377\377\377\377\377\377\353\377\311\312\332\250\200\2542$T\16" "\377\377\377\377\377\377\236\277\236\377\377\377\317\344\266\367\377\336" "\377\377\377t\2702\40n\16t\2702\377\377\377\212\303\212\377\377\377\377\377" "\377\377\377\377\325\355\305\325\355\305<\2477\377\377\377\377\377\377O\276" "Ah\3042h\3042\237\377i\377\377\377\377\377\377H\317H\377\377\377\377\377" "\377c\335c\377\377\377\377\377\377\377\377\377\377\377\377\335\364\323>\337" ";\335\364\323\377\377\377D\3502\362\375\360P\3342\346\371\342\\\3202\364" "\377\336h\3042\367\377\324t\2702\375\377\310\200\2542\377\377\276\214\240" "2\377\377\262\232\2211\377\377\377\245\2041\377\377\377\262x1\377\377\377" "\277l1\310d2\312`1\324X2\327T1\260|2\377\377\377\307\260|\244\2102\377\377" "\377\307\300\213\232\2211\230\2242\377\377\377\377\377\262\310\316\231\214" "\2402\214\2402\377\377\377\377\377\377\312\332\250\312\332\250\200\2542\200" "\2542\200\2542\377\377\377\377\377\377\377\377\377\317\344\266\317\344\266" "\317\344\266\377\377\377t\2702t\2702t\2702\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305\325\355" "\305\377\377\377\377\377\377h\3042h\3042h\3042h\3042\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377D\3502\362\375\360P\3342\346\371\342\\\3202\335" "\364\323h\3042\325\355\305t\2702\317\344\266\377\377\377\200\2521\377\377" "\377\215\2351\377\377\377\232\2211\377\377\377\245\2041\377\377\377\262x" "1\377\377\377\277l1\377\377\377\312`1\377\310|\327T1\227/\14\377\377\377" "\307\260|\244\2102\244\2102\377\377\377\307\300\213\230\2242\230\2242\377" "\377\377\310\316\231\310\316\231\214\2402\214\2402\377\377\377\377\377\377" "\312\332\250\312\332\250\377\377\377\200\2542\200\2542\377\377\377\377\377" "\377\377\377\377\377\377\377\317\344\266\317\344\266\377\377\377\377\377" "\377t\2702t\2702\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305\377\377" "\377\377\377\377\377\377\377h\3042h\3042h\3042\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362\375\360" "T\11TO\3321\377\377\377Z\3002\377\377\377h\3042\377\377\334t\2702\375\377" "\310*\30\20\312\332\250\214\2402\262\260\214\230\2242\307\300\213\377\377" "\377\245\2041\377\377\377:\35\20\377\377\377\277l1\316\264w\310d2\377\310" "|\356qL\227/\14\260|2TZ3\307\260|\244\2102\274\302\274\307\300\213\307\300" "\213\273\301U\377\377\377\377\377\377A^2\310\316\231\214\2402o\216B\377\377" "\377\377\377\377\366\377\324\312\332\250\312\332\250*a\20\200\2542\377\377" "\377\230\301\230\377\377\377\377\377\377\377\377\353\317\344\266\317\344" "\266T\253Tt\2702t\2702]\265I\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377T\306T\377\377\377\325\355\305l\324i\325\355\305\377\377" "\377\377\377\377\377\377\377h\3042\"\254\20h\3042h\3042b\353b\377\377\377" "\377\377\377D\3502\362\375\360\377\377\377O\3321\377\377\377\\\3202\364\377" "\336h\3042\325\355\305t\2702\317\344\266\377\377\377\200\2521\377\377\377" "\214\2402\377\377\262\230\2242\307\300\213\244\2102\307\260|\377\377\377" "\262x1\377\377\377\274p2\377\337\207\310d2\377\310|\324X2\333bB\260|2\377" "\377\377\307\260|\244\2102\244\2102\377\377\377\307\300\213\232\2211\230" "\2242\377\377\377\377\377\377\310\316\231\310\316\231\214\2402\214\2402\377" "\377\377\377\377\377\377\377\377\312\332\250\312\332\250\200\2542\200\254" "2\200\2542\377\377\377\377\377\377\377\377\377\377\377\377\317\344\266\317" "\344\266\317\344\266\377\377\377t\2702t\2702t\2702\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\325\355\305" "\325\355\305\325\355\305\325\355\305\377\377\377\377\377\377\377\377\377" "h\3042h\3042\377\377\377\377\377\377D\3471\377\377\377P\3342\364\377\352" "\\\3202\335\364\323\377\377\377h\3021\377\377\377t\2702\375\377\310\200\254" "2\312\332\250\377\377\377\215\2351\377\377\377\230\2242\377\377\250\244\210" "2\307\260|\377\377\377\262x1\377\377\377\274p2\377\337\207\310d2\323xQ\324" "X2\327T1\227/\14\260|2\377\377\234\307\260|\244\2102\377\377\377\377\377" "\377\307\300\213\230\2242\230\2242\377\377\377\377\377\377\310\316\231\310" "\316\231\214\2402\214\2402\377\377\377\377\377\377\377\377\377\312\332\250" "\312\332\250\377\377\377\200\2542\200\2542\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\317\344\266\317\344\266\377\377\377\377\377" "\377t\2702t\2702t\2702\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\325\355\305\325\355\305\325" "\355\305\377\377\377\377\377\377`\0`\377\377\377D\3471\371\366\371P\3342" "\346\371\342\377\377\377\\\3161\377\377\377'\24\22\325\355\305t\2702\276" "\310\251\377\377\377\200\2542\377\377\316\214\2402\310\316\231`6`\230\224" "2\377\377\250\222u<\307\260|\377\377\377\315\214L\377\377\377\274p2M,#\310" "d2\312`1\306\304\306\324X2\333bB\325\242W\377\377\377\307\260|=9\22\244\210" "2\377\377\377\227\234w\307\300\213\230\2242\307\322a\377\377\377\377\377" "\377Km9\310\316\231\214\2402r\226K\377\377\377\377\377\377\377\377\377\312" "\332\250\312\332\250`\242`\200\2542\200\2542\224\306\224\377\377\377\377" "\377\377\377\377\377\377\377\377\317\344\266M\250D\317\344\266\377\377\377" "\203\322\203t\2702t\2702\301\377\177\377\377\377\377\377\377`\330`\377\377" "\377\377\377\377r\344r\377\377\377\377\377\377\377\377\377\325\355\305\377" "\377\377\377\377\377D\3502\371\377\364P\3342\346\371\342\377\377\377\\\320" "2\364\377\336h\3042\325\355\305\377\377\377t\2702\317\344\266\200\2542\312" "\332\250\377\377\377\214\2402\310\316\231\230\2242\307\300\213\377\377\377" "\244\2102\307\260|\377\377\377\200U0\220^\377\7\4/\227U[\246]\377\255Q1\377" "\242y\10\3/\306M@\6\4/{^\377mVvmVv\6\5/h\\\377h\\\377\\U\204\12\12\360\5" "\5/VX\377VX\377\12\12\360LR\221\12\12\360\5\6/\214\2402\377\377\377\377\377" "\377\377\377\377\312\332\250\312\332\250\377\377\377\200\2542\200\2542\200" "\2542\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\317\344" "\266\317\344\266\317\344\266\377\377\377\377\377\377t\2702t\2702\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377D\3502\362\375\360P\3342\346\371" "\342\377\377\377\\\3202\335\364\323\377\377\377h\3042\367\377\324t\2702\317" "\344\266\377\377\377\200\2542\312\332\250\377\377\377\214\2402\377\377\262" "\230\2242\307\300\213\377\377\377\244\2102\307\260|{^\377\200U0\220^\377" "\7\4/\227U[\246]\377\7\3/\377\242y\236\37""2\306M0\210%\14T-2{^\377mVv\6" "\5/\6\5/h\\\377\\U\204\\U\204\5\5/\5\5/VX\377VX\377LR\221LR\221\377\377\377" "\214\2402\214\2402\377\377\377\377\377\377\377\377\377\312\332\250\312\332" "\250\312\332\250\377\377\377\200\2542\200\2542\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\317\344\266\317\344\266\377" "\377\377\377\377\377t\2702t\2702t\2702\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377D\3502\365\375\363\377\377" "\377O\3321l\22l\\\3202\335\364\323\357\346\357h\3042\325\355\305\377\377" "\377t\2702\317\344\266l-l\200\2521\377\377\377\204\211=\310\316\231\377\377" "\377\262\243L\307\300\213\377\377\377E&\25mVv{^\377ySB\220^\377\7\4/\275" "t\201\246]\377\7\3/I\37!\277Z\377\10\3/\237YQ\6\4/{^\377\236\213\247mVv\6" "\5/,-lh\\\377\\U\204dow\5\5/\5\5/\222\251\377VX\377\310\316\231T{@\377\377" "\377\214\2402w\240V\377\377\377\377\377\377\377\377\377\377\377\377\312\332" "\250U\231G\377\377\377\200\2542q\270\\\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377l\317l\317\344\266\317\344\266z\330v\377\377\377" "\377\377\377\323\377\221t\2702t\2702l\352l\377\377\377\377\377\377\377\377" "\377D\3502\362\375\360\377\377\377P\3342\346\371\342\377\377\377\\\3202\364" "\377\336h\3042\325\355\305\377\377\377t\2702\317\344\266\377\377\377\200" "\2542\312\332\250\377\377\377\214\2402\310\316\231\377\377\377\230\2242\307" "\300\213\377\377\377\6\5/mVv{^\377\200U0\220^\377\7\4/\227U[\246]\377\7\3" "/\255RN\277Z\377\10\3/\306M@\6\4/{^\377{^\377mVv\6\5/\6\5/h\\\377h\\\377" "\\U\204\12\12\360\5\5/\12\12\360\377\377\377\377\377\377\310\316\231\310" "\316\231\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377\377\377" "\377\377\377\312\332\250\312\332\250\377\377\377\200\2542\200\2542\200\254" "2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\317\344\266\317\344\266\317\344\266\377\377\377\377\377\377t\2702t\2702" "\377\377\377\377\377\377D\3502\362\375\360\377\377\377P\3342\346\371\342" "\377\377\377\\\3202\335\364\323\377\377\377h\3042\325\355\305\377\377\377" "t\2702\317\344\266\377\377\377\200\2542\312\332\250\377\377\377\214\2402" "\310\316\231\377\377\377\230\2242\307\300\213h\\\377\6\5/mVv{^\377\200U0" "\220^\377\7\4/\227U[\246]\377\7\3/\255RN\277Z\377\10\3/\306M@\6\4/\6\4/{" "^\377mVvmVv\6\5/\12\12\360h\\\377\\U\204\\U\204\5\5/\230\2242\377\377\377" "\377\377\377\377\377\377\310\316\231\310\316\231\377\377\377\214\2402\214" "\2402\377\377\377\377\377\377\377\377\377\377\377\377\312\332\250\312\332" "\250\377\377\377\377\377\377\200\2542\200\2542\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\317\344\266\317" "\344\266\377\377\377\377\377\377\377\377\377\377\377\377D\3502q\10p\377\377" "\377P\3342\335\350\332\377\377\377\\\3202\351\366\337\377\377\377h\3042d" "!\\\377\377\377t\2702\277\302\252\377\377\377\200\2542\343\345\301\377\377" "\377\214\2402^2H\377\377\377\230\2242\257\235\204h\\\377\6\5/\223o\234{^" "\377\6\4/<\36""1\377\252\215j)2\211XK\377\250\203\202$2\337~c\377\242y\236" "\37""2]#\26\306M@\6\4/ym\274{^\377mVvELn\6\5/h\\\37703x\\U\204\307\300\213" "\204\226\\\230\2242\377\377\377\377\377\377\377\377\377\310\316\231^\212" "H\377\377\377\214\2402}\256b\377\377\377\377\377\377\377\377\377\377\377" "\377\312\332\250_\251O\377\377\377\377\377\377y\310j\200\2542\377\377\377" "\377\377\377\377\377\377\377\377\377x\341x\377\377\377\377\377\377\177\350" "|\317\344\266\377\377\377\377\377\377D\3502\362\375\360\377\377\377P\334" "2\346\371\342\377\377\377\\\3202\335\364\323\377\377\377\377\377\377h\304" "2\325\355\305\377\377\377t\2702\317\344\266\377\377\377\200\2542\312\332" "\250\377\377\377\214\2402\310\316\231\377\377\377\230\2242\\U\204h\\\377" "\6\5/mVv{^\377\6\4/\12\12\360\201Vi\220^\377\7\4/\227U[\246]\377\7\3/\255" "RN\277Z\377\10\3/\306M@\6\4/\12\12\360{^\377mVvmVv\6\5/\12\12\360h\\\377" "\377\377\377\307\300\213\377\377\377\230\2242\230\2242\377\377\377\377\377" "\377\377\377\377\310\316\231\310\316\231\377\377\377\214\2402\214\2402\377" "\377\377\377\377\377\377\377\377\377\377\377\312\332\250\312\332\250\312" "\332\250\377\377\377\200\2542\200\2542\200\2542\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\350" "2\362\375\360\377\377\377P\3342\377\377\377\346\371\342\377\377\377\\\320" "2\335\364\323\377\377\377h\3042\325\355\305\377\377\377t\2702\317\344\266" "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\214\2402\310\316" "\231\377\377\377\5\5/\\U\204h\\\377\6\5/mVv{^\377\6\4/\12\12\360\201Vi\220" "^\377\7\4/\227U[\246]\377\7\3/\255RN\277Z\377\10\3/\306M@\6\4/\6\4/{^\377" "\12\12\360mVv\6\5/\6\5/\377\377\377\377\377\377\307\300\213\307\300\213\377" "\377\377\230\2242\377\377\377\377\377\377\377\377\377\377\377\377\310\316" "\231\310\316\231\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\312\332\250\312\332\250\377\377\377\377" "\377\377\200\2542\200\2542\377\377\377\377\377\377\377\377\377\377\377\377" "\204\0\204\377\377\377D\3502\355\364\353\377\377\377\377\377\377Y\335;\346" "\371\342\377\377\377/\26\31\335\364\323\377\377\377k\255<\325\355\305\377" "\377\377\377\377\377t\2702\317\344\266\2046\204\200\2542\312\332\250\340" "\317\340\214\2402\310\316\231\377\377\377VX\377\5\5//\33Dh\\\377\6\5/tVz" "{^\377\6\4/=0\377\201Vi\220^\377\3\1\30\227U[\246]\377?6U\255RN\277Z\377" "\337]s\306M0\306M@\3\2\30{^\377{^\377yv}mVv\244\2102\377\377\377\377\377" "\377\377\377\377gyG\307\300\213\230\2242\212\242h\377\377\377\377\377\377" "\377\377\377\377\377\377\310\316\231g\230O\377\377\377\214\2402\205\274q" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377h\270V\312\332" "\250\377\377\377\222\344\222\200\2542\200\2542\377\377\377\377\377\377\377" "\377\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377P\3342\346" "\371\342\377\377\377\\\3202\335\364\323\377\377\377\377\377\377h\3042\325" "\355\305\377\377\377t\2702\317\344\266\377\377\377\377\377\377\200\2542\312" "\332\250\377\377\377\214\2402\310\316\231VX\377\12\12\360\5\5/\\U\204h\\" "\377\6\5/mVv{^\377\6\4/\12\12\360\201Vi\220^\377\7\4/\227U[\246]\377\7\3" "/\255RN\255RN\277Z\377\10\3/\306M@\6\4/\12\12\360{^\377\12\12\360\307\260" "|\244\2102\244\2102\377\377\377\377\377\377\377\377\377\307\300\213\377\377" "\377\230\2242\230\2242\377\377\377\377\377\377\377\377\377\377\377\377\310" "\316\231\377\377\377\377\377\377\214\2402\214\2402\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\312\332\250\312\332\250\377\377\377" "\377\377\377\200\2542\200\2542\377\377\377\377\377\377D\3502\377\377\377" "\362\375\360\377\377\377P\3342\346\371\342\377\377\377\\\3202\377\377\377" "\335\364\323\377\377\377h\3042\325\355\305\377\377\377\377\377\377t\2702" "\317\344\266\377\377\377\200\2542\312\332\250\377\377\377\377\377\377\214" "\2402LR\221VX\377\5\5/\\U\204\12\12\360h\\\377\6\5/mVv{^\377\6\4/\12\12\360" "\201Vi\220^\377\7\4/\227U[\246]\377\7\3/\7\3/\255RN\277Z\377\10\3/\306M@" "\6\4/\6\4/{^\377\377\377\377\307\260|\377\377\377\244\2102\377\377\377\377" "\377\377\377\377\377\307\300\213\307\300\213\377\377\377\230\2242\377\377" "\377\377\377\377\377\377\377\377\377\377\310\316\231\310\316\231\377\377" "\377\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\312\332\250\312\332\250\377\377\377\377\377\377\377" "\377\377\377\377\377D\3502\377\377\377\362\375\360\377\377\377-\17\34\346" "\371\342\377\377\377\363\346\363\\\3202\335\364\323\377\377\377h\3042\377" "\377\377x)o\377\377\377t\2702\301\276\255\377\377\377\377\377\377\243\273" "U\312\332\250\377\377\377O-\34\12\12\360LR\221gU\333\5\5/\\U\204<)\377h\\" "\377\6\5/=!B{^\377\6\4/A2\306\201Vi\220^\377I9q\227U[\246]\377]-\220\7\3" "/\255RN\245q\304\10\3/\306M0\377\236\221\6\4/\377\377\377\220\231\220\307" "\260|\307\260|\226\227m\244\2102\377\377\377\377\377\377\377\377\377\307" "\300\213p\207N\230\2242\230\2242\254\316\254\377\377\377\377\377\377\377" "\377\377\310\316\231\310\316\231\220\317\220\377\377\377\214\2402\216\316" "\200\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377r\310^\312" "\332\250\377\377\377\377\377\377\377\377\377D\3502\362\375\360\377\377\377" "P\3342\377\377\377\346\371\342\377\377\377\\\3202\335\364\323\377\377\377" "\377\377\377h\3042\325\355\305\377\377\377\377\377\377t\2702\317\344\266" "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\5\6/LR\221\12\12" "\360VX\377\5\5/\\U\204h\\\377\12\12\360\6\5/mVv{^\377\6\4/\12\12\360\201" "Vi\220^\377\7\4/\227U[\12\12\360\246]\377\7\3/\255RN\277Z\377\277Z\377\10" "\3/\306M@\260|2\260|2\377\377\377\377\377\377\307\260|\377\377\377\244\210" "2\377\377\377\377\377\377\377\377\377\377\377\377\307\300\213\377\377\377" "\230\2242\230\2242\377\377\377\377\377\377\377\377\377\377\377\377\310\316" "\231\310\316\231\377\377\377\377\377\377\214\2402\214\2402\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377D\3502\362\375\360\377\377\377P\3342\377\377\377\346\371\342\377" "\377\377\\\3202\377\377\377\335\364\323\377\377\377h\3042\325\355\305\377" "\377\377\377\377\377t\2702\317\344\266\377\377\377\377\377\377\200\2542\312" "\332\250\377\377\377\12\12\360\5\6/LR\221VX\377\12\12\360\5\5/\\U\204h\\" "\377\6\5/\12\12\360mVv{^\377\6\4/\12\12\360\201Vi\220^\377\7\4/\227U[\227" "U[\246]\377\7\3/\255RN\12\12\360\277Z\377\10\3/\333bB\377\377\377\260|2\377" "\377\377\377\377\377\307\260|\307\260|\244\2102\244\2102\377\377\377\377" "\377\377\377\377\377\307\300\213\307\300\213\377\377\377\230\2242\230\224" "2\377\377\377\377\377\377\377\377\377\377\377\377\310\316\231\310\316\231" "\377\377\377\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377)\10\36\362\375\360\377\377\377\370" "\356\370P\3342\346\371\342\377\377\377\377\377\377\\\3202\207\"\201\377\377" "\377\377\377\377p\250D\325\355\305\377\377\377\377\377\377t\2702\317\344" "\266\234?\234\200\2542\377\377\377\274\260\244FS\377\5\6/;#\377LR\221VX\377" "\3\1\34\12\12\360\\U\204{^\330\6\5/\12\12\360\257\203\270{^\377\6\4/\6\4" "\222\201Vi\220^\377P@d\12\12\360\227U[\370\244\377\7\3/\255RNi./\277Z\377" "\324X2\264\202w\333bB\260|2\377\377\377\377\377\377\377\377\377yvK\377\377" "\377\244\2102\236\247|\377\377\377\377\377\377\377\377\377\307\300\213\307" "\300\213\234\306\234\230\2242\377\377\377\256\330\256\377\377\377\377\377" "\377\377\377\377\310\316\231\310\316\231\234\341\234\377\377\377\214\240" "2\232\343\223\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362\375" "\360\377\377\377\377\377\377P\3342\346\371\342\377\377\377\377\377\377\\" "\3202\335\364\323\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377" "\377\377t\2702\317\344\266\377\377\377\377\377\377\200\2542\312\332\250\12" "\12\360FS\377\5\6/LR\221\12\12\360RW\255\3\5\35\6\11\224ZT\\d[\261\3\4\35" "\6\11\224lVTw]\264\4\4\35\6\11\224\200VN\214]\270\4\3\35\6\11\224\226UG\242" "\\\274\4\3\35\4\3\35\254R@\377\377\311\203U\36\203U\36\323a:my\36my\36\377" "\377\276\377\377\276\243\255X\243\255X\236\371\236e\204\36\236\371\236\374" "\377\273\236\371\236\236\371\236\234\275`\236\371\236^\220\36^\220\36\236" "\371\236\352\377\267\352\377\267\236\371\236\236\371\236\310\316\231\310" "\316\231\377\377\377\377\377\377\214\2402\377\377\377\377\377\377\377\377" "\377D\3502\362\375\360\377\377\377\377\377\377P\3342\346\371\342\377\377" "\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377h\3042\377\377" "\377\325\355\305\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377" "\377\377\200\2542<L\237FS\377\12\12\360\5\6/LR\221\6\11\224RW\255\3\5\35" "ZT\\\6\11\224d[\261\3\4\35\6\11\224lVTw]\264\4\4\35\6\11\224\200VN\214]\270" "\4\3\35\4\3\35\226UG\242\\\274\6\11\224\4\3\35\304wB\377\377\311\377\377" "\311\203U\36\323a:\236\371\236my\36\236\371\236\377\377\276\236\371\236\243" "\255X\236\371\236e\204\36e\204\36\374\377\273\374\377\273\236\371\236\234" "\275`\234\275`\236\371\236^\220\36^\220\36\236\371\236\352\377\267\352\377" "\267\377\377\377\377\377\377\310\316\231\310\316\231\377\377\377\250\0\250" "\377\377\377\377\377\377F\3375\362\375\360\377\377\377\377\377\377P\3342" "\377\377\377\227\32\224\377\377\377\\\3202\362\340\362\335\364\323\377\377" "\377\377\377\377h\3042\325\355\305\2506\250\377\377\377t\2702\304\272\262" "\377\377\377\377\377\377\257\300a\12\12\360<L\237.\32\250\5\6/\12\12\360" "jSzRW\255\6\11\224D+^ZT\\\6\11\224A&t\3\4\35lVTP9\235w]\264\4\4\35YG\347" "\200VN\214]\270\3\4a\4\3\35\226UG\244y\257\6\11\224{a\36\377\322\246\236" "\371\236\377\377\311V6\23\323a:\323a:\223\231y\236\371\236\377\377\276\377" "\377\377\243\255X\243\255Xh\270he\204\36\236\371\236\272\322\253\374\377" "\273\236\371\236\377\377\350\236\371\236\236\371\236=y\23\236\371\236\236" "\371\236\262\344\262\377\377\377\377\377\377\377\377\377\310\316\231\377" "\377\377\377\377\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377" "P\3342\377\377\377\346\371\342\377\377\377\377\377\377\\\3202\335\364\323" "\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377\377\377t\2702" "\377\377\377\317\344\266\377\377\377\377\377\377\5\6/<L\237\12\12\360FS\377" "\5\6/\6\11\224JQbRW\255\6\11\224\3\5\35ZT\\d[\261\6\11\224\3\4\35lVT\6\11" "\224w]\264\4\4\35\6\11\224\200VN\214]\270\6\11\224\4\3\35\226UG\242\\\274" "\377\377\306{a\36\304wB\304wB\377\377\311\203U\36\203U\36\323a:my\36my\36" "\377\377\276\377\377\276\236\371\236\243\255X\236\371\236e\204\36e\204\36" "\236\371\236\374\377\273\236\371\236\234\275`\234\275`\236\371\236^\220\36" "^\220\36\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377" "P\3342\377\377\377\346\371\342\377\377\377\377\377\377\\\3202\335\364\323" "\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377\377\377\377\377" "\377t\2702\317\344\266\377\377\377\377\377\377\5\6/\12\12\360<L\237FS\377" "\12\12\360\3\5\35JQb\6\11\224RW\255\3\5\35\6\11\224ZT\\d[\261\6\11\224\3" "\4\35lVT\6\11\224w]\264\4\4\35\6\11\224\200VN\214]\270\6\11\224\4\3\35\226" "UG\236\371\236\377\377\306{a\36\236\371\236\304wB\377\377\311\236\371\236" "\203U\36\323a:\236\371\236my\36\236\371\236\377\377\276\236\371\236\243\255" "X\243\255X\236\371\236e\204\36\236\371\236\374\377\273\374\377\273\236\371" "\236\234\275`\234\275`\236\371\236\230\2242\230\2242\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377J\3508\377\377\377\362" "\375\360\264\22\264\377\377\377P\3342\340\340\335\377\377\377\377\377\377" "u\325K\377\377\377\335\364\323\264-\264\377\377\377h\3042\315\305\301\377" "\377\377\377\377\377\240\307^\377\377\377\317\344\266\264H\264\12\12\360" "\5\6/aL\245\12\12\360FS\377E(\323\3\5\35JQb\4\3hRW\255\3\5\35O2\241ZT\\d" "[\261X>\346\3\4\35lVT\4\4hw]\264\4\4\35aK\244\200VN\214]\270kZ\371\4\3\35" "\270\212Io\225o\377\377\306{a\36\253\300\253\304wB\377\377\311\377\377\377" "\203U\36\323a:\224D(my\36\236\371\236\307\316\266\377\377\276\236\371\236" "\377\377\343\236\371\236e\204\36Gk\25\236\371\236\374\377\273\260\334\260" "\236\371\236\234\275`\377\377\377\377\377\377\230\2242k\207#\377\377\377" "\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362\375\360\377\377" "\377\377\377\377P\3342\346\371\342\377\377\377\377\377\377\\\3202\377\377" "\377\335\364\323\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377" "\377\377\377\377\377t\2702\317\344\266\377\377\3778L\377\12\12\360\5\6/<" "L\237\12\12\360BR\252\3\5\35\6\11\224JQbRW\255\6\11\224\3\5\35ZT\\\6\11\224" "d[\261\6\11\224\3\4\35lVT\6\11\224w]\264\4\4\35\6\11\224\200VN\214]\270\6" "\11\224tm\36\270\212I\270\212I\377\377\306{a\36{a\36\304wB\236\371\236\377" "\377\311\203U\36\236\371\236\323a:my\36my\36\236\371\236\377\377\276\236" "\371\236\243\255X\243\255X\236\371\236e\204\36\236\371\236\374\377\273\374" "\377\273\236\371\236\307\300\213\307\300\213\377\377\377\377\377\377\230" "\2242\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362\375\360\377" "\377\377\377\377\377P\3342\377\377\377\346\371\342\377\377\377\377\377\377" "\\\3202\335\364\323\377\377\377\377\377\377\377\377\377h\3042\325\355\305" "\377\377\377\377\377\377t\2702\377\377\377\317\344\2668L\377\12\12\360\5" "\6/\12\12\360<L\237BR\252\6\11\224\3\5\35JQb\6\11\224RW\255\6\11\224\3\5" "\35ZT\\\6\11\224d[\261\3\4\35\6\11\224lVT\6\11\224w]\264\4\4\35\6\11\224" "\200VN\214]\270\236\371\236tm\36\236\371\236\270\212I\377\377\306\236\371" "\236{a\36\304wB\236\371\236\377\377\311\203U\36\203U\36\323a:\236\371\236" "my\36\236\371\236\377\377\276\377\377\276\236\371\236\243\255X\236\371\236" "e\204\36e\204\36\236\371\236\374\377\273\377\377\377\377\377\377\307\300" "\213\307\300\213\377\377\377\377\377\377\377\377\377\377\377\3773\10%\377" "\377\377\362\375\360\372\356\372\377\377\377P\3342\377\377\377\346\371\342" "\377\377\377\300$\300\\\3202\377\377\377\327\317\316\377\377\377\377\377" "\377\220\317Z\377\377\377\325\355\305\300?\300\377\377\377t\2702\312\267" "\270\12\12\3608L\377F#\377\5\6/<L\237\4\3oBR\252\6\11\224K)[JQb\6\11\224" "\243\204\376\3\5\35\6\11\224C&E\6\11\224d[\261_@l\6\11\224lVTkP\371w]\264" "\4\4\35\4\5o\200VN\377\377\302\262\276\262tm\36\236\371\236\377\360\302\377" "\377\306\236\371\236\\A\26\304wB\304wB\322\312\302\236\371\236\203U\36\377" "\355\310\323a:my\36R]\26\236\371\236\377\377\276\270\326\270\243\255X\236" "\371\236\377\377\377e\204\36\236\371\236\300\341\300\377\377\377\377\377" "\377\305\353\305\307\300\213\377\377\377\377\377\377\377\377\377D\3502\377" "\377\377\362\375\360\377\377\377\377\377\377P\3342\377\377\377\346\371\342" "\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377\377\377" "\377h\3042\377\377\377\325\355\305\377\377\377\377\377\377t\2702\377\377" "\3770E\254\12\12\3608L\377\5\6/\12\12\360:Lj\6\11\224BR\252\3\5\35\6\11\224" "JQb\6\11\224RW\255\3\5\35\6\11\224ZT\\\6\11\224d[\261\3\4\35\6\11\224lVT" "\6\11\224w]\264\4\4\35\6\11\224\255\235Q\377\377\302\377\377\302tm\36\236" "\371\236\270\212I\377\377\306\377\377\306{a\36\236\371\236\304wB\377\377" "\311\377\377\311\203U\36\236\371\236\323a:\236\371\236my\36\236\371\236\377" "\377\276\236\371\236\243\255X\243\255X\236\371\236e\204\36\244\2102\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377D\3502\377\377\377\362\375\360\377\377\377\377\377\377P\3342\377\377" "\377\346\371\342\377\377\377\377\377\377\377\377\377\\\3202\335\364\323\377" "\377\377\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377\377\377" "\377\377\377t\2702\317\344\266\377\377\377\377\377\377\377\377\377\200\254" "2\236\371\236\222\326p\332\377\264\236\371\236V\234\36\236\371\236\226\312" "g\352\377\267\236\371\236^\220\36\236\371\236\234\275`\374\377\273\236\371" "\236e\204\36\236\371\236\243\255X\377\377\276\236\371\236my\36\236\371\236" "\255\235Q\236\371\236\377\377\302tm\36\236\371\236\270\212I\236\371\236\377" "\377\306{a\36\236\371\236\304wB\236\371\236\377\377\311\203U\36\203U\36\323" "a:\236\371\236my\36\236\371\236\377\377\276\377\377\276\236\371\236\243\255" "X\236\371\236\377\377\377\244\2102\377\377\377\377\377\377\377\377\377\314" "\0\314\377\377\377\377\377\377H\3377\377\377\377\362\375\360\377\377\377" "\377\377\377\377\377\377@\27(\346\371\342\377\377\377\367\340\367\377\377" "\377\\\3202\377\377\377\335\364\323\377\377\377\3146\314h\3042\377\377\377" "\322\301\306\377\377\377\377\377\377\255\314k\377\377\377\317\344\266\314" "Q\314\377\377\377\200\2542\256\300\256\222\326p\236\371\236\377\377\377\236" "\371\236V\234\36xUR\236\371\236\352\377\267\262\273\262^\220\36\234\275`" "\377\377\377\374\377\273\236\371\236PE\30\236\371\236\243\255X\342\300\305" "\236\371\236my\36\377\377\377\255\235Q\236\371\236\314\242\233tm\36\236\371" "\236\304\237\240\236\371\236\377\377\306\377\340\256{a\36\304wB~\270~\377" "\377\311\236\371\236\273\254\244\323a:\323a:\377\377\303my\36\236\371\236" "\314\330\230\236\371\236\243\255X\313\332\302\377\377\377\244\2102\377\377" "\355\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362" "\375\360\377\377\377\377\377\377\377\377\377P\3342\377\377\377\346\371\342" "\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377\377\377" "\377h\3042\377\377\377\325\355\305\377\377\377\377\377\377\377\377\377t\270" "2\317\344\266\377\377\377\377\377\377\377\377\377O\247\36\236\371\236\222" "\326p\332\377\264\236\371\236V\234\36\236\371\236\226\312g\236\371\236\352" "\377\267\236\371\236^\220\36\234\275`\236\371\236\374\377\273\236\371\236" "e\204\36\236\371\236\243\255X\377\377\276\236\371\236my\36\236\371\236\255" "\235Q\236\371\236\377\377\302tm\36\236\371\236\270\212I\236\371\236\377\377" "\306\236\371\236{a\36\304wB\304wB\377\377\311\236\371\236\203U\36\236\371" "\236\323a:\236\371\236my\36\236\371\236\377\377\276\377\377\276\377\377\377" "\307\260|\377\377\377\377\377\377\244\2102\377\377\377\377\377\377\377\377" "\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377\377\377\377P\334" "2\377\377\377\346\371\342\377\377\377\377\377\377\\\3202\377\377\377\335" "\364\323\377\377\377\377\377\377\377\377\377h\3042\377\377\377\325\355\305" "\377\377\377\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377\377" "\377\236\371\236O\247\36\222\326p\236\371\236\332\377\264\236\371\236V\234" "\36\236\371\236\226\312g\236\371\236\352\377\267^\220\36\236\371\236\234" "\275`\236\371\236\374\377\273\236\371\236e\204\36\236\371\236\243\255X\377" "\377\276\236\371\236my\36\236\371\236\255\235Q\236\371\236\377\377\302tm" "\36tm\36\270\212I\236\371\236\377\377\306\236\371\236{a\36\236\371\236\304" "wB\377\377\311\377\377\311\203U\36\236\371\236\323a:\236\371\236my\36\236" "\371\236\236\371\236\377\377\377\377\377\377\307\260|\307\260|\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362\375\360\330\22" "\330\377\377\377\377\377\377]\306B\377\377\377\346\371\342\377\377\377\377" "\377\377\377\377\377M$*\335\364\323\377\377\377\366\324\366\377\377\377h" "\3042\377\377\377\325\355\305\377\377\377\330H\330\377\377\377t\2702\321" "\264\300\377\377\377\377\377\377\352\377\352O\247\36\236\371\236{S^\236\371" "\236\332\377\264\266\274\266V\234\36\226\312g\377\377\377\352\377\267\236" "\371\236OG\31\236\371\236\234\275`\274\274\274\374\377\273\236\371\236\336" "\325\227\243\255X\236\371\236\330\231\240\236\371\236my\36\302\300\302\255" "\235Q\236\371\236\377\377\377\236\371\236tm\36\233a=\236\371\236\377\377" "\306\310\314\310{a\36\236\371\236\377\377\351\236\371\236\377\377\311nE\31" "\203U\36\323a:\326\304\276my\36my\36\377\377\377\377\377\377\377\377\377" "\330\352\330\307\260|\377\377\377\377\377\377\377\377\377\377\377\377D\350" "2\377\377\377\362\375\360\377\377\377\377\377\377P\3342\377\377\377\346\371" "\342\377\377\377\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377" "\377\377\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377\377\377" "\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377\377\377\377\377" "\377\200\2542\377\377\377\312\332\250\377\377\377\377\377\377\214\2402\377" "\377\377\310\316\231\377\377\377\377\377\377\377\377\377\230\2242\377\377" "\377\307\300\213\377\377\377\377\377\377\244\2102\377\377\377\307\260|\377" "\377\377\377\377\377\377\377\377\260|2\377\377\377\312\237n\377\377\377\377" "\377\377\377\377\377\274p2\316\214_\316\214_\377\377\377\377\377\377\310" "d2\377\377\377\323xQ\377\377\377\377\377\377\377\377\377\324X2\377\377\377" "\333bB\377\377\377\260|2\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362\375" "\360\377\377\377\377\377\377P\3342\377\377\377\346\371\342\377\377\377\377" "\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377\377\377\377" "\377\377\377h\3042\377\377\377\325\355\305\377\377\377\377\377\377\377\377" "\377t\2702\317\344\266\377\377\377\377\377\377\377\377\377\200\2542\377\377" "\377\312\332\250\377\377\377\377\377\377\377\377\377\214\2402\377\377\377" "\310\316\231\377\377\377\377\377\377\377\377\377\230\2242\377\377\377\307" "\300\213\377\377\377\377\377\377\244\2102\377\377\377\307\260|\377\377\377" "\377\377\377\377\377\377\260|2\377\377\377\312\237n\377\377\377\377\377\377" "\377\377\377\274p2\377\377\377\316\214_\377\377\377\377\377\377\310d2\310" "d2\323xQ\377\377\377\377\377\377\377\377\377\324X2\377\377\377\333bB\377" "\377\377\260|2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" "\377\377\377\344\11\344D\3502\377\377\377\360\354\357\377\377\377\377\377" "\377\377\377\377P\3342\377\377\377\315#\312\377\377\377\377\377\377s\262" "Q\377\377\377\335\364\323\377\377\377\377\377\377\377\377\377\\0,\377\377" "\377\325\355\305\367\313\367\377\377\377\377\377\377\274\321z\377\377\377" "\317\344\266\344Z\344\377\377\377\377\377\377\246\217v\377\377\377\312\332" "\250\377\377\377\377\377\377\377\377\377}I,\377\377\377\310\316\231\361\277" "\361\377\377\377\230\2242\377\377\377\307\300\213\377\377\377\344\220\344" "\377\377\377\244\2102\356\301\356\307\260|\377\377\377\377\377\377\377\377" "\377\260|2\344\253\344\312\237n\377\377\377\353\312\353\377\377\377\274p" "2\377\377\377\316\214_\377\377\377\344\306\344\377\377\377\310d2\340\276" "\310\323xQ\377\377\377\377\377\377\324X2\324X2\303V;\333bB\260|2\337\340" "\325\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\3502\377" "\377\377\362\375\360\377\377\377\377\377\377\377\377\377P\3342\377\377\377" "\346\371\342\377\377\377\377\377\377\377\377\377\\\3202\377\377\377\335\364" "\323\377\377\377\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377" "\377\377\377\377\377\377\377\377t\2702\317\344\266\377\377\377\377\377\377" "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\377\377\377\377" "\377\377\214\2402\377\377\377\310\316\231\377\377\377\377\377\377\377\377" "\377\230\2242\377\377\377\307\300\213\377\377\377\377\377\377\377\377\377" "\244\2102\377\377\377\307\260|\377\377\377\377\377\377\377\377\377\260|2" "\377\377\377\312\237n\377\377\377\377\377\377\377\377\377\274p2\377\377\377" "\316\214_\377\377\377\377\377\377\377\377\377\310d2\377\377\377\323xQ\377" "\377\377\377\377\377\377\377\377\324X2\377\377\377\333bB\377\377\377\260" "|2\377\377\377\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362" "\375\360\377\377\377\377\377\377\377\377\377P\3342\377\377\377\346\371\342" "\377\377\377\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377" "\377\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377\377\377\377" "\377\377\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377\377\377" "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\377\377\377\377" "\377\377\214\2402\377\377\377\310\316\231\377\377\377\377\377\377\377\377" "\377\230\2242\377\377\377\307\300\213\377\377\377\377\377\377\377\377\377" "\244\2102\377\377\377\307\260|\377\377\377\377\377\377\377\377\377\260|2" "\377\377\377\312\237n\377\377\377\377\377\377\377\377\377\274p2\377\377\377" "\316\214_\377\377\377\377\377\377\377\377\377\310d2\377\377\377\323xQ\377" "\377\377\377\377\377\377\377\377\324X2\377\377\377\333bB\377\377\377", }; /** * \brief Returns the PrimitivesBlend test image as SDL_Surface. */ SDL_Surface *SDLTest_ImagePrimitivesBlend() { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( (void*)SDLTest_imagePrimitivesBlend.pixel_data, SDLTest_imagePrimitivesBlend.width, SDLTest_imagePrimitivesBlend.height, SDLTest_imagePrimitivesBlend.bytes_per_pixel * 8, SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel, #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) 0xff000000, /* Red bit mask. */ 0x00ff0000, /* Green bit mask. */ 0x0000ff00, /* Blue bit mask. */ 0x000000ff /* Alpha bit mask. */ #else 0x000000ff, /* Red bit mask. */ 0x0000ff00, /* Green bit mask. */ 0x00ff0000, /* Blue bit mask. */ 0xff000000 /* Alpha bit mask. */ #endif ); return surface; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_imagePrimitivesBlend.c
C
apache-2.0
52,011
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* Used by the test framework and test cases. */ /* quiet windows compiler warnings */ #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) # define _CRT_SECURE_NO_WARNINGS #endif #include "SDL_config.h" #include <stdarg.h> /* va_list */ #include <stdio.h> #include <string.h> #include <time.h> #include "SDL.h" #include "SDL_test.h" /* work around compiler warning on older GCCs. */ #if (defined(__GNUC__) && (__GNUC__ <= 2)) static size_t strftime_gcc2_workaround(char *s, size_t max, const char *fmt, const struct tm *tm) { return strftime(s, max, fmt, tm); } #ifdef strftime #undef strftime #endif #define strftime strftime_gcc2_workaround #endif /* ! * Converts unix timestamp to its ascii representation in localtime * * Note: Uses a static buffer internally, so the return value * isn't valid after the next call of this function. If you * want to retain the return value, make a copy of it. * * \param timestamp A Timestamp, i.e. time(0) * * \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02' */ static char *SDLTest_TimestampToString(const time_t timestamp) { time_t copy; static char buffer[64]; struct tm *local; SDL_memset(buffer, 0, sizeof(buffer)); copy = timestamp; local = localtime(&copy); strftime(buffer, sizeof(buffer), "%x %X", local); return buffer; } /* * Prints given message with a timestamp in the TEST category and INFO priority. */ void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { va_list list; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; /* Print log message into a buffer */ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH); va_start(list, fmt); SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list); va_end(list); /* Log with timestamp and newline */ SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_INFO, " %s: %s", SDLTest_TimestampToString(time(0)), logMessage); } /* * Prints given message with a timestamp in the TEST category and the ERROR priority. */ void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { va_list list; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; /* Print log message into a buffer */ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH); va_start(list, fmt); SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list); va_end(list); /* Log with timestamp and newline */ SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s", SDLTest_TimestampToString(time(0)), logMessage); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_log.c
C
apache-2.0
3,604
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* *********************************************************************** ** RSA Data Security, Inc. MD5 Message-Digest Algorithm ** ** Created: 2/17/90 RLR ** ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. ** *********************************************************************** */ /* *********************************************************************** ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. ** ** ** ** License to copy and use this software is granted provided that ** ** it is identified as the "RSA Data Security, Inc. MD5 Message- ** ** Digest Algorithm" in all material mentioning or referencing this ** ** software or this function. ** ** ** ** License is also granted to make and use derivative works ** ** provided that such works are identified as "derived from the RSA ** ** Data Security, Inc. MD5 Message-Digest Algorithm" in all ** ** material mentioning or referencing the derived work. ** ** ** ** RSA Data Security, Inc. makes no representations concerning ** ** either the merchantability of this software or the suitability ** ** of this software for any particular purpose. It is provided "as ** ** is" without express or implied warranty of any kind. ** ** ** ** These notices must be retained in any copies of any part of this ** ** documentation and/or software. ** *********************************************************************** */ #include "SDL_config.h" #include "SDL_test.h" /* Forward declaration of static helper function */ static void SDLTest_Md5Transform(MD5UINT4 * buf, const MD5UINT4 * in); static unsigned char MD5PADDING[64] = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* F, G, H and I are basic MD5 functions */ #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) #define H(x, y, z) ((x) ^ (y) ^ (z)) #define I(x, y, z) ((y) ^ ((x) | (~z))) /* ROTATE_LEFT rotates x left n bits */ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */ /* Rotation is separate from addition to prevent recomputation */ #define FF(a, b, c, d, x, s, ac) \ {(a) += F ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define GG(a, b, c, d, x, s, ac) \ {(a) += G ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define HH(a, b, c, d, x, s, ac) \ {(a) += H ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } #define II(a, b, c, d, x, s, ac) \ {(a) += I ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \ (a) = ROTATE_LEFT ((a), (s)); \ (a) += (b); \ } /* The routine MD5Init initializes the message-digest context mdContext. All fields are set to zero. */ void SDLTest_Md5Init(SDLTest_Md5Context * mdContext) { if (mdContext==NULL) return; mdContext->i[0] = mdContext->i[1] = (MD5UINT4) 0; /* * Load magic initialization constants. */ mdContext->buf[0] = (MD5UINT4) 0x67452301; mdContext->buf[1] = (MD5UINT4) 0xefcdab89; mdContext->buf[2] = (MD5UINT4) 0x98badcfe; mdContext->buf[3] = (MD5UINT4) 0x10325476; } /* The routine MD5Update updates the message-digest context to account for the presence of each of the characters inBuf[0..inLen-1] in the message whose digest is being computed. */ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf, unsigned int inLen) { MD5UINT4 in[16]; int mdi; unsigned int i, ii; if (mdContext == NULL) return; if (inBuf == NULL || inLen < 1) return; /* * compute number of bytes mod 64 */ mdi = (int) ((mdContext->i[0] >> 3) & 0x3F); /* * update number of bits */ if ((mdContext->i[0] + ((MD5UINT4) inLen << 3)) < mdContext->i[0]) mdContext->i[1]++; mdContext->i[0] += ((MD5UINT4) inLen << 3); mdContext->i[1] += ((MD5UINT4) inLen >> 29); while (inLen--) { /* * add new character to buffer, increment mdi */ mdContext->in[mdi++] = *inBuf++; /* * transform if necessary */ if (mdi == 0x40) { for (i = 0, ii = 0; i < 16; i++, ii += 4) in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) | (((MD5UINT4) mdContext->in[ii + 2]) << 16) | (((MD5UINT4) mdContext->in[ii + 1]) << 8) | ((MD5UINT4) mdContext->in[ii]); SDLTest_Md5Transform(mdContext->buf, in); mdi = 0; } } } /* The routine MD5Final terminates the message-digest computation and ends with the desired message digest in mdContext->digest[0...15]. */ void SDLTest_Md5Final(SDLTest_Md5Context * mdContext) { MD5UINT4 in[16]; int mdi; unsigned int i, ii; unsigned int padLen; if (mdContext == NULL) return; /* * save number of bits */ in[14] = mdContext->i[0]; in[15] = mdContext->i[1]; /* * compute number of bytes mod 64 */ mdi = (int) ((mdContext->i[0] >> 3) & 0x3F); /* * pad out to 56 mod 64 */ padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi); SDLTest_Md5Update(mdContext, MD5PADDING, padLen); /* * append length in bits and transform */ for (i = 0, ii = 0; i < 14; i++, ii += 4) in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) | (((MD5UINT4) mdContext->in[ii + 2]) << 16) | (((MD5UINT4) mdContext->in[ii + 1]) << 8) | ((MD5UINT4) mdContext->in[ii]); SDLTest_Md5Transform(mdContext->buf, in); /* * store buffer in digest */ for (i = 0, ii = 0; i < 4; i++, ii += 4) { mdContext->digest[ii] = (unsigned char) (mdContext->buf[i] & 0xFF); mdContext->digest[ii + 1] = (unsigned char) ((mdContext->buf[i] >> 8) & 0xFF); mdContext->digest[ii + 2] = (unsigned char) ((mdContext->buf[i] >> 16) & 0xFF); mdContext->digest[ii + 3] = (unsigned char) ((mdContext->buf[i] >> 24) & 0xFF); } } /* Basic MD5 step. Transforms buf based on in. */ static void SDLTest_Md5Transform(MD5UINT4 * buf, const MD5UINT4 * in) { MD5UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3]; /* * Round 1 */ #define S11 7 #define S12 12 #define S13 17 #define S14 22 FF(a, b, c, d, in[0], S11, 3614090360u); /* 1 */ FF(d, a, b, c, in[1], S12, 3905402710u); /* 2 */ FF(c, d, a, b, in[2], S13, 606105819u); /* 3 */ FF(b, c, d, a, in[3], S14, 3250441966u); /* 4 */ FF(a, b, c, d, in[4], S11, 4118548399u); /* 5 */ FF(d, a, b, c, in[5], S12, 1200080426u); /* 6 */ FF(c, d, a, b, in[6], S13, 2821735955u); /* 7 */ FF(b, c, d, a, in[7], S14, 4249261313u); /* 8 */ FF(a, b, c, d, in[8], S11, 1770035416u); /* 9 */ FF(d, a, b, c, in[9], S12, 2336552879u); /* 10 */ FF(c, d, a, b, in[10], S13, 4294925233u); /* 11 */ FF(b, c, d, a, in[11], S14, 2304563134u); /* 12 */ FF(a, b, c, d, in[12], S11, 1804603682u); /* 13 */ FF(d, a, b, c, in[13], S12, 4254626195u); /* 14 */ FF(c, d, a, b, in[14], S13, 2792965006u); /* 15 */ FF(b, c, d, a, in[15], S14, 1236535329u); /* 16 */ /* * Round 2 */ #define S21 5 #define S22 9 #define S23 14 #define S24 20 GG(a, b, c, d, in[1], S21, 4129170786u); /* 17 */ GG(d, a, b, c, in[6], S22, 3225465664u); /* 18 */ GG(c, d, a, b, in[11], S23, 643717713u); /* 19 */ GG(b, c, d, a, in[0], S24, 3921069994u); /* 20 */ GG(a, b, c, d, in[5], S21, 3593408605u); /* 21 */ GG(d, a, b, c, in[10], S22, 38016083u); /* 22 */ GG(c, d, a, b, in[15], S23, 3634488961u); /* 23 */ GG(b, c, d, a, in[4], S24, 3889429448u); /* 24 */ GG(a, b, c, d, in[9], S21, 568446438u); /* 25 */ GG(d, a, b, c, in[14], S22, 3275163606u); /* 26 */ GG(c, d, a, b, in[3], S23, 4107603335u); /* 27 */ GG(b, c, d, a, in[8], S24, 1163531501u); /* 28 */ GG(a, b, c, d, in[13], S21, 2850285829u); /* 29 */ GG(d, a, b, c, in[2], S22, 4243563512u); /* 30 */ GG(c, d, a, b, in[7], S23, 1735328473u); /* 31 */ GG(b, c, d, a, in[12], S24, 2368359562u); /* 32 */ /* * Round 3 */ #define S31 4 #define S32 11 #define S33 16 #define S34 23 HH(a, b, c, d, in[5], S31, 4294588738u); /* 33 */ HH(d, a, b, c, in[8], S32, 2272392833u); /* 34 */ HH(c, d, a, b, in[11], S33, 1839030562u); /* 35 */ HH(b, c, d, a, in[14], S34, 4259657740u); /* 36 */ HH(a, b, c, d, in[1], S31, 2763975236u); /* 37 */ HH(d, a, b, c, in[4], S32, 1272893353u); /* 38 */ HH(c, d, a, b, in[7], S33, 4139469664u); /* 39 */ HH(b, c, d, a, in[10], S34, 3200236656u); /* 40 */ HH(a, b, c, d, in[13], S31, 681279174u); /* 41 */ HH(d, a, b, c, in[0], S32, 3936430074u); /* 42 */ HH(c, d, a, b, in[3], S33, 3572445317u); /* 43 */ HH(b, c, d, a, in[6], S34, 76029189u); /* 44 */ HH(a, b, c, d, in[9], S31, 3654602809u); /* 45 */ HH(d, a, b, c, in[12], S32, 3873151461u); /* 46 */ HH(c, d, a, b, in[15], S33, 530742520u); /* 47 */ HH(b, c, d, a, in[2], S34, 3299628645u); /* 48 */ /* * Round 4 */ #define S41 6 #define S42 10 #define S43 15 #define S44 21 II(a, b, c, d, in[0], S41, 4096336452u); /* 49 */ II(d, a, b, c, in[7], S42, 1126891415u); /* 50 */ II(c, d, a, b, in[14], S43, 2878612391u); /* 51 */ II(b, c, d, a, in[5], S44, 4237533241u); /* 52 */ II(a, b, c, d, in[12], S41, 1700485571u); /* 53 */ II(d, a, b, c, in[3], S42, 2399980690u); /* 54 */ II(c, d, a, b, in[10], S43, 4293915773u); /* 55 */ II(b, c, d, a, in[1], S44, 2240044497u); /* 56 */ II(a, b, c, d, in[8], S41, 1873313359u); /* 57 */ II(d, a, b, c, in[15], S42, 4264355552u); /* 58 */ II(c, d, a, b, in[6], S43, 2734768916u); /* 59 */ II(b, c, d, a, in[13], S44, 1309151649u); /* 60 */ II(a, b, c, d, in[4], S41, 4149444226u); /* 61 */ II(d, a, b, c, in[11], S42, 3174756917u); /* 62 */ II(c, d, a, b, in[2], S43, 718787259u); /* 63 */ II(b, c, d, a, in[9], S44, 3951481745u); /* 64 */ buf[0] += a; buf[1] += b; buf[2] += c; buf[3] += d; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_md5.c
C
apache-2.0
11,663
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include "SDL_assert.h" #include "SDL_stdinc.h" #include "SDL_log.h" #include "SDL_test_crc32.h" #include "SDL_test_memory.h" #ifdef HAVE_LIBUNWIND_H #include <libunwind.h> #endif /* This is a simple tracking allocator to demonstrate the use of SDL's memory allocation replacement functionality. It gets slow with large numbers of allocations and shouldn't be used for production code. */ typedef struct SDL_tracked_allocation { void *mem; size_t size; Uint64 stack[10]; char stack_names[10][256]; struct SDL_tracked_allocation *next; } SDL_tracked_allocation; static SDLTest_Crc32Context s_crc32_context; static SDL_malloc_func SDL_malloc_orig = NULL; static SDL_calloc_func SDL_calloc_orig = NULL; static SDL_realloc_func SDL_realloc_orig = NULL; static SDL_free_func SDL_free_orig = NULL; static int s_previous_allocations = 0; static SDL_tracked_allocation *s_tracked_allocations[256]; static unsigned int get_allocation_bucket(void *mem) { CrcUint32 crc_value; unsigned int index; SDLTest_Crc32Calc(&s_crc32_context, (CrcUint8 *)&mem, sizeof(mem), &crc_value); index = (crc_value & (SDL_arraysize(s_tracked_allocations) - 1)); return index; } static SDL_bool SDL_IsAllocationTracked(void *mem) { SDL_tracked_allocation *entry; int index = get_allocation_bucket(mem); for (entry = s_tracked_allocations[index]; entry; entry = entry->next) { if (mem == entry->mem) { return SDL_TRUE; } } return SDL_FALSE; } static void SDL_TrackAllocation(void *mem, size_t size) { SDL_tracked_allocation *entry; int index = get_allocation_bucket(mem); if (SDL_IsAllocationTracked(mem)) { return; } entry = (SDL_tracked_allocation *)SDL_malloc_orig(sizeof(*entry)); if (!entry) { return; } entry->mem = mem; entry->size = size; /* Generate the stack trace for the allocation */ SDL_zeroa(entry->stack); #ifdef HAVE_LIBUNWIND_H { int stack_index; unw_cursor_t cursor; unw_context_t context; unw_getcontext(&context); unw_init_local(&cursor, &context); stack_index = 0; while (unw_step(&cursor) > 0) { unw_word_t offset, pc; char sym[256]; unw_get_reg(&cursor, UNW_REG_IP, &pc); entry->stack[stack_index] = pc; if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) { snprintf(entry->stack_names[stack_index], sizeof(entry->stack_names[stack_index]), "%s+0x%llx", sym, (unsigned long long)offset); } ++stack_index; if (stack_index == SDL_arraysize(entry->stack)) { break; } } } #endif /* HAVE_LIBUNWIND_H */ entry->next = s_tracked_allocations[index]; s_tracked_allocations[index] = entry; } static void SDL_UntrackAllocation(void *mem) { SDL_tracked_allocation *entry, *prev; int index = get_allocation_bucket(mem); prev = NULL; for (entry = s_tracked_allocations[index]; entry; entry = entry->next) { if (mem == entry->mem) { if (prev) { prev->next = entry->next; } else { s_tracked_allocations[index] = entry->next; } SDL_free_orig(entry); return; } prev = entry; } } static void * SDLCALL SDLTest_TrackedMalloc(size_t size) { void *mem; mem = SDL_malloc_orig(size); if (mem) { SDL_TrackAllocation(mem, size); } return mem; } static void * SDLCALL SDLTest_TrackedCalloc(size_t nmemb, size_t size) { void *mem; mem = SDL_calloc_orig(nmemb, size); if (mem) { SDL_TrackAllocation(mem, nmemb * size); } return mem; } static void * SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size) { void *mem; SDL_assert(!ptr || SDL_IsAllocationTracked(ptr)); mem = SDL_realloc_orig(ptr, size); if (mem && mem != ptr) { if (ptr) { SDL_UntrackAllocation(ptr); } SDL_TrackAllocation(mem, size); } return mem; } static void SDLCALL SDLTest_TrackedFree(void *ptr) { if (!ptr) { return; } if (!s_previous_allocations) { SDL_assert(SDL_IsAllocationTracked(ptr)); } SDL_UntrackAllocation(ptr); SDL_free_orig(ptr); } int SDLTest_TrackAllocations() { if (SDL_malloc_orig) { return 0; } SDLTest_Crc32Init(&s_crc32_context); s_previous_allocations = SDL_GetNumAllocations(); if (s_previous_allocations != 0) { SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations); } SDL_GetMemoryFunctions(&SDL_malloc_orig, &SDL_calloc_orig, &SDL_realloc_orig, &SDL_free_orig); SDL_SetMemoryFunctions(SDLTest_TrackedMalloc, SDLTest_TrackedCalloc, SDLTest_TrackedRealloc, SDLTest_TrackedFree); return 0; } void SDLTest_LogAllocations() { char *message = NULL; size_t message_size = 0; char line[128], *tmp; SDL_tracked_allocation *entry; int index, count, stack_index; Uint64 total_allocated; if (!SDL_malloc_orig) { return; } #define ADD_LINE() \ message_size += (SDL_strlen(line) + 1); \ tmp = (char *)SDL_realloc_orig(message, message_size); \ if (!tmp) { \ return; \ } \ message = tmp; \ SDL_strlcat(message, line, message_size) SDL_strlcpy(line, "Memory allocations:\n", sizeof(line)); ADD_LINE(); SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof(line)); ADD_LINE(); count = 0; total_allocated = 0; for (index = 0; index < SDL_arraysize(s_tracked_allocations); ++index) { for (entry = s_tracked_allocations[index]; entry; entry = entry->next) { SDL_snprintf(line, sizeof(line), "Allocation %d: %d bytes\n", count, (int)entry->size); ADD_LINE(); /* Start at stack index 1 to skip our tracking functions */ for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) { if (!entry->stack[stack_index]) { break; } SDL_snprintf(line, sizeof(line), "\t0x%"SDL_PRIx64": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]); ADD_LINE(); } total_allocated += entry->size; ++count; } } SDL_snprintf(line, sizeof(line), "Total: %.2f Kb in %d allocations\n", (float)total_allocated / 1024, count); ADD_LINE(); #undef ADD_LINE SDL_Log("%s", message); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_memory.c
C
apache-2.0
7,855
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* A portable "32-bit Multiply with carry" random number generator. Used by the fuzzer component. Original source code contributed by A. Schiffler for GSOC project. */ #include "SDL_config.h" #include <stdlib.h> #include <stdio.h> #include <time.h> #include "SDL_test.h" /* Initialize random number generator with two integer variables */ void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, unsigned int ci) { if (rndContext==NULL) return; /* * Choose a value for 'a' from this list * 1791398085 1929682203 1683268614 1965537969 1675393560 * 1967773755 1517746329 1447497129 1655692410 1606218150 * 2051013963 1075433238 1557985959 1781943330 1893513180 * 1631296680 2131995753 2083801278 1873196400 1554115554 */ rndContext->a = 1655692410; rndContext->x = 30903; rndContext->c = 0; if (xi != 0) { rndContext->x = xi; } rndContext->c = ci; rndContext->ah = rndContext->a >> 16; rndContext->al = rndContext->a & 65535; } /* Initialize random number generator from system time */ void SDLTest_RandomInitTime(SDLTest_RandomContext * rndContext) { int a, b; if (rndContext==NULL) return; srand((unsigned int)time(NULL)); a=rand(); srand((unsigned int)clock()); b=rand(); SDLTest_RandomInit(rndContext, a, b); } /* Returns random numbers */ unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext) { unsigned int xh, xl; if (rndContext==NULL) return -1; xh = rndContext->x >> 16, xl = rndContext->x & 65535; rndContext->x = rndContext->x * rndContext->a + rndContext->c; rndContext->c = xh * rndContext->ah + ((xh * rndContext->al) >> 16) + ((xl * rndContext->ah) >> 16); if (xl * rndContext->al >= (~rndContext->c + 1)) rndContext->c++; return (rndContext->x); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/test/SDL_test_random.c
C
apache-2.0
2,772
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" /* These are functions that need to be implemented by a port of SDL */ #ifndef SDL_systhread_h_ #define SDL_systhread_h_ #include "SDL_thread.h" #include "SDL_thread_c.h" /* This function creates a thread, passing args to SDL_RunThread(), saves a system-dependent thread id in thread->id, and returns 0 on success. */ #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD extern int SDL_SYS_CreateThread(SDL_Thread * thread, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread); #else extern int SDL_SYS_CreateThread(SDL_Thread * thread); #endif /* This function does any necessary setup in the child thread */ extern void SDL_SYS_SetupThread(const char *name); /* This function sets the current thread priority */ extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority); /* This function waits for the thread to finish and frees any data allocated by SDL_SYS_CreateThread() */ extern void SDL_SYS_WaitThread(SDL_Thread * thread); /* Mark thread as cleaned up as soon as it exits, without joining. */ extern void SDL_SYS_DetachThread(SDL_Thread * thread); /* Get the thread local storage for this thread */ extern SDL_TLSData *SDL_SYS_GetTLSData(void); /* Set the thread local storage for this thread */ extern int SDL_SYS_SetTLSData(SDL_TLSData *data); /* This is for internal SDL use, so we don't need #ifdefs everywhere. */ extern SDL_Thread * SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name, const size_t stacksize, void *data); #endif /* SDL_systhread_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/SDL_systhread.h
C
apache-2.0
2,624
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" /* System independent thread management routines for SDL */ #include "SDL_assert.h" #include "SDL_thread.h" #include "SDL_thread_c.h" #include "SDL_systhread.h" #include "SDL_hints.h" #include "../SDL_error_c.h" SDL_TLSID SDL_TLSCreate() { static SDL_atomic_t SDL_tls_id; return SDL_AtomicIncRef(&SDL_tls_id)+1; } void * SDL_TLSGet(SDL_TLSID id) { SDL_TLSData *storage; storage = SDL_SYS_GetTLSData(); if (!storage || id == 0 || id > storage->limit) { return NULL; } return storage->array[id-1].data; } int SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *)) { SDL_TLSData *storage; if (id == 0) { return SDL_InvalidParamError("id"); } storage = SDL_SYS_GetTLSData(); if (!storage || (id > storage->limit)) { unsigned int i, oldlimit, newlimit; oldlimit = storage ? storage->limit : 0; newlimit = (id + TLS_ALLOC_CHUNKSIZE); storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage)+(newlimit-1)*sizeof(storage->array[0])); if (!storage) { return SDL_OutOfMemory(); } storage->limit = newlimit; for (i = oldlimit; i < newlimit; ++i) { storage->array[i].data = NULL; storage->array[i].destructor = NULL; } if (SDL_SYS_SetTLSData(storage) != 0) { return -1; } } storage->array[id-1].data = SDL_const_cast(void*, value); storage->array[id-1].destructor = destructor; return 0; } static void SDL_TLSCleanup() { SDL_TLSData *storage; storage = SDL_SYS_GetTLSData(); if (storage) { unsigned int i; for (i = 0; i < storage->limit; ++i) { if (storage->array[i].destructor) { storage->array[i].destructor(storage->array[i].data); } } SDL_SYS_SetTLSData(NULL); SDL_free(storage); } } /* This is a generic implementation of thread-local storage which doesn't require additional OS support. It is not especially efficient and doesn't clean up thread-local storage as threads exit. If there is a real OS that doesn't support thread-local storage this implementation should be improved to be production quality. */ typedef struct SDL_TLSEntry { SDL_threadID thread; SDL_TLSData *storage; struct SDL_TLSEntry *next; } SDL_TLSEntry; static SDL_mutex *SDL_generic_TLS_mutex; static SDL_TLSEntry *SDL_generic_TLS; SDL_TLSData * SDL_Generic_GetTLSData(void) { SDL_threadID thread = SDL_ThreadID(); SDL_TLSEntry *entry; SDL_TLSData *storage = NULL; #if !SDL_THREADS_DISABLED if (!SDL_generic_TLS_mutex) { static SDL_SpinLock tls_lock; SDL_AtomicLock(&tls_lock); if (!SDL_generic_TLS_mutex) { SDL_mutex *mutex = SDL_CreateMutex(); SDL_MemoryBarrierRelease(); SDL_generic_TLS_mutex = mutex; if (!SDL_generic_TLS_mutex) { SDL_AtomicUnlock(&tls_lock); return NULL; } } SDL_AtomicUnlock(&tls_lock); } #endif /* SDL_THREADS_DISABLED */ SDL_MemoryBarrierAcquire(); SDL_LockMutex(SDL_generic_TLS_mutex); for (entry = SDL_generic_TLS; entry; entry = entry->next) { if (entry->thread == thread) { storage = entry->storage; break; } } #if !SDL_THREADS_DISABLED SDL_UnlockMutex(SDL_generic_TLS_mutex); #endif return storage; } int SDL_Generic_SetTLSData(SDL_TLSData *storage) { SDL_threadID thread = SDL_ThreadID(); SDL_TLSEntry *prev, *entry; /* SDL_Generic_GetTLSData() is always called first, so we can assume SDL_generic_TLS_mutex */ SDL_LockMutex(SDL_generic_TLS_mutex); prev = NULL; for (entry = SDL_generic_TLS; entry; entry = entry->next) { if (entry->thread == thread) { if (storage) { entry->storage = storage; } else { if (prev) { prev->next = entry->next; } else { SDL_generic_TLS = entry->next; } SDL_free(entry); } break; } prev = entry; } if (!entry) { entry = (SDL_TLSEntry *)SDL_malloc(sizeof(*entry)); if (entry) { entry->thread = thread; entry->storage = storage; entry->next = SDL_generic_TLS; SDL_generic_TLS = entry; } } SDL_UnlockMutex(SDL_generic_TLS_mutex); if (!entry) { return SDL_OutOfMemory(); } return 0; } /* Routine to get the thread-specific error variable */ SDL_error * SDL_GetErrBuf(void) { #if SDL_THREADS_DISABLED /* Non-thread-safe global error variable */ static SDL_error SDL_global_error; return &SDL_global_error; #else static SDL_SpinLock tls_lock; static SDL_bool tls_being_created; static SDL_TLSID tls_errbuf; static SDL_error SDL_global_errbuf; const SDL_error *ALLOCATION_IN_PROGRESS = (SDL_error *)-1; SDL_error *errbuf; /* tls_being_created is there simply to prevent recursion if SDL_TLSCreate() fails. It also means it's possible for another thread to also use SDL_global_errbuf, but that's very unlikely and hopefully won't cause issues. */ if (!tls_errbuf && !tls_being_created) { SDL_AtomicLock(&tls_lock); if (!tls_errbuf) { SDL_TLSID slot; tls_being_created = SDL_TRUE; slot = SDL_TLSCreate(); tls_being_created = SDL_FALSE; SDL_MemoryBarrierRelease(); tls_errbuf = slot; } SDL_AtomicUnlock(&tls_lock); } if (!tls_errbuf) { return &SDL_global_errbuf; } SDL_MemoryBarrierAcquire(); errbuf = (SDL_error *)SDL_TLSGet(tls_errbuf); if (errbuf == ALLOCATION_IN_PROGRESS) { return &SDL_global_errbuf; } if (!errbuf) { /* Mark that we're in the middle of allocating our buffer */ SDL_TLSSet(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL); errbuf = (SDL_error *)SDL_malloc(sizeof(*errbuf)); if (!errbuf) { SDL_TLSSet(tls_errbuf, NULL, NULL); return &SDL_global_errbuf; } SDL_zerop(errbuf); SDL_TLSSet(tls_errbuf, errbuf, SDL_free); } return errbuf; #endif /* SDL_THREADS_DISABLED */ } void SDL_RunThread(SDL_Thread *thread) { void *userdata = thread->userdata; int (SDLCALL * userfunc) (void *) = thread->userfunc; int *statusloc = &thread->status; /* Perform any system-dependent setup - this function may not fail */ SDL_SYS_SetupThread(thread->name); /* Get the thread id */ thread->threadid = SDL_ThreadID(); /* Run the function */ *statusloc = userfunc(userdata); /* Clean up thread-local storage */ SDL_TLSCleanup(); /* Mark us as ready to be joined (or detached) */ if (!SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) { /* Clean up if something already detached us. */ if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_CLEANED)) { if (thread->name) { SDL_free(thread->name); } SDL_free(thread); } } } #ifdef SDL_CreateThread #undef SDL_CreateThread #undef SDL_CreateThreadWithStackSize #endif #if SDL_DYNAMIC_API #define SDL_CreateThread SDL_CreateThread_REAL #define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL #endif #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD SDL_Thread * SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), const char *name, const size_t stacksize, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) #else SDL_Thread * SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *), const char *name, const size_t stacksize, void *data) #endif { SDL_Thread *thread; int ret; /* Allocate memory for the thread info structure */ thread = (SDL_Thread *) SDL_calloc(1, sizeof(*thread)); if (thread == NULL) { SDL_OutOfMemory(); return NULL; } thread->status = -1; SDL_AtomicSet(&thread->state, SDL_THREAD_STATE_ALIVE); /* Set up the arguments for the thread */ if (name != NULL) { thread->name = SDL_strdup(name); if (thread->name == NULL) { SDL_OutOfMemory(); SDL_free(thread); return NULL; } } thread->userfunc = fn; thread->userdata = data; thread->stacksize = stacksize; /* Create the thread and go! */ #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD ret = SDL_SYS_CreateThread(thread, pfnBeginThread, pfnEndThread); #else ret = SDL_SYS_CreateThread(thread); #endif if (ret < 0) { /* Oops, failed. Gotta free everything */ SDL_free(thread->name); SDL_free(thread); thread = NULL; } /* Everything is running now */ return thread; } #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(int (SDLCALL * fn) (void *), const char *name, void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) #else DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(int (SDLCALL * fn) (void *), const char *name, void *data) #endif { /* !!! FIXME: in 2.1, just make stackhint part of the usual API. */ const char *stackhint = SDL_GetHint(SDL_HINT_THREAD_STACK_SIZE); size_t stacksize = 0; /* If the SDL_HINT_THREAD_STACK_SIZE exists, use it */ if (stackhint != NULL) { char *endp = NULL; const Sint64 hintval = SDL_strtoll(stackhint, &endp, 10); if ((*stackhint != '\0') && (*endp == '\0')) { /* a valid number? */ if (hintval > 0) { /* reject bogus values. */ stacksize = (size_t) hintval; } } } #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, pfnBeginThread, pfnEndThread); #else #ifdef __ALIOS__ stacksize = 8192 * 6; #endif return SDL_CreateThreadWithStackSize(fn, name, stacksize, data); #endif } SDL_Thread * SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name, const size_t stacksize, void *data) { #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, NULL, NULL); #else return SDL_CreateThreadWithStackSize(fn, name, stacksize, data); #endif } SDL_threadID SDL_GetThreadID(SDL_Thread * thread) { SDL_threadID id; if (thread) { id = thread->threadid; } else { id = SDL_ThreadID(); } return id; } const char * SDL_GetThreadName(SDL_Thread * thread) { if (thread) { return thread->name; } else { return NULL; } } int SDL_SetThreadPriority(SDL_ThreadPriority priority) { return SDL_SYS_SetThreadPriority(priority); } void SDL_WaitThread(SDL_Thread * thread, int *status) { if (thread) { SDL_SYS_WaitThread(thread); if (status) { *status = thread->status; } if (thread->name) { SDL_free(thread->name); } SDL_free(thread); } } void SDL_DetachThread(SDL_Thread * thread) { if (!thread) { return; } /* Grab dibs if the state is alive+joinable. */ if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED)) { SDL_SYS_DetachThread(thread); } else { /* all other states are pretty final, see where we landed. */ const int thread_state = SDL_AtomicGet(&thread->state); if ((thread_state == SDL_THREAD_STATE_DETACHED) || (thread_state == SDL_THREAD_STATE_CLEANED)) { return; /* already detached (you shouldn't call this twice!) */ } else if (thread_state == SDL_THREAD_STATE_ZOMBIE) { SDL_WaitThread(thread, NULL); /* already done, clean it up. */ } else { SDL_assert(0 && "Unexpected thread state"); } } } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/SDL_thread.c
C
apache-2.0
13,299
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #ifndef SDL_thread_c_h_ #define SDL_thread_c_h_ #include "SDL_thread.h" /* Need the definitions of SYS_ThreadHandle */ #if SDL_THREADS_DISABLED #include "generic/SDL_systhread_c.h" #elif SDL_THREAD_PTHREAD #include "pthread/SDL_systhread_c.h" #elif SDL_THREAD_WINDOWS #include "windows/SDL_systhread_c.h" #elif SDL_THREAD_PSP #include "psp/SDL_systhread_c.h" #elif SDL_THREAD_STDCPP #include "stdcpp/SDL_systhread_c.h" #else #error Need thread implementation for this platform #include "generic/SDL_systhread_c.h" #endif #include "../SDL_error_c.h" typedef enum SDL_ThreadState { SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_ZOMBIE, SDL_THREAD_STATE_CLEANED, } SDL_ThreadState; /* This is the system-independent thread info structure */ struct SDL_Thread { SDL_threadID threadid; SYS_ThreadHandle handle; int status; SDL_atomic_t state; /* SDL_THREAD_STATE_* */ SDL_error errbuf; char *name; size_t stacksize; /* 0 for default, >0 for user-specified stack size. */ int (SDLCALL * userfunc) (void *); void *userdata; void *data; void *endfunc; /* only used on some platforms. */ }; /* This is the function called to run a thread */ extern void SDL_RunThread(SDL_Thread *thread); /* This is the system-independent thread local storage structure */ typedef struct { unsigned int limit; struct { void *data; void (SDLCALL *destructor)(void*); } array[1]; } SDL_TLSData; /* This is how many TLS entries we allocate at once */ #define TLS_ALLOC_CHUNKSIZE 4 /* Get cross-platform, slow, thread local storage for this thread. This is only intended as a fallback if getting real thread-local storage fails or isn't supported on this platform. */ extern SDL_TLSData *SDL_Generic_GetTLSData(void); /* Set cross-platform, slow, thread local storage for this thread. This is only intended as a fallback if getting real thread-local storage fails or isn't supported on this platform. */ extern int SDL_Generic_SetTLSData(SDL_TLSData *data); #endif /* SDL_thread_c_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/SDL_thread_c.h
C
apache-2.0
3,099
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* An implementation of condition variables using semaphores and mutexes */ /* This implementation borrows heavily from the BeOS condition variable implementation, written by Christopher Tate and Owen Smith. Thanks! */ #include "SDL_thread.h" struct SDL_cond { SDL_mutex *lock; int waiting; int signals; SDL_sem *wait_sem; SDL_sem *wait_done; }; /* Create a condition variable */ SDL_cond * SDL_CreateCond(void) { SDL_cond *cond; cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); if (cond) { cond->lock = SDL_CreateMutex(); cond->wait_sem = SDL_CreateSemaphore(0); cond->wait_done = SDL_CreateSemaphore(0); cond->waiting = cond->signals = 0; if (!cond->lock || !cond->wait_sem || !cond->wait_done) { SDL_DestroyCond(cond); cond = NULL; } } else { SDL_OutOfMemory(); } return (cond); } /* Destroy a condition variable */ void SDL_DestroyCond(SDL_cond * cond) { if (cond) { if (cond->wait_sem) { SDL_DestroySemaphore(cond->wait_sem); } if (cond->wait_done) { SDL_DestroySemaphore(cond->wait_done); } if (cond->lock) { SDL_DestroyMutex(cond->lock); } SDL_free(cond); } } /* Restart one of the threads that are waiting on the condition variable */ int SDL_CondSignal(SDL_cond * cond) { if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then signal the condition and wait for the thread to respond. */ SDL_LockMutex(cond->lock); if (cond->waiting > cond->signals) { ++cond->signals; SDL_SemPost(cond->wait_sem); SDL_UnlockMutex(cond->lock); SDL_SemWait(cond->wait_done); } else { SDL_UnlockMutex(cond->lock); } return 0; } /* Restart all threads that are waiting on the condition variable */ int SDL_CondBroadcast(SDL_cond * cond) { if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then signal the condition and wait for the thread to respond. */ SDL_LockMutex(cond->lock); if (cond->waiting > cond->signals) { int i, num_waiting; num_waiting = (cond->waiting - cond->signals); cond->signals = cond->waiting; for (i = 0; i < num_waiting; ++i) { SDL_SemPost(cond->wait_sem); } /* Now all released threads are blocked here, waiting for us. Collect them all (and win fabulous prizes!) :-) */ SDL_UnlockMutex(cond->lock); for (i = 0; i < num_waiting; ++i) { SDL_SemWait(cond->wait_done); } } else { SDL_UnlockMutex(cond->lock); } return 0; } /* Wait on the condition variable for at most 'ms' milliseconds. The mutex must be locked before entering this function! The mutex is unlocked during the wait, and locked again after the wait. Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { SDL_CondWait(cond, lock); } SDL_UnlockMutex(lock); Thread B: SDL_LockMutex(lock); ... condition = true; ... SDL_CondSignal(cond); SDL_UnlockMutex(lock); */ int SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { int retval; if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } /* Obtain the protection mutex, and increment the number of waiters. This allows the signal mechanism to only perform a signal if there are waiting threads. */ SDL_LockMutex(cond->lock); ++cond->waiting; SDL_UnlockMutex(cond->lock); /* Unlock the mutex, as is required by condition variable semantics */ SDL_UnlockMutex(mutex); /* Wait for a signal */ if (ms == SDL_MUTEX_MAXWAIT) { retval = SDL_SemWait(cond->wait_sem); } else { retval = SDL_SemWaitTimeout(cond->wait_sem, ms); } /* Let the signaler know we have completed the wait, otherwise the signaler can race ahead and get the condition semaphore if we are stopped between the mutex unlock and semaphore wait, giving a deadlock. See the following URL for details: http://web.archive.org/web/20010914175514/http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html#Workshop */ SDL_LockMutex(cond->lock); if (cond->signals > 0) { /* If we timed out, we need to eat a condition signal */ if (retval > 0) { SDL_SemWait(cond->wait_sem); } /* We always notify the signal thread that we are done */ SDL_SemPost(cond->wait_done); /* Signal handshake complete */ --cond->signals; } --cond->waiting; SDL_UnlockMutex(cond->lock); /* Lock the mutex, as is required by condition variable semantics */ SDL_LockMutex(mutex); return retval; } /* Wait on the condition variable forever */ int SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) { return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/generic/SDL_syscond.c
C
apache-2.0
6,246
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* An implementation of mutexes using semaphores */ #include "SDL_thread.h" #include "SDL_systhread_c.h" struct SDL_mutex { int recursive; SDL_threadID owner; SDL_sem *sem; }; /* Create a mutex */ SDL_mutex * SDL_CreateMutex(void) { SDL_mutex *mutex; /* Allocate mutex memory */ mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex)); if (mutex) { /* Create the mutex semaphore, with initial value 1 */ mutex->sem = SDL_CreateSemaphore(1); mutex->recursive = 0; mutex->owner = 0; if (!mutex->sem) { SDL_free(mutex); mutex = NULL; } } else { SDL_OutOfMemory(); } return mutex; } /* Free the mutex */ void SDL_DestroyMutex(SDL_mutex * mutex) { if (mutex) { if (mutex->sem) { SDL_DestroySemaphore(mutex->sem); } SDL_free(mutex); } } /* Lock the mutex */ int SDL_LockMutex(SDL_mutex * mutex) { #if SDL_THREADS_DISABLED return 0; #else SDL_threadID this_thread; if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); if (mutex->owner == this_thread) { ++mutex->recursive; } else { /* The order of operations is important. We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ SDL_SemWait(mutex->sem); mutex->owner = this_thread; mutex->recursive = 0; } return 0; #endif /* SDL_THREADS_DISABLED */ } /* try Lock the mutex */ int SDL_TryLockMutex(SDL_mutex * mutex) { #if SDL_THREADS_DISABLED return 0; #else int retval = 0; SDL_threadID this_thread; if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); if (mutex->owner == this_thread) { ++mutex->recursive; } else { /* The order of operations is important. We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ retval = SDL_SemWait(mutex->sem); if (retval == 0) { mutex->owner = this_thread; mutex->recursive = 0; } } return retval; #endif /* SDL_THREADS_DISABLED */ } /* Unlock the mutex */ int SDL_mutexV(SDL_mutex * mutex) { #if SDL_THREADS_DISABLED return 0; #else if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } /* If we don't own the mutex, we can't unlock it */ if (SDL_ThreadID() != mutex->owner) { return SDL_SetError("mutex not owned by this thread"); } if (mutex->recursive) { --mutex->recursive; } else { /* The order of operations is important. First reset the owner so another thread doesn't lock the mutex and set the ownership before we reset it, then release the lock semaphore. */ mutex->owner = 0; SDL_SemPost(mutex->sem); } return 0; #endif /* SDL_THREADS_DISABLED */ } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/generic/SDL_sysmutex.c
C
apache-2.0
4,095
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/generic/SDL_sysmutex_c.h
C
apache-2.0
1,006
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* An implementation of semaphores using mutexes and condition variables */ #include "SDL_timer.h" #include "SDL_thread.h" #include "SDL_systhread_c.h" #if SDL_THREADS_DISABLED SDL_sem * SDL_CreateSemaphore(Uint32 initial_value) { SDL_SetError("SDL not built with thread support"); return (SDL_sem *) 0; } void SDL_DestroySemaphore(SDL_sem * sem) { } int SDL_SemTryWait(SDL_sem * sem) { return SDL_SetError("SDL not built with thread support"); } int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { return SDL_SetError("SDL not built with thread support"); } int SDL_SemWait(SDL_sem * sem) { return SDL_SetError("SDL not built with thread support"); } Uint32 SDL_SemValue(SDL_sem * sem) { return 0; } int SDL_SemPost(SDL_sem * sem) { return SDL_SetError("SDL not built with thread support"); } #else struct SDL_semaphore { Uint32 count; Uint32 waiters_count; SDL_mutex *count_lock; SDL_cond *count_nonzero; }; SDL_sem * SDL_CreateSemaphore(Uint32 initial_value) { SDL_sem *sem; sem = (SDL_sem *) SDL_malloc(sizeof(*sem)); if (!sem) { SDL_OutOfMemory(); return NULL; } sem->count = initial_value; sem->waiters_count = 0; sem->count_lock = SDL_CreateMutex(); sem->count_nonzero = SDL_CreateCond(); if (!sem->count_lock || !sem->count_nonzero) { SDL_DestroySemaphore(sem); return NULL; } return sem; } /* WARNING: You cannot call this function when another thread is using the semaphore. */ void SDL_DestroySemaphore(SDL_sem * sem) { if (sem) { sem->count = 0xFFFFFFFF; while (sem->waiters_count > 0) { SDL_CondSignal(sem->count_nonzero); SDL_Delay(10); } SDL_DestroyCond(sem->count_nonzero); if (sem->count_lock) { SDL_LockMutex(sem->count_lock); SDL_UnlockMutex(sem->count_lock); SDL_DestroyMutex(sem->count_lock); } SDL_free(sem); } } int SDL_SemTryWait(SDL_sem * sem) { int retval; if (!sem) { return SDL_SetError("Passed a NULL semaphore"); } retval = SDL_MUTEX_TIMEDOUT; SDL_LockMutex(sem->count_lock); if (sem->count > 0) { --sem->count; retval = 0; } SDL_UnlockMutex(sem->count_lock); return retval; } int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { int retval; if (!sem) { return SDL_SetError("Passed a NULL semaphore"); } /* A timeout of 0 is an easy case */ if (timeout == 0) { return SDL_SemTryWait(sem); } SDL_LockMutex(sem->count_lock); ++sem->waiters_count; retval = 0; while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { retval = SDL_CondWaitTimeout(sem->count_nonzero, sem->count_lock, timeout); } --sem->waiters_count; if (retval == 0) { --sem->count; } SDL_UnlockMutex(sem->count_lock); return retval; } int SDL_SemWait(SDL_sem * sem) { return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); } Uint32 SDL_SemValue(SDL_sem * sem) { Uint32 value; value = 0; if (sem) { SDL_LockMutex(sem->count_lock); value = sem->count; SDL_UnlockMutex(sem->count_lock); } return value; } int SDL_SemPost(SDL_sem * sem) { if (!sem) { return SDL_SetError("Passed a NULL semaphore"); } SDL_LockMutex(sem->count_lock); if (sem->waiters_count > 0) { SDL_CondSignal(sem->count_nonzero); } ++sem->count; SDL_UnlockMutex(sem->count_lock); return 0; } #endif /* SDL_THREADS_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/generic/SDL_syssem.c
C
apache-2.0
4,670
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* Thread management routines for SDL */ #include "SDL_thread.h" #include "../SDL_systhread.h" #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD int SDL_SYS_CreateThread(SDL_Thread * thread, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) #else int SDL_SYS_CreateThread(SDL_Thread * thread) #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */ { return SDL_SetError("Threads are not supported on this platform"); } void SDL_SYS_SetupThread(const char *name) { return; } SDL_threadID SDL_ThreadID(void) { return (0); } int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { return (0); } void SDL_SYS_WaitThread(SDL_Thread * thread) { return; } void SDL_SYS_DetachThread(SDL_Thread * thread) { return; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/generic/SDL_systhread.c
C
apache-2.0
1,805
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* Stub until we implement threads on this platform */ typedef int SYS_ThreadHandle; /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/generic/SDL_systhread_c.h
C
apache-2.0
1,093
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include "../SDL_thread_c.h" SDL_TLSData * SDL_SYS_GetTLSData(void) { return SDL_Generic_GetTLSData(); } int SDL_SYS_SetTLSData(SDL_TLSData *data) { return SDL_Generic_SetTLSData(data); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/generic/SDL_systls.c
C
apache-2.0
1,207
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_PSP /* An implementation of condition variables using semaphores and mutexes */ /* This implementation borrows heavily from the BeOS condition variable implementation, written by Christopher Tate and Owen Smith. Thanks! */ #include "SDL_thread.h" struct SDL_cond { SDL_mutex *lock; int waiting; int signals; SDL_sem *wait_sem; SDL_sem *wait_done; }; /* Create a condition variable */ SDL_cond * SDL_CreateCond(void) { SDL_cond *cond; cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); if (cond) { cond->lock = SDL_CreateMutex(); cond->wait_sem = SDL_CreateSemaphore(0); cond->wait_done = SDL_CreateSemaphore(0); cond->waiting = cond->signals = 0; if (!cond->lock || !cond->wait_sem || !cond->wait_done) { SDL_DestroyCond(cond); cond = NULL; } } else { SDL_OutOfMemory(); } return (cond); } /* Destroy a condition variable */ void SDL_DestroyCond(SDL_cond * cond) { if (cond) { if (cond->wait_sem) { SDL_DestroySemaphore(cond->wait_sem); } if (cond->wait_done) { SDL_DestroySemaphore(cond->wait_done); } if (cond->lock) { SDL_DestroyMutex(cond->lock); } SDL_free(cond); } } /* Restart one of the threads that are waiting on the condition variable */ int SDL_CondSignal(SDL_cond * cond) { if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then signal the condition and wait for the thread to respond. */ SDL_LockMutex(cond->lock); if (cond->waiting > cond->signals) { ++cond->signals; SDL_SemPost(cond->wait_sem); SDL_UnlockMutex(cond->lock); SDL_SemWait(cond->wait_done); } else { SDL_UnlockMutex(cond->lock); } return 0; } /* Restart all threads that are waiting on the condition variable */ int SDL_CondBroadcast(SDL_cond * cond) { if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } /* If there are waiting threads not already signalled, then signal the condition and wait for the thread to respond. */ SDL_LockMutex(cond->lock); if (cond->waiting > cond->signals) { int i, num_waiting; num_waiting = (cond->waiting - cond->signals); cond->signals = cond->waiting; for (i = 0; i < num_waiting; ++i) { SDL_SemPost(cond->wait_sem); } /* Now all released threads are blocked here, waiting for us. Collect them all (and win fabulous prizes!) :-) */ SDL_UnlockMutex(cond->lock); for (i = 0; i < num_waiting; ++i) { SDL_SemWait(cond->wait_done); } } else { SDL_UnlockMutex(cond->lock); } return 0; } /* Wait on the condition variable for at most 'ms' milliseconds. The mutex must be locked before entering this function! The mutex is unlocked during the wait, and locked again after the wait. Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { SDL_CondWait(cond, lock); } SDL_UnlockMutex(lock); Thread B: SDL_LockMutex(lock); ... condition = true; ... SDL_CondSignal(cond); SDL_UnlockMutex(lock); */ int SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { int retval; if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } /* Obtain the protection mutex, and increment the number of waiters. This allows the signal mechanism to only perform a signal if there are waiting threads. */ SDL_LockMutex(cond->lock); ++cond->waiting; SDL_UnlockMutex(cond->lock); /* Unlock the mutex, as is required by condition variable semantics */ SDL_UnlockMutex(mutex); /* Wait for a signal */ if (ms == SDL_MUTEX_MAXWAIT) { retval = SDL_SemWait(cond->wait_sem); } else { retval = SDL_SemWaitTimeout(cond->wait_sem, ms); } /* Let the signaler know we have completed the wait, otherwise the signaler can race ahead and get the condition semaphore if we are stopped between the mutex unlock and semaphore wait, giving a deadlock. See the following URL for details: http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html */ SDL_LockMutex(cond->lock); if (cond->signals > 0) { /* If we timed out, we need to eat a condition signal */ if (retval > 0) { SDL_SemWait(cond->wait_sem); } /* We always notify the signal thread that we are done */ SDL_SemPost(cond->wait_done); /* Signal handshake complete */ --cond->signals; } --cond->waiting; SDL_UnlockMutex(cond->lock); /* Lock the mutex, as is required by condition variable semantics */ SDL_LockMutex(mutex); return retval; } /* Wait on the condition variable forever */ int SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) { return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); } #endif /* SDL_THREAD_PSP */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/psp/SDL_syscond.c
C
apache-2.0
6,244
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_PSP /* An implementation of mutexes using semaphores */ #include "SDL_thread.h" #include "SDL_systhread_c.h" struct SDL_mutex { int recursive; SDL_threadID owner; SDL_sem *sem; }; /* Create a mutex */ SDL_mutex * SDL_CreateMutex(void) { SDL_mutex *mutex; /* Allocate mutex memory */ mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex)); if (mutex) { /* Create the mutex semaphore, with initial value 1 */ mutex->sem = SDL_CreateSemaphore(1); mutex->recursive = 0; mutex->owner = 0; if (!mutex->sem) { SDL_free(mutex); mutex = NULL; } } else { SDL_OutOfMemory(); } return mutex; } /* Free the mutex */ void SDL_DestroyMutex(SDL_mutex * mutex) { if (mutex) { if (mutex->sem) { SDL_DestroySemaphore(mutex->sem); } SDL_free(mutex); } } /* Lock the semaphore */ int SDL_mutexP(SDL_mutex * mutex) { #if SDL_THREADS_DISABLED return 0; #else SDL_threadID this_thread; if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } this_thread = SDL_ThreadID(); if (mutex->owner == this_thread) { ++mutex->recursive; } else { /* The order of operations is important. We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ SDL_SemWait(mutex->sem); mutex->owner = this_thread; mutex->recursive = 0; } return 0; #endif /* SDL_THREADS_DISABLED */ } /* Unlock the mutex */ int SDL_mutexV(SDL_mutex * mutex) { #if SDL_THREADS_DISABLED return 0; #else if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } /* If we don't own the mutex, we can't unlock it */ if (SDL_ThreadID() != mutex->owner) { return SDL_SetError("mutex not owned by this thread"); } if (mutex->recursive) { --mutex->recursive; } else { /* The order of operations is important. First reset the owner so another thread doesn't lock the mutex and set the ownership before we reset it, then release the lock semaphore. */ mutex->owner = 0; SDL_SemPost(mutex->sem); } return 0; #endif /* SDL_THREADS_DISABLED */ } #endif /* SDL_THREAD_PSP */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/psp/SDL_sysmutex.c
C
apache-2.0
3,394
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/psp/SDL_sysmutex_c.h
C
apache-2.0
1,006
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_PSP /* Semaphore functions for the PSP. */ #include <stdio.h> #include <stdlib.h> #include "SDL_error.h" #include "SDL_thread.h" #include <pspthreadman.h> #include <pspkerror.h> struct SDL_semaphore { SceUID semid; }; /* Create a semaphore */ SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) { SDL_sem *sem; sem = (SDL_sem *) malloc(sizeof(*sem)); if (sem != NULL) { /* TODO: Figure out the limit on the maximum value. */ sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL); if (sem->semid < 0) { SDL_SetError("Couldn't create semaphore"); free(sem); sem = NULL; } } else { SDL_OutOfMemory(); } return sem; } /* Free the semaphore */ void SDL_DestroySemaphore(SDL_sem *sem) { if (sem != NULL) { if (sem->semid > 0) { sceKernelDeleteSema(sem->semid); sem->semid = 0; } free(sem); } } /* TODO: This routine is a bit overloaded. * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout * is specified, convert it to microseconds. */ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) { Uint32 *pTimeout; int res; if (sem == NULL) { SDL_SetError("Passed a NULL sem"); return 0; } if (timeout == 0) { res = sceKernelPollSema(sem->semid, 1); if (res < 0) { return SDL_MUTEX_TIMEDOUT; } return 0; } if (timeout == SDL_MUTEX_MAXWAIT) { pTimeout = NULL; } else { timeout *= 1000; /* Convert to microseconds. */ pTimeout = &timeout; } res = sceKernelWaitSema(sem->semid, 1, pTimeout); switch (res) { case SCE_KERNEL_ERROR_OK: return 0; case SCE_KERNEL_ERROR_WAIT_TIMEOUT: return SDL_MUTEX_TIMEDOUT; default: return SDL_SetError("sceKernelWaitSema() failed"); } } int SDL_SemTryWait(SDL_sem *sem) { return SDL_SemWaitTimeout(sem, 0); } int SDL_SemWait(SDL_sem *sem) { return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); } /* Returns the current count of the semaphore */ Uint32 SDL_SemValue(SDL_sem *sem) { SceKernelSemaInfo info; if (sem == NULL) { SDL_SetError("Passed a NULL sem"); return 0; } if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) { return info.currentCount; } return 0; } int SDL_SemPost(SDL_sem *sem) { int res; if (sem == NULL) { return SDL_SetError("Passed a NULL sem"); } res = sceKernelSignalSema(sem->semid, 1); if (res < 0) { return SDL_SetError("sceKernelSignalSema() failed"); } return 0; } #endif /* SDL_THREAD_PSP */ /* vim: ts=4 sw=4 */
YifuLiu/AliOS-Things
components/SDL2/src/thread/psp/SDL_syssem.c
C
apache-2.0
3,921
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_PSP /* PSP thread management routines for SDL */ #include <stdio.h> #include <stdlib.h> #include "SDL_error.h" #include "SDL_thread.h" #include "../SDL_systhread.h" #include "../SDL_thread_c.h" #include <pspkerneltypes.h> #include <pspthreadman.h> static int ThreadEntry(SceSize args, void *argp) { SDL_RunThread(*(SDL_Thread **) argp); return 0; } int SDL_SYS_CreateThread(SDL_Thread *thread) { SceKernelThreadInfo status; int priority = 32; /* Set priority of new thread to the same as the current thread */ status.size = sizeof(SceKernelThreadInfo); if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) { priority = status.currentPriority; } thread->handle = sceKernelCreateThread(thread->name, ThreadEntry, priority, thread->stacksize ? ((int) thread->stacksize) : 0x8000, PSP_THREAD_ATTR_VFPU, NULL); if (thread->handle < 0) { return SDL_SetError("sceKernelCreateThread() failed"); } sceKernelStartThread(thread->handle, 4, &thread); return 0; } void SDL_SYS_SetupThread(const char *name) { /* Do nothing. */ } SDL_threadID SDL_ThreadID(void) { return (SDL_threadID) sceKernelGetThreadId(); } void SDL_SYS_WaitThread(SDL_Thread *thread) { sceKernelWaitThreadEnd(thread->handle, NULL); sceKernelDeleteThread(thread->handle); } void SDL_SYS_DetachThread(SDL_Thread *thread) { /* !!! FIXME: is this correct? */ sceKernelDeleteThread(thread->handle); } void SDL_SYS_KillThread(SDL_Thread *thread) { sceKernelTerminateDeleteThread(thread->handle); } int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int value; if (priority == SDL_THREAD_PRIORITY_LOW) { value = 19; } else if (priority == SDL_THREAD_PRIORITY_HIGH) { value = -10; } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) { value = -20; } else { value = 0; } return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value); } #endif /* SDL_THREAD_PSP */ /* vim: ts=4 sw=4 */
YifuLiu/AliOS-Things
components/SDL2/src/thread/psp/SDL_systhread.c
C
apache-2.0
3,090
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include <pspkerneltypes.h> typedef SceUID SYS_ThreadHandle;
YifuLiu/AliOS-Things
components/SDL2/src/thread/psp/SDL_systhread_c.h
C
apache-2.0
1,002
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include <sys/time.h> #include <time.h> #include <unistd.h> #include <errno.h> #include <pthread.h> #include "SDL_thread.h" #include "SDL_sysmutex_c.h" struct SDL_cond { pthread_cond_t cond; }; /* Create a condition variable */ SDL_cond * SDL_CreateCond(void) { SDL_cond *cond; cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); if (cond) { if (pthread_cond_init(&cond->cond, NULL) != 0) { SDL_SetError("pthread_cond_init() failed"); SDL_free(cond); cond = NULL; } } return (cond); } /* Destroy a condition variable */ void SDL_DestroyCond(SDL_cond * cond) { if (cond) { pthread_cond_destroy(&cond->cond); SDL_free(cond); } } /* Restart one of the threads that are waiting on the condition variable */ int SDL_CondSignal(SDL_cond * cond) { int retval; if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } retval = 0; if (pthread_cond_signal(&cond->cond) != 0) { return SDL_SetError("pthread_cond_signal() failed"); } return retval; } /* Restart all threads that are waiting on the condition variable */ int SDL_CondBroadcast(SDL_cond * cond) { int retval; if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } retval = 0; if (pthread_cond_broadcast(&cond->cond) != 0) { return SDL_SetError("pthread_cond_broadcast() failed"); } return retval; } int SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { int retval; #ifndef HAVE_CLOCK_GETTIME struct timeval delta; #endif struct timespec abstime; if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } #ifdef HAVE_CLOCK_GETTIME clock_gettime(CLOCK_REALTIME, &abstime); abstime.tv_nsec += (ms % 1000) * 1000000; abstime.tv_sec += ms / 1000; #else gettimeofday(&delta, NULL); abstime.tv_sec = delta.tv_sec + (ms / 1000); abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000; #endif if (abstime.tv_nsec > 1000000000) { abstime.tv_sec += 1; abstime.tv_nsec -= 1000000000; } tryagain: retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime); switch (retval) { case EINTR: goto tryagain; /* break; -Wunreachable-code-break */ case ETIMEDOUT: retval = SDL_MUTEX_TIMEDOUT; break; case 0: break; default: retval = SDL_SetError("pthread_cond_timedwait() failed"); } return retval; } /* Wait on the condition variable, unlocking the provided mutex. The mutex must be locked before entering this function! */ int SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) { if (!cond) { return SDL_SetError("Passed a NULL condition variable"); } else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { return SDL_SetError("pthread_cond_wait() failed"); } return 0; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/pthread/SDL_syscond.c
C
apache-2.0
3,994
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include <errno.h> #include <pthread.h> #include "SDL_thread.h" #if !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX && \ !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP #define FAKE_RECURSIVE_MUTEX 1 #endif struct SDL_mutex { pthread_mutex_t id; #if FAKE_RECURSIVE_MUTEX int recursive; pthread_t owner; #endif }; SDL_mutex * SDL_CreateMutex(void) { SDL_mutex *mutex; pthread_mutexattr_t attr; /* Allocate the structure */ mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex)); if (mutex) { pthread_mutexattr_init(&attr); #if SDL_THREAD_PTHREAD_RECURSIVE_MUTEX pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); #elif SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP); #else /* No extra attributes necessary */ #endif if (pthread_mutex_init(&mutex->id, &attr) != 0) { SDL_SetError("pthread_mutex_init() failed"); SDL_free(mutex); mutex = NULL; } } else { SDL_OutOfMemory(); } return (mutex); } void SDL_DestroyMutex(SDL_mutex * mutex) { if (mutex) { pthread_mutex_destroy(&mutex->id); SDL_free(mutex); } } /* Lock the mutex */ int SDL_LockMutex(SDL_mutex * mutex) { #if FAKE_RECURSIVE_MUTEX pthread_t this_thread; #endif if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } #if FAKE_RECURSIVE_MUTEX this_thread = pthread_self(); if (mutex->owner == this_thread) { ++mutex->recursive; } else { /* The order of operations is important. We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ if (pthread_mutex_lock(&mutex->id) == 0) { mutex->owner = this_thread; mutex->recursive = 0; } else { return SDL_SetError("pthread_mutex_lock() failed"); } } #else if (pthread_mutex_lock(&mutex->id) != 0) { return SDL_SetError("pthread_mutex_lock() failed"); } #endif return 0; } int SDL_TryLockMutex(SDL_mutex * mutex) { int retval; int result; #if FAKE_RECURSIVE_MUTEX pthread_t this_thread; #endif if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } retval = 0; #if FAKE_RECURSIVE_MUTEX this_thread = pthread_self(); if (mutex->owner == this_thread) { ++mutex->recursive; } else { /* The order of operations is important. We set the locking thread id after we obtain the lock so unlocks from other threads will fail. */ result = pthread_mutex_trylock(&mutex->id); if (result == 0) { mutex->owner = this_thread; mutex->recursive = 0; } else if (result == EBUSY) { retval = SDL_MUTEX_TIMEDOUT; } else { retval = SDL_SetError("pthread_mutex_trylock() failed"); } } #else result = pthread_mutex_trylock(&mutex->id); if (result != 0) { if (result == EBUSY) { retval = SDL_MUTEX_TIMEDOUT; } else { retval = SDL_SetError("pthread_mutex_trylock() failed"); } } #endif return retval; } int SDL_UnlockMutex(SDL_mutex * mutex) { if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } #if FAKE_RECURSIVE_MUTEX /* We can only unlock the mutex if we own it */ if (pthread_self() == mutex->owner) { if (mutex->recursive) { --mutex->recursive; } else { /* The order of operations is important. First reset the owner so another thread doesn't lock the mutex and set the ownership before we reset it, then release the lock semaphore. */ mutex->owner = 0; pthread_mutex_unlock(&mutex->id); } } else { return SDL_SetError("mutex not owned by this thread"); } #else if (pthread_mutex_unlock(&mutex->id) != 0) { return SDL_SetError("pthread_mutex_unlock() failed"); } #endif /* FAKE_RECURSIVE_MUTEX */ return 0; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/pthread/SDL_sysmutex.c
C
apache-2.0
5,188
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifndef SDL_mutex_c_h_ #define SDL_mutex_c_h_ struct SDL_mutex { pthread_mutex_t id; }; #endif /* SDL_mutex_c_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/pthread/SDL_sysmutex_c.h
C
apache-2.0
1,129
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include <errno.h> #include <pthread.h> #include <semaphore.h> #include <sys/time.h> #include <time.h> #include "SDL_thread.h" #include "SDL_timer.h" /* Wrapper around POSIX 1003.1b semaphores */ #if defined(__MACOSX__) || defined(__IPHONEOS__) /* Mac OS X doesn't support sem_getvalue() as of version 10.4 */ #include "../generic/SDL_syssem.c" #else struct SDL_semaphore { sem_t sem; }; /* Create a semaphore, initialized with value */ SDL_sem * SDL_CreateSemaphore(Uint32 initial_value) { SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem)); if (sem) { if (sem_init(&sem->sem, 0, initial_value) < 0) { SDL_SetError("sem_init() failed"); SDL_free(sem); sem = NULL; } } else { SDL_OutOfMemory(); } return sem; } void SDL_DestroySemaphore(SDL_sem * sem) { if (sem) { sem_destroy(&sem->sem); SDL_free(sem); } } int SDL_SemTryWait(SDL_sem * sem) { int retval; if (!sem) { return SDL_SetError("Passed a NULL semaphore"); } retval = SDL_MUTEX_TIMEDOUT; if (sem_trywait(&sem->sem) == 0) { retval = 0; } return retval; } int SDL_SemWait(SDL_sem * sem) { int retval; if (!sem) { return SDL_SetError("Passed a NULL semaphore"); } do { retval = sem_wait(&sem->sem); } while (retval < 0 && errno == EINTR); if (retval < 0) { retval = SDL_SetError("sem_wait() failed"); } return retval; } int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { int retval; #ifdef HAVE_SEM_TIMEDWAIT #ifndef HAVE_CLOCK_GETTIME struct timeval now; #endif struct timespec ts_timeout; #else Uint32 end; #endif if (!sem) { return SDL_SetError("Passed a NULL semaphore"); } /* Try the easy cases first */ if (timeout == 0) { return SDL_SemTryWait(sem); } if (timeout == SDL_MUTEX_MAXWAIT) { return SDL_SemWait(sem); } #ifdef HAVE_SEM_TIMEDWAIT /* Setup the timeout. sem_timedwait doesn't wait for * a lapse of time, but until we reach a certain time. * This time is now plus the timeout. */ #ifdef HAVE_CLOCK_GETTIME clock_gettime(CLOCK_REALTIME, &ts_timeout); /* Add our timeout to current time */ ts_timeout.tv_nsec += (timeout % 1000) * 1000000; ts_timeout.tv_sec += timeout / 1000; #else gettimeofday(&now, NULL); /* Add our timeout to current time */ ts_timeout.tv_sec = now.tv_sec + (timeout / 1000); ts_timeout.tv_nsec = (now.tv_usec + (timeout % 1000) * 1000) * 1000; #endif /* Wrap the second if needed */ if (ts_timeout.tv_nsec > 1000000000) { ts_timeout.tv_sec += 1; ts_timeout.tv_nsec -= 1000000000; } /* Wait. */ do { retval = sem_timedwait(&sem->sem, &ts_timeout); } while (retval < 0 && errno == EINTR); if (retval < 0) { if (errno == ETIMEDOUT) { retval = SDL_MUTEX_TIMEDOUT; } else { SDL_SetError("sem_timedwait returned an error: %s", strerror(errno)); } } #else end = SDL_GetTicks() + timeout; while ((retval = SDL_SemTryWait(sem)) == SDL_MUTEX_TIMEDOUT) { if (SDL_TICKS_PASSED(SDL_GetTicks(), end)) { break; } SDL_Delay(1); } #endif /* HAVE_SEM_TIMEDWAIT */ return retval; } Uint32 SDL_SemValue(SDL_sem * sem) { int ret = 0; if (sem) { sem_getvalue(&sem->sem, &ret); if (ret < 0) { ret = 0; } } return (Uint32) ret; } int SDL_SemPost(SDL_sem * sem) { int retval; if (!sem) { return SDL_SetError("Passed a NULL semaphore"); } retval = sem_post(&sem->sem); if (retval < 0) { SDL_SetError("sem_post() failed"); } return retval; } #endif /* __MACOSX__ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/pthread/SDL_syssem.c
C
apache-2.0
4,850
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include "SDL_system.h" #include "SDL_hints.h" #include <pthread.h> #if HAVE_PTHREAD_NP_H #include <pthread_np.h> #endif #include <signal.h> #ifdef __LINUX__ #include <sys/time.h> #include <sys/resource.h> #include <sys/syscall.h> #include <unistd.h> #include <errno.h> #include "../../core/linux/SDL_dbus.h" #endif /* __LINUX__ */ #if defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__) #include <dlfcn.h> #ifndef RTLD_DEFAULT #define RTLD_DEFAULT NULL #endif #endif #include "SDL_platform.h" #include "SDL_thread.h" #include "../SDL_thread_c.h" #include "../SDL_systhread.h" #ifdef __ANDROID__ #include "../../core/android/SDL_android.h" #endif #ifdef __HAIKU__ #include <kernel/OS.h> #endif #include "SDL_assert.h" #ifndef __NACL__ /* List of signals to mask in the subthreads */ static const int sig_list[] = { SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH, SIGVTALRM, SIGPROF, 0 }; #endif static void * RunThread(void *data) { #ifdef __ANDROID__ Android_JNI_SetupThread(); #endif SDL_RunThread((SDL_Thread *) data); return NULL; } #if defined(__MACOSX__) || defined(__IPHONEOS__) static SDL_bool checked_setname = SDL_FALSE; static int (*ppthread_setname_np)(const char*) = NULL; #elif defined(__LINUX__) static SDL_bool checked_setname = SDL_FALSE; static int (*ppthread_setname_np)(pthread_t, const char*) = NULL; #endif int SDL_SYS_CreateThread(SDL_Thread * thread) { pthread_attr_t type; /* do this here before any threads exist, so there's no race condition. */ #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__) if (!checked_setname) { void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np"); #if defined(__MACOSX__) || defined(__IPHONEOS__) ppthread_setname_np = (int(*)(const char*)) fn; #elif defined(__LINUX__) ppthread_setname_np = (int(*)(pthread_t, const char*)) fn; #endif checked_setname = SDL_TRUE; } #endif /* Set the thread attributes */ if (pthread_attr_init(&type) != 0) { return SDL_SetError("Couldn't initialize pthread attributes"); } pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); /* Set caller-requested stack size. Otherwise: use the system default. */ if (thread->stacksize) { pthread_attr_setstacksize(&type, thread->stacksize); } /* Create the thread and go! */ if (pthread_create(&thread->handle, &type, RunThread, thread) != 0) { return SDL_SetError("Not enough resources to create thread"); } return 0; } void SDL_SYS_SetupThread(const char *name) { #if !defined(__NACL__) int i; sigset_t mask; #endif /* !__NACL__ */ if (name != NULL) { #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__) SDL_assert(checked_setname); if (ppthread_setname_np != NULL) { #if defined(__MACOSX__) || defined(__IPHONEOS__) ppthread_setname_np(name); #elif defined(__LINUX__) ppthread_setname_np(pthread_self(), name); #endif } #elif HAVE_PTHREAD_SETNAME_NP #if defined(__NETBSD__) pthread_setname_np(pthread_self(), "%s", name); #else pthread_setname_np(pthread_self(), name); #endif #elif HAVE_PTHREAD_SET_NAME_NP pthread_set_name_np(pthread_self(), name); #elif defined(__HAIKU__) /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */ char namebuf[B_OS_NAME_LENGTH]; SDL_snprintf(namebuf, sizeof (namebuf), "%s", name); namebuf[sizeof (namebuf) - 1] = '\0'; rename_thread(find_thread(NULL), namebuf); #endif } /* NativeClient does not yet support signals.*/ #if !defined(__NACL__) /* Mask asynchronous signals for this thread */ sigemptyset(&mask); for (i = 0; sig_list[i]; ++i) { sigaddset(&mask, sig_list[i]); } pthread_sigmask(SIG_BLOCK, &mask, 0); #endif /* !__NACL__ */ #ifdef PTHREAD_CANCEL_ASYNCHRONOUS /* Allow ourselves to be asynchronously cancelled */ { int oldstate; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); } #endif } SDL_threadID SDL_ThreadID(void) { return ((SDL_threadID) pthread_self()); } #if __LINUX__ /** \brief Sets the SDL priority (not nice level) for a thread, using setpriority() if appropriate, and RealtimeKit if available. Differs from SDL_LinuxSetThreadPriority in also taking the desired scheduler policy, such as SCHED_OTHER or SCHED_RR. \return 0 on success, or -1 on error. */ extern DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy); #endif int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { #if __NACL__ || __RISCOS__ /* FIXME: Setting thread priority does not seem to be supported in NACL */ return 0; #else struct sched_param sched; int policy; int pri_policy; pthread_t thread = pthread_self(); const char *policyhint = SDL_GetHint(SDL_HINT_THREAD_PRIORITY_POLICY); if (pthread_getschedparam(thread, &policy, &sched) != 0) { return SDL_SetError("pthread_getschedparam() failed"); } /* Higher priority levels may require changing the pthread scheduler policy * for the thread. SDL will make such changes by default but there is * also a hint allowing that behavior to be overridden. */ switch (priority) { case SDL_THREAD_PRIORITY_LOW: case SDL_THREAD_PRIORITY_NORMAL: pri_policy = SCHED_OTHER; break; case SDL_THREAD_PRIORITY_HIGH: case SDL_THREAD_PRIORITY_TIME_CRITICAL: pri_policy = SCHED_RR; break; default: pri_policy = policy; break; } if (policyhint) { if (SDL_strcmp(policyhint, "current") == 0) { /* Leave current thread scheduler policy unchanged */ } else if (SDL_strcmp(policyhint, "other") == 0) { policy = SCHED_OTHER; } else if (SDL_strcmp(policyhint, "rr") == 0) { policy = SCHED_RR; } else if (SDL_strcmp(policyhint, "fifo") == 0) { policy = SCHED_FIFO; } else { policy = pri_policy; } } else { policy = pri_policy; } #if __LINUX__ { pid_t linuxTid = syscall(SYS_gettid); return SDL_LinuxSetThreadPriorityAndPolicy(linuxTid, priority, policy); } #else if (priority == SDL_THREAD_PRIORITY_LOW) { sched.sched_priority = sched_get_priority_min(policy); } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) { sched.sched_priority = sched_get_priority_max(policy); } else { int min_priority = sched_get_priority_min(policy); int max_priority = sched_get_priority_max(policy); #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__) if (min_priority == 15 && max_priority == 47) { /* Apple has a specific set of thread priorities */ if (priority == SDL_THREAD_PRIORITY_HIGH) { sched.sched_priority = 45; } else { sched.sched_priority = 37; } } else #endif /* __MACOSX__ || __IPHONEOS__ || __TVOS__ */ { sched.sched_priority = (min_priority + (max_priority - min_priority) / 2); if (priority == SDL_THREAD_PRIORITY_HIGH) { sched.sched_priority += ((max_priority - min_priority) / 4); } } } if (pthread_setschedparam(thread, policy, &sched) != 0) { return SDL_SetError("pthread_setschedparam() failed"); } return 0; #endif /* linux */ #endif /* #if __NACL__ || __RISCOS__ */ } void SDL_SYS_WaitThread(SDL_Thread * thread) { pthread_join(thread->handle, 0); } void SDL_SYS_DetachThread(SDL_Thread * thread) { pthread_detach(thread->handle); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/pthread/SDL_systhread.c
C
apache-2.0
9,013
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include <pthread.h> typedef pthread_t SYS_ThreadHandle; /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/pthread/SDL_systhread_c.h
C
apache-2.0
1,066
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #include "SDL_thread.h" #include "../SDL_systhread.h" #include "../SDL_thread_c.h" #include <pthread.h> #define INVALID_PTHREAD_KEY ((pthread_key_t)-1) static pthread_key_t thread_local_storage = INVALID_PTHREAD_KEY; static SDL_bool generic_local_storage = SDL_FALSE; SDL_TLSData * SDL_SYS_GetTLSData(void) { if (thread_local_storage == INVALID_PTHREAD_KEY && !generic_local_storage) { static SDL_SpinLock lock; SDL_AtomicLock(&lock); if (thread_local_storage == INVALID_PTHREAD_KEY && !generic_local_storage) { pthread_key_t storage; if (pthread_key_create(&storage, NULL) == 0) { SDL_MemoryBarrierRelease(); thread_local_storage = storage; } else { generic_local_storage = SDL_TRUE; } } SDL_AtomicUnlock(&lock); } if (generic_local_storage) { return SDL_Generic_GetTLSData(); } SDL_MemoryBarrierAcquire(); return (SDL_TLSData *)pthread_getspecific(thread_local_storage); } int SDL_SYS_SetTLSData(SDL_TLSData *data) { if (generic_local_storage) { return SDL_Generic_SetTLSData(data); } if (pthread_setspecific(thread_local_storage, data) != 0) { return SDL_SetError("pthread_setspecific() failed"); } return 0; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/pthread/SDL_systls.c
C
apache-2.0
2,329
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" extern "C" { #include "SDL_thread.h" } #include <chrono> #include <condition_variable> #include <ratio> #include <system_error> #include "SDL_sysmutex_c.h" struct SDL_cond { std::condition_variable_any cpp_cond; }; /* Create a condition variable */ extern "C" SDL_cond * SDL_CreateCond(void) { /* Allocate and initialize the condition variable */ try { SDL_cond * cond = new SDL_cond; return cond; } catch (std::system_error & ex) { SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what()); return NULL; } catch (std::bad_alloc &) { SDL_OutOfMemory(); return NULL; } } /* Destroy a condition variable */ extern "C" void SDL_DestroyCond(SDL_cond * cond) { if (cond) { delete cond; } } /* Restart one of the threads that are waiting on the condition variable */ extern "C" int SDL_CondSignal(SDL_cond * cond) { if (!cond) { SDL_SetError("Passed a NULL condition variable"); return -1; } cond->cpp_cond.notify_one(); return 0; } /* Restart all threads that are waiting on the condition variable */ extern "C" int SDL_CondBroadcast(SDL_cond * cond) { if (!cond) { SDL_SetError("Passed a NULL condition variable"); return -1; } cond->cpp_cond.notify_all(); return 0; } /* Wait on the condition variable for at most 'ms' milliseconds. The mutex must be locked before entering this function! The mutex is unlocked during the wait, and locked again after the wait. Typical use: Thread A: SDL_LockMutex(lock); while ( ! condition ) { SDL_CondWait(cond, lock); } SDL_UnlockMutex(lock); Thread B: SDL_LockMutex(lock); ... condition = true; ... SDL_CondSignal(cond); SDL_UnlockMutex(lock); */ extern "C" int SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) { if (!cond) { SDL_SetError("Passed a NULL condition variable"); return -1; } if (!mutex) { SDL_SetError("Passed a NULL mutex variable"); return -1; } try { std::unique_lock<std::recursive_mutex> cpp_lock(mutex->cpp_mutex, std::adopt_lock_t()); if (ms == SDL_MUTEX_MAXWAIT) { cond->cpp_cond.wait( cpp_lock ); cpp_lock.release(); return 0; } else { auto wait_result = cond->cpp_cond.wait_for( cpp_lock, std::chrono::duration<Uint32, std::milli>(ms) ); cpp_lock.release(); if (wait_result == std::cv_status::timeout) { return SDL_MUTEX_TIMEDOUT; } else { return 0; } } } catch (std::system_error & ex) { SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what()); return -1; } } /* Wait on the condition variable forever */ extern "C" int SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) { return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/stdcpp/SDL_syscond.cpp
C++
apache-2.0
4,135
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" extern "C" { #include "SDL_thread.h" #include "SDL_systhread_c.h" } #include <system_error> #include "SDL_sysmutex_c.h" #include <Windows.h> /* Create a mutex */ extern "C" SDL_mutex * SDL_CreateMutex(void) { /* Allocate and initialize the mutex */ try { SDL_mutex * mutex = new SDL_mutex; return mutex; } catch (std::system_error & ex) { SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what()); return NULL; } catch (std::bad_alloc &) { SDL_OutOfMemory(); return NULL; } } /* Free the mutex */ extern "C" void SDL_DestroyMutex(SDL_mutex * mutex) { if (mutex) { delete mutex; } } /* Lock the semaphore */ extern "C" int SDL_mutexP(SDL_mutex * mutex) { if (mutex == NULL) { SDL_SetError("Passed a NULL mutex"); return -1; } try { mutex->cpp_mutex.lock(); return 0; } catch (std::system_error & ex) { SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what()); return -1; } } /* TryLock the mutex */ int SDL_TryLockMutex(SDL_mutex * mutex) { int retval = 0; if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } if (mutex->cpp_mutex.try_lock() == false) { retval = SDL_MUTEX_TIMEDOUT; } return retval; } /* Unlock the mutex */ extern "C" int SDL_mutexV(SDL_mutex * mutex) { if (mutex == NULL) { SDL_SetError("Passed a NULL mutex"); return -1; } mutex->cpp_mutex.unlock(); return 0; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/stdcpp/SDL_sysmutex.cpp
C++
apache-2.0
2,581
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" #include <mutex> struct SDL_mutex { std::recursive_mutex cpp_mutex; }; /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/stdcpp/SDL_sysmutex_c.h
C++
apache-2.0
1,076
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* Thread management routines for SDL */ extern "C" { #include "SDL_thread.h" #include "../SDL_thread_c.h" #include "../SDL_systhread.h" } #include <mutex> #include <thread> #include <system_error> #ifdef __WINRT__ #include <Windows.h> #endif static void RunThread(void *args) { SDL_RunThread((SDL_Thread *) args); } extern "C" int SDL_SYS_CreateThread(SDL_Thread * thread) { try { // !!! FIXME: no way to set a thread stack size here. std::thread cpp_thread(RunThread, thread); thread->handle = (void *) new std::thread(std::move(cpp_thread)); return 0; } catch (std::system_error & ex) { SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what()); return -1; } catch (std::bad_alloc &) { SDL_OutOfMemory(); return -1; } } extern "C" void SDL_SYS_SetupThread(const char *name) { // Make sure a thread ID gets assigned ASAP, for debugging purposes: SDL_ThreadID(); return; } extern "C" SDL_threadID SDL_ThreadID(void) { #ifdef __WINRT__ return GetCurrentThreadId(); #else // HACK: Mimick a thread ID, if one isn't otherwise available. static thread_local SDL_threadID current_thread_id = 0; static SDL_threadID next_thread_id = 1; static std::mutex next_thread_id_mutex; if (current_thread_id == 0) { std::lock_guard<std::mutex> lock(next_thread_id_mutex); current_thread_id = next_thread_id; ++next_thread_id; } return current_thread_id; #endif } extern "C" int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { #ifdef __WINRT__ int value; if (priority == SDL_THREAD_PRIORITY_LOW) { value = THREAD_PRIORITY_LOWEST; } else if (priority == SDL_THREAD_PRIORITY_HIGH) { value = THREAD_PRIORITY_HIGHEST; } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) { // FIXME: WinRT does not support TIME_CRITICAL! -flibit SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "TIME_CRITICAL unsupported, falling back to HIGHEST"); value = THREAD_PRIORITY_HIGHEST; } else { value = THREAD_PRIORITY_NORMAL; } if (!SetThreadPriority(GetCurrentThread(), value)) { return WIN_SetError("SetThreadPriority()"); } return 0; #else return SDL_Unsupported(); #endif } extern "C" void SDL_SYS_WaitThread(SDL_Thread * thread) { if ( ! thread) { return; } try { std::thread * cpp_thread = (std::thread *) thread->handle; if (cpp_thread->joinable()) { cpp_thread->join(); } } catch (std::system_error &) { // An error occurred when joining the thread. SDL_WaitThread does not, // however, seem to provide a means to report errors to its callers // though! } } extern "C" void SDL_SYS_DetachThread(SDL_Thread * thread) { if ( ! thread) { return; } try { std::thread * cpp_thread = (std::thread *) thread->handle; if (cpp_thread->joinable()) { cpp_thread->detach(); } } catch (std::system_error &) { // An error occurred when detaching the thread. SDL_DetachThread does not, // however, seem to provide a means to report errors to its callers // though! } } extern "C" SDL_TLSData * SDL_SYS_GetTLSData(void) { return SDL_Generic_GetTLSData(); } extern "C" int SDL_SYS_SetTLSData(SDL_TLSData *data) { return SDL_Generic_SetTLSData(data); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/stdcpp/SDL_systhread.cpp
C++
apache-2.0
4,498
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" /* For a thread handle, use a void pointer to a std::thread */ typedef void * SYS_ThreadHandle; /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/stdcpp/SDL_systhread_c.h
C++
apache-2.0
1,096
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_WINDOWS /* Mutex functions using the Win32 API */ #include "../../core/windows/SDL_windows.h" #include "SDL_mutex.h" struct SDL_mutex { CRITICAL_SECTION cs; }; /* Create a mutex */ SDL_mutex * SDL_CreateMutex(void) { SDL_mutex *mutex; /* Allocate mutex memory */ mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex)); if (mutex) { /* Initialize */ /* On SMP systems, a non-zero spin count generally helps performance */ #if __WINRT__ InitializeCriticalSectionEx(&mutex->cs, 2000, 0); #else InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000); #endif } else { SDL_OutOfMemory(); } return (mutex); } /* Free the mutex */ void SDL_DestroyMutex(SDL_mutex * mutex) { if (mutex) { DeleteCriticalSection(&mutex->cs); SDL_free(mutex); } } /* Lock the mutex */ int SDL_LockMutex(SDL_mutex * mutex) { if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } EnterCriticalSection(&mutex->cs); return (0); } /* TryLock the mutex */ int SDL_TryLockMutex(SDL_mutex * mutex) { int retval = 0; if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } if (TryEnterCriticalSection(&mutex->cs) == 0) { retval = SDL_MUTEX_TIMEDOUT; } return retval; } /* Unlock the mutex */ int SDL_UnlockMutex(SDL_mutex * mutex) { if (mutex == NULL) { return SDL_SetError("Passed a NULL mutex"); } LeaveCriticalSection(&mutex->cs); return (0); } #endif /* SDL_THREAD_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/windows/SDL_sysmutex.c
C
apache-2.0
2,583
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_WINDOWS /* Semaphore functions using the Win32 API */ #include "../../core/windows/SDL_windows.h" #include "SDL_thread.h" struct SDL_semaphore { HANDLE id; LONG count; }; /* Create a semaphore */ SDL_sem * SDL_CreateSemaphore(Uint32 initial_value) { SDL_sem *sem; /* Allocate sem memory */ sem = (SDL_sem *) SDL_malloc(sizeof(*sem)); if (sem) { /* Create the semaphore, with max value 32K */ #if __WINRT__ sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS); #else sem->id = CreateSemaphore(NULL, initial_value, 32 * 1024, NULL); #endif sem->count = initial_value; if (!sem->id) { SDL_SetError("Couldn't create semaphore"); SDL_free(sem); sem = NULL; } } else { SDL_OutOfMemory(); } return (sem); } /* Free the semaphore */ void SDL_DestroySemaphore(SDL_sem * sem) { if (sem) { if (sem->id) { CloseHandle(sem->id); sem->id = 0; } SDL_free(sem); } } int SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) { int retval; DWORD dwMilliseconds; if (!sem) { return SDL_SetError("Passed a NULL sem"); } if (timeout == SDL_MUTEX_MAXWAIT) { dwMilliseconds = INFINITE; } else { dwMilliseconds = (DWORD) timeout; } switch (WaitForSingleObjectEx(sem->id, dwMilliseconds, FALSE)) { case WAIT_OBJECT_0: InterlockedDecrement(&sem->count); retval = 0; break; case WAIT_TIMEOUT: retval = SDL_MUTEX_TIMEDOUT; break; default: retval = SDL_SetError("WaitForSingleObject() failed"); break; } return retval; } int SDL_SemTryWait(SDL_sem * sem) { return SDL_SemWaitTimeout(sem, 0); } int SDL_SemWait(SDL_sem * sem) { return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); } /* Returns the current count of the semaphore */ Uint32 SDL_SemValue(SDL_sem * sem) { if (!sem) { SDL_SetError("Passed a NULL sem"); return 0; } return (Uint32)sem->count; } int SDL_SemPost(SDL_sem * sem) { if (!sem) { return SDL_SetError("Passed a NULL sem"); } /* Increase the counter in the first place, because * after a successful release the semaphore may * immediately get destroyed by another thread which * is waiting for this semaphore. */ InterlockedIncrement(&sem->count); if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) { InterlockedDecrement(&sem->count); /* restore */ return SDL_SetError("ReleaseSemaphore() failed"); } return 0; } #endif /* SDL_THREAD_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/windows/SDL_syssem.c
C
apache-2.0
3,734
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_WINDOWS /* Win32 thread management routines for SDL */ #include "SDL_hints.h" #include "SDL_thread.h" #include "../SDL_thread_c.h" #include "../SDL_systhread.h" #include "SDL_systhread_c.h" #ifndef SDL_PASSED_BEGINTHREAD_ENDTHREAD /* We'll use the C library from this DLL */ #include <process.h> #ifndef STACK_SIZE_PARAM_IS_A_RESERVATION #define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000 #endif /* Cygwin gcc-3 ... MingW64 (even with a i386 host) does this like MSVC. */ #if (defined(__MINGW32__) && (__GNUC__ < 4)) typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned, unsigned (__stdcall *func)(void *), void *arg, unsigned, unsigned *threadID); typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code); #elif defined(__WATCOMC__) /* This is for Watcom targets except OS2 */ #if __WATCOMC__ < 1240 #define __watcall #endif typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (void *, unsigned, unsigned (__stdcall * func) (void *), void *arg, unsigned, unsigned *threadID); typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code); #else typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned, unsigned (__stdcall * func) (void *), void *arg, unsigned, unsigned *threadID); typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code); #endif #endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */ static DWORD RunThread(void *data) { SDL_Thread *thread = (SDL_Thread *) data; pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread) thread->endfunc; SDL_RunThread(thread); if (pfnEndThread != NULL) { pfnEndThread(0); } return 0; } static DWORD WINAPI RunThreadViaCreateThread(LPVOID data) { return RunThread(data); } static unsigned __stdcall RunThreadViaBeginThreadEx(void *data) { return (unsigned) RunThread(data); } #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD int SDL_SYS_CreateThread(SDL_Thread * thread, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread) { #elif defined(__CYGWIN__) || defined(__WINRT__) int SDL_SYS_CreateThread(SDL_Thread * thread) { pfnSDL_CurrentBeginThread pfnBeginThread = NULL; pfnSDL_CurrentEndThread pfnEndThread = NULL; #else int SDL_SYS_CreateThread(SDL_Thread * thread) { pfnSDL_CurrentBeginThread pfnBeginThread = (pfnSDL_CurrentBeginThread)_beginthreadex; pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)_endthreadex; #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */ const DWORD flags = thread->stacksize ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0; /* Save the function which we will have to call to clear the RTL of calling app! */ thread->endfunc = pfnEndThread; /* thread->stacksize == 0 means "system default", same as win32 expects */ if (pfnBeginThread) { unsigned threadid = 0; thread->handle = (SYS_ThreadHandle) ((size_t) pfnBeginThread(NULL, (unsigned int) thread->stacksize, RunThreadViaBeginThreadEx, thread, flags, &threadid)); } else { DWORD threadid = 0; thread->handle = CreateThread(NULL, thread->stacksize, RunThreadViaCreateThread, thread, flags, &threadid); } if (thread->handle == NULL) { return SDL_SetError("Not enough resources to create thread"); } return 0; } #pragma pack(push,8) typedef struct tagTHREADNAME_INFO { DWORD dwType; /* must be 0x1000 */ LPCSTR szName; /* pointer to name (in user addr space) */ DWORD dwThreadID; /* thread ID (-1=caller thread) */ DWORD dwFlags; /* reserved for future use, must be zero */ } THREADNAME_INFO; #pragma pack(pop) typedef HRESULT (WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR); void SDL_SYS_SetupThread(const char *name) { if (name != NULL) { #ifndef __WINRT__ /* !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment. */ static pfnSetThreadDescription pSetThreadDescription = NULL; static HMODULE kernel32 = 0; if (!kernel32) { kernel32 = LoadLibraryW(L"kernel32.dll"); if (kernel32) { pSetThreadDescription = (pfnSetThreadDescription) GetProcAddress(kernel32, "SetThreadDescription"); } } if (pSetThreadDescription != NULL) { WCHAR *strw = WIN_UTF8ToString(name); if (strw) { pSetThreadDescription(GetCurrentThread(), strw); SDL_free(strw); } } #endif /* Presumably some version of Visual Studio will understand SetThreadDescription(), but we still need to deal with older OSes and debuggers. Set it with the arcane exception magic, too. */ if (IsDebuggerPresent()) { THREADNAME_INFO inf; /* C# and friends will try to catch this Exception, let's avoid it. */ if (SDL_GetHintBoolean(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, SDL_TRUE)) { return; } /* This magic tells the debugger to name a thread if it's listening. */ SDL_zero(inf); inf.dwType = 0x1000; inf.szName = name; inf.dwThreadID = (DWORD) -1; inf.dwFlags = 0; /* The debugger catches this, renames the thread, continues on. */ RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR*) &inf); } } } SDL_threadID SDL_ThreadID(void) { return ((SDL_threadID) GetCurrentThreadId()); } int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int value; if (priority == SDL_THREAD_PRIORITY_LOW) { value = THREAD_PRIORITY_LOWEST; } else if (priority == SDL_THREAD_PRIORITY_HIGH) { value = THREAD_PRIORITY_HIGHEST; } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) { value = THREAD_PRIORITY_TIME_CRITICAL; } else { value = THREAD_PRIORITY_NORMAL; } if (!SetThreadPriority(GetCurrentThread(), value)) { return WIN_SetError("SetThreadPriority()"); } return 0; } void SDL_SYS_WaitThread(SDL_Thread * thread) { WaitForSingleObjectEx(thread->handle, INFINITE, FALSE); CloseHandle(thread->handle); } void SDL_SYS_DetachThread(SDL_Thread * thread) { CloseHandle(thread->handle); } #endif /* SDL_THREAD_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/windows/SDL_systhread.c
C
apache-2.0
8,480
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifndef SDL_systhread_c_h_ #define SDL_systhread_c_h_ #include "../../core/windows/SDL_windows.h" typedef HANDLE SYS_ThreadHandle; #endif /* SDL_systhread_c_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/windows/SDL_systhread_c.h
C
apache-2.0
1,174
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if SDL_THREAD_WINDOWS #include "../../core/windows/SDL_windows.h" #include "SDL_thread.h" #include "../SDL_thread_c.h" #if WINAPI_FAMILY_WINRT #include <fibersapi.h> #ifndef TLS_OUT_OF_INDEXES #define TLS_OUT_OF_INDEXES FLS_OUT_OF_INDEXES #endif #define TlsAlloc() FlsAlloc(NULL) #define TlsSetValue FlsSetValue #define TlsGetValue FlsGetValue #endif static DWORD thread_local_storage = TLS_OUT_OF_INDEXES; static SDL_bool generic_local_storage = SDL_FALSE; SDL_TLSData * SDL_SYS_GetTLSData(void) { if (thread_local_storage == TLS_OUT_OF_INDEXES && !generic_local_storage) { static SDL_SpinLock lock; SDL_AtomicLock(&lock); if (thread_local_storage == TLS_OUT_OF_INDEXES && !generic_local_storage) { DWORD storage = TlsAlloc(); if (storage != TLS_OUT_OF_INDEXES) { SDL_MemoryBarrierRelease(); thread_local_storage = storage; } else { generic_local_storage = SDL_TRUE; } } SDL_AtomicUnlock(&lock); } if (generic_local_storage) { return SDL_Generic_GetTLSData(); } SDL_MemoryBarrierAcquire(); return (SDL_TLSData *)TlsGetValue(thread_local_storage); } int SDL_SYS_SetTLSData(SDL_TLSData *data) { if (generic_local_storage) { return SDL_Generic_SetTLSData(data); } if (!TlsSetValue(thread_local_storage, data)) { return SDL_SetError("TlsSetValue() failed"); } return 0; } #endif /* SDL_THREAD_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/thread/windows/SDL_systls.c
C
apache-2.0
2,526
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #include "SDL_timer.h" #include "SDL_timer_c.h" #include "SDL_atomic.h" #include "SDL_cpuinfo.h" #include "../thread/SDL_systhread.h" /* #define DEBUG_TIMERS */ typedef struct _SDL_Timer { int timerID; SDL_TimerCallback callback; void *param; Uint32 interval; Uint32 scheduled; SDL_atomic_t canceled; struct _SDL_Timer *next; } SDL_Timer; typedef struct _SDL_TimerMap { int timerID; SDL_Timer *timer; struct _SDL_TimerMap *next; } SDL_TimerMap; /* The timers are kept in a sorted list */ typedef struct { /* Data used by the main thread */ SDL_Thread *thread; SDL_atomic_t nextID; SDL_TimerMap *timermap; SDL_mutex *timermap_lock; /* Padding to separate cache lines between threads */ char cache_pad[SDL_CACHELINE_SIZE]; /* Data used to communicate with the timer thread */ SDL_SpinLock lock; SDL_sem *sem; SDL_Timer *pending; SDL_Timer *freelist; SDL_atomic_t active; /* List of timers - this is only touched by the timer thread */ SDL_Timer *timers; } SDL_TimerData; static SDL_TimerData SDL_timer_data; /* The idea here is that any thread might add a timer, but a single * thread manages the active timer queue, sorted by scheduling time. * * Timers are removed by simply setting a canceled flag */ static void SDL_AddTimerInternal(SDL_TimerData *data, SDL_Timer *timer) { SDL_Timer *prev, *curr; prev = NULL; for (curr = data->timers; curr; prev = curr, curr = curr->next) { if ((Sint32)(timer->scheduled-curr->scheduled) < 0) { break; } } /* Insert the timer here! */ if (prev) { prev->next = timer; } else { data->timers = timer; } timer->next = curr; } static int SDLCALL SDL_TimerThread(void *_data) { SDL_TimerData *data = (SDL_TimerData *)_data; SDL_Timer *pending; SDL_Timer *current; SDL_Timer *freelist_head = NULL; SDL_Timer *freelist_tail = NULL; Uint32 tick, now, interval, delay; /* Threaded timer loop: * 1. Queue timers added by other threads * 2. Handle any timers that should dispatch this cycle * 3. Wait until next dispatch time or new timer arrives */ for ( ; ; ) { /* Pending and freelist maintenance */ SDL_AtomicLock(&data->lock); { /* Get any timers ready to be queued */ pending = data->pending; data->pending = NULL; /* Make any unused timer structures available */ if (freelist_head) { freelist_tail->next = data->freelist; data->freelist = freelist_head; } } SDL_AtomicUnlock(&data->lock); /* Sort the pending timers into our list */ while (pending) { current = pending; pending = pending->next; SDL_AddTimerInternal(data, current); } freelist_head = NULL; freelist_tail = NULL; /* Check to see if we're still running, after maintenance */ if (!SDL_AtomicGet(&data->active)) { break; } /* Initial delay if there are no timers */ delay = SDL_MUTEX_MAXWAIT; tick = SDL_GetTicks(); /* Process all the pending timers for this tick */ while (data->timers) { current = data->timers; if ((Sint32)(tick-current->scheduled) < 0) { /* Scheduled for the future, wait a bit */ delay = (current->scheduled - tick); break; } /* We're going to do something with this timer */ data->timers = current->next; if (SDL_AtomicGet(&current->canceled)) { interval = 0; } else { interval = current->callback(current->interval, current->param); } if (interval > 0) { /* Reschedule this timer */ current->interval = interval; current->scheduled = tick + interval; SDL_AddTimerInternal(data, current); } else { if (!freelist_head) { freelist_head = current; } if (freelist_tail) { freelist_tail->next = current; } freelist_tail = current; SDL_AtomicSet(&current->canceled, 1); } } /* Adjust the delay based on processing time */ now = SDL_GetTicks(); interval = (now - tick); if (interval > delay) { delay = 0; } else { delay -= interval; } /* Note that each time a timer is added, this will return immediately, but we process the timers added all at once. That's okay, it just means we run through the loop a few extra times. */ SDL_SemWaitTimeout(data->sem, delay); } return 0; } int SDL_TimerInit(void) { SDL_TimerData *data = &SDL_timer_data; if (!SDL_AtomicGet(&data->active)) { const char *name = "SDLTimer"; data->timermap_lock = SDL_CreateMutex(); if (!data->timermap_lock) { return -1; } data->sem = SDL_CreateSemaphore(0); if (!data->sem) { SDL_DestroyMutex(data->timermap_lock); return -1; } SDL_AtomicSet(&data->active, 1); /* Timer threads use a callback into the app, so we can't set a limited stack size here. */ data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data); if (!data->thread) { SDL_TimerQuit(); return -1; } SDL_AtomicSet(&data->nextID, 1); } return 0; } void SDL_TimerQuit(void) { SDL_TimerData *data = &SDL_timer_data; SDL_Timer *timer; SDL_TimerMap *entry; if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */ /* Shutdown the timer thread */ if (data->thread) { SDL_SemPost(data->sem); SDL_WaitThread(data->thread, NULL); data->thread = NULL; } SDL_DestroySemaphore(data->sem); data->sem = NULL; /* Clean up the timer entries */ while (data->timers) { timer = data->timers; data->timers = timer->next; SDL_free(timer); } while (data->freelist) { timer = data->freelist; data->freelist = timer->next; SDL_free(timer); } while (data->timermap) { entry = data->timermap; data->timermap = entry->next; SDL_free(entry); } SDL_DestroyMutex(data->timermap_lock); data->timermap_lock = NULL; } } SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) { SDL_TimerData *data = &SDL_timer_data; SDL_Timer *timer; SDL_TimerMap *entry; SDL_AtomicLock(&data->lock); if (!SDL_AtomicGet(&data->active)) { if (SDL_TimerInit() < 0) { SDL_AtomicUnlock(&data->lock); return 0; } } timer = data->freelist; if (timer) { data->freelist = timer->next; } SDL_AtomicUnlock(&data->lock); if (timer) { SDL_RemoveTimer(timer->timerID); } else { timer = (SDL_Timer *)SDL_malloc(sizeof(*timer)); if (!timer) { SDL_OutOfMemory(); return 0; } } timer->timerID = SDL_AtomicIncRef(&data->nextID); timer->callback = callback; timer->param = param; timer->interval = interval; timer->scheduled = SDL_GetTicks() + interval; SDL_AtomicSet(&timer->canceled, 0); entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry)); if (!entry) { SDL_free(timer); SDL_OutOfMemory(); return 0; } entry->timer = timer; entry->timerID = timer->timerID; SDL_LockMutex(data->timermap_lock); entry->next = data->timermap; data->timermap = entry; SDL_UnlockMutex(data->timermap_lock); /* Add the timer to the pending list for the timer thread */ SDL_AtomicLock(&data->lock); timer->next = data->pending; data->pending = timer; SDL_AtomicUnlock(&data->lock); /* Wake up the timer thread if necessary */ SDL_SemPost(data->sem); return entry->timerID; } SDL_bool SDL_RemoveTimer(SDL_TimerID id) { SDL_TimerData *data = &SDL_timer_data; SDL_TimerMap *prev, *entry; SDL_bool canceled = SDL_FALSE; /* Find the timer */ SDL_LockMutex(data->timermap_lock); prev = NULL; for (entry = data->timermap; entry; prev = entry, entry = entry->next) { if (entry->timerID == id) { if (prev) { prev->next = entry->next; } else { data->timermap = entry->next; } break; } } SDL_UnlockMutex(data->timermap_lock); if (entry) { if (!SDL_AtomicGet(&entry->timer->canceled)) { SDL_AtomicSet(&entry->timer->canceled, 1); canceled = SDL_TRUE; } SDL_free(entry); } return canceled; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/timer/SDL_timer.c
C
apache-2.0
10,259
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_timer_c_h_ #define SDL_timer_c_h_ #include "../SDL_internal.h" /* Useful functions and variables from SDL_timer.c */ #include "SDL_timer.h" #define ROUND_RESOLUTION(X) \ (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION) extern void SDL_TicksInit(void); extern void SDL_TicksQuit(void); extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); #endif /* SDL_timer_c_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/timer/SDL_timer_c.h
C
apache-2.0
1,387
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED) #include "SDL_timer.h" static SDL_bool ticks_started = SDL_FALSE; void SDL_TicksInit(void) { if (ticks_started) { return; } ticks_started = SDL_TRUE; } void SDL_TicksQuit(void) { ticks_started = SDL_FALSE; } Uint32 SDL_GetTicks(void) { if (!ticks_started) { SDL_TicksInit(); } SDL_Unsupported(); return 0; } Uint64 SDL_GetPerformanceCounter(void) { return SDL_GetTicks(); } Uint64 SDL_GetPerformanceFrequency(void) { return 1000; } void SDL_Delay(Uint32 ms) { SDL_Unsupported(); } #endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/timer/dummy/SDL_systimer.c
C
apache-2.0
1,672
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifdef SDL_TIMER_HAIKU #include <kernel/OS.h> #include "SDL_timer.h" static bigtime_t start; static SDL_bool ticks_started = SDL_FALSE; void SDL_TicksInit(void) { if (ticks_started) { return; } ticks_started = SDL_TRUE; /* Set first ticks value */ start = system_time(); } void SDL_TicksQuit(void) { ticks_started = SDL_FALSE; } Uint32 SDL_GetTicks(void) { if (!ticks_started) { SDL_TicksInit(); } return ((system_time() - start) / 1000); } Uint64 SDL_GetPerformanceCounter(void) { return system_time(); } Uint64 SDL_GetPerformanceFrequency(void) { return 1000000; } void SDL_Delay(Uint32 ms) { snooze(ms * 1000); } #endif /* SDL_TIMER_HAIKU */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/timer/haiku/SDL_systimer.c
C
apache-2.0
1,729
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifdef SDL_TIMERS_PSP #include "SDL_thread.h" #include "SDL_timer.h" #include "SDL_error.h" #include "../SDL_timer_c.h" #include <stdlib.h> #include <time.h> #include <sys/time.h> #include <pspthreadman.h> static struct timeval start; static SDL_bool ticks_started = SDL_FALSE; void SDL_TicksInit(void) { if (ticks_started) { return; } ticks_started = SDL_TRUE; gettimeofday(&start, NULL); } void SDL_TicksQuit(void) { ticks_started = SDL_FALSE; } Uint32 SDL_GetTicks(void) { if (!ticks_started) { SDL_TicksInit(); } struct timeval now; Uint32 ticks; gettimeofday(&now, NULL); ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; return(ticks); } Uint64 SDL_GetPerformanceCounter(void) { return SDL_GetTicks(); } Uint64 SDL_GetPerformanceFrequency(void) { return 1000; } void SDL_Delay(Uint32 ms) { const Uint32 max_delay = 0xffffffffUL / 1000; if(ms > max_delay) ms = max_delay; sceKernelDelayThreadCB(ms * 1000); } #endif /* SDL_TIMERS_PSP */ /* vim: ts=4 sw=4 */
YifuLiu/AliOS-Things
components/SDL2/src/timer/psp/SDL_systimer.c
C
apache-2.0
2,062
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifdef SDL_TIMER_UNIX #include <stdio.h> #include <sys/time.h> #include <unistd.h> #include <errno.h> #include "SDL_timer.h" #include "SDL_assert.h" #include "SDL_hints.h" #include "../SDL_timer_c.h" #ifdef __EMSCRIPTEN__ #include <emscripten.h> #endif /* The clock_gettime provides monotonous time, so we should use it if it's available. The clock_gettime function is behind ifdef for __USE_POSIX199309 Tommi Kyntola (tommi.kyntola@ray.fi) 27/09/2005 */ /* Reworked monotonic clock to not assume the current system has one as not all linux kernels provide a monotonic clock (yeah recent ones probably do) Also added OS X Monotonic clock support Based on work in https://github.com/ThomasHabets/monotonic_clock */ #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME #include <time.h> #endif #ifdef __APPLE__ #include <mach/mach_time.h> #endif /* Use CLOCK_MONOTONIC_RAW, if available, which is not subject to adjustment by NTP */ #if HAVE_CLOCK_GETTIME #ifdef CLOCK_MONOTONIC_RAW #define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW #else #define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC #endif #endif /* The first ticks value of the application */ #if HAVE_CLOCK_GETTIME static struct timespec start_ts; #elif defined(__APPLE__) static uint64_t start_mach; mach_timebase_info_data_t mach_base_info; #endif static SDL_bool has_monotonic_time = SDL_FALSE; static struct timeval start_tv; static SDL_bool ticks_started = SDL_FALSE; void SDL_TicksInit(void) { if (ticks_started) { return; } ticks_started = SDL_TRUE; /* Set first ticks value */ #if HAVE_CLOCK_GETTIME if (clock_gettime(SDL_MONOTONIC_CLOCK, &start_ts) == 0) { has_monotonic_time = SDL_TRUE; } else #elif defined(__APPLE__) kern_return_t ret = mach_timebase_info(&mach_base_info); if (ret == 0) { has_monotonic_time = SDL_TRUE; start_mach = mach_absolute_time(); } else #endif { gettimeofday(&start_tv, NULL); } } void SDL_TicksQuit(void) { ticks_started = SDL_FALSE; } Uint32 SDL_GetTicks(void) { Uint32 ticks; if (!ticks_started) { SDL_TicksInit(); } if (has_monotonic_time) { #if HAVE_CLOCK_GETTIME struct timespec now; clock_gettime(SDL_MONOTONIC_CLOCK, &now); ticks = (Uint32)((now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec - start_ts.tv_nsec) / 1000000); #elif defined(__APPLE__) uint64_t now = mach_absolute_time(); ticks = (Uint32)((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000); #else SDL_assert(SDL_FALSE); ticks = 0; #endif } else { struct timeval now; gettimeofday(&now, NULL); ticks = (Uint32)((now.tv_sec - start_tv.tv_sec) * 1000 + (now.tv_usec - start_tv.tv_usec) / 1000); } return (ticks); } Uint64 SDL_GetPerformanceCounter(void) { Uint64 ticks; if (!ticks_started) { SDL_TicksInit(); } if (has_monotonic_time) { #if HAVE_CLOCK_GETTIME struct timespec now; clock_gettime(SDL_MONOTONIC_CLOCK, &now); ticks = now.tv_sec; ticks *= 1000000000; ticks += now.tv_nsec; #elif defined(__APPLE__) ticks = mach_absolute_time(); #else SDL_assert(SDL_FALSE); ticks = 0; #endif } else { struct timeval now; gettimeofday(&now, NULL); ticks = now.tv_sec; ticks *= 1000000; ticks += now.tv_usec; } return (ticks); } Uint64 SDL_GetPerformanceFrequency(void) { if (!ticks_started) { SDL_TicksInit(); } if (has_monotonic_time) { #if HAVE_CLOCK_GETTIME return 1000000000; #elif defined(__APPLE__) Uint64 freq = mach_base_info.denom; freq *= 1000000000; freq /= mach_base_info.numer; return freq; #endif } return 1000000; } void SDL_Delay(Uint32 ms) { #ifdef __EMSCRIPTEN__ if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, SDL_TRUE)) { /* pseudo-synchronous pause, used directly or through e.g. SDL_WaitEvent */ emscripten_sleep(ms); return; } #endif int was_error; #if HAVE_NANOSLEEP struct timespec elapsed, tv; #else struct timeval tv; Uint32 then, now, elapsed; #endif /* Set the timeout interval */ #if HAVE_NANOSLEEP elapsed.tv_sec = ms / 1000; elapsed.tv_nsec = (ms % 1000) * 1000000; #else then = SDL_GetTicks(); #endif do { errno = 0; #if HAVE_NANOSLEEP tv.tv_sec = elapsed.tv_sec; tv.tv_nsec = elapsed.tv_nsec; was_error = nanosleep(&tv, &elapsed); #else /* Calculate the time interval left (in case of interrupt) */ now = SDL_GetTicks(); elapsed = (now - then); then = now; if (elapsed >= ms) { break; } ms -= elapsed; tv.tv_sec = ms / 1000; tv.tv_usec = (ms % 1000) * 1000; was_error = select(0, NULL, NULL, NULL, &tv); #endif /* HAVE_NANOSLEEP */ } while (was_error && (errno == EINTR)); } #endif /* SDL_TIMER_UNIX */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/timer/unix/SDL_systimer.c
C
apache-2.0
6,112
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifdef SDL_TIMER_WINDOWS #include "../../core/windows/SDL_windows.h" #include <mmsystem.h> #include "SDL_timer.h" #include "SDL_hints.h" /* The first (low-resolution) ticks value of the application */ static DWORD start = 0; static BOOL ticks_started = FALSE; /* Store if a high-resolution performance counter exists on the system */ static BOOL hires_timer_available; /* The first high-resolution ticks value of the application */ static LARGE_INTEGER hires_start_ticks; /* The number of ticks per second of the high-resolution performance counter */ static LARGE_INTEGER hires_ticks_per_second; static void SDL_SetSystemTimerResolution(const UINT uPeriod) { #ifndef __WINRT__ static UINT timer_period = 0; if (uPeriod != timer_period) { if (timer_period) { timeEndPeriod(timer_period); } timer_period = uPeriod; if (timer_period) { timeBeginPeriod(timer_period); } } #endif } static void SDLCALL SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { UINT uPeriod; /* Unless the hint says otherwise, let's have good sleep precision */ if (hint && *hint) { uPeriod = SDL_atoi(hint); } else { uPeriod = 1; } if (uPeriod || oldValue != hint) { SDL_SetSystemTimerResolution(uPeriod); } } void SDL_TicksInit(void) { if (ticks_started) { return; } ticks_started = SDL_TRUE; /* if we didn't set a precision, set it high. This affects lots of things on Windows besides the SDL timers, like audio callbacks, etc. */ SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION, SDL_TimerResolutionChanged, NULL); /* Set first ticks value */ /* QueryPerformanceCounter has had problems in the past, but lots of games use it, so we'll rely on it here. */ if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) { hires_timer_available = TRUE; QueryPerformanceCounter(&hires_start_ticks); } else { hires_timer_available = FALSE; #ifndef __WINRT__ start = timeGetTime(); #endif /* __WINRT__ */ } } void SDL_TicksQuit(void) { SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION, SDL_TimerResolutionChanged, NULL); SDL_SetSystemTimerResolution(0); /* always release our timer resolution request. */ start = 0; ticks_started = SDL_FALSE; } Uint32 SDL_GetTicks(void) { DWORD now = 0; LARGE_INTEGER hires_now; if (!ticks_started) { SDL_TicksInit(); } if (hires_timer_available) { QueryPerformanceCounter(&hires_now); hires_now.QuadPart -= hires_start_ticks.QuadPart; hires_now.QuadPart *= 1000; hires_now.QuadPart /= hires_ticks_per_second.QuadPart; return (DWORD) hires_now.QuadPart; } else { #ifndef __WINRT__ now = timeGetTime(); #endif /* __WINRT__ */ } return (now - start); } Uint64 SDL_GetPerformanceCounter(void) { LARGE_INTEGER counter; if (!QueryPerformanceCounter(&counter)) { return SDL_GetTicks(); } return counter.QuadPart; } Uint64 SDL_GetPerformanceFrequency(void) { LARGE_INTEGER frequency; if (!QueryPerformanceFrequency(&frequency)) { return 1000; } return frequency.QuadPart; } void SDL_Delay(Uint32 ms) { /* Sleep() is not publicly available to apps in early versions of WinRT. * * Visual C++ 2013 Update 4 re-introduced Sleep() for Windows 8.1 and * Windows Phone 8.1. * * Use the compiler version to determine availability. * * NOTE #1: _MSC_FULL_VER == 180030723 for Visual C++ 2013 Update 3. * NOTE #2: Visual C++ 2013, when compiling for Windows 8.0 and * Windows Phone 8.0, uses the Visual C++ 2012 compiler to build * apps and libraries. */ #if defined(__WINRT__) && defined(_MSC_FULL_VER) && (_MSC_FULL_VER <= 180030723) static HANDLE mutex = 0; if (!mutex) { mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS); } WaitForSingleObjectEx(mutex, ms, FALSE); #else if (!ticks_started) { SDL_TicksInit(); } Sleep(ms); #endif } #endif /* SDL_TIMER_WINDOWS */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/timer/windows/SDL_systimer.c
C
apache-2.0
5,275
/* SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts Copyright (C) 2001-2018 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ft2build.h> #include FT_FREETYPE_H #include FT_OUTLINE_H #include FT_STROKER_H #include FT_GLYPH_H #include FT_TRUETYPE_IDS_H #include "SDL.h" #include "SDL_endian.h" #include "SDL_ttf.h" /* FIXME: Right now we assume the gray-scale renderer Freetype is using supports 256 shades of gray, but we should instead key off of num_grays in the result FT_Bitmap after the FT_Render_Glyph() call. */ #define NUM_GRAYS 256 #define DEBUG_FONTS /* Handy routines for converting from fixed point */ #define FT_FLOOR(X) ((X & -64) / 64) #define FT_CEIL(X) (((X + 63) & -64) / 64) #define CACHED_METRICS 0x10 #define CACHED_BITMAP 0x01 #define CACHED_PIXMAP 0x02 /* Cached glyph information */ typedef struct cached_glyph { int stored; FT_UInt index; FT_Bitmap bitmap; FT_Bitmap pixmap; int minx; int maxx; int miny; int maxy; int yoffset; int advance; Uint32 cached; } c_glyph; /* The structure used to hold internal font information */ struct _TTF_Font { /* Freetype2 maintains all sorts of useful info itself */ FT_Face face; /* We'll cache these ourselves */ int height; int ascent; int descent; int lineskip; /* The font style */ int face_style; int style; int outline; /* Whether kerning is desired */ int kerning; /* Extra width in glyph bounds for text styles */ int glyph_overhang; float glyph_italics; /* Information in the font for underlining */ int underline_offset; int underline_height; /* Cache for style-transformed glyphs */ c_glyph *current; c_glyph cache[257]; /* 257 is a prime */ /* We are responsible for closing the font stream */ SDL_RWops *src; int freesrc; FT_Open_Args args; /* For non-scalable formats, we must remember which font index size */ int font_size_family; /* really just flags passed into FT_Load_Glyph */ int hinting; }; /* Handle a style only if the font does not already handle it */ #define TTF_HANDLE_STYLE_BOLD(font) (((font)->style & TTF_STYLE_BOLD) && \ !((font)->face_style & TTF_STYLE_BOLD)) #define TTF_HANDLE_STYLE_ITALIC(font) (((font)->style & TTF_STYLE_ITALIC) && \ !((font)->face_style & TTF_STYLE_ITALIC)) #define TTF_HANDLE_STYLE_UNDERLINE(font) ((font)->style & TTF_STYLE_UNDERLINE) #define TTF_HANDLE_STYLE_STRIKETHROUGH(font) ((font)->style & TTF_STYLE_STRIKETHROUGH) /* Font styles that does not impact glyph drawing */ #define TTF_STYLE_NO_GLYPH_CHANGE (TTF_STYLE_UNDERLINE | TTF_STYLE_STRIKETHROUGH) /* The FreeType font engine/library */ static FT_Library library; static int TTF_initialized = 0; static int TTF_byteswapped = 0; #define TTF_CHECKPOINTER(p, errval) \ if (!TTF_initialized) { \ TTF_SetError("Library not initialized"); \ return errval; \ } \ if (!p) { \ TTF_SetError("Passed a NULL pointer"); \ return errval; \ } /* Gets the top row of the underline. The outline is taken into account. */ static int TTF_underline_top_row(TTF_Font *font) { /* With outline, the underline_offset is underline_offset+outline. */ /* So, we don't have to remove the top part of the outline height. */ return font->ascent - font->underline_offset - 1; } /* Gets the top row of the underline. for a given glyph. The outline is taken into account. Need to update row according to height difference between font and glyph: font_value - font->ascent + glyph->maxy */ static int TTF_Glyph_underline_top_row(TTF_Font *font, c_glyph *glyph) { return glyph->maxy - font->underline_offset - 1; } /* Gets the bottom row of the underline. The outline is taken into account. */ static int TTF_underline_bottom_row(TTF_Font *font) { int row = TTF_underline_top_row(font) + font->underline_height; if (font->outline > 0) { /* Add underline_offset outline offset and */ /* the bottom part of the outline. */ row += font->outline * 2; } return row; } /* Gets the bottom row of the underline. for a given glyph. The outline is taken into account. Need to update row according to height difference between font and glyph: font_value - font->ascent + glyph->maxy */ static int TTF_Glyph_underline_bottom_row(TTF_Font *font, c_glyph *glyph) { return TTF_underline_bottom_row(font) - font->ascent + glyph->maxy; } /* Gets the top row of the strikethrough. The outline is taken into account. */ static int TTF_strikethrough_top_row(TTF_Font *font) { /* With outline, the first text row is 'outline'. */ /* So, we don't have to remove the top part of the outline height. */ return font->height / 2; } /* Gets the top row of the strikethrough for a given glyph. The outline is taken into account. Need to update row according to height difference between font and glyph: font_value - font->ascent + glyph->maxy */ static int TTF_Glyph_strikethrough_top_row(TTF_Font *font, c_glyph *glyph) { return TTF_strikethrough_top_row(font) - font->ascent + glyph->maxy; } static void TTF_initLineMectrics(const TTF_Font *font, const SDL_Surface *textbuf, const int row, Uint8 **pdst, int *pheight) { Uint8 *dst; int height; dst = (Uint8 *)textbuf->pixels; if (row > 0) { dst += row * textbuf->pitch; } height = font->underline_height; /* Take outline into account */ if (font->outline > 0) { height += font->outline * 2; } *pdst = dst; *pheight = height; } /* Draw a solid line of underline_height (+ optional outline) at the given row. The row value must take the outline into account. */ static void TTF_drawLine_Solid(const TTF_Font *font, const SDL_Surface *textbuf, const int row) { int line; Uint8 *dst_check = (Uint8*)textbuf->pixels + textbuf->pitch * textbuf->h; Uint8 *dst; int height; TTF_initLineMectrics(font, textbuf, row, &dst, &height); /* Draw line */ for (line=height; line>0 && dst < dst_check; --line) { /* 1 because 0 is the bg color */ SDL_memset(dst, 1, textbuf->w); dst += textbuf->pitch; } } /* Draw a shaded line of underline_height (+ optional outline) at the given row. The row value must take the outline into account. */ static void TTF_drawLine_Shaded(const TTF_Font *font, const SDL_Surface *textbuf, const int row) { int line; Uint8 *dst_check = (Uint8*)textbuf->pixels + textbuf->pitch * textbuf->h; Uint8 *dst; int height; TTF_initLineMectrics(font, textbuf, row, &dst, &height); /* Draw line */ for (line=height; line>0 && dst < dst_check; --line) { SDL_memset(dst, NUM_GRAYS - 1, textbuf->w); dst += textbuf->pitch; } } /* Draw a blended line of underline_height (+ optional outline) at the given row. The row value must take the outline into account. */ static void TTF_drawLine_Blended(const TTF_Font *font, const SDL_Surface *textbuf, const int row, const Uint32 color) { int line; Uint32 *dst_check = (Uint32*)textbuf->pixels + textbuf->pitch/4 * textbuf->h; Uint8 *dst8; /* destination, byte version */ Uint32 *dst; int height; int col; Uint32 pixel = color | 0xFF000000; /* Amask */ TTF_initLineMectrics(font, textbuf, row, &dst8, &height); dst = (Uint32 *) dst8; /* Draw line */ for (line=height; line>0 && dst < dst_check; --line) { for (col=0; col < textbuf->w; ++col) { dst[col] = pixel; } dst += textbuf->pitch/4; } } /* rcg06192001 get linked library's version. */ const SDL_version *TTF_Linked_Version(void) { static SDL_version linked_version; SDL_TTF_VERSION(&linked_version); return(&linked_version); } /* This function tells the library whether UNICODE text is generally byteswapped. A UNICODE BOM character at the beginning of a string will override this setting for that string. */ void TTF_ByteSwappedUNICODE(int swapped) { TTF_byteswapped = swapped; } static void TTF_SetFTError(const char *msg, FT_Error error) { #ifdef USE_FREETYPE_ERRORS #undef FTERRORS_H #define FT_ERRORDEF(e, v, s) { e, s }, static const struct { int err_code; const char* err_msg; } ft_errors[] = { #include <freetype/fterrors.h> }; int i; const char *err_msg; char buffer[1024]; err_msg = NULL; for (i=0; i<((sizeof ft_errors)/(sizeof ft_errors[0])); ++i) { if (error == ft_errors[i].err_code) { err_msg = ft_errors[i].err_msg; break; } } if (!err_msg) { err_msg = "unknown FreeType error"; } TTF_SetError("%s: %s", msg, err_msg); #else TTF_SetError("%s", msg); #endif /* USE_FREETYPE_ERRORS */ } int TTF_Init(void) { int status = 0; if (!TTF_initialized) { FT_Error error = FT_Init_FreeType(&library); if (error) { TTF_SetFTError("Couldn't init FreeType engine", error); status = -1; } } if (status == 0) { ++TTF_initialized; } return status; } static unsigned long RWread( FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count ) { SDL_RWops *src; src = (SDL_RWops *)stream->descriptor.pointer; SDL_RWseek(src, (int)offset, RW_SEEK_SET); if (count == 0) { return 0; } return (unsigned long)SDL_RWread(src, buffer, 1, (int)count); } TTF_Font* TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index) { TTF_Font* font; FT_Error error; FT_Face face; FT_Fixed scale; FT_Stream stream; FT_CharMap found; Sint64 position; int i; if (!TTF_initialized) { TTF_SetError("Library not initialized"); printf("Library not initialized"); if (src && freesrc) { SDL_RWclose(src); } return NULL; } if (!src) { TTF_SetError("Passed a NULL font source"); return NULL; } /* Check to make sure we can seek in this stream */ position = SDL_RWtell(src); if (position < 0) { printf("Can't seek in stream"); TTF_SetError("Can't seek in stream"); if (freesrc) { SDL_RWclose(src); } return NULL; } font = (TTF_Font*)SDL_malloc(sizeof *font); if (font == NULL) { printf("Out of memory"); TTF_SetError("Out of memory"); if (freesrc) { SDL_RWclose(src); } return NULL; } SDL_memset(font, 0, sizeof(*font)); font->src = src; font->freesrc = freesrc; stream = (FT_Stream)SDL_malloc(sizeof(*stream)); if (stream == NULL) { printf("Out of memory"); TTF_SetError("Out of memory"); TTF_CloseFont(font); return NULL; } SDL_memset(stream, 0, sizeof(*stream)); stream->read = RWread; stream->descriptor.pointer = src; stream->pos = (unsigned long)position; stream->size = (unsigned long)(SDL_RWsize(src) - position); font->args.flags = FT_OPEN_STREAM; font->args.stream = stream; error = FT_Open_Face(library, &font->args, index, &font->face); if (error) { printf("Couldn't load font file", error); TTF_SetFTError("Couldn't load font file", error); TTF_CloseFont(font); return NULL; } face = font->face; /* Set charmap for loaded font */ found = 0; #if 0 /* Font debug code */ for (i = 0; i < face->num_charmaps; i++) { FT_CharMap charmap = face->charmaps[i]; printf("Found charmap: platform id %d, encoding id %d\n", charmap->platform_id, charmap->encoding_id); } #endif if (!found) { for (i = 0; i < face->num_charmaps; i++) { FT_CharMap charmap = face->charmaps[i]; if (charmap->platform_id == 3 && charmap->encoding_id == 10) { /* UCS-4 Unicode */ found = charmap; break; } } } if (!found) { for (i = 0; i < face->num_charmaps; i++) { FT_CharMap charmap = face->charmaps[i]; if ((charmap->platform_id == 3 && charmap->encoding_id == 1) /* Windows Unicode */ || (charmap->platform_id == 3 && charmap->encoding_id == 0) /* Windows Symbol */ || (charmap->platform_id == 2 && charmap->encoding_id == 1) /* ISO Unicode */ || (charmap->platform_id == 0)) { /* Apple Unicode */ found = charmap; break; } } } if (found) { /* If this fails, continue using the default charmap */ FT_Set_Charmap(face, found); } /* Make sure that our font face is scalable (global metrics) */ if (FT_IS_SCALABLE(face)) { /* Set the character size and use default DPI (72) */ error = FT_Set_Char_Size(font->face, 0, ptsize * 64, 0, 0); if (error) { TTF_SetFTError("Couldn't set font size", error); TTF_CloseFont(font); return NULL; } /* Get the scalable font metrics for this font */ scale = face->size->metrics.y_scale; font->ascent = FT_CEIL(FT_MulFix(face->ascender, scale)); font->descent = FT_CEIL(FT_MulFix(face->descender, scale)); font->height = font->ascent - font->descent + /* baseline */ 1; font->lineskip = FT_CEIL(FT_MulFix(face->height, scale)); font->underline_offset = FT_FLOOR(FT_MulFix(face->underline_position, scale)); font->underline_height = FT_FLOOR(FT_MulFix(face->underline_thickness, scale)); } else { /* Non-scalable font case. ptsize determines which family * or series of fonts to grab from the non-scalable format. * It is not the point size of the font. * */ if (ptsize >= font->face->num_fixed_sizes) ptsize = font->face->num_fixed_sizes - 1; font->font_size_family = ptsize; error = FT_Set_Pixel_Sizes(face, face->available_sizes[ptsize].width, face->available_sizes[ptsize].height); /* With non-scalale fonts, Freetype2 likes to fill many of the * font metrics with the value of 0. The size of the * non-scalable fonts must be determined differently * or sometimes cannot be determined. * */ font->ascent = face->available_sizes[ptsize].height; font->descent = 0; font->height = face->available_sizes[ptsize].height; font->lineskip = FT_CEIL(font->ascent); font->underline_offset = FT_FLOOR(face->underline_position); font->underline_height = FT_FLOOR(face->underline_thickness); } if (font->underline_height < 1) { font->underline_height = 1; } #ifdef DEBUG_FONTS printf("Font metrics:\n"); printf("\tascent = %d, descent = %d\n", font->ascent, font->descent); printf("\theight = %d, lineskip = %d\n", font->height, font->lineskip); printf("\tunderline_offset = %d, underline_height = %d\n", font->underline_offset, font->underline_height); printf("\tunderline_top_row = %d, strikethrough_top_row = %d\n", TTF_underline_top_row(font), TTF_strikethrough_top_row(font)); #endif /* Initialize the font face style */ font->face_style = TTF_STYLE_NORMAL; if (font->face->style_flags & FT_STYLE_FLAG_BOLD) { font->face_style |= TTF_STYLE_BOLD; } if (font->face->style_flags & FT_STYLE_FLAG_ITALIC) { font->face_style |= TTF_STYLE_ITALIC; } /* Set the default font style */ font->style = font->face_style; font->outline = 0; font->kerning = 1; font->glyph_overhang = face->size->metrics.y_ppem / 10; /* x offset = cos(((90.0-12)/360)*2*M_PI), or 12 degree angle */ font->glyph_italics = 0.207f; font->glyph_italics *= font->height; return font; } TTF_Font* TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize) { return TTF_OpenFontIndexRW(src, freesrc, ptsize, 0); } TTF_Font* TTF_OpenFontIndex(const char *file, int ptsize, long index) { SDL_RWops *rw = SDL_RWFromFile(file, "rb"); if (rw == NULL) { return NULL; } return TTF_OpenFontIndexRW(rw, 1, ptsize, index); } TTF_Font* TTF_OpenFont(const char *file, int ptsize) { return TTF_OpenFontIndex(file, ptsize, 0); } static void Flush_Glyph(c_glyph* glyph) { glyph->stored = 0; glyph->index = 0; if (glyph->bitmap.buffer) { SDL_free(glyph->bitmap.buffer); glyph->bitmap.buffer = 0; } if (glyph->pixmap.buffer) { SDL_free(glyph->pixmap.buffer); glyph->pixmap.buffer = 0; } glyph->cached = 0; } static void Flush_Cache(TTF_Font* font) { int i; int size = sizeof(font->cache) / sizeof(font->cache[0]); for (i = 0; i < size; ++i) { if (font->cache[i].cached) { Flush_Glyph(&font->cache[i]); } } } static FT_Error Load_Glyph(TTF_Font* font, Uint32 ch, c_glyph* cached, int want) { FT_Face face; FT_Error error; FT_GlyphSlot glyph; FT_Glyph_Metrics* metrics; FT_Outline* outline; if (!font || !font->face) { return FT_Err_Invalid_Handle; } face = font->face; /* Load the glyph */ if (!cached->index) { cached->index = FT_Get_Char_Index(face, ch); } error = FT_Load_Glyph(face, cached->index, FT_LOAD_DEFAULT | font->hinting); if (error) { return error; } /* Get our glyph shortcuts */ glyph = face->glyph; metrics = &glyph->metrics; outline = &glyph->outline; /* Get the glyph metrics if desired */ if ((want & CACHED_METRICS) && !(cached->stored & CACHED_METRICS)) { if (FT_IS_SCALABLE(face)) { /* Get the bounding box */ cached->minx = FT_FLOOR(metrics->horiBearingX); cached->maxx = FT_CEIL(metrics->horiBearingX + metrics->width); cached->maxy = FT_FLOOR(metrics->horiBearingY); cached->miny = cached->maxy - FT_CEIL(metrics->height); cached->yoffset = font->ascent - cached->maxy; cached->advance = FT_CEIL(metrics->horiAdvance); } else { /* Get the bounding box for non-scalable format. * Again, freetype2 fills in many of the font metrics * with the value of 0, so some of the values we * need must be calculated differently with certain * assumptions about non-scalable formats. * */ cached->minx = FT_FLOOR(metrics->horiBearingX); cached->maxx = FT_CEIL(metrics->horiBearingX + metrics->width); cached->maxy = FT_FLOOR(metrics->horiBearingY); cached->miny = cached->maxy - FT_CEIL(face->available_sizes[font->font_size_family].height); cached->yoffset = 0; cached->advance = FT_CEIL(metrics->horiAdvance); } /* Adjust for bold and italic text */ if (TTF_HANDLE_STYLE_BOLD(font)) { cached->maxx += font->glyph_overhang; } if (TTF_HANDLE_STYLE_ITALIC(font)) { cached->maxx += (int)SDL_ceil(font->glyph_italics); } cached->stored |= CACHED_METRICS; } if (((want & CACHED_BITMAP) && !(cached->stored & CACHED_BITMAP)) || ((want & CACHED_PIXMAP) && !(cached->stored & CACHED_PIXMAP))) { int mono = (want & CACHED_BITMAP); int i; FT_Bitmap* src; FT_Bitmap* dst; FT_Glyph bitmap_glyph = NULL; /* Handle the italic style */ if (TTF_HANDLE_STYLE_ITALIC(font)) { FT_Matrix shear; shear.xx = 1 << 16; shear.xy = (int) (font->glyph_italics * (1 << 16)) / font->height; shear.yx = 0; shear.yy = 1 << 16; FT_Outline_Transform(outline, &shear); } /* Render as outline */ if ((font->outline > 0) && glyph->format != FT_GLYPH_FORMAT_BITMAP) { FT_Stroker stroker; FT_Get_Glyph(glyph, &bitmap_glyph); error = FT_Stroker_New(library, &stroker); if (error) { return error; } FT_Stroker_Set(stroker, font->outline * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); FT_Glyph_Stroke(&bitmap_glyph, stroker, 1 /* delete the original glyph */); FT_Stroker_Done(stroker); /* Render the glyph */ error = FT_Glyph_To_Bitmap(&bitmap_glyph, mono ? ft_render_mode_mono : ft_render_mode_normal, 0, 1); if (error) { FT_Done_Glyph(bitmap_glyph); return error; } src = &((FT_BitmapGlyph)bitmap_glyph)->bitmap; } else { /* Render the glyph */ error = FT_Render_Glyph(glyph, mono ? ft_render_mode_mono : ft_render_mode_normal); if (error) { return error; } src = &glyph->bitmap; } /* Copy over information to cache */ if (mono) { dst = &cached->bitmap; } else { dst = &cached->pixmap; } SDL_memcpy(dst, src, sizeof(*dst)); /* FT_Render_Glyph() and .fon fonts always generate a * two-color (black and white) glyphslot surface, even * when rendered in ft_render_mode_normal. */ /* FT_IS_SCALABLE() means that the font is in outline format, * but does not imply that outline is rendered as 8-bit * grayscale, because embedded bitmap/graymap is preferred * (see FT_LOAD_DEFAULT section of FreeType2 API Reference). * FT_Render_Glyph() canreturn two-color bitmap or 4/16/256- * color graymap according to the format of embedded bitmap/ * graymap. */ if (src->pixel_mode == FT_PIXEL_MODE_MONO) { dst->pitch *= 8; } else if (src->pixel_mode == FT_PIXEL_MODE_GRAY2) { dst->pitch *= 4; } else if (src->pixel_mode == FT_PIXEL_MODE_GRAY4) { dst->pitch *= 2; } /* Adjust for bold and italic text */ if (TTF_HANDLE_STYLE_BOLD(font)) { int bump = font->glyph_overhang; dst->pitch += bump; dst->width += bump; } if (TTF_HANDLE_STYLE_ITALIC(font)) { int bump = (int)SDL_ceil(font->glyph_italics); dst->pitch += bump; dst->width += bump; } if (dst->rows != 0) { dst->buffer = (unsigned char *)SDL_malloc(dst->pitch * dst->rows); if (!dst->buffer) { return FT_Err_Out_Of_Memory; } SDL_memset(dst->buffer, 0, dst->pitch * dst->rows); for (i = 0; i < src->rows; i++) { int soffset = i * src->pitch; int doffset = i * dst->pitch; if (mono) { unsigned char *srcp = src->buffer + soffset; unsigned char *dstp = dst->buffer + doffset; int j; if (src->pixel_mode == FT_PIXEL_MODE_MONO) { for (j = 0; j < src->width; j += 8) { unsigned char c = *srcp++; *dstp++ = (c&0x80) >> 7; c <<= 1; *dstp++ = (c&0x80) >> 7; c <<= 1; *dstp++ = (c&0x80) >> 7; c <<= 1; *dstp++ = (c&0x80) >> 7; c <<= 1; *dstp++ = (c&0x80) >> 7; c <<= 1; *dstp++ = (c&0x80) >> 7; c <<= 1; *dstp++ = (c&0x80) >> 7; c <<= 1; *dstp++ = (c&0x80) >> 7; } } else if (src->pixel_mode == FT_PIXEL_MODE_GRAY2) { for (j = 0; j < src->width; j += 4) { unsigned char c = *srcp++; *dstp++ = (((c&0xA0) >> 6) >= 0x2) ? 1 : 0; c <<= 2; *dstp++ = (((c&0xA0) >> 6) >= 0x2) ? 1 : 0; c <<= 2; *dstp++ = (((c&0xA0) >> 6) >= 0x2) ? 1 : 0; c <<= 2; *dstp++ = (((c&0xA0) >> 6) >= 0x2) ? 1 : 0; } } else if (src->pixel_mode == FT_PIXEL_MODE_GRAY4) { for (j = 0; j < src->width; j += 2) { unsigned char c = *srcp++; *dstp++ = (((c&0xF0) >> 4) >= 0x8) ? 1 : 0; c <<= 4; *dstp++ = (((c&0xF0) >> 4) >= 0x8) ? 1 : 0; } } else { for (j = 0; j < src->width; j++) { unsigned char c = *srcp++; *dstp++ = (c >= 0x80) ? 1 : 0; } } } else if (src->pixel_mode == FT_PIXEL_MODE_MONO) { /* This special case wouldn't * be here if the FT_Render_Glyph() * function wasn't buggy when it tried * to render a .fon font with 256 * shades of gray. Instead, it * returns a black and white surface * and we have to translate it back * to a 256 gray shaded surface. * */ unsigned char *srcp = src->buffer + soffset; unsigned char *dstp = dst->buffer + doffset; unsigned char c; int j, k; for (j = 0; j < src->width; j += 8) { c = *srcp++; for (k = 0; k < 8; ++k) { if ((c&0x80) >> 7) { *dstp++ = NUM_GRAYS - 1; } else { *dstp++ = 0x00; } c <<= 1; } } } else if (src->pixel_mode == FT_PIXEL_MODE_GRAY2) { unsigned char *srcp = src->buffer + soffset; unsigned char *dstp = dst->buffer + doffset; unsigned char c; int j, k; for (j = 0; j < src->width; j += 4) { c = *srcp++; for (k = 0; k < 4; ++k) { if ((c&0xA0) >> 6) { *dstp++ = NUM_GRAYS * ((c&0xA0) >> 6) / 3 - 1; } else { *dstp++ = 0x00; } c <<= 2; } } } else if (src->pixel_mode == FT_PIXEL_MODE_GRAY4) { unsigned char *srcp = src->buffer + soffset; unsigned char *dstp = dst->buffer + doffset; unsigned char c; int j, k; for (j = 0; j < src->width; j += 2) { c = *srcp++; for (k = 0; k < 2; ++k) { if ((c&0xF0) >> 4) { *dstp++ = NUM_GRAYS * ((c&0xF0) >> 4) / 15 - 1; } else { *dstp++ = 0x00; } c <<= 4; } } } else { SDL_memcpy(dst->buffer+doffset, src->buffer+soffset, src->pitch); } } } /* Handle the bold style */ if (TTF_HANDLE_STYLE_BOLD(font)) { int row; int col; int offset; int pixel; Uint8* pixmap; /* The pixmap is a little hard, we have to add and clamp */ for (row = dst->rows - 1; row >= 0; --row) { pixmap = (Uint8*) dst->buffer + row * dst->pitch; for (offset=1; offset <= font->glyph_overhang; ++offset) { for (col = dst->width - 1; col > 0; --col) { if (mono) { pixmap[col] |= pixmap[col-1]; } else { pixel = (pixmap[col] + pixmap[col-1]); if (pixel > NUM_GRAYS - 1) { pixel = NUM_GRAYS - 1; } pixmap[col] = (Uint8) pixel; } } } } } /* Mark that we rendered this format */ if (mono) { cached->stored |= CACHED_BITMAP; } else { cached->stored |= CACHED_PIXMAP; } /* Free outlined glyph */ if (bitmap_glyph) { FT_Done_Glyph(bitmap_glyph); } } /* We're done, mark this glyph cached */ cached->cached = ch; return 0; } static FT_Error Find_Glyph(TTF_Font* font, Uint32 ch, int want) { int retval = 0; int hsize = sizeof(font->cache) / sizeof(font->cache[0]); int h = ch % hsize; font->current = &font->cache[h]; if (font->current->cached != ch) Flush_Glyph(font->current); if ((font->current->stored & want) != want) { retval = Load_Glyph(font, ch, font->current, want); } return retval; } void TTF_CloseFont(TTF_Font* font) { if (font) { Flush_Cache(font); if (font->face) { FT_Done_Face(font->face); } if (font->args.stream) { SDL_free(font->args.stream); } if (font->freesrc) { SDL_RWclose(font->src); } SDL_free(font); } } /* Gets the number of bytes needed to convert a Latin-1 string to UTF-8 */ static size_t LATIN1_to_UTF8_len(const char *text) { size_t bytes = 1; while (*text) { Uint8 ch = *(Uint8*)text++; if (ch <= 0x7F) { bytes += 1; } else { bytes += 2; } } return bytes; } /* Gets the number of bytes needed to convert a UCS2 string to UTF-8 */ static size_t UCS2_to_UTF8_len(const Uint16 *text) { size_t bytes = 1; while (*text) { Uint16 ch = *text++; if (ch <= 0x7F) { bytes += 1; } else if (ch <= 0x7FF) { bytes += 2; } else { bytes += 3; } } return bytes; } /* Convert a Latin-1 string to a UTF-8 string */ static void LATIN1_to_UTF8(const char *src, Uint8 *dst) { while (*src) { Uint8 ch = *(Uint8*)src++; if (ch <= 0x7F) { *dst++ = ch; } else { *dst++ = 0xC0 | ((ch >> 6) & 0x1F); *dst++ = 0x80 | (ch & 0x3F); } } *dst = '\0'; } /* Convert a UCS-2 string to a UTF-8 string */ static void UCS2_to_UTF8(const Uint16 *src, Uint8 *dst) { int swapped = TTF_byteswapped; while (*src) { Uint16 ch = *src++; if (ch == UNICODE_BOM_NATIVE) { swapped = 0; continue; } if (ch == UNICODE_BOM_SWAPPED) { swapped = 1; continue; } if (swapped) { ch = SDL_Swap16(ch); } if (ch <= 0x7F) { *dst++ = (Uint8) ch; } else if (ch <= 0x7FF) { *dst++ = 0xC0 | (Uint8) ((ch >> 6) & 0x1F); *dst++ = 0x80 | (Uint8) (ch & 0x3F); } else { *dst++ = 0xE0 | (Uint8) ((ch >> 12) & 0x0F); *dst++ = 0x80 | (Uint8) ((ch >> 6) & 0x3F); *dst++ = 0x80 | (Uint8) (ch & 0x3F); } } *dst = '\0'; } /* Gets a unicode value from a UTF-8 encoded string and advance the string */ #define UNKNOWN_UNICODE 0xFFFD static Uint32 UTF8_getch(const char **src, size_t *srclen) { const Uint8 *p = *(const Uint8**)src; size_t left = 0; SDL_bool overlong = SDL_FALSE; SDL_bool underflow = SDL_FALSE; Uint32 ch = UNKNOWN_UNICODE; if (*srclen == 0) { return UNKNOWN_UNICODE; } if (p[0] >= 0xFC) { if ((p[0] & 0xFE) == 0xFC) { if (p[0] == 0xFC && (p[1] & 0xFC) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x01); left = 5; } } else if (p[0] >= 0xF8) { if ((p[0] & 0xFC) == 0xF8) { if (p[0] == 0xF8 && (p[1] & 0xF8) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x03); left = 4; } } else if (p[0] >= 0xF0) { if ((p[0] & 0xF8) == 0xF0) { if (p[0] == 0xF0 && (p[1] & 0xF0) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x07); left = 3; } } else if (p[0] >= 0xE0) { if ((p[0] & 0xF0) == 0xE0) { if (p[0] == 0xE0 && (p[1] & 0xE0) == 0x80) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x0F); left = 2; } } else if (p[0] >= 0xC0) { if ((p[0] & 0xE0) == 0xC0) { if ((p[0] & 0xDE) == 0xC0) { overlong = SDL_TRUE; } ch = (Uint32) (p[0] & 0x1F); left = 1; } } else { if ((p[0] & 0x80) == 0x00) { ch = (Uint32) p[0]; } } ++*src; --*srclen; while (left > 0 && *srclen > 0) { ++p; if ((p[0] & 0xC0) != 0x80) { ch = UNKNOWN_UNICODE; break; } ch <<= 6; ch |= (p[0] & 0x3F); ++*src; --*srclen; --left; } if (left > 0) { underflow = SDL_TRUE; } /* Technically overlong sequences are invalid and should not be interpreted. However, it doesn't cause a security risk here and I don't see any harm in displaying them. The application is responsible for any other side effects of allowing overlong sequences (e.g. string compares failing, etc.) See bug 1931 for sample input that triggers this. */ /*if (overlong) return UNKNOWN_UNICODE;*/ if (underflow || (ch >= 0xD800 && ch <= 0xDFFF) || (ch == 0xFFFE || ch == 0xFFFF) || ch > 0x10FFFF) { ch = UNKNOWN_UNICODE; } return ch; } int TTF_FontHeight(const TTF_Font *font) { return(font->height); } int TTF_FontAscent(const TTF_Font *font) { return(font->ascent); } int TTF_FontDescent(const TTF_Font *font) { return(font->descent); } int TTF_FontLineSkip(const TTF_Font *font) { return(font->lineskip); } int TTF_GetFontKerning(const TTF_Font *font) { return(font->kerning); } void TTF_SetFontKerning(TTF_Font *font, int allowed) { font->kerning = allowed; } long TTF_FontFaces(const TTF_Font *font) { return(font->face->num_faces); } int TTF_FontFaceIsFixedWidth(const TTF_Font *font) { return(FT_IS_FIXED_WIDTH(font->face)); } char *TTF_FontFaceFamilyName(const TTF_Font *font) { return(font->face->family_name); } char *TTF_FontFaceStyleName(const TTF_Font *font) { return(font->face->style_name); } int TTF_GlyphIsProvided(const TTF_Font *font, Uint16 ch) { return(FT_Get_Char_Index(font->face, ch)); } int TTF_GlyphMetrics(TTF_Font *font, Uint16 ch, int* minx, int* maxx, int* miny, int* maxy, int* advance) { FT_Error error; error = Find_Glyph(font, ch, CACHED_METRICS); if (error) { TTF_SetFTError("Couldn't find glyph", error); return -1; } if (minx) { *minx = font->current->minx; } if (maxx) { *maxx = font->current->maxx; if (TTF_HANDLE_STYLE_BOLD(font)) { *maxx += font->glyph_overhang; } } if (miny) { *miny = font->current->miny; } if (maxy) { *maxy = font->current->maxy; } if (advance) { *advance = font->current->advance; if (TTF_HANDLE_STYLE_BOLD(font)) { *advance += font->glyph_overhang; } } return 0; } int TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h) { int status = -1; Uint8 *utf8; TTF_CHECKPOINTER(text, -1); utf8 = SDL_stack_alloc(Uint8, LATIN1_to_UTF8_len(text)); if (utf8) { LATIN1_to_UTF8(text, utf8); status = TTF_SizeUTF8(font, (char *)utf8, w, h); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return status; } int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h) { int status; int x, z; int minx, maxx; int miny, maxy; c_glyph *glyph; FT_Error error; FT_Long use_kerning; FT_UInt prev_index = 0; int outline_delta = 0; size_t textlen; TTF_CHECKPOINTER(text, -1); /* Initialize everything to 0 */ status = 0; minx = maxx = 0; miny = maxy = 0; /* check kerning */ use_kerning = FT_HAS_KERNING(font->face) && font->kerning; /* Init outline handling */ if (font->outline > 0) { outline_delta = font->outline * 2; } /* Load each character and sum it's bounding box */ textlen = SDL_strlen(text); x= 0; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { continue; } error = Find_Glyph(font, c, CACHED_METRICS); if (error) { TTF_SetFTError("Couldn't find glyph", error); return -1; } glyph = font->current; /* handle kerning */ if (use_kerning && prev_index && glyph->index) { FT_Vector delta; FT_Get_Kerning(font->face, prev_index, glyph->index, ft_kerning_default, &delta); x += delta.x >> 6; } #if 0 if ((ch == text) && (glyph->minx < 0)) { /* Fixes the texture wrapping bug when the first letter * has a negative minx value or horibearing value. The entire * bounding box must be adjusted to be bigger so the entire * letter can fit without any texture corruption or wrapping. * * Effects: First enlarges bounding box. * Second, xstart has to start ahead of its normal spot in the * negative direction of the negative minx value. * (pushes everything to the right). * * This will make the memory copy of the glyph bitmap data * work out correctly. * */ z -= glyph->minx; } #endif z = x + glyph->minx; if (minx > z) { minx = z; } if (TTF_HANDLE_STYLE_BOLD(font)) { x += font->glyph_overhang; } if (glyph->advance > glyph->maxx) { z = x + glyph->advance; } else { z = x + glyph->maxx; } if (maxx < z) { maxx = z; } x += glyph->advance; if (glyph->miny < miny) { miny = glyph->miny; } if (glyph->maxy > maxy) { maxy = glyph->maxy; } prev_index = glyph->index; } /* Fill the bounds rectangle */ if (w) { /* Add outline extra width */ *w = (maxx - minx) + outline_delta; } if (h) { /* Some fonts descend below font height (FletcherGothicFLF) */ /* Add outline extra height */ *h = (font->ascent - miny) + outline_delta; if (*h < font->height) { *h = font->height; } /* Update height according to the needs of the underline style */ if (TTF_HANDLE_STYLE_UNDERLINE(font)) { int bottom_row = TTF_underline_bottom_row(font); if (*h < bottom_row) { *h = bottom_row; } } } return status; } int TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h) { int status = -1; Uint8 *utf8; TTF_CHECKPOINTER(text, -1); utf8 = SDL_stack_alloc(Uint8, UCS2_to_UTF8_len(text)); if (utf8) { UCS2_to_UTF8(text, utf8); status = TTF_SizeUTF8(font, (char *)utf8, w, h); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return status; } SDL_Surface *TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, LATIN1_to_UTF8_len(text)); if (utf8) { LATIN1_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Solid(font, (char *)utf8, fg); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } SDL_Surface *TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg) { int xstart; int width; int height; SDL_Surface* textbuf; SDL_Palette* palette; Uint8* src; Uint8* dst; Uint8 *dst_check; int row, col; c_glyph *glyph; FT_Bitmap *current; FT_Error error; FT_Long use_kerning; FT_UInt prev_index = 0; size_t textlen; TTF_CHECKPOINTER(text, NULL); /* Get the dimensions of the text surface */ if ((TTF_SizeUTF8(font, text, &width, &height) < 0) || !width) { TTF_SetError("Text has zero width"); return NULL; } /* Create the target surface */ textbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0); if (textbuf == NULL) { return NULL; } /* Adding bound checking to avoid all kinds of memory corruption errors that may occur. */ dst_check = (Uint8*)textbuf->pixels + textbuf->pitch * textbuf->h; /* Fill the palette with the foreground color */ palette = textbuf->format->palette; palette->colors[0].r = 255 - fg.r; palette->colors[0].g = 255 - fg.g; palette->colors[0].b = 255 - fg.b; palette->colors[1].r = fg.r; palette->colors[1].g = fg.g; palette->colors[1].b = fg.b; palette->colors[1].a = fg.a ? fg.a : SDL_ALPHA_OPAQUE; SDL_SetColorKey(textbuf, SDL_TRUE, 0); /* check kerning */ use_kerning = FT_HAS_KERNING(font->face) && font->kerning; /* Load and render each character */ textlen = SDL_strlen(text); xstart = 0; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { continue; } error = Find_Glyph(font, c, CACHED_METRICS|CACHED_BITMAP); if (error) { TTF_SetFTError("Couldn't find glyph", error); SDL_FreeSurface(textbuf); return NULL; } glyph = font->current; current = &glyph->bitmap; /* Ensure the width of the pixmap is correct. On some cases, * freetype may report a larger pixmap than possible.*/ width = current->width; if (font->outline <= 0 && width > glyph->maxx - glyph->minx) { width = glyph->maxx - glyph->minx; } /* do kerning, if possible AC-Patch */ if (use_kerning && prev_index && glyph->index) { FT_Vector delta; FT_Get_Kerning(font->face, prev_index, glyph->index, ft_kerning_default, &delta); xstart += delta.x >> 6; } for (row = 0; row < current->rows; ++row) { /* Make sure we don't go either over, or under the limit */ if ((xstart + glyph->minx) < 0) { xstart -= (xstart + glyph->minx); } if ((row + glyph->yoffset) < 0) { continue; } if ((row + glyph->yoffset) >= textbuf->h) { continue; } dst = (Uint8 *)textbuf->pixels + (row+glyph->yoffset) * textbuf->pitch + xstart + glyph->minx; src = current->buffer + row * current->pitch; for (col = width; col > 0 && dst < dst_check; --col) { *dst++ |= *src++; } } xstart += glyph->advance; if (TTF_HANDLE_STYLE_BOLD(font)) { xstart += font->glyph_overhang; } prev_index = glyph->index; } /* Handle the underline style */ if (TTF_HANDLE_STYLE_UNDERLINE(font)) { row = TTF_underline_top_row(font); TTF_drawLine_Solid(font, textbuf, row); } /* Handle the strikethrough style */ if (TTF_HANDLE_STYLE_STRIKETHROUGH(font)) { row = TTF_strikethrough_top_row(font); TTF_drawLine_Solid(font, textbuf, row); } return textbuf; } SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font, const Uint16 *text, SDL_Color fg) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, UCS2_to_UTF8_len(text)); if (utf8) { UCS2_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Solid(font, (char *)utf8, fg); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } SDL_Surface *TTF_RenderGlyph_Solid(TTF_Font *font, Uint16 ch, SDL_Color fg) { Uint16 ucs2[2]; Uint8 utf8[4]; ucs2[0] = ch; ucs2[1] = 0; UCS2_to_UTF8(ucs2, utf8); return TTF_RenderUTF8_Solid(font, (char *)utf8, fg); } SDL_Surface *TTF_RenderText_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, LATIN1_to_UTF8_len(text)); if (utf8) { LATIN1_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Shaded(font, (char *)utf8, fg, bg); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } /* Convert the UTF-8 text to UNICODE and render it */ SDL_Surface *TTF_RenderUTF8_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg) { int xstart; int width; int height; SDL_Surface* textbuf; SDL_Palette* palette; int index; int rdiff; int gdiff; int bdiff; int adiff; Uint8* src; Uint8* dst; Uint8* dst_check; int row, col; FT_Bitmap* current; c_glyph *glyph; FT_Error error; FT_Long use_kerning; FT_UInt prev_index = 0; size_t textlen; TTF_CHECKPOINTER(text, NULL); /* Get the dimensions of the text surface */ if ((TTF_SizeUTF8(font, text, &width, &height) < 0) || !width) { TTF_SetError("Text has zero width"); return NULL; } /* Create the target surface */ textbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0); if (textbuf == NULL) { return NULL; } /* Adding bound checking to avoid all kinds of memory corruption errors that may occur. */ dst_check = (Uint8*)textbuf->pixels + textbuf->pitch * textbuf->h; /* Support alpha blending */ if (!fg.a) { fg.a = SDL_ALPHA_OPAQUE; } if (!bg.a) { bg.a = SDL_ALPHA_OPAQUE; } if (fg.a != SDL_ALPHA_OPAQUE || bg.a != SDL_ALPHA_OPAQUE) { SDL_SetSurfaceBlendMode(textbuf, SDL_BLENDMODE_BLEND); } /* Fill the palette with NUM_GRAYS levels of shading from bg to fg */ palette = textbuf->format->palette; rdiff = fg.r - bg.r; gdiff = fg.g - bg.g; bdiff = fg.b - bg.b; adiff = fg.a - bg.a; for (index = 0; index < NUM_GRAYS; ++index) { palette->colors[index].r = bg.r + (index*rdiff) / (NUM_GRAYS-1); palette->colors[index].g = bg.g + (index*gdiff) / (NUM_GRAYS-1); palette->colors[index].b = bg.b + (index*bdiff) / (NUM_GRAYS-1); palette->colors[index].a = bg.a + (index*adiff) / (NUM_GRAYS-1); } /* check kerning */ use_kerning = FT_HAS_KERNING(font->face) && font->kerning; /* Load and render each character */ textlen = SDL_strlen(text); xstart = 0; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { continue; } error = Find_Glyph(font, c, CACHED_METRICS|CACHED_PIXMAP); if (error) { TTF_SetFTError("Couldn't find glyph", error); SDL_FreeSurface(textbuf); return NULL; } glyph = font->current; /* Ensure the width of the pixmap is correct. On some cases, * freetype may report a larger pixmap than possible.*/ width = glyph->pixmap.width; if (font->outline <= 0 && width > glyph->maxx - glyph->minx) { width = glyph->maxx - glyph->minx; } /* do kerning, if possible AC-Patch */ if (use_kerning && prev_index && glyph->index) { FT_Vector delta; FT_Get_Kerning(font->face, prev_index, glyph->index, ft_kerning_default, &delta); xstart += delta.x >> 6; } current = &glyph->pixmap; for (row = 0; row < current->rows; ++row) { /* Make sure we don't go either over, or under the limit */ if ((xstart + glyph->minx) < 0) { xstart -= (xstart + glyph->minx); } if ((row + glyph->yoffset) < 0) { continue; } if ((row + glyph->yoffset) >= textbuf->h) { continue; } dst = (Uint8 *)textbuf->pixels + (row+glyph->yoffset) * textbuf->pitch + xstart + glyph->minx; src = current->buffer + row * current->pitch; for (col = width; col > 0 && dst < dst_check; --col) { *dst++ |= *src++; } } xstart += glyph->advance; if (TTF_HANDLE_STYLE_BOLD(font)) { xstart += font->glyph_overhang; } prev_index = glyph->index; } /* Handle the underline style */ if (TTF_HANDLE_STYLE_UNDERLINE(font)) { row = TTF_underline_top_row(font); TTF_drawLine_Shaded(font, textbuf, row); } /* Handle the strikethrough style */ if (TTF_HANDLE_STYLE_STRIKETHROUGH(font)) { row = TTF_strikethrough_top_row(font); TTF_drawLine_Shaded(font, textbuf, row); } return textbuf; } SDL_Surface* TTF_RenderUNICODE_Shaded(TTF_Font* font, const Uint16* text, SDL_Color fg, SDL_Color bg) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, UCS2_to_UTF8_len(text)); if (utf8) { UCS2_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Shaded(font, (char *)utf8, fg, bg); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } SDL_Surface* TTF_RenderGlyph_Shaded(TTF_Font* font, Uint16 ch, SDL_Color fg, SDL_Color bg) { Uint16 ucs2[2]; Uint8 utf8[4]; ucs2[0] = ch; ucs2[1] = 0; UCS2_to_UTF8(ucs2, utf8); return TTF_RenderUTF8_Shaded(font, (char *)utf8, fg, bg); } SDL_Surface *TTF_RenderText_Blended(TTF_Font *font, const char *text, SDL_Color fg) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, LATIN1_to_UTF8_len(text)); if (utf8) { LATIN1_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Blended(font, (char *)utf8, fg); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } SDL_Surface *TTF_RenderUTF8_Blended(TTF_Font *font, const char *text, SDL_Color fg) { int i; int xstart; int width, height; SDL_Surface *textbuf; Uint8 alpha; Uint8 alpha_table[256]; Uint32 pixel; Uint8 *src; Uint32 *dst; Uint32 *dst_check; int row, col; c_glyph *glyph; FT_Error error; FT_Long use_kerning; FT_UInt prev_index = 0; size_t textlen; TTF_CHECKPOINTER(text, NULL); /* Get the dimensions of the text surface */ if ((TTF_SizeUTF8(font, text, &width, &height) < 0) || !width) { TTF_SetError("Text has zero width"); return(NULL); } /* Create the target surface */ textbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); if (textbuf == NULL) { return(NULL); } /* Adding bound checking to avoid all kinds of memory corruption errors that may occur. */ dst_check = (Uint32*)textbuf->pixels + textbuf->pitch/4 * textbuf->h; /* check kerning */ use_kerning = FT_HAS_KERNING(font->face) && font->kerning; /* Support alpha blending */ if (!fg.a) { fg.a = SDL_ALPHA_OPAQUE; } if (fg.a == SDL_ALPHA_OPAQUE) { for (i = 0; i < SDL_arraysize(alpha_table); ++i) { alpha_table[i] = (Uint8)i; } } else { for (i = 0; i < SDL_arraysize(alpha_table); ++i) { alpha_table[i] = (Uint8)(i * fg.a / 255); } SDL_SetSurfaceBlendMode(textbuf, SDL_BLENDMODE_BLEND); } /* Load and render each character */ textlen = SDL_strlen(text); xstart = 0; pixel = (fg.r<<16)|(fg.g<<8)|fg.b; SDL_FillRect(textbuf, NULL, pixel); /* Initialize with fg and 0 alpha */ while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { continue; } error = Find_Glyph(font, c, CACHED_METRICS|CACHED_PIXMAP); if (error) { TTF_SetFTError("Couldn't find glyph", error); SDL_FreeSurface(textbuf); return NULL; } glyph = font->current; /* Ensure the width of the pixmap is correct. On some cases, * freetype may report a larger pixmap than possible.*/ width = glyph->pixmap.width; if (font->outline <= 0 && width > glyph->maxx - glyph->minx) { width = glyph->maxx - glyph->minx; } /* do kerning, if possible AC-Patch */ if (use_kerning && prev_index && glyph->index) { FT_Vector delta; FT_Get_Kerning(font->face, prev_index, glyph->index, ft_kerning_default, &delta); xstart += delta.x >> 6; } for (row = 0; row < glyph->pixmap.rows; ++row) { /* Make sure we don't go either over, or under the limit */ if ((xstart + glyph->minx) < 0) { xstart -= (xstart + glyph->minx); } if ((row + glyph->yoffset) < 0) { continue; } if ((row + glyph->yoffset) >= textbuf->h) { continue; } dst = (Uint32 *)textbuf->pixels + (row+glyph->yoffset) * textbuf->pitch/4 + xstart + glyph->minx; src = (Uint8*)glyph->pixmap.buffer + row * glyph->pixmap.pitch; for (col = width; col > 0 && dst < dst_check; --col) { alpha = *src++; *dst++ |= pixel | ((Uint32)alpha_table[alpha] << 24); } } xstart += glyph->advance; if (TTF_HANDLE_STYLE_BOLD(font)) { xstart += font->glyph_overhang; } prev_index = glyph->index; } /* Handle the underline style */ if (TTF_HANDLE_STYLE_UNDERLINE(font)) { row = TTF_underline_top_row(font); TTF_drawLine_Blended(font, textbuf, row, pixel | (Uint32)fg.a << 24); } /* Handle the strikethrough style */ if (TTF_HANDLE_STYLE_STRIKETHROUGH(font)) { row = TTF_strikethrough_top_row(font); TTF_drawLine_Blended(font, textbuf, row, pixel | (Uint32)fg.a << 24); } return(textbuf); } SDL_Surface *TTF_RenderUNICODE_Blended(TTF_Font *font, const Uint16 *text, SDL_Color fg) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, UCS2_to_UTF8_len(text)); if (utf8) { UCS2_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Blended(font, (char *)utf8, fg); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } SDL_Surface *TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, LATIN1_to_UTF8_len(text)); if (utf8) { LATIN1_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Blended_Wrapped(font, (char *)utf8, fg, wrapLength); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } static SDL_bool CharacterIsDelimiter(char c, const char *delimiters) { while (*delimiters) { if (c == *delimiters) { return SDL_TRUE; } ++delimiters; } return SDL_FALSE; } /* Don't define this until we have a release where we can change font rendering #define TTF_USE_LINESKIP */ SDL_Surface *TTF_RenderUTF8_Blended_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength) { int i; int xstart; int width, height; SDL_Surface *textbuf; Uint8 alpha; Uint8 alpha_table[256]; Uint32 pixel; Uint8 *src; Uint32 *dst; Uint32 *dst_check; int row, col; c_glyph *glyph; FT_Error error; FT_Long use_kerning; FT_UInt prev_index = 0; #ifndef TTF_USE_LINESKIP const int lineSpace = 2; #endif int line, numLines, rowSize; char *str, **strLines, **newLines; size_t textlen; TTF_CHECKPOINTER(text, NULL); /* Get the dimensions of the text surface */ if ((TTF_SizeUTF8(font, text, &width, &height) < 0) || !width) { TTF_SetError("Text has zero width"); return(NULL); } numLines = 1; str = NULL; strLines = NULL; if (wrapLength > 0 && *text) { const char *wrapDelims = " \t\r\n"; int w, h; char *spot, *tok, *next_tok, *end; char delim; size_t str_len = SDL_strlen(text); numLines = 0; str = SDL_stack_alloc(char, str_len+1); if (str == NULL) { TTF_SetError("Out of memory"); return(NULL); } SDL_strlcpy(str, text, str_len+1); tok = str; end = str + str_len; do { newLines = (char **)SDL_realloc(strLines, (numLines+1)*sizeof(*strLines)); if (!newLines) { TTF_SetError("Out of memory"); SDL_free(strLines); SDL_stack_free(str); return(NULL); } strLines = newLines; strLines[numLines++] = tok; /* Look for the end of the line */ if ((spot = SDL_strchr(tok, '\r')) != NULL || (spot = SDL_strchr(tok, '\n')) != NULL) { if (*spot == '\r') { ++spot; } if (*spot == '\n') { ++spot; } } else { spot = end; } next_tok = spot; /* Get the longest string that will fit in the desired space */ for (; ;) { /* Strip trailing whitespace */ while (spot > tok && CharacterIsDelimiter(spot[-1], wrapDelims)) { --spot; } if (spot == tok) { if (CharacterIsDelimiter(*spot, wrapDelims)) { *spot = '\0'; } break; } delim = *spot; *spot = '\0'; TTF_SizeUTF8(font, tok, &w, &h); if ((Uint32)w <= wrapLength) { break; } else { /* Back up and try again... */ *spot = delim; } while (spot > tok && !CharacterIsDelimiter(spot[-1], wrapDelims)) { --spot; } if (spot > tok) { next_tok = spot; } } tok = next_tok; } while (tok < end); } /* Create the target surface */ textbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, (numLines > 1) ? wrapLength : width, #ifdef TTF_USE_LINESKIP numLines * TTF_FontLineSkip(font), #else height * numLines + (lineSpace * (numLines - 1)), #endif 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); if (textbuf == NULL) { if (strLines) { SDL_free(strLines); SDL_stack_free(str); } return(NULL); } #ifdef TTF_USE_LINESKIP rowSize = textbuf->pitch/4 * TTF_FontLineSkip(font); #else rowSize = textbuf->pitch/4 * height; #endif /* Adding bound checking to avoid all kinds of memory corruption errors that may occur. */ dst_check = (Uint32*)textbuf->pixels + textbuf->pitch/4 * textbuf->h; /* check kerning */ use_kerning = FT_HAS_KERNING(font->face) && font->kerning; /* Support alpha blending */ if (!fg.a) { fg.a = SDL_ALPHA_OPAQUE; } if (fg.a == SDL_ALPHA_OPAQUE) { for (i = 0; i < SDL_arraysize(alpha_table); ++i) { alpha_table[i] = (Uint8)i; } } else { for (i = 0; i < SDL_arraysize(alpha_table); ++i) { alpha_table[i] = (Uint8)(i * fg.a / 255); } SDL_SetSurfaceBlendMode(textbuf, SDL_BLENDMODE_BLEND); } /* Load and render each character */ pixel = (fg.r<<16)|(fg.g<<8)|fg.b; SDL_FillRect(textbuf, NULL, pixel); /* Initialize with fg and 0 alpha */ for (line = 0; line < numLines; line++) { if (strLines) { text = strLines[line]; } textlen = SDL_strlen(text); xstart = 0; while (textlen > 0) { Uint32 c = UTF8_getch(&text, &textlen); if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) { continue; } error = Find_Glyph(font, c, CACHED_METRICS|CACHED_PIXMAP); if (error) { TTF_SetFTError("Couldn't find glyph", error); SDL_FreeSurface(textbuf); if (strLines) { SDL_free(strLines); SDL_stack_free(str); } return NULL; } glyph = font->current; /* Ensure the width of the pixmap is correct. On some cases, * freetype may report a larger pixmap than possible.*/ width = glyph->pixmap.width; if (font->outline <= 0 && width > glyph->maxx - glyph->minx) { width = glyph->maxx - glyph->minx; } /* do kerning, if possible AC-Patch */ if (use_kerning && prev_index && glyph->index) { FT_Vector delta; FT_Get_Kerning(font->face, prev_index, glyph->index, ft_kerning_default, &delta); xstart += delta.x >> 6; } for (row = 0; row < glyph->pixmap.rows; ++row) { /* Make sure we don't go either over, or under the limit */ if ((xstart + glyph->minx) < 0) { xstart -= (xstart + glyph->minx); } if ((row + glyph->yoffset) < 0) { continue; } if ((row + glyph->yoffset) >= textbuf->h) { continue; } dst = ((Uint32*)textbuf->pixels + rowSize * line) + (row+glyph->yoffset) * textbuf->pitch/4 + xstart + glyph->minx; src = (Uint8*)glyph->pixmap.buffer + row * glyph->pixmap.pitch; for (col = width; col > 0 && dst < dst_check; --col) { alpha = *src++; *dst++ |= pixel | ((Uint32)alpha_table[alpha] << 24); } } xstart += glyph->advance; if (TTF_HANDLE_STYLE_BOLD(font)) { xstart += font->glyph_overhang; } prev_index = glyph->index; } /* Handle the underline style * if (TTF_HANDLE_STYLE_UNDERLINE(font)) { row = TTF_underline_top_row(font); TTF_drawLine_Blended(font, textbuf, row, pixel | (Uint32)fg.a << 24); } */ /* Handle the strikethrough style * if (TTF_HANDLE_STYLE_STRIKETHROUGH(font)) { row = TTF_strikethrough_top_row(font); TTF_drawLine_Blended(font, textbuf, row, pixel | (Uint32)fg.a << 24); } */ } if (strLines) { SDL_free(strLines); SDL_stack_free(str); } return(textbuf); } SDL_Surface *TTF_RenderUNICODE_Blended_Wrapped(TTF_Font *font, const Uint16* text, SDL_Color fg, Uint32 wrapLength) { SDL_Surface *surface = NULL; Uint8 *utf8; TTF_CHECKPOINTER(text, NULL); utf8 = SDL_stack_alloc(Uint8, UCS2_to_UTF8_len(text)); if (utf8) { UCS2_to_UTF8(text, utf8); surface = TTF_RenderUTF8_Blended_Wrapped(font, (char *)utf8, fg, wrapLength); SDL_stack_free(utf8); } else { SDL_OutOfMemory(); } return surface; } SDL_Surface *TTF_RenderGlyph_Blended(TTF_Font *font, Uint16 ch, SDL_Color fg) { Uint16 ucs2[2]; Uint8 utf8[4]; ucs2[0] = ch; ucs2[1] = 0; UCS2_to_UTF8(ucs2, utf8); return TTF_RenderUTF8_Blended(font, (char *)utf8, fg); } void TTF_SetFontStyle(TTF_Font* font, int style) { int prev_style = font->style; font->style = style | font->face_style; /* Flush the cache if the style has changed. * Ignore UNDERLINE which does not impact glyph drawning. * */ if ((font->style | TTF_STYLE_NO_GLYPH_CHANGE) != (prev_style | TTF_STYLE_NO_GLYPH_CHANGE)) { Flush_Cache(font); } } int TTF_GetFontStyle(const TTF_Font* font) { return font->style; } void TTF_SetFontOutline(TTF_Font* font, int outline) { font->outline = outline; Flush_Cache(font); } int TTF_GetFontOutline(const TTF_Font* font) { return font->outline; } void TTF_SetFontHinting(TTF_Font* font, int hinting) { if (hinting == TTF_HINTING_LIGHT) font->hinting = FT_LOAD_TARGET_LIGHT; else if (hinting == TTF_HINTING_MONO) font->hinting = FT_LOAD_TARGET_MONO; else if (hinting == TTF_HINTING_NONE) font->hinting = FT_LOAD_NO_HINTING; else font->hinting = 0; Flush_Cache(font); } int TTF_GetFontHinting(const TTF_Font* font) { if (font->hinting == FT_LOAD_TARGET_LIGHT) return TTF_HINTING_LIGHT; else if (font->hinting == FT_LOAD_TARGET_MONO) return TTF_HINTING_MONO; else if (font->hinting == FT_LOAD_NO_HINTING) return TTF_HINTING_NONE; return 0; } void TTF_Quit(void) { if (TTF_initialized) { if (--TTF_initialized == 0) { FT_Done_FreeType(library); } } } int TTF_WasInit(void) { return TTF_initialized; } /* don't use this function. It's just here for binary compatibility. */ int TTF_GetFontKerningSize(TTF_Font* font, int prev_index, int index) { FT_Vector delta; FT_Get_Kerning(font->face, prev_index, index, ft_kerning_default, &delta); return (delta.x >> 6); } int TTF_GetFontKerningSizeGlyphs(TTF_Font *font, Uint16 previous_ch, Uint16 ch) { int error; int glyph_index, prev_index; FT_Vector delta; if (ch == UNICODE_BOM_NATIVE || ch == UNICODE_BOM_SWAPPED) { return 0; } if (previous_ch == UNICODE_BOM_NATIVE || previous_ch == UNICODE_BOM_SWAPPED) { return 0; } error = Find_Glyph(font, ch, CACHED_METRICS); if (error) { TTF_SetFTError("Couldn't find glyph", error); return -1; } glyph_index = font->current->index; error = Find_Glyph(font, previous_ch, CACHED_METRICS); if (error) { TTF_SetFTError("Couldn't find glyph", error); return -1; } prev_index = font->current->index; error = FT_Get_Kerning(font->face, prev_index, glyph_index, ft_kerning_default, &delta); if (error) { TTF_SetFTError("Couldn't get glyph kerning", error); return -1; } return (delta.x >> 6); } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/ttf/SDL_ttf.c
C
apache-2.0
70,490
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_RLEaccel_c_h_ #define SDL_RLEaccel_c_h_ #include "../SDL_internal.h" /* Useful functions and variables from SDL_RLEaccel.c */ extern int SDL_RLESurface(SDL_Surface * surface); extern void SDL_UnRLESurface(SDL_Surface * surface, int recode); #endif /* SDL_RLEaccel_c_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_RLEaccel_c.h
C
apache-2.0
1,264
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #include "SDL_video.h" #include "SDL_sysvideo.h" #include "SDL_blit.h" #include "SDL_blit_auto.h" #include "SDL_blit_copy.h" #include "SDL_blit_slow.h" #include "SDL_RLEaccel_c.h" #include "SDL_pixels_c.h" /* The general purpose software blit routine */ static int SDLCALL SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect) { int okay; int src_locked; int dst_locked; /* Everything is okay at the beginning... */ okay = 1; /* Lock the destination if it's in hardware */ dst_locked = 0; if (SDL_MUSTLOCK(dst)) { if (SDL_LockSurface(dst) < 0) { okay = 0; } else { dst_locked = 1; } } /* Lock the source if it's in hardware */ src_locked = 0; if (SDL_MUSTLOCK(src)) { if (SDL_LockSurface(src) < 0) { okay = 0; } else { src_locked = 1; } } /* Set up source and destination buffer pointers, and BLIT! */ if (okay && !SDL_RectEmpty(srcrect)) { SDL_BlitFunc RunBlit; SDL_BlitInfo *info = &src->map->info; /* Set up the blit information */ info->src = (Uint8 *) src->pixels + (Uint16) srcrect->y * src->pitch + (Uint16) srcrect->x * info->src_fmt->BytesPerPixel; info->src_w = srcrect->w; info->src_h = srcrect->h; info->src_pitch = src->pitch; info->src_skip = info->src_pitch - info->src_w * info->src_fmt->BytesPerPixel; info->dst = (Uint8 *) dst->pixels + (Uint16) dstrect->y * dst->pitch + (Uint16) dstrect->x * info->dst_fmt->BytesPerPixel; info->dst_w = dstrect->w; info->dst_h = dstrect->h; info->dst_pitch = dst->pitch; info->dst_skip = info->dst_pitch - info->dst_w * info->dst_fmt->BytesPerPixel; RunBlit = (SDL_BlitFunc) src->map->data; /* Run the actual software blit */ RunBlit(info); } /* We need to unlock the surfaces if they're locked */ if (dst_locked) { SDL_UnlockSurface(dst); } if (src_locked) { SDL_UnlockSurface(src); } /* Blit is done! */ return (okay ? 0 : -1); } #if SDL_HAVE_BLIT_AUTO #ifdef __MACOSX__ #include <sys/sysctl.h> static SDL_bool SDL_UseAltivecPrefetch() { const char key[] = "hw.l3cachesize"; u_int64_t result = 0; size_t typeSize = sizeof(result); if (sysctlbyname(key, &result, &typeSize, NULL, 0) == 0 && result > 0) { return SDL_TRUE; } else { return SDL_FALSE; } } #else static SDL_bool SDL_UseAltivecPrefetch() { /* Just guess G4 */ return SDL_TRUE; } #endif /* __MACOSX__ */ static SDL_BlitFunc SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, SDL_BlitFuncEntry * entries) { int i, flagcheck = (flags & (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL | SDL_COPY_COLORKEY | SDL_COPY_NEAREST)); static int features = 0x7fffffff; /* Get the available CPU features */ if (features == 0x7fffffff) { const char *override = SDL_getenv("SDL_BLIT_CPU_FEATURES"); features = SDL_CPU_ANY; /* Allow an override for testing .. */ if (override) { SDL_sscanf(override, "%u", &features); } else { if (SDL_HasMMX()) { features |= SDL_CPU_MMX; } if (SDL_Has3DNow()) { features |= SDL_CPU_3DNOW; } if (SDL_HasSSE()) { features |= SDL_CPU_SSE; } if (SDL_HasSSE2()) { features |= SDL_CPU_SSE2; } if (SDL_HasAltiVec()) { if (SDL_UseAltivecPrefetch()) { features |= SDL_CPU_ALTIVEC_PREFETCH; } else { features |= SDL_CPU_ALTIVEC_NOPREFETCH; } } } } for (i = 0; entries[i].func; ++i) { /* Check for matching pixel formats */ if (src_format != entries[i].src_format) { continue; } if (dst_format != entries[i].dst_format) { continue; } /* Check flags */ if ((flagcheck & entries[i].flags) != flagcheck) { continue; } /* Check CPU features */ if ((entries[i].cpu & features) != entries[i].cpu) { continue; } /* We found the best one! */ return entries[i].func; } return NULL; } #endif /* SDL_HAVE_BLIT_AUTO */ /* Figure out which of many blit routines to set up on a surface */ int SDL_CalculateBlit(SDL_Surface * surface) { SDL_BlitFunc blit = NULL; SDL_BlitMap *map = surface->map; SDL_Surface *dst = map->dst; /* We don't currently support blitting to < 8 bpp surfaces */ if (dst->format->BitsPerPixel < 8) { SDL_InvalidateMap(map); return SDL_SetError("Blit combination not supported"); } #if SDL_HAVE_RLE /* Clean everything out to start */ if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { SDL_UnRLESurface(surface, 1); } #endif map->blit = SDL_SoftBlit; map->info.src_fmt = surface->format; map->info.src_pitch = surface->pitch; map->info.dst_fmt = dst->format; map->info.dst_pitch = dst->pitch; #if SDL_HAVE_RLE /* See if we can do RLE acceleration */ if (map->info.flags & SDL_COPY_RLE_DESIRED) { if (SDL_RLESurface(surface) == 0) { return 0; } } #endif /* Choose a standard blit function */ if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) { blit = SDL_BlitCopy; } else if (surface->format->Rloss > 8 || dst->format->Rloss > 8) { /* Greater than 8 bits per channel not supported yet */ SDL_InvalidateMap(map); return SDL_SetError("Blit combination not supported"); } #if SDL_HAVE_BLIT_0 else if (surface->format->BitsPerPixel < 8 && SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) { blit = SDL_CalculateBlit0(surface); } #endif #if SDL_HAVE_BLIT_1 else if (surface->format->BytesPerPixel == 1 && SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) { blit = SDL_CalculateBlit1(surface); } #endif #if SDL_HAVE_BLIT_A else if (map->info.flags & SDL_COPY_BLEND) { blit = SDL_CalculateBlitA(surface); } #endif #if SDL_HAVE_BLIT_N else { blit = SDL_CalculateBlitN(surface); } #endif #if SDL_HAVE_BLIT_AUTO if (blit == NULL) { Uint32 src_format = surface->format->format; Uint32 dst_format = dst->format->format; blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_GeneratedBlitFuncTable); } #endif #ifndef TEST_SLOW_BLIT if (blit == NULL) #endif { Uint32 src_format = surface->format->format; Uint32 dst_format = dst->format->format; if (!SDL_ISPIXELFORMAT_INDEXED(src_format) && !SDL_ISPIXELFORMAT_FOURCC(src_format) && !SDL_ISPIXELFORMAT_INDEXED(dst_format) && !SDL_ISPIXELFORMAT_FOURCC(dst_format)) { blit = SDL_Blit_Slow; } } map->data = blit; /* Make sure we have a blit function */ if (blit == NULL) { SDL_InvalidateMap(map); return SDL_SetError("Blit combination not supported"); } return 0; } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit.c
C
apache-2.0
8,589
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #ifndef SDL_blit_h_ #define SDL_blit_h_ #include "SDL_cpuinfo.h" #include "SDL_endian.h" #include "SDL_surface.h" /* Table to do pixel byte expansion */ extern Uint8* SDL_expand_byte[9]; /* SDL blit copy flags */ #define SDL_COPY_MODULATE_COLOR 0x00000001 #define SDL_COPY_MODULATE_ALPHA 0x00000002 #define SDL_COPY_BLEND 0x00000010 #define SDL_COPY_ADD 0x00000020 #define SDL_COPY_MOD 0x00000040 #define SDL_COPY_MUL 0x00000080 #define SDL_COPY_COLORKEY 0x00000100 #define SDL_COPY_NEAREST 0x00000200 #define SDL_COPY_RLE_DESIRED 0x00001000 #define SDL_COPY_RLE_COLORKEY 0x00002000 #define SDL_COPY_RLE_ALPHAKEY 0x00004000 #define SDL_COPY_RLE_MASK (SDL_COPY_RLE_DESIRED|SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY) /* SDL blit CPU flags */ #define SDL_CPU_ANY 0x00000000 #define SDL_CPU_MMX 0x00000001 #define SDL_CPU_3DNOW 0x00000002 #define SDL_CPU_SSE 0x00000004 #define SDL_CPU_SSE2 0x00000008 #define SDL_CPU_ALTIVEC_PREFETCH 0x00000010 #define SDL_CPU_ALTIVEC_NOPREFETCH 0x00000020 typedef struct { Uint8 *src; int src_w, src_h; int src_pitch; int src_skip; Uint8 *dst; int dst_w, dst_h; int dst_pitch; int dst_skip; SDL_PixelFormat *src_fmt; SDL_PixelFormat *dst_fmt; Uint8 *table; int flags; Uint32 colorkey; Uint8 r, g, b, a; } SDL_BlitInfo; typedef void (*SDL_BlitFunc) (SDL_BlitInfo *info); typedef struct { Uint32 src_format; Uint32 dst_format; int flags; int cpu; SDL_BlitFunc func; } SDL_BlitFuncEntry; /* Blit mapping definition */ typedef struct SDL_BlitMap { SDL_Surface *dst; int identity; SDL_blit blit; void *data; SDL_BlitInfo info; /* the version count matches the destination; mismatch indicates an invalid mapping */ Uint32 dst_palette_version; Uint32 src_palette_version; } SDL_BlitMap; /* Functions found in SDL_blit.c */ extern int SDL_CalculateBlit(SDL_Surface * surface); /* Functions found in SDL_blit_*.c */ extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface * surface); extern SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface * surface); extern SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface * surface); extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface); /* * Useful macros for blitting routines */ #if defined(__GNUC__) #define DECLARE_ALIGNED(t,v,a) t __attribute__((aligned(a))) v #elif defined(_MSC_VER) #define DECLARE_ALIGNED(t,v,a) __declspec(align(a)) t v #else #define DECLARE_ALIGNED(t,v,a) t v #endif /* Load pixel of the specified format from a buffer and get its R-G-B values */ #define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \ { \ r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \ g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \ b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \ } #define RGB_FROM_RGB565(Pixel, r, g, b) \ { \ r = SDL_expand_byte[3][((Pixel&0xF800)>>11)]; \ g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)]; \ b = SDL_expand_byte[3][(Pixel&0x001F)]; \ } #define RGB_FROM_RGB555(Pixel, r, g, b) \ { \ r = SDL_expand_byte[3][((Pixel&0x7C00)>>10)]; \ g = SDL_expand_byte[3][((Pixel&0x03E0)>>5)]; \ b = SDL_expand_byte[3][(Pixel&0x001F)]; \ } #define RGB_FROM_RGB888(Pixel, r, g, b) \ { \ r = ((Pixel&0xFF0000)>>16); \ g = ((Pixel&0xFF00)>>8); \ b = (Pixel&0xFF); \ } #define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \ do { \ switch (bpp) { \ case 1: \ Pixel = *((Uint8 *)(buf)); \ break; \ \ case 2: \ Pixel = *((Uint16 *)(buf)); \ break; \ \ case 3: { \ Uint8 *B = (Uint8 *)(buf); \ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \ } else { \ Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \ } \ } \ break; \ \ case 4: \ Pixel = *((Uint32 *)(buf)); \ break; \ \ default: \ Pixel = 0; /* stop gcc complaints */ \ break; \ } \ } while (0) #define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \ do { \ switch (bpp) { \ case 1: \ Pixel = *((Uint8 *)(buf)); \ RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \ break; \ \ case 2: \ Pixel = *((Uint16 *)(buf)); \ RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \ break; \ \ case 3: { \ Pixel = 0; \ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ r = *((buf)+fmt->Rshift/8); \ g = *((buf)+fmt->Gshift/8); \ b = *((buf)+fmt->Bshift/8); \ } else { \ r = *((buf)+2-fmt->Rshift/8); \ g = *((buf)+2-fmt->Gshift/8); \ b = *((buf)+2-fmt->Bshift/8); \ } \ } \ break; \ \ case 4: \ Pixel = *((Uint32 *)(buf)); \ RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \ break; \ \ default: \ /* stop gcc complaints */ \ Pixel = 0; \ r = g = b = 0; \ break; \ } \ } while (0) /* Assemble R-G-B values into a specified pixel format and store them */ #define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \ { \ Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ ((g>>fmt->Gloss)<<fmt->Gshift)| \ ((b>>fmt->Bloss)<<fmt->Bshift)| \ fmt->Amask; \ } #define RGB565_FROM_RGB(Pixel, r, g, b) \ { \ Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \ } #define RGB555_FROM_RGB(Pixel, r, g, b) \ { \ Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \ } #define RGB888_FROM_RGB(Pixel, r, g, b) \ { \ Pixel = (r<<16)|(g<<8)|b; \ } #define ARGB8888_FROM_RGBA(Pixel, r, g, b, a) \ { \ Pixel = (a<<24)|(r<<16)|(g<<8)|b; \ } #define RGBA8888_FROM_RGBA(Pixel, r, g, b, a) \ { \ Pixel = (r<<24)|(g<<16)|(b<<8)|a; \ } #define ABGR8888_FROM_RGBA(Pixel, r, g, b, a) \ { \ Pixel = (a<<24)|(b<<16)|(g<<8)|r; \ } #define BGRA8888_FROM_RGBA(Pixel, r, g, b, a) \ { \ Pixel = (b<<24)|(g<<16)|(r<<8)|a; \ } #define ARGB2101010_FROM_RGBA(Pixel, r, g, b, a) \ { \ r = r ? ((r << 2) | 0x3) : 0; \ g = g ? ((g << 2) | 0x3) : 0; \ b = b ? ((b << 2) | 0x3) : 0; \ a = (a * 3) / 255; \ Pixel = (a<<30)|(r<<20)|(g<<10)|b; \ } #define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \ { \ switch (bpp) { \ case 1: { \ Uint8 _Pixel; \ \ PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \ *((Uint8 *)(buf)) = _Pixel; \ } \ break; \ \ case 2: { \ Uint16 _Pixel; \ \ PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \ *((Uint16 *)(buf)) = _Pixel; \ } \ break; \ \ case 3: { \ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ *((buf)+fmt->Rshift/8) = r; \ *((buf)+fmt->Gshift/8) = g; \ *((buf)+fmt->Bshift/8) = b; \ } else { \ *((buf)+2-fmt->Rshift/8) = r; \ *((buf)+2-fmt->Gshift/8) = g; \ *((buf)+2-fmt->Bshift/8) = b; \ } \ } \ break; \ \ case 4: { \ Uint32 _Pixel; \ \ PIXEL_FROM_RGB(_Pixel, fmt, r, g, b); \ *((Uint32 *)(buf)) = _Pixel; \ } \ break; \ } \ } /* FIXME: Should we rescale alpha into 0..255 here? */ #define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a) \ { \ r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \ g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \ b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \ a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \ } #define RGBA_FROM_8888(Pixel, fmt, r, g, b, a) \ { \ r = (Pixel&fmt->Rmask)>>fmt->Rshift; \ g = (Pixel&fmt->Gmask)>>fmt->Gshift; \ b = (Pixel&fmt->Bmask)>>fmt->Bshift; \ a = (Pixel&fmt->Amask)>>fmt->Ashift; \ } #define RGBA_FROM_RGBA8888(Pixel, r, g, b, a) \ { \ r = (Pixel>>24); \ g = ((Pixel>>16)&0xFF); \ b = ((Pixel>>8)&0xFF); \ a = (Pixel&0xFF); \ } #define RGBA_FROM_ARGB8888(Pixel, r, g, b, a) \ { \ r = ((Pixel>>16)&0xFF); \ g = ((Pixel>>8)&0xFF); \ b = (Pixel&0xFF); \ a = (Pixel>>24); \ } #define RGBA_FROM_ABGR8888(Pixel, r, g, b, a) \ { \ r = (Pixel&0xFF); \ g = ((Pixel>>8)&0xFF); \ b = ((Pixel>>16)&0xFF); \ a = (Pixel>>24); \ } #define RGBA_FROM_BGRA8888(Pixel, r, g, b, a) \ { \ r = ((Pixel>>8)&0xFF); \ g = ((Pixel>>16)&0xFF); \ b = (Pixel>>24); \ a = (Pixel&0xFF); \ } #define RGBA_FROM_ARGB2101010(Pixel, r, g, b, a) \ { \ r = ((Pixel>>22)&0xFF); \ g = ((Pixel>>12)&0xFF); \ b = ((Pixel>>2)&0xFF); \ a = SDL_expand_byte[6][(Pixel>>30)]; \ } #define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a) \ do { \ switch (bpp) { \ case 1: \ Pixel = *((Uint8 *)(buf)); \ RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \ break; \ \ case 2: \ Pixel = *((Uint16 *)(buf)); \ RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \ break; \ \ case 3: { \ Pixel = 0; \ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ r = *((buf)+fmt->Rshift/8); \ g = *((buf)+fmt->Gshift/8); \ b = *((buf)+fmt->Bshift/8); \ } else { \ r = *((buf)+2-fmt->Rshift/8); \ g = *((buf)+2-fmt->Gshift/8); \ b = *((buf)+2-fmt->Bshift/8); \ } \ a = 0xFF; \ } \ break; \ \ case 4: \ Pixel = *((Uint32 *)(buf)); \ RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \ break; \ \ default: \ /* stop gcc complaints */ \ Pixel = 0; \ r = g = b = a = 0; \ break; \ } \ } while (0) /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */ #define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \ { \ Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ ((g>>fmt->Gloss)<<fmt->Gshift)| \ ((b>>fmt->Bloss)<<fmt->Bshift)| \ ((a>>fmt->Aloss)<<fmt->Ashift); \ } #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \ { \ switch (bpp) { \ case 1: { \ Uint8 _pixel; \ \ PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \ *((Uint8 *)(buf)) = _pixel; \ } \ break; \ \ case 2: { \ Uint16 _pixel; \ \ PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \ *((Uint16 *)(buf)) = _pixel; \ } \ break; \ \ case 3: { \ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \ *((buf)+fmt->Rshift/8) = r; \ *((buf)+fmt->Gshift/8) = g; \ *((buf)+fmt->Bshift/8) = b; \ } else { \ *((buf)+2-fmt->Rshift/8) = r; \ *((buf)+2-fmt->Gshift/8) = g; \ *((buf)+2-fmt->Bshift/8) = b; \ } \ } \ break; \ \ case 4: { \ Uint32 _pixel; \ \ PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \ *((Uint32 *)(buf)) = _pixel; \ } \ break; \ } \ } /* Blend the RGB values of two pixels with an alpha value */ #define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB) \ do { \ dR = (Uint8)((((int)(sR-dR)*(int)A)/255)+dR); \ dG = (Uint8)((((int)(sG-dG)*(int)A)/255)+dG); \ dB = (Uint8)((((int)(sB-dB)*(int)A)/255)+dB); \ } while(0) /* Blend the RGBA values of two pixels */ #define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA) \ do { \ dR = (Uint8)((((int)(sR-dR)*(int)sA)/255)+dR); \ dG = (Uint8)((((int)(sG-dG)*(int)sA)/255)+dG); \ dB = (Uint8)((((int)(sB-dB)*(int)sA)/255)+dB); \ dA = (Uint8)((int)sA+dA-((int)sA*dA)/255); \ } while(0) /* This is a very useful loop for optimizing blitters */ #if defined(_MSC_VER) && (_MSC_VER == 1300) /* There's a bug in the Visual C++ 7 optimizer when compiling this code */ #else #define USE_DUFFS_LOOP #endif #ifdef USE_DUFFS_LOOP /* 8-times unrolled loop */ #define DUFFS_LOOP8(pixel_copy_increment, width) \ { int n = (width+7)/8; \ switch (width & 7) { \ case 0: do { pixel_copy_increment; /* fallthrough */ \ case 7: pixel_copy_increment; /* fallthrough */ \ case 6: pixel_copy_increment; /* fallthrough */ \ case 5: pixel_copy_increment; /* fallthrough */ \ case 4: pixel_copy_increment; /* fallthrough */ \ case 3: pixel_copy_increment; /* fallthrough */ \ case 2: pixel_copy_increment; /* fallthrough */ \ case 1: pixel_copy_increment; /* fallthrough */ \ } while ( --n > 0 ); \ } \ } /* 4-times unrolled loop */ #define DUFFS_LOOP4(pixel_copy_increment, width) \ { int n = (width+3)/4; \ switch (width & 3) { \ case 0: do { pixel_copy_increment; /* fallthrough */ \ case 3: pixel_copy_increment; /* fallthrough */ \ case 2: pixel_copy_increment; /* fallthrough */ \ case 1: pixel_copy_increment; /* fallthrough */ \ } while (--n > 0); \ } \ } /* Use the 8-times version of the loop by default */ #define DUFFS_LOOP(pixel_copy_increment, width) \ DUFFS_LOOP8(pixel_copy_increment, width) /* Special version of Duff's device for even more optimization */ #define DUFFS_LOOP_124(pixel_copy_increment1, \ pixel_copy_increment2, \ pixel_copy_increment4, width) \ { int n = width; \ if (n & 1) { \ pixel_copy_increment1; n -= 1; \ } \ if (n & 2) { \ pixel_copy_increment2; n -= 2; \ } \ if (n & 4) { \ pixel_copy_increment4; n -= 4; \ } \ if (n) { \ n /= 8; \ do { \ pixel_copy_increment4; \ pixel_copy_increment4; \ } while (--n > 0); \ } \ } #else /* Don't use Duff's device to unroll loops */ #define DUFFS_LOOP(pixel_copy_increment, width) \ { int n; \ for ( n=width; n > 0; --n ) { \ pixel_copy_increment; \ } \ } #define DUFFS_LOOP8(pixel_copy_increment, width) \ DUFFS_LOOP(pixel_copy_increment, width) #define DUFFS_LOOP4(pixel_copy_increment, width) \ DUFFS_LOOP(pixel_copy_increment, width) #define DUFFS_LOOP_124(pixel_copy_increment1, \ pixel_copy_increment2, \ pixel_copy_increment4, width) \ DUFFS_LOOP(pixel_copy_increment1, width) #endif /* USE_DUFFS_LOOP */ /* Prevent Visual C++ 6.0 from printing out stupid warnings */ #if defined(_MSC_VER) && (_MSC_VER >= 600) #pragma warning(disable: 4550) #endif #endif /* SDL_blit_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit.h
C
apache-2.0
31,083
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #if SDL_HAVE_BLIT_0 #include "SDL_video.h" #include "SDL_blit.h" /* Functions to blit from bitmaps to other surfaces */ static void BlitBto1(SDL_BlitInfo * info) { int c; int width, height; Uint8 *src, *map, *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = info->dst; dstskip = info->dst_skip; map = info->table; srcskip += width - (width + 7) / 8; if (map) { while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (1) { *dst = map[bit]; } dst++; byte <<= 1; } src += srcskip; dst += dstskip; } } else { while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (1) { *dst = bit; } dst++; byte <<= 1; } src += srcskip; dst += dstskip; } } } static void BlitBto2(SDL_BlitInfo * info) { int c; int width, height; Uint8 *src; Uint16 *map, *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = (Uint16 *) info->dst; dstskip = info->dst_skip / 2; map = (Uint16 *) info->table; srcskip += width - (width + 7) / 8; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (1) { *dst = map[bit]; } byte <<= 1; dst++; } src += srcskip; dst += dstskip; } } static void BlitBto3(SDL_BlitInfo * info) { int c, o; int width, height; Uint8 *src, *map, *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = info->dst; dstskip = info->dst_skip; map = info->table; srcskip += width - (width + 7) / 8; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (1) { o = bit * 4; dst[0] = map[o++]; dst[1] = map[o++]; dst[2] = map[o++]; } byte <<= 1; dst += 3; } src += srcskip; dst += dstskip; } } static void BlitBto4(SDL_BlitInfo * info) { int width, height; Uint8 *src; Uint32 *map, *dst; int srcskip, dstskip; int c; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = (Uint32 *) info->dst; dstskip = info->dst_skip / 4; map = (Uint32 *) info->table; srcskip += width - (width + 7) / 8; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (1) { *dst = map[bit]; } byte <<= 1; dst++; } src += srcskip; dst += dstskip; } } static void BlitBto1Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; int srcskip = info->src_skip; int dstskip = info->dst_skip; Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; /* Set up some basic variables */ srcskip += width - (width + 7) / 8; if (palmap) { while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (bit != ckey) { *dst = palmap[bit]; } dst++; byte <<= 1; } src += srcskip; dst += dstskip; } } else { while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (bit != ckey) { *dst = bit; } dst++; byte <<= 1; } src += srcskip; dst += dstskip; } } } static void BlitBto2Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; Uint16 *dstp = (Uint16 *) info->dst; int srcskip = info->src_skip; int dstskip = info->dst_skip; Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; /* Set up some basic variables */ srcskip += width - (width + 7) / 8; dstskip /= 2; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (bit != ckey) { *dstp = ((Uint16 *) palmap)[bit]; } byte <<= 1; dstp++; } src += srcskip; dstp += dstskip; } } static void BlitBto3Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; int srcskip = info->src_skip; int dstskip = info->dst_skip; Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; /* Set up some basic variables */ srcskip += width - (width + 7) / 8; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (bit != ckey) { SDL_memcpy(dst, &palmap[bit * 4], 3); } byte <<= 1; dst += 3; } src += srcskip; dst += dstskip; } } static void BlitBto4Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; Uint32 *dstp = (Uint32 *) info->dst; int srcskip = info->src_skip; int dstskip = info->dst_skip; Uint32 ckey = info->colorkey; Uint8 *palmap = info->table; int c; /* Set up some basic variables */ srcskip += width - (width + 7) / 8; dstskip /= 4; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (bit != ckey) { *dstp = ((Uint32 *) palmap)[bit]; } byte <<= 1; dstp++; } src += srcskip; dstp += dstskip; } } static void BlitBtoNAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; int srcskip = info->src_skip; int dstskip = info->dst_skip; const SDL_Color *srcpal = info->src_fmt->palette->colors; SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp; int c; Uint32 pixel; unsigned sR, sG, sB; unsigned dR, dG, dB, dA; const unsigned A = info->a; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; srcskip += width - (width + 7) / 8; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (1) { sR = srcpal[bit].r; sG = srcpal[bit].g; sB = srcpal[bit].b; DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); } byte <<= 1; dst += dstbpp; } src += srcskip; dst += dstskip; } } static void BlitBtoNAlphaKey(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; Uint8 *dst = info->dst; int srcskip = info->src_skip; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; const SDL_Color *srcpal = srcfmt->palette->colors; int dstbpp; int c; Uint32 pixel; unsigned sR, sG, sB; unsigned dR, dG, dB, dA; const unsigned A = info->a; Uint32 ckey = info->colorkey; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; srcskip += width - (width + 7) / 8; while (height--) { Uint8 byte = 0, bit; for (c = 0; c < width; ++c) { if ((c & 7) == 0) { byte = *src++; } bit = (byte & 0x80) >> 7; if (bit != ckey) { sR = srcpal[bit].r; sG = srcpal[bit].g; sB = srcpal[bit].b; DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); } byte <<= 1; dst += dstbpp; } src += srcskip; dst += dstskip; } } static const SDL_BlitFunc bitmap_blit[] = { (SDL_BlitFunc) NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4 }; static const SDL_BlitFunc colorkey_blit[] = { (SDL_BlitFunc) NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key }; SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface * surface) { int which; if (surface->format->BitsPerPixel != 1) { /* We don't support sub 8-bit packed pixel modes */ return (SDL_BlitFunc) NULL; } if (surface->map->dst->format->BitsPerPixel < 8) { which = 0; } else { which = surface->map->dst->format->BytesPerPixel; } switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { case 0: return bitmap_blit[which]; case SDL_COPY_COLORKEY: return colorkey_blit[which]; case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL; } return (SDL_BlitFunc) NULL; } #endif /* SDL_HAVE_BLIT_0 */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit_0.c
C
apache-2.0
12,447
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #if SDL_HAVE_BLIT_1 #include "SDL_video.h" #include "SDL_blit.h" #include "SDL_sysvideo.h" #include "SDL_endian.h" /* Functions to blit from 8-bit surfaces to other surfaces */ static void Blit1to1(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint8 *src, *map, *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = info->dst; dstskip = info->dst_skip; map = info->table; while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( { *dst = map[*src]; } dst++; src++; , width); /* *INDENT-ON* */ #else for (c = width; c; --c) { *dst = map[*src]; dst++; src++; } #endif src += srcskip; dst += dstskip; } } /* This is now endian dependent */ #ifndef USE_DUFFS_LOOP # if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) # define HI 1 # define LO 0 # else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */ # define HI 0 # define LO 1 # endif #endif static void Blit1to2(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint8 *src, *dst; Uint16 *map; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = info->dst; dstskip = info->dst_skip; map = (Uint16 *) info->table; #ifdef USE_DUFFS_LOOP while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { *(Uint16 *)dst = map[*src++]; dst += 2; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } #else /* Memory align at 4-byte boundary, if necessary */ if ((long) dst & 0x03) { /* Don't do anything if width is 0 */ if (width == 0) { return; } --width; while (height--) { /* Perform copy alignment */ *(Uint16 *) dst = map[*src++]; dst += 2; /* Copy in 4 pixel chunks */ for (c = width / 4; c; --c) { *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); src += 2; dst += 4; *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); src += 2; dst += 4; } /* Get any leftovers */ switch (width & 3) { case 3: *(Uint16 *) dst = map[*src++]; dst += 2; case 2: *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); src += 2; dst += 4; break; case 1: *(Uint16 *) dst = map[*src++]; dst += 2; break; } src += srcskip; dst += dstskip; } } else { while (height--) { /* Copy in 4 pixel chunks */ for (c = width / 4; c; --c) { *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); src += 2; dst += 4; *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); src += 2; dst += 4; } /* Get any leftovers */ switch (width & 3) { case 3: *(Uint16 *) dst = map[*src++]; dst += 2; case 2: *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]); src += 2; dst += 4; break; case 1: *(Uint16 *) dst = map[*src++]; dst += 2; break; } src += srcskip; dst += dstskip; } } #endif /* USE_DUFFS_LOOP */ } static void Blit1to3(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int o; int width, height; Uint8 *src, *map, *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = info->dst; dstskip = info->dst_skip; map = info->table; while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( { o = *src * 4; dst[0] = map[o++]; dst[1] = map[o++]; dst[2] = map[o++]; } src++; dst += 3; , width); /* *INDENT-ON* */ #else for (c = width; c; --c) { o = *src * 4; dst[0] = map[o++]; dst[1] = map[o++]; dst[2] = map[o++]; src++; dst += 3; } #endif /* USE_DUFFS_LOOP */ src += srcskip; dst += dstskip; } } static void Blit1to4(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint8 *src; Uint32 *map, *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = (Uint32 *) info->dst; dstskip = info->dst_skip / 4; map = (Uint32 *) info->table; while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( *dst++ = map[*src++]; , width); /* *INDENT-ON* */ #else for (c = width / 4; c; --c) { *dst++ = map[*src++]; *dst++ = map[*src++]; *dst++ = map[*src++]; *dst++ = map[*src++]; } switch (width & 3) { case 3: *dst++ = map[*src++]; case 2: *dst++ = map[*src++]; case 1: *dst++ = map[*src++]; } #endif /* USE_DUFFS_LOOP */ src += srcskip; dst += dstskip; } } static void Blit1to1Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint8 *palmap = info->table; Uint32 ckey = info->colorkey; if (palmap) { while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { *dst = palmap[*src]; } dst++; src++; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } else { while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { *dst = *src; } dst++; src++; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } } static void Blit1to2Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip; Uint16 *palmap = (Uint16 *) info->table; Uint32 ckey = info->colorkey; /* Set up some basic variables */ dstskip /= 2; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { *dstp=palmap[*src]; } src++; dstp++; }, width); /* *INDENT-ON* */ src += srcskip; dstp += dstskip; } } static void Blit1to3Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint8 *palmap = info->table; Uint32 ckey = info->colorkey; int o; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { o = *src * 4; dst[0] = palmap[o++]; dst[1] = palmap[o++]; dst[2] = palmap[o++]; } src++; dst += 3; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } static void Blit1to4Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip; Uint32 *palmap = (Uint32 *) info->table; Uint32 ckey = info->colorkey; /* Set up some basic variables */ dstskip /= 4; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { *dstp = palmap[*src]; } src++; dstp++; }, width); /* *INDENT-ON* */ src += srcskip; dstp += dstskip; } } static void Blit1toNAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *dstfmt = info->dst_fmt; const SDL_Color *srcpal = info->src_fmt->palette->colors; int dstbpp; Uint32 pixel; unsigned sR, sG, sB; unsigned dR, dG, dB, dA; const unsigned A = info->a; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4( { sR = srcpal[*src].r; sG = srcpal[*src].g; sB = srcpal[*src].b; DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); src++; dst += dstbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } static void Blit1toNAlphaKey(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *dstfmt = info->dst_fmt; const SDL_Color *srcpal = info->src_fmt->palette->colors; Uint32 ckey = info->colorkey; int dstbpp; Uint32 pixel; unsigned sR, sG, sB; unsigned dR, dG, dB, dA; const unsigned A = info->a; /* Set up some basic variables */ dstbpp = dstfmt->BytesPerPixel; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ( *src != ckey ) { sR = srcpal[*src].r; sG = srcpal[*src].g; sB = srcpal[*src].b; DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); } src++; dst += dstbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } static const SDL_BlitFunc one_blit[] = { (SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4 }; static const SDL_BlitFunc one_blitkey[] = { (SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key }; SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface * surface) { int which; SDL_PixelFormat *dstfmt; dstfmt = surface->map->dst->format; if (dstfmt->BitsPerPixel < 8) { which = 0; } else { which = dstfmt->BytesPerPixel; } switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { case 0: return one_blit[which]; case SDL_COPY_COLORKEY: return one_blitkey[which]; case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: /* Supporting 8bpp->8bpp alpha is doable but requires lots of tables which consume space and takes time to precompute, so is better left to the user */ return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc) NULL; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL; } return (SDL_BlitFunc) NULL; } #endif /* SDL_HAVE_BLIT_1 */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit_1.c
C
apache-2.0
13,726
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #if SDL_HAVE_BLIT_A #include "SDL_video.h" #include "SDL_blit.h" /* Functions to perform alpha blended blitting */ /* N->1 blending with per-surface alpha */ static void BlitNto1SurfaceAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint8 *palmap = info->table; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; Uint32 Pixel; unsigned sR, sG, sB; unsigned dR, dG, dB; const unsigned A = info->a; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); dR = dstfmt->palette->colors[*dst].r; dG = dstfmt->palette->colors[*dst].g; dB = dstfmt->palette->colors[*dst].b; ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB); dR &= 0xff; dG &= 0xff; dB &= 0xff; /* Pack RGB into 8bit pixel */ if ( palmap == NULL ) { *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); } else { *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; } dst++; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } /* N->1 blending with pixel alpha */ static void BlitNto1PixelAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint8 *palmap = info->table; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; Uint32 Pixel; unsigned sR, sG, sB, sA; unsigned dR, dG, dB; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4( { DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA); dR = dstfmt->palette->colors[*dst].r; dG = dstfmt->palette->colors[*dst].g; dB = dstfmt->palette->colors[*dst].b; ALPHA_BLEND_RGB(sR, sG, sB, sA, dR, dG, dB); dR &= 0xff; dG &= 0xff; dB &= 0xff; /* Pack RGB into 8bit pixel */ if ( palmap == NULL ) { *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); } else { *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; } dst++; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } /* colorkeyed N->1 blending with per-surface alpha */ static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint8 *palmap = info->table; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; Uint32 ckey = info->colorkey; Uint32 Pixel; unsigned sR, sG, sB; unsigned dR, dG, dB; const unsigned A = info->a; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); if ( Pixel != ckey ) { dR = dstfmt->palette->colors[*dst].r; dG = dstfmt->palette->colors[*dst].g; dB = dstfmt->palette->colors[*dst].b; ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB); dR &= 0xff; dG &= 0xff; dB &= 0xff; /* Pack RGB into 8bit pixel */ if ( palmap == NULL ) { *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0)); } else { *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))]; } } dst++; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } #ifdef __MMX__ /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */ static void BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip >> 2; Uint32 dalpha = info->dst_fmt->Amask; __m64 src1, src2, dst1, dst2, lmask, hmask, dsta; hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */ lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */ dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */ while (height--) { int n = width; if (n & 1) { Uint32 s = *srcp++; Uint32 d = *dstp; *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) + (s & d & 0x00010101)) | dalpha; n--; } for (n >>= 1; n > 0; --n) { dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */ dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */ src2 = src1; /* 2 x src -> src2(ARGBARGB) */ dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */ src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */ src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */ src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */ dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */ dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */ dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */ dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */ *(__m64 *) dstp = dst1; /* dst1 -> 2 x dst pixels */ dstp += 2; srcp += 2; } srcp += srcskip; dstp += dstskip; } _mm_empty(); } /* fast RGB888->(A)RGB888 blending with surface alpha */ static void BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info) { SDL_PixelFormat *df = info->dst_fmt; Uint32 chanmask; unsigned alpha = info->a; if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) { /* only call a128 version when R,G,B occupy lower bits */ BlitRGBtoRGBSurfaceAlpha128MMX(info); } else { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip >> 2; Uint32 dalpha = df->Amask; Uint32 amult; __m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta; mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ /* form the alpha mult */ amult = alpha | (alpha << 8); amult = amult | (amult << 16); chanmask = (0xff << df->Rshift) | (0xff << df-> Gshift) | (0xff << df->Bshift); mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */ mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */ /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */ dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */ while (height--) { int n = width; if (n & 1) { /* One Pixel Blend */ src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB) */ src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */ dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */ dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */ dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */ dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */ *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ ++srcp; ++dstp; n--; } for (n >>= 1; n > 0; --n) { /* Two Pixels Blend */ src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */ src2 = src1; /* 2 x src -> src2(ARGBARGB) */ src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */ src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */ dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */ dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */ dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */ src1 = _mm_sub_pi16(src1, dst1); /* src1 - dst1 -> src1 */ src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */ src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */ dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */ src2 = _mm_sub_pi16(src2, dst2); /* src2 - dst2 -> src2 */ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */ dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */ dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */ dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */ *(__m64 *) dstp = dst1; /* dst1 -> 2 x pixel */ srcp += 2; dstp += 2; } srcp += srcskip; dstp += dstskip; } _mm_empty(); } } /* fast ARGB888->(A)RGB888 blending with pixel alpha */ static void BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip >> 2; SDL_PixelFormat *sf = info->src_fmt; Uint32 amask = sf->Amask; Uint32 ashift = sf->Ashift; Uint64 multmask, multmask2; __m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2; mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ multmask = 0x00FF; multmask <<= (ashift * 2); multmask2 = 0x00FF00FF00FF00FFULL; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 alpha = *srcp & amask; if (alpha == 0) { /* do nothing */ } else if (alpha == amask) { *dstp = *srcp; } else { src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */ src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */ mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */ mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */ /* blend */ src1 = _mm_mullo_pi16(src1, mm_alpha); src1 = _mm_srli_pi16(src1, 8); dst1 = _mm_mullo_pi16(dst1, mm_alpha2); dst1 = _mm_srli_pi16(dst1, 8); dst1 = _mm_add_pi16(src1, dst1); dst1 = _mm_packs_pu16(dst1, mm_zero); *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ } ++srcp; ++dstp; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } _mm_empty(); } #endif /* __MMX__ */ #if SDL_ARM_SIMD_BLITTERS void BlitARGBto565PixelAlphaARMSIMDAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride); static void BlitARGBto565PixelAlphaARMSIMD(SDL_BlitInfo * info) { int32_t width = info->dst_w; int32_t height = info->dst_h; uint16_t *dstp = (uint16_t *)info->dst; int32_t dststride = width + (info->dst_skip >> 1); uint32_t *srcp = (uint32_t *)info->src; int32_t srcstride = width + (info->src_skip >> 2); BlitARGBto565PixelAlphaARMSIMDAsm(width, height, dstp, dststride, srcp, srcstride); } void BlitRGBtoRGBPixelAlphaARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride); static void BlitRGBtoRGBPixelAlphaARMSIMD(SDL_BlitInfo * info) { int32_t width = info->dst_w; int32_t height = info->dst_h; uint32_t *dstp = (uint32_t *)info->dst; int32_t dststride = width + (info->dst_skip >> 2); uint32_t *srcp = (uint32_t *)info->src; int32_t srcstride = width + (info->src_skip >> 2); BlitRGBtoRGBPixelAlphaARMSIMDAsm(width, height, dstp, dststride, srcp, srcstride); } #endif #if SDL_ARM_NEON_BLITTERS void BlitARGBto565PixelAlphaARMNEONAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride); static void BlitARGBto565PixelAlphaARMNEON(SDL_BlitInfo * info) { int32_t width = info->dst_w; int32_t height = info->dst_h; uint16_t *dstp = (uint16_t *)info->dst; int32_t dststride = width + (info->dst_skip >> 1); uint32_t *srcp = (uint32_t *)info->src; int32_t srcstride = width + (info->src_skip >> 2); BlitARGBto565PixelAlphaARMNEONAsm(width, height, dstp, dststride, srcp, srcstride); } void BlitRGBtoRGBPixelAlphaARMNEONAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride); static void BlitRGBtoRGBPixelAlphaARMNEON(SDL_BlitInfo * info) { int32_t width = info->dst_w; int32_t height = info->dst_h; uint32_t *dstp = (uint32_t *)info->dst; int32_t dststride = width + (info->dst_skip >> 2); uint32_t *srcp = (uint32_t *)info->src; int32_t srcstride = width + (info->src_skip >> 2); BlitRGBtoRGBPixelAlphaARMNEONAsm(width, height, dstp, dststride, srcp, srcstride); } #endif /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */ static void BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip >> 2; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp++; Uint32 d = *dstp; *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) + (s & d & 0x00010101)) | 0xff000000; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } /* fast RGB888->(A)RGB888 blending with surface alpha */ static void BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info) { unsigned alpha = info->a; if (alpha == 128) { BlitRGBtoRGBSurfaceAlpha128(info); } else { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip >> 2; Uint32 s; Uint32 d; Uint32 s1; Uint32 d1; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ s = *srcp; d = *dstp; s1 = s & 0xff00ff; d1 = d & 0xff00ff; d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; s &= 0xff00; d &= 0xff00; d = (d + ((s - d) * alpha >> 8)) & 0xff00; *dstp = d1 | d | 0xff000000; ++srcp; ++dstp; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } } /* fast ARGB888->(A)RGB888 blending with pixel alpha */ static void BlitRGBtoRGBPixelAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip >> 2; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 dalpha; Uint32 d; Uint32 s1; Uint32 d1; Uint32 s = *srcp; Uint32 alpha = s >> 24; /* FIXME: Here we special-case opaque alpha since the compositioning used (>>8 instead of /255) doesn't handle it correctly. Also special-case alpha=0 for speed? Benchmark this! */ if (alpha) { if (alpha == SDL_ALPHA_OPAQUE) { *dstp = *srcp; } else { /* * take out the middle component (green), and process * the other two in parallel. One multiply less. */ d = *dstp; dalpha = d >> 24; s1 = s & 0xff00ff; d1 = d & 0xff00ff; d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; s &= 0xff00; d &= 0xff00; d = (d + ((s - d) * alpha >> 8)) & 0xff00; dalpha = alpha + (dalpha * (alpha ^ 0xFF) >> 8); *dstp = d1 | d | (dalpha << 24); } } ++srcp; ++dstp; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } #ifdef __3dNOW__ /* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */ static void BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip >> 2; SDL_PixelFormat *sf = info->src_fmt; Uint32 amask = sf->Amask; Uint32 ashift = sf->Ashift; Uint64 multmask, multmask2; __m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2; mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */ multmask = 0x00FF; multmask <<= (ashift * 2); multmask2 = 0x00FF00FF00FF00FFULL; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 alpha; _m_prefetch(srcp + 16); _m_prefetch(dstp + 16); alpha = *srcp & amask; if (alpha == 0) { /* do nothing */ } else if (alpha == amask) { *dstp = *srcp; } else { src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */ src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */ dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */ mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */ mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */ mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */ mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */ /* blend */ src1 = _mm_mullo_pi16(src1, mm_alpha); src1 = _mm_srli_pi16(src1, 8); dst1 = _mm_mullo_pi16(dst1, mm_alpha2); dst1 = _mm_srli_pi16(dst1, 8); dst1 = _mm_add_pi16(src1, dst1); dst1 = _mm_packs_pu16(dst1, mm_zero); *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */ } ++srcp; ++dstp; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } _mm_empty(); } #endif /* __3dNOW__ */ /* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */ /* blend a single 16 bit pixel at 50% */ #define BLEND16_50(d, s, mask) \ ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff))) /* blend two 16 bit pixels at 50% */ #define BLEND2x16_50(d, s, mask) \ (((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \ + (s & d & (~(mask | mask << 16)))) static void Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask) { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip >> 1; while (height--) { if (((uintptr_t) srcp ^ (uintptr_t) dstp) & 2) { /* * Source and destination not aligned, pipeline it. * This is mostly a win for big blits but no loss for * small ones */ Uint32 prev_sw; int w = width; /* handle odd destination */ if ((uintptr_t) dstp & 2) { Uint16 d = *dstp, s = *srcp; *dstp = BLEND16_50(d, s, mask); dstp++; srcp++; w--; } srcp++; /* srcp is now 32-bit aligned */ /* bootstrap pipeline with first halfword */ prev_sw = ((Uint32 *) srcp)[-1]; while (w > 1) { Uint32 sw, dw, s; sw = *(Uint32 *) srcp; dw = *(Uint32 *) dstp; #if SDL_BYTEORDER == SDL_BIG_ENDIAN s = (prev_sw << 16) + (sw >> 16); #else s = (prev_sw >> 16) + (sw << 16); #endif prev_sw = sw; *(Uint32 *) dstp = BLEND2x16_50(dw, s, mask); dstp += 2; srcp += 2; w -= 2; } /* final pixel if any */ if (w) { Uint16 d = *dstp, s; #if SDL_BYTEORDER == SDL_BIG_ENDIAN s = (Uint16) prev_sw; #else s = (Uint16) (prev_sw >> 16); #endif *dstp = BLEND16_50(d, s, mask); srcp++; dstp++; } srcp += srcskip - 1; dstp += dstskip; } else { /* source and destination are aligned */ int w = width; /* first odd pixel? */ if ((uintptr_t) srcp & 2) { Uint16 d = *dstp, s = *srcp; *dstp = BLEND16_50(d, s, mask); srcp++; dstp++; w--; } /* srcp and dstp are now 32-bit aligned */ while (w > 1) { Uint32 sw = *(Uint32 *) srcp; Uint32 dw = *(Uint32 *) dstp; *(Uint32 *) dstp = BLEND2x16_50(dw, sw, mask); srcp += 2; dstp += 2; w -= 2; } /* last odd pixel? */ if (w) { Uint16 d = *dstp, s = *srcp; *dstp = BLEND16_50(d, s, mask); srcp++; dstp++; } srcp += srcskip; dstp += dstskip; } } } #ifdef __MMX__ /* fast RGB565->RGB565 blending with surface alpha */ static void Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info) { unsigned alpha = info->a; if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xf7de); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip >> 1; Uint32 s, d; __m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha; alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */ alpha >>= 3; /* downscale alpha to 5 bits */ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ /* position alpha to allow for mullo and mulhi on diff channels to reduce the number of operations */ mm_alpha = _mm_slli_si64(mm_alpha, 3); /* Setup the 565 color channel masks */ gmask = _mm_set_pi32(0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */ bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP_124( { s = *srcp++; d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x07e0f81f; d = (d | d << 16) & 0x07e0f81f; d += (s - d) * alpha >> 5; d &= 0x07e0f81f; *dstp++ = (Uint16)(d | d >> 16); },{ s = *srcp++; d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x07e0f81f; d = (d | d << 16) & 0x07e0f81f; d += (s - d) * alpha >> 5; d &= 0x07e0f81f; *dstp++ = (Uint16)(d | d >> 16); s = *srcp++; d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x07e0f81f; d = (d | d << 16) & 0x07e0f81f; d += (s - d) * alpha >> 5; d &= 0x07e0f81f; *dstp++ = (Uint16)(d | d >> 16); },{ src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ /* red */ src2 = src1; src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 [000r 000r 000r 000r] */ dst2 = dst1; dst2 = _mm_srli_pi16(dst2, 11); /* dst2 >> 11 -> dst2 [000r 000r 000r 000r] */ /* blend */ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ dst2 = _mm_slli_pi16(dst2, 11); /* dst2 << 11 -> dst2 */ mm_res = dst2; /* RED -> mm_res */ /* green -- process the bits in place */ src2 = src1; src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ dst2 = dst1; dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ /* blend */ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ /* blue */ src2 = src1; src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ dst2 = dst1; dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ /* blend */ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ srcp += 4; dstp += 4; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } _mm_empty(); } } /* fast RGB555->RGB555 blending with surface alpha */ static void Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info) { unsigned alpha = info->a; if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xfbde); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip >> 1; Uint32 s, d; __m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha; alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */ mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */ alpha >>= 3; /* downscale alpha to 5 bits */ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */ mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */ /* position alpha to allow for mullo and mulhi on diff channels to reduce the number of operations */ mm_alpha = _mm_slli_si64(mm_alpha, 3); /* Setup the 555 color channel masks */ rmask = _mm_set_pi32(0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */ gmask = _mm_set_pi32(0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */ bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */ while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP_124( { s = *srcp++; d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x03e07c1f; d = (d | d << 16) & 0x03e07c1f; d += (s - d) * alpha >> 5; d &= 0x03e07c1f; *dstp++ = (Uint16)(d | d >> 16); },{ s = *srcp++; d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x03e07c1f; d = (d | d << 16) & 0x03e07c1f; d += (s - d) * alpha >> 5; d &= 0x03e07c1f; *dstp++ = (Uint16)(d | d >> 16); s = *srcp++; d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x03e07c1f; d = (d | d << 16) & 0x03e07c1f; d += (s - d) * alpha >> 5; d &= 0x03e07c1f; *dstp++ = (Uint16)(d | d >> 16); },{ src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */ dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */ /* red -- process the bits in place */ src2 = src1; src2 = _mm_and_si64(src2, rmask); /* src & MASKRED -> src2 */ dst2 = dst1; dst2 = _mm_and_si64(dst2, rmask); /* dst & MASKRED -> dst2 */ /* blend */ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ dst2 = _mm_and_si64(dst2, rmask); /* dst2 & MASKRED -> dst2 */ mm_res = dst2; /* RED -> mm_res */ /* green -- process the bits in place */ src2 = src1; src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */ dst2 = dst1; dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */ /* blend */ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */ /* blue */ src2 = src1; /* src -> src2 */ src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */ dst2 = dst1; /* dst -> dst2 */ dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */ /* blend */ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */ src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */ dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */ *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */ srcp += 4; dstp += 4; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } _mm_empty(); } } #endif /* __MMX__ */ /* fast RGB565->RGB565 blending with surface alpha */ static void Blit565to565SurfaceAlpha(SDL_BlitInfo * info) { unsigned alpha = info->a; if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xf7de); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip >> 1; alpha >>= 3; /* downscale alpha to 5 bits */ while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp++; Uint32 d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x07e0f81f; d = (d | d << 16) & 0x07e0f81f; d += (s - d) * alpha >> 5; d &= 0x07e0f81f; *dstp++ = (Uint16)(d | d >> 16); }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } } /* fast RGB555->RGB555 blending with surface alpha */ static void Blit555to555SurfaceAlpha(SDL_BlitInfo * info) { unsigned alpha = info->a; /* downscale alpha to 5 bits */ if (alpha == 128) { Blit16to16SurfaceAlpha128(info, 0xfbde); } else { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; int srcskip = info->src_skip >> 1; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip >> 1; alpha >>= 3; /* downscale alpha to 5 bits */ while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp++; Uint32 d = *dstp; /* * shift out the middle component (green) to * the high 16 bits, and process all three RGB * components at the same time. */ s = (s | s << 16) & 0x03e07c1f; d = (d | d << 16) & 0x03e07c1f; d += (s - d) * alpha >> 5; d &= 0x03e07c1f; *dstp++ = (Uint16)(d | d >> 16); }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } } /* fast ARGB8888->RGB565 blending with pixel alpha */ static void BlitARGBto565PixelAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip >> 1; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ Uint32 s = *srcp; unsigned alpha = s >> 27; /* downscale alpha to 5 bits */ /* FIXME: Here we special-case opaque alpha since the compositioning used (>>8 instead of /255) doesn't handle it correctly. Also special-case alpha=0 for speed? Benchmark this! */ if(alpha) { if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f)); } else { Uint32 d = *dstp; /* * convert source and destination to G0RAB65565 * and blend all components at the same time */ s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800) + (s >> 3 & 0x1f); d = (d | d << 16) & 0x07e0f81f; d += (s - d) * alpha >> 5; d &= 0x07e0f81f; *dstp = (Uint16)(d | d >> 16); } } srcp++; dstp++; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } /* fast ARGB8888->RGB555 blending with pixel alpha */ static void BlitARGBto555PixelAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip >> 2; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip >> 1; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4({ unsigned alpha; Uint32 s = *srcp; alpha = s >> 27; /* downscale alpha to 5 bits */ /* FIXME: Here we special-case opaque alpha since the compositioning used (>>8 instead of /255) doesn't handle it correctly. Also special-case alpha=0 for speed? Benchmark this! */ if(alpha) { if(alpha == (SDL_ALPHA_OPAQUE >> 3)) { *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f)); } else { Uint32 d = *dstp; /* * convert source and destination to G0RAB65565 * and blend all components at the same time */ s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00) + (s >> 3 & 0x1f); d = (d | d << 16) & 0x03e07c1f; d += (s - d) * alpha >> 5; d &= 0x03e07c1f; *dstp = (Uint16)(d | d >> 16); } } srcp++; dstp++; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } /* General (slow) N->N blending with per-surface alpha */ static void BlitNtoNSurfaceAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; Uint32 Pixel; unsigned sR, sG, sB; unsigned dR, dG, dB, dA; const unsigned sA = info->a; if (sA) { while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); src += srcbpp; dst += dstbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } } /* General (slow) colorkeyed N->N blending with per-surface alpha */ static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; Uint32 ckey = info->colorkey; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; Uint32 Pixel; unsigned sR, sG, sB; unsigned dR, dG, dB, dA; const unsigned sA = info->a; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4( { RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel); if(sA && Pixel != ckey) { RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); } src += srcbpp; dst += dstbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } /* General (slow) N->N blending with pixel alpha */ static void BlitNtoNPixelAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp; int dstbpp; Uint32 Pixel; unsigned sR, sG, sB, sA; unsigned dR, dG, dB, dA; /* Set up some basic variables */ srcbpp = srcfmt->BytesPerPixel; dstbpp = dstfmt->BytesPerPixel; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP4( { DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); if(sA) { DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA); ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA); } src += srcbpp; dst += dstbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface) { SDL_PixelFormat *sf = surface->format; SDL_PixelFormat *df = surface->map->dst->format; switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { case SDL_COPY_BLEND: /* Per-pixel alpha blits */ switch (df->BytesPerPixel) { case 1: if (df->palette != NULL) { return BlitNto1PixelAlpha; } else { /* RGB332 has no palette ! */ return BlitNtoNPixelAlpha; } case 2: #if SDL_ARM_NEON_BLITTERS || SDL_ARM_SIMD_BLITTERS if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 && sf->Gmask == 0xff00 && df->Gmask == 0x7e0 && ((sf->Rmask == 0xff && df->Rmask == 0x1f) || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { #if SDL_ARM_NEON_BLITTERS if (SDL_HasNEON()) return BlitARGBto565PixelAlphaARMNEON; #endif #if SDL_ARM_SIMD_BLITTERS if (SDL_HasARMSIMD()) return BlitARGBto565PixelAlphaARMSIMD; #endif } #endif if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000 && sf->Gmask == 0xff00 && ((sf->Rmask == 0xff && df->Rmask == 0x1f) || (sf->Bmask == 0xff && df->Bmask == 0x1f))) { if (df->Gmask == 0x7e0) return BlitARGBto565PixelAlpha; else if (df->Gmask == 0x3e0) return BlitARGBto555PixelAlpha; } return BlitNtoNPixelAlpha; case 4: if (sf->Rmask == df->Rmask && sf->Gmask == df->Gmask && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { #if defined(__MMX__) || defined(__3dNOW__) if (sf->Rshift % 8 == 0 && sf->Gshift % 8 == 0 && sf->Bshift % 8 == 0 && sf->Ashift % 8 == 0 && sf->Aloss == 0) { #ifdef __3dNOW__ if (SDL_Has3DNow()) return BlitRGBtoRGBPixelAlphaMMX3DNOW; #endif #ifdef __MMX__ if (SDL_HasMMX()) return BlitRGBtoRGBPixelAlphaMMX; #endif } #endif /* __MMX__ || __3dNOW__ */ if (sf->Amask == 0xff000000) { #if SDL_ARM_NEON_BLITTERS if (SDL_HasNEON()) return BlitRGBtoRGBPixelAlphaARMNEON; #endif #if SDL_ARM_SIMD_BLITTERS if (SDL_HasARMSIMD()) return BlitRGBtoRGBPixelAlphaARMSIMD; #endif return BlitRGBtoRGBPixelAlpha; } } return BlitNtoNPixelAlpha; case 3: default: break; } return BlitNtoNPixelAlpha; case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: if (sf->Amask == 0) { /* Per-surface alpha blits */ switch (df->BytesPerPixel) { case 1: if (df->palette != NULL) { return BlitNto1SurfaceAlpha; } else { /* RGB332 has no palette ! */ return BlitNtoNSurfaceAlpha; } case 2: if (surface->map->identity) { if (df->Gmask == 0x7e0) { #ifdef __MMX__ if (SDL_HasMMX()) return Blit565to565SurfaceAlphaMMX; else #endif return Blit565to565SurfaceAlpha; } else if (df->Gmask == 0x3e0) { #ifdef __MMX__ if (SDL_HasMMX()) return Blit555to555SurfaceAlphaMMX; else #endif return Blit555to555SurfaceAlpha; } } return BlitNtoNSurfaceAlpha; case 4: if (sf->Rmask == df->Rmask && sf->Gmask == df->Gmask && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) { #ifdef __MMX__ if (sf->Rshift % 8 == 0 && sf->Gshift % 8 == 0 && sf->Bshift % 8 == 0 && SDL_HasMMX()) return BlitRGBtoRGBSurfaceAlphaMMX; #endif if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) { return BlitRGBtoRGBSurfaceAlpha; } } return BlitNtoNSurfaceAlpha; case 3: default: return BlitNtoNSurfaceAlpha; } } break; case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND: if (sf->Amask == 0) { if (df->BytesPerPixel == 1) { if (df->palette != NULL) { return BlitNto1SurfaceAlphaKey; } else { /* RGB332 has no palette ! */ return BlitNtoNSurfaceAlphaKey; } } else { return BlitNtoNSurfaceAlphaKey; } } break; } return NULL; } #endif /* SDL_HAVE_BLIT_A */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit_A.c
C
apache-2.0
51,115
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #if SDL_HAVE_BLIT_N #include "SDL_video.h" #include "SDL_endian.h" #include "SDL_cpuinfo.h" #include "SDL_blit.h" #include "SDL_assert.h" /* General optimized routines that write char by char */ #define HAVE_FAST_WRITE_INT8 1 /* On some CPU, it's slower than combining and write a word */ #if defined(__MIPS__) # undef HAVE_FAST_WRITE_INT8 # define HAVE_FAST_WRITE_INT8 0 #endif /* Functions to blit from N-bit surfaces to other surfaces */ enum blit_features { BLIT_FEATURE_NONE = 0, BLIT_FEATURE_HAS_MMX = 1, BLIT_FEATURE_HAS_ALTIVEC = 2, BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH = 4, BLIT_FEATURE_HAS_ARM_SIMD = 8 }; #if SDL_ALTIVEC_BLITTERS #ifdef HAVE_ALTIVEC_H #include <altivec.h> #endif #ifdef __MACOSX__ #include <sys/sysctl.h> static size_t GetL3CacheSize(void) { const char key[] = "hw.l3cachesize"; u_int64_t result = 0; size_t typeSize = sizeof(result); int err = sysctlbyname(key, &result, &typeSize, NULL, 0); if (0 != err) return 0; return result; } #else static size_t GetL3CacheSize(void) { /* XXX: Just guess G4 */ return 2097152; } #endif /* __MACOSX__ */ #if (defined(__MACOSX__) && (__GNUC__ < 4)) #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p ) #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ (vector unsigned short) ( a,b,c,d,e,f,g,h ) #else #define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p } #define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \ (vector unsigned short) { a,b,c,d,e,f,g,h } #endif #define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F) #define VSWIZZLE32(a,b,c,d) (vector unsigned char) \ ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \ 0x04+a, 0x04+b, 0x04+c, 0x04+d, \ 0x08+a, 0x08+b, 0x08+c, 0x08+d, \ 0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d ) #define MAKE8888(dstfmt, r, g, b, a) \ ( ((r<<dstfmt->Rshift)&dstfmt->Rmask) | \ ((g<<dstfmt->Gshift)&dstfmt->Gmask) | \ ((b<<dstfmt->Bshift)&dstfmt->Bmask) | \ ((a<<dstfmt->Ashift)&dstfmt->Amask) ) /* * Data Stream Touch...Altivec cache prefetching. * * Don't use this on a G5...however, the speed boost is very significant * on a G4. */ #define DST_CHAN_SRC 1 #define DST_CHAN_DEST 2 /* macro to set DST control word value... */ #define DST_CTRL(size, count, stride) \ (((size) << 24) | ((count) << 16) | (stride)) #define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \ ? vec_lvsl(0, src) \ : vec_add(vec_lvsl(8, src), vec_splat_u8(8))) /* Calculate the permute vector used for 32->32 swizzling */ static vector unsigned char calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt) { /* * We have to assume that the bits that aren't used by other * colors is alpha, and it's one complete byte, since some formats * leave alpha with a zero mask, but we should still swizzle the bits. */ /* ARGB */ const static const struct SDL_PixelFormat default_pixel_format = { 0, NULL, 0, 0, {0, 0}, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 0, 0, 0, 0, 16, 8, 0, 24, 0, NULL }; const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x0C, 0x0C); vector unsigned char vswiz; vector unsigned int srcvec; Uint32 rmask, gmask, bmask, amask; if (!srcfmt) { srcfmt = &default_pixel_format; } if (!dstfmt) { dstfmt = &default_pixel_format; } #define RESHIFT(X) (3 - ((X) >> 3)) rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift); gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift); bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift); /* Use zero for alpha if either surface doesn't have alpha */ if (dstfmt->Amask) { amask = ((srcfmt->Amask) ? RESHIFT(srcfmt-> Ashift) : 0x10) << (dstfmt->Ashift); } else { amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ 0xFFFFFFFF); } #undef RESHIFT ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask); vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0)); return (vswiz); } #if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN) /* reorder bytes for PowerPC little endian */ static vector unsigned char reorder_ppc64le_vec(vector unsigned char vpermute) { /* The result vector of calc_swizzle32 reorder bytes using vec_perm. The LE transformation for vec_perm has an implicit assumption that the permutation is being used to reorder vector elements, not to reorder bytes within those elements. Unfortunatly the result order is not the expected one for powerpc little endian when the two first vector parameters of vec_perm are not of type 'vector char'. This is because the numbering from the left for BE, and numbering from the right for LE, produces a different interpretation of what the odd and even lanes are. Refer to fedora bug 1392465 */ const vector unsigned char ppc64le_reorder = VECUINT8_LITERAL( 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, 0x09, 0x08, 0x0B, 0x0A, 0x0D, 0x0C, 0x0F, 0x0E ); vector unsigned char vswiz_ppc64le; vswiz_ppc64le = vec_perm(vpermute, vpermute, ppc64le_reorder); return(vswiz_ppc64le); } #endif static void Blit_RGB888_RGB565(SDL_BlitInfo * info); static void Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint8 *src = (Uint8 *) info->src; int srcskip = info->src_skip; Uint8 *dst = (Uint8 *) info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; vector unsigned char valpha = vec_splat_u8(0); vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL); vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06, 0x00, 0x0a, 0x00, 0x0e, 0x00, 0x12, 0x00, 0x16, 0x00, 0x1a, 0x00, 0x1e); vector unsigned short v1 = vec_splat_u16(1); vector unsigned short v3 = vec_splat_u16(3); vector unsigned short v3f = VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f, 0x003f); vector unsigned short vfc = VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc, 0x00fc, 0x00fc, 0x00fc, 0x00fc); vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7); vf800 = vec_sl(vf800, vec_splat_u16(8)); while (height--) { vector unsigned char valigner; vector unsigned char voverflow; vector unsigned char vsrc; int width = info->dst_w; int extrawidth; /* do scalar until we can align... */ #define ONE_PIXEL_BLEND(condition, widthvar) \ while (condition) { \ Uint32 Pixel; \ unsigned sR, sG, sB, sA; \ DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \ sR, sG, sB, sA); \ *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \ ((sG << 3) & 0x000007E0) | \ ((sB >> 3) & 0x0000001F)); \ dst += 2; \ src += 4; \ widthvar--; \ } ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); /* After all that work, here's the vector part! */ extrawidth = (width % 8); /* trailing unaligned stores */ width -= extrawidth; vsrc = vec_ld(0, src); valigner = VEC_ALIGNER(src); while (width) { vector unsigned short vpixel, vrpixel, vgpixel, vbpixel; vector unsigned int vsrc1, vsrc2; vector unsigned char vdst; voverflow = vec_ld(15, src); vsrc = vec_perm(vsrc, voverflow, valigner); vsrc1 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute); src += 16; vsrc = voverflow; voverflow = vec_ld(15, src); vsrc = vec_perm(vsrc, voverflow, valigner); vsrc2 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute); /* 1555 */ vpixel = (vector unsigned short) vec_packpx(vsrc1, vsrc2); vgpixel = (vector unsigned short) vec_perm(vsrc1, vsrc2, vgmerge); vgpixel = vec_and(vgpixel, vfc); vgpixel = vec_sl(vgpixel, v3); vrpixel = vec_sl(vpixel, v1); vrpixel = vec_and(vrpixel, vf800); vbpixel = vec_and(vpixel, v3f); vdst = vec_or((vector unsigned char) vrpixel, (vector unsigned char) vgpixel); /* 565 */ vdst = vec_or(vdst, (vector unsigned char) vbpixel); vec_st(vdst, 0, dst); width -= 8; src += 16; dst += 16; vsrc = voverflow; } SDL_assert(width == 0); /* do scalar until we can align... */ ONE_PIXEL_BLEND((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND src += srcskip; /* move to next row, accounting for pitch. */ dst += dstskip; } } static void Blit_RGB565_32Altivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint8 *src = (Uint8 *) info->src; int srcskip = info->src_skip; Uint8 *dst = (Uint8 *) info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; unsigned alpha; vector unsigned char valpha; vector unsigned char vpermute; vector unsigned short vf800; vector unsigned int v8 = vec_splat_u32(8); vector unsigned int v16 = vec_add(v8, v8); vector unsigned short v2 = vec_splat_u16(2); vector unsigned short v3 = vec_splat_u16(3); /* 0x10 - 0x1f is the alpha 0x00 - 0x0e evens are the red 0x01 - 0x0f odds are zero */ vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01, 0x10, 0x02, 0x01, 0x01, 0x10, 0x04, 0x01, 0x01, 0x10, 0x06, 0x01, 0x01); vector unsigned char vredalpha2 = (vector unsigned char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16)) ); /* 0x00 - 0x0f is ARxx ARxx ARxx ARxx 0x11 - 0x0f odds are blue */ vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11, 0x04, 0x05, 0x06, 0x13, 0x08, 0x09, 0x0a, 0x15, 0x0c, 0x0d, 0x0e, 0x17); vector unsigned char vblue2 = (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8) ); /* 0x00 - 0x0f is ARxB ARxB ARxB ARxB 0x10 - 0x0e evens are green */ vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03, 0x04, 0x05, 0x12, 0x07, 0x08, 0x09, 0x14, 0x0b, 0x0c, 0x0d, 0x16, 0x0f); vector unsigned char vgreen2 = (vector unsigned char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8)) ); SDL_assert(srcfmt->BytesPerPixel == 2); SDL_assert(dstfmt->BytesPerPixel == 4); vf800 = (vector unsigned short) vec_splat_u8(-7); vf800 = vec_sl(vf800, vec_splat_u16(8)); if (dstfmt->Amask && info->a) { ((unsigned char *) &valpha)[0] = alpha = info->a; valpha = vec_splat(valpha, 0); } else { alpha = 0; valpha = vec_splat_u8(0); } vpermute = calc_swizzle32(NULL, dstfmt); while (height--) { vector unsigned char valigner; vector unsigned char voverflow; vector unsigned char vsrc; int width = info->dst_w; int extrawidth; /* do scalar until we can align... */ #define ONE_PIXEL_BLEND(condition, widthvar) \ while (condition) { \ unsigned sR, sG, sB; \ unsigned short Pixel = *((unsigned short *)src); \ sR = (Pixel >> 8) & 0xf8; \ sG = (Pixel >> 3) & 0xfc; \ sB = (Pixel << 3) & 0xf8; \ ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \ src += 2; \ dst += 4; \ widthvar--; \ } ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); /* After all that work, here's the vector part! */ extrawidth = (width % 8); /* trailing unaligned stores */ width -= extrawidth; vsrc = vec_ld(0, src); valigner = VEC_ALIGNER(src); while (width) { vector unsigned short vR, vG, vB; vector unsigned char vdst1, vdst2; voverflow = vec_ld(15, src); vsrc = vec_perm(vsrc, voverflow, valigner); vR = vec_and((vector unsigned short) vsrc, vf800); vB = vec_sl((vector unsigned short) vsrc, v3); vG = vec_sl(vB, v2); vdst1 = (vector unsigned char) vec_perm((vector unsigned char) vR, valpha, vredalpha1); vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1); vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1); vdst1 = vec_perm(vdst1, valpha, vpermute); vec_st(vdst1, 0, dst); vdst2 = (vector unsigned char) vec_perm((vector unsigned char) vR, valpha, vredalpha2); vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2); vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2); vdst2 = vec_perm(vdst2, valpha, vpermute); vec_st(vdst2, 16, dst); width -= 8; dst += 32; src += 16; vsrc = voverflow; } SDL_assert(width == 0); /* do scalar until we can align... */ ONE_PIXEL_BLEND((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND src += srcskip; /* move to next row, accounting for pitch. */ dst += dstskip; } } static void Blit_RGB555_32Altivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint8 *src = (Uint8 *) info->src; int srcskip = info->src_skip; Uint8 *dst = (Uint8 *) info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; unsigned alpha; vector unsigned char valpha; vector unsigned char vpermute; vector unsigned short vf800; vector unsigned int v8 = vec_splat_u32(8); vector unsigned int v16 = vec_add(v8, v8); vector unsigned short v1 = vec_splat_u16(1); vector unsigned short v3 = vec_splat_u16(3); /* 0x10 - 0x1f is the alpha 0x00 - 0x0e evens are the red 0x01 - 0x0f odds are zero */ vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01, 0x10, 0x02, 0x01, 0x01, 0x10, 0x04, 0x01, 0x01, 0x10, 0x06, 0x01, 0x01); vector unsigned char vredalpha2 = (vector unsigned char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16)) ); /* 0x00 - 0x0f is ARxx ARxx ARxx ARxx 0x11 - 0x0f odds are blue */ vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11, 0x04, 0x05, 0x06, 0x13, 0x08, 0x09, 0x0a, 0x15, 0x0c, 0x0d, 0x0e, 0x17); vector unsigned char vblue2 = (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8) ); /* 0x00 - 0x0f is ARxB ARxB ARxB ARxB 0x10 - 0x0e evens are green */ vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03, 0x04, 0x05, 0x12, 0x07, 0x08, 0x09, 0x14, 0x0b, 0x0c, 0x0d, 0x16, 0x0f); vector unsigned char vgreen2 = (vector unsigned char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8)) ); SDL_assert(srcfmt->BytesPerPixel == 2); SDL_assert(dstfmt->BytesPerPixel == 4); vf800 = (vector unsigned short) vec_splat_u8(-7); vf800 = vec_sl(vf800, vec_splat_u16(8)); if (dstfmt->Amask && info->a) { ((unsigned char *) &valpha)[0] = alpha = info->a; valpha = vec_splat(valpha, 0); } else { alpha = 0; valpha = vec_splat_u8(0); } vpermute = calc_swizzle32(NULL, dstfmt); while (height--) { vector unsigned char valigner; vector unsigned char voverflow; vector unsigned char vsrc; int width = info->dst_w; int extrawidth; /* do scalar until we can align... */ #define ONE_PIXEL_BLEND(condition, widthvar) \ while (condition) { \ unsigned sR, sG, sB; \ unsigned short Pixel = *((unsigned short *)src); \ sR = (Pixel >> 7) & 0xf8; \ sG = (Pixel >> 2) & 0xf8; \ sB = (Pixel << 3) & 0xf8; \ ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \ src += 2; \ dst += 4; \ widthvar--; \ } ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width); /* After all that work, here's the vector part! */ extrawidth = (width % 8); /* trailing unaligned stores */ width -= extrawidth; vsrc = vec_ld(0, src); valigner = VEC_ALIGNER(src); while (width) { vector unsigned short vR, vG, vB; vector unsigned char vdst1, vdst2; voverflow = vec_ld(15, src); vsrc = vec_perm(vsrc, voverflow, valigner); vR = vec_and(vec_sl((vector unsigned short) vsrc, v1), vf800); vB = vec_sl((vector unsigned short) vsrc, v3); vG = vec_sl(vB, v3); vdst1 = (vector unsigned char) vec_perm((vector unsigned char) vR, valpha, vredalpha1); vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1); vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1); vdst1 = vec_perm(vdst1, valpha, vpermute); vec_st(vdst1, 0, dst); vdst2 = (vector unsigned char) vec_perm((vector unsigned char) vR, valpha, vredalpha2); vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2); vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2); vdst2 = vec_perm(vdst2, valpha, vpermute); vec_st(vdst2, 16, dst); width -= 8; dst += 32; src += 16; vsrc = voverflow; } SDL_assert(width == 0); /* do scalar until we can align... */ ONE_PIXEL_BLEND((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND src += srcskip; /* move to next row, accounting for pitch. */ dst += dstskip; } } static void BlitNtoNKey(SDL_BlitInfo * info); static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info); static void Blit32to32KeyAltivec(SDL_BlitInfo * info) { int height = info->dst_h; Uint32 *srcp = (Uint32 *) info->src; int srcskip = info->src_skip / 4; Uint32 *dstp = (Uint32 *) info->dst; int dstskip = info->dst_skip / 4; SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; int copy_alpha = (srcfmt->Amask && dstfmt->Amask); unsigned alpha = dstfmt->Amask ? info->a : 0; Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; Uint32 ckey = info->colorkey; vector unsigned int valpha; vector unsigned char vpermute; vector unsigned char vzero; vector unsigned int vckey; vector unsigned int vrgbmask; vpermute = calc_swizzle32(srcfmt, dstfmt); if (info->dst_w < 16) { if (copy_alpha) { BlitNtoNKeyCopyAlpha(info); } else { BlitNtoNKey(info); } return; } vzero = vec_splat_u8(0); if (alpha) { ((unsigned char *) &valpha)[0] = (unsigned char) alpha; valpha = (vector unsigned int) vec_splat((vector unsigned char) valpha, 0); } else { valpha = (vector unsigned int) vzero; } ckey &= rgbmask; ((unsigned int *) (char *) &vckey)[0] = ckey; vckey = vec_splat(vckey, 0); ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask; vrgbmask = vec_splat(vrgbmask, 0); while (height--) { #define ONE_PIXEL_BLEND(condition, widthvar) \ if (copy_alpha) { \ while (condition) { \ Uint32 Pixel; \ unsigned sR, sG, sB, sA; \ DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \ sR, sG, sB, sA); \ if ( (Pixel & rgbmask) != ckey ) { \ ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \ sR, sG, sB, sA); \ } \ dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \ srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \ widthvar--; \ } \ } else { \ while (condition) { \ Uint32 Pixel; \ unsigned sR, sG, sB; \ RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \ if ( Pixel != ckey ) { \ RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \ ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \ sR, sG, sB, alpha); \ } \ dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \ srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \ widthvar--; \ } \ } int width = info->dst_w; ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width); SDL_assert(width > 0); if (width > 0) { int extrawidth = (width % 4); vector unsigned char valigner = VEC_ALIGNER(srcp); vector unsigned int vs = vec_ld(0, srcp); width -= extrawidth; SDL_assert(width >= 4); while (width) { vector unsigned char vsel; vector unsigned int vd; vector unsigned int voverflow = vec_ld(15, srcp); /* load the source vec */ vs = vec_perm(vs, voverflow, valigner); /* vsel is set for items that match the key */ vsel = (vector unsigned char) vec_and(vs, vrgbmask); vsel = (vector unsigned char) vec_cmpeq(vs, vckey); #if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN) /* reorder bytes for PowerPC little endian */ vpermute = reorder_ppc64le_vec(vpermute); #endif /* permute the src vec to the dest format */ vs = vec_perm(vs, valpha, vpermute); /* load the destination vec */ vd = vec_ld(0, dstp); /* select the source and dest into vs */ vd = (vector unsigned int) vec_sel((vector unsigned char) vs, (vector unsigned char) vd, vsel); vec_st(vd, 0, dstp); srcp += 4; width -= 4; dstp += 4; vs = voverflow; } ONE_PIXEL_BLEND((extrawidth), extrawidth); #undef ONE_PIXEL_BLEND srcp += srcskip; dstp += dstskip; } } } /* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */ /* Use this on a G5 */ static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info) { int height = info->dst_h; Uint32 *src = (Uint32 *) info->src; int srcskip = info->src_skip / 4; Uint32 *dst = (Uint32 *) info->dst; int dstskip = info->dst_skip / 4; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; vector unsigned int vzero = vec_splat_u32(0); vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); if (dstfmt->Amask && !srcfmt->Amask) { if (info->a) { vector unsigned char valpha; ((unsigned char *) &valpha)[0] = info->a; vzero = (vector unsigned int) vec_splat(valpha, 0); } } SDL_assert(srcfmt->BytesPerPixel == 4); SDL_assert(dstfmt->BytesPerPixel == 4); while (height--) { vector unsigned char valigner; vector unsigned int vbits; vector unsigned int voverflow; Uint32 bits; Uint8 r, g, b, a; int width = info->dst_w; int extrawidth; /* do scalar until we can align... */ while ((UNALIGNED_PTR(dst)) && (width)) { bits = *(src++); RGBA_FROM_8888(bits, srcfmt, r, g, b, a); if(!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); width--; } /* After all that work, here's the vector part! */ extrawidth = (width % 4); width -= extrawidth; valigner = VEC_ALIGNER(src); vbits = vec_ld(0, src); while (width) { voverflow = vec_ld(15, src); src += 4; width -= 4; vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */ #if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN) /* reorder bytes for PowerPC little endian */ vpermute = reorder_ppc64le_vec(vpermute); #endif vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */ vec_st(vbits, 0, dst); /* store it back out. */ dst += 4; vbits = voverflow; } SDL_assert(width == 0); /* cover pixels at the end of the row that didn't fit in 16 bytes. */ while (extrawidth) { bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ RGBA_FROM_8888(bits, srcfmt, r, g, b, a); if(!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); extrawidth--; } src += srcskip; dst += dstskip; } } /* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */ /* Use this on a G4 */ static void ConvertAltivec32to32_prefetch(SDL_BlitInfo * info) { const int scalar_dst_lead = sizeof(Uint32) * 4; const int vector_dst_lead = sizeof(Uint32) * 16; int height = info->dst_h; Uint32 *src = (Uint32 *) info->src; int srcskip = info->src_skip / 4; Uint32 *dst = (Uint32 *) info->dst; int dstskip = info->dst_skip / 4; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; vector unsigned int vzero = vec_splat_u32(0); vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); if (dstfmt->Amask && !srcfmt->Amask) { if (info->a) { vector unsigned char valpha; ((unsigned char *) &valpha)[0] = info->a; vzero = (vector unsigned int) vec_splat(valpha, 0); } } SDL_assert(srcfmt->BytesPerPixel == 4); SDL_assert(dstfmt->BytesPerPixel == 4); while (height--) { vector unsigned char valigner; vector unsigned int vbits; vector unsigned int voverflow; Uint32 bits; Uint8 r, g, b, a; int width = info->dst_w; int extrawidth; /* do scalar until we can align... */ while ((UNALIGNED_PTR(dst)) && (width)) { vec_dstt(src + scalar_dst_lead, DST_CTRL(2, 32, 1024), DST_CHAN_SRC); vec_dstst(dst + scalar_dst_lead, DST_CTRL(2, 32, 1024), DST_CHAN_DEST); bits = *(src++); RGBA_FROM_8888(bits, srcfmt, r, g, b, a); if(!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); width--; } /* After all that work, here's the vector part! */ extrawidth = (width % 4); width -= extrawidth; valigner = VEC_ALIGNER(src); vbits = vec_ld(0, src); while (width) { vec_dstt(src + vector_dst_lead, DST_CTRL(2, 32, 1024), DST_CHAN_SRC); vec_dstst(dst + vector_dst_lead, DST_CTRL(2, 32, 1024), DST_CHAN_DEST); voverflow = vec_ld(15, src); src += 4; width -= 4; vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */ #if defined(__powerpc__) && (SDL_BYTEORDER == SDL_LIL_ENDIAN) /* reorder bytes for PowerPC little endian */ vpermute = reorder_ppc64le_vec(vpermute); #endif vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */ vec_st(vbits, 0, dst); /* store it back out. */ dst += 4; vbits = voverflow; } SDL_assert(width == 0); /* cover pixels at the end of the row that didn't fit in 16 bytes. */ while (extrawidth) { bits = *(src++); /* max 7 pixels, don't bother with prefetch. */ RGBA_FROM_8888(bits, srcfmt, r, g, b, a); if(!srcfmt->Amask) a = info->a; *(dst++) = MAKE8888(dstfmt, r, g, b, a); extrawidth--; } src += srcskip; dst += dstskip; } vec_dss(DST_CHAN_SRC); vec_dss(DST_CHAN_DEST); } static enum blit_features GetBlitFeatures(void) { static enum blit_features features = -1; if (features == (enum blit_features) -1) { /* Provide an override for testing .. */ char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES"); if (override) { unsigned int features_as_uint = 0; SDL_sscanf(override, "%u", &features_as_uint); features = (enum blit_features) features_as_uint; } else { features = (0 /* Feature 1 is has-MMX */ | ((SDL_HasMMX())? BLIT_FEATURE_HAS_MMX : 0) /* Feature 2 is has-AltiVec */ | ((SDL_HasAltiVec())? BLIT_FEATURE_HAS_ALTIVEC : 0) /* Feature 4 is dont-use-prefetch */ /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */ | ((GetL3CacheSize() == 0) ? BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH : 0) ); } } return features; } #if __MWERKS__ #pragma altivec_model off #endif #else /* Feature 1 is has-MMX */ #define GetBlitFeatures() ((SDL_HasMMX() ? BLIT_FEATURE_HAS_MMX : 0) | (SDL_HasARMSIMD() ? BLIT_FEATURE_HAS_ARM_SIMD : 0)) #endif #if SDL_ARM_SIMD_BLITTERS void Blit_BGR888_RGB888ARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride); static void Blit_BGR888_RGB888ARMSIMD(SDL_BlitInfo * info) { int32_t width = info->dst_w; int32_t height = info->dst_h; uint32_t *dstp = (uint32_t *)info->dst; int32_t dststride = width + (info->dst_skip >> 2); uint32_t *srcp = (uint32_t *)info->src; int32_t srcstride = width + (info->src_skip >> 2); Blit_BGR888_RGB888ARMSIMDAsm(width, height, dstp, dststride, srcp, srcstride); } void Blit_RGB444_RGB888ARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint16_t *src, int32_t src_stride); static void Blit_RGB444_RGB888ARMSIMD(SDL_BlitInfo * info) { int32_t width = info->dst_w; int32_t height = info->dst_h; uint32_t *dstp = (uint32_t *)info->dst; int32_t dststride = width + (info->dst_skip >> 2); uint16_t *srcp = (uint16_t *)info->src; int32_t srcstride = width + (info->src_skip >> 1); Blit_RGB444_RGB888ARMSIMDAsm(width, height, dstp, dststride, srcp, srcstride); } #endif /* This is now endian dependent */ #if SDL_BYTEORDER == SDL_LIL_ENDIAN #define HI 1 #define LO 0 #else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */ #define HI 0 #define LO 1 #endif /* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */ #define RGB888_RGB332(dst, src) { \ dst = (Uint8)((((src)&0x00E00000)>>16)| \ (((src)&0x0000E000)>>11)| \ (((src)&0x000000C0)>>6)); \ } static void Blit_RGB888_index8(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint32 *src; const Uint8 *map; Uint8 *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; srcskip = info->src_skip / 4; dst = info->dst; dstskip = info->dst_skip; map = info->table; if (map == NULL) { while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB332(*dst++, *src); , width); /* *INDENT-ON* */ #else for (c = width / 4; c; --c) { /* Pack RGB into 8bit pixel */ ++src; RGB888_RGB332(*dst++, *src); ++src; RGB888_RGB332(*dst++, *src); ++src; RGB888_RGB332(*dst++, *src); ++src; } switch (width & 3) { case 3: RGB888_RGB332(*dst++, *src); ++src; case 2: RGB888_RGB332(*dst++, *src); ++src; case 1: RGB888_RGB332(*dst++, *src); ++src; } #endif /* USE_DUFFS_LOOP */ src += srcskip; dst += dstskip; } } else { int Pixel; while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; , width); /* *INDENT-ON* */ #else for (c = width / 4; c; --c) { /* Pack RGB into 8bit pixel */ RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; } switch (width & 3) { case 3: RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; case 2: RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; case 1: RGB888_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; } #endif /* USE_DUFFS_LOOP */ src += srcskip; dst += dstskip; } } } /* Special optimized blit for RGB 10-10-10 --> RGB 3-3-2 */ #define RGB101010_RGB332(dst, src) { \ dst = (Uint8)((((src)&0x38000000)>>22)| \ (((src)&0x000E0000)>>15)| \ (((src)&0x00000300)>>8)); \ } static void Blit_RGB101010_index8(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint32 *src; const Uint8 *map; Uint8 *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; srcskip = info->src_skip / 4; dst = info->dst; dstskip = info->dst_skip; map = info->table; if (map == NULL) { while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( RGB101010_RGB332(*dst++, *src); , width); /* *INDENT-ON* */ #else for (c = width / 4; c; --c) { /* Pack RGB into 8bit pixel */ ++src; RGB101010_RGB332(*dst++, *src); ++src; RGB101010_RGB332(*dst++, *src); ++src; RGB101010_RGB332(*dst++, *src); ++src; } switch (width & 3) { case 3: RGB101010_RGB332(*dst++, *src); ++src; case 2: RGB101010_RGB332(*dst++, *src); ++src; case 1: RGB101010_RGB332(*dst++, *src); ++src; } #endif /* USE_DUFFS_LOOP */ src += srcskip; dst += dstskip; } } else { int Pixel; while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; , width); /* *INDENT-ON* */ #else for (c = width / 4; c; --c) { /* Pack RGB into 8bit pixel */ RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; } switch (width & 3) { case 3: RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; case 2: RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; case 1: RGB101010_RGB332(Pixel, *src); *dst++ = map[Pixel]; ++src; } #endif /* USE_DUFFS_LOOP */ src += srcskip; dst += dstskip; } } } /* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */ #define RGB888_RGB555(dst, src) { \ *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>9)| \ (((*src)&0x0000F800)>>6)| \ (((*src)&0x000000F8)>>3)); \ } #ifndef USE_DUFFS_LOOP #define RGB888_RGB555_TWO(dst, src) { \ *(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>9)| \ (((src[HI])&0x0000F800)>>6)| \ (((src[HI])&0x000000F8)>>3))<<16)| \ (((src[LO])&0x00F80000)>>9)| \ (((src[LO])&0x0000F800)>>6)| \ (((src[LO])&0x000000F8)>>3); \ } #endif static void Blit_RGB888_RGB555(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint32 *src; Uint16 *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; srcskip = info->src_skip / 4; dst = (Uint16 *) info->dst; dstskip = info->dst_skip / 2; #ifdef USE_DUFFS_LOOP while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB555(dst, src); ++src; ++dst; , width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } #else /* Memory align at 4-byte boundary, if necessary */ if ((long) dst & 0x03) { /* Don't do anything if width is 0 */ if (width == 0) { return; } --width; while (height--) { /* Perform copy alignment */ RGB888_RGB555(dst, src); ++src; ++dst; /* Copy in 4 pixel chunks */ for (c = width / 4; c; --c) { RGB888_RGB555_TWO(dst, src); src += 2; dst += 2; RGB888_RGB555_TWO(dst, src); src += 2; dst += 2; } /* Get any leftovers */ switch (width & 3) { case 3: RGB888_RGB555(dst, src); ++src; ++dst; case 2: RGB888_RGB555_TWO(dst, src); src += 2; dst += 2; break; case 1: RGB888_RGB555(dst, src); ++src; ++dst; break; } src += srcskip; dst += dstskip; } } else { while (height--) { /* Copy in 4 pixel chunks */ for (c = width / 4; c; --c) { RGB888_RGB555_TWO(dst, src); src += 2; dst += 2; RGB888_RGB555_TWO(dst, src); src += 2; dst += 2; } /* Get any leftovers */ switch (width & 3) { case 3: RGB888_RGB555(dst, src); ++src; ++dst; case 2: RGB888_RGB555_TWO(dst, src); src += 2; dst += 2; break; case 1: RGB888_RGB555(dst, src); ++src; ++dst; break; } src += srcskip; dst += dstskip; } } #endif /* USE_DUFFS_LOOP */ } /* Special optimized blit for RGB 8-8-8 --> RGB 5-6-5 */ #define RGB888_RGB565(dst, src) { \ *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>8)| \ (((*src)&0x0000FC00)>>5)| \ (((*src)&0x000000F8)>>3)); \ } #ifndef USE_DUFFS_LOOP #define RGB888_RGB565_TWO(dst, src) { \ *(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>8)| \ (((src[HI])&0x0000FC00)>>5)| \ (((src[HI])&0x000000F8)>>3))<<16)| \ (((src[LO])&0x00F80000)>>8)| \ (((src[LO])&0x0000FC00)>>5)| \ (((src[LO])&0x000000F8)>>3); \ } #endif static void Blit_RGB888_RGB565(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint32 *src; Uint16 *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = (Uint32 *) info->src; srcskip = info->src_skip / 4; dst = (Uint16 *) info->dst; dstskip = info->dst_skip / 2; #ifdef USE_DUFFS_LOOP while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( RGB888_RGB565(dst, src); ++src; ++dst; , width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } #else /* Memory align at 4-byte boundary, if necessary */ if ((long) dst & 0x03) { /* Don't do anything if width is 0 */ if (width == 0) { return; } --width; while (height--) { /* Perform copy alignment */ RGB888_RGB565(dst, src); ++src; ++dst; /* Copy in 4 pixel chunks */ for (c = width / 4; c; --c) { RGB888_RGB565_TWO(dst, src); src += 2; dst += 2; RGB888_RGB565_TWO(dst, src); src += 2; dst += 2; } /* Get any leftovers */ switch (width & 3) { case 3: RGB888_RGB565(dst, src); ++src; ++dst; case 2: RGB888_RGB565_TWO(dst, src); src += 2; dst += 2; break; case 1: RGB888_RGB565(dst, src); ++src; ++dst; break; } src += srcskip; dst += dstskip; } } else { while (height--) { /* Copy in 4 pixel chunks */ for (c = width / 4; c; --c) { RGB888_RGB565_TWO(dst, src); src += 2; dst += 2; RGB888_RGB565_TWO(dst, src); src += 2; dst += 2; } /* Get any leftovers */ switch (width & 3) { case 3: RGB888_RGB565(dst, src); ++src; ++dst; case 2: RGB888_RGB565_TWO(dst, src); src += 2; dst += 2; break; case 1: RGB888_RGB565(dst, src); ++src; ++dst; break; } src += srcskip; dst += dstskip; } } #endif /* USE_DUFFS_LOOP */ } #if SDL_HAVE_BLIT_N_RGB565 /* Special optimized blit for RGB 5-6-5 --> 32-bit RGB surfaces */ #define RGB565_32(dst, src, map) (map[src[LO]*2] + map[src[HI]*2+1]) static void Blit_RGB565_32(SDL_BlitInfo * info, const Uint32 * map) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint8 *src; Uint32 *dst; int srcskip, dstskip; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = (Uint32 *) info->dst; dstskip = info->dst_skip / 4; #ifdef USE_DUFFS_LOOP while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { *dst++ = RGB565_32(dst, src, map); src += 2; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } #else while (height--) { /* Copy in 4 pixel chunks */ for (c = width / 4; c; --c) { *dst++ = RGB565_32(dst, src, map); src += 2; *dst++ = RGB565_32(dst, src, map); src += 2; *dst++ = RGB565_32(dst, src, map); src += 2; *dst++ = RGB565_32(dst, src, map); src += 2; } /* Get any leftovers */ switch (width & 3) { case 3: *dst++ = RGB565_32(dst, src, map); src += 2; case 2: *dst++ = RGB565_32(dst, src, map); src += 2; case 1: *dst++ = RGB565_32(dst, src, map); src += 2; break; } src += srcskip; dst += dstskip; } #endif /* USE_DUFFS_LOOP */ } /* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */ static const Uint32 RGB565_ARGB8888_LUT[512] = { 0x00000000, 0xff000000, 0x00000008, 0xff002000, 0x00000010, 0xff004000, 0x00000018, 0xff006100, 0x00000020, 0xff008100, 0x00000029, 0xff00a100, 0x00000031, 0xff00c200, 0x00000039, 0xff00e200, 0x00000041, 0xff080000, 0x0000004a, 0xff082000, 0x00000052, 0xff084000, 0x0000005a, 0xff086100, 0x00000062, 0xff088100, 0x0000006a, 0xff08a100, 0x00000073, 0xff08c200, 0x0000007b, 0xff08e200, 0x00000083, 0xff100000, 0x0000008b, 0xff102000, 0x00000094, 0xff104000, 0x0000009c, 0xff106100, 0x000000a4, 0xff108100, 0x000000ac, 0xff10a100, 0x000000b4, 0xff10c200, 0x000000bd, 0xff10e200, 0x000000c5, 0xff180000, 0x000000cd, 0xff182000, 0x000000d5, 0xff184000, 0x000000de, 0xff186100, 0x000000e6, 0xff188100, 0x000000ee, 0xff18a100, 0x000000f6, 0xff18c200, 0x000000ff, 0xff18e200, 0x00000400, 0xff200000, 0x00000408, 0xff202000, 0x00000410, 0xff204000, 0x00000418, 0xff206100, 0x00000420, 0xff208100, 0x00000429, 0xff20a100, 0x00000431, 0xff20c200, 0x00000439, 0xff20e200, 0x00000441, 0xff290000, 0x0000044a, 0xff292000, 0x00000452, 0xff294000, 0x0000045a, 0xff296100, 0x00000462, 0xff298100, 0x0000046a, 0xff29a100, 0x00000473, 0xff29c200, 0x0000047b, 0xff29e200, 0x00000483, 0xff310000, 0x0000048b, 0xff312000, 0x00000494, 0xff314000, 0x0000049c, 0xff316100, 0x000004a4, 0xff318100, 0x000004ac, 0xff31a100, 0x000004b4, 0xff31c200, 0x000004bd, 0xff31e200, 0x000004c5, 0xff390000, 0x000004cd, 0xff392000, 0x000004d5, 0xff394000, 0x000004de, 0xff396100, 0x000004e6, 0xff398100, 0x000004ee, 0xff39a100, 0x000004f6, 0xff39c200, 0x000004ff, 0xff39e200, 0x00000800, 0xff410000, 0x00000808, 0xff412000, 0x00000810, 0xff414000, 0x00000818, 0xff416100, 0x00000820, 0xff418100, 0x00000829, 0xff41a100, 0x00000831, 0xff41c200, 0x00000839, 0xff41e200, 0x00000841, 0xff4a0000, 0x0000084a, 0xff4a2000, 0x00000852, 0xff4a4000, 0x0000085a, 0xff4a6100, 0x00000862, 0xff4a8100, 0x0000086a, 0xff4aa100, 0x00000873, 0xff4ac200, 0x0000087b, 0xff4ae200, 0x00000883, 0xff520000, 0x0000088b, 0xff522000, 0x00000894, 0xff524000, 0x0000089c, 0xff526100, 0x000008a4, 0xff528100, 0x000008ac, 0xff52a100, 0x000008b4, 0xff52c200, 0x000008bd, 0xff52e200, 0x000008c5, 0xff5a0000, 0x000008cd, 0xff5a2000, 0x000008d5, 0xff5a4000, 0x000008de, 0xff5a6100, 0x000008e6, 0xff5a8100, 0x000008ee, 0xff5aa100, 0x000008f6, 0xff5ac200, 0x000008ff, 0xff5ae200, 0x00000c00, 0xff620000, 0x00000c08, 0xff622000, 0x00000c10, 0xff624000, 0x00000c18, 0xff626100, 0x00000c20, 0xff628100, 0x00000c29, 0xff62a100, 0x00000c31, 0xff62c200, 0x00000c39, 0xff62e200, 0x00000c41, 0xff6a0000, 0x00000c4a, 0xff6a2000, 0x00000c52, 0xff6a4000, 0x00000c5a, 0xff6a6100, 0x00000c62, 0xff6a8100, 0x00000c6a, 0xff6aa100, 0x00000c73, 0xff6ac200, 0x00000c7b, 0xff6ae200, 0x00000c83, 0xff730000, 0x00000c8b, 0xff732000, 0x00000c94, 0xff734000, 0x00000c9c, 0xff736100, 0x00000ca4, 0xff738100, 0x00000cac, 0xff73a100, 0x00000cb4, 0xff73c200, 0x00000cbd, 0xff73e200, 0x00000cc5, 0xff7b0000, 0x00000ccd, 0xff7b2000, 0x00000cd5, 0xff7b4000, 0x00000cde, 0xff7b6100, 0x00000ce6, 0xff7b8100, 0x00000cee, 0xff7ba100, 0x00000cf6, 0xff7bc200, 0x00000cff, 0xff7be200, 0x00001000, 0xff830000, 0x00001008, 0xff832000, 0x00001010, 0xff834000, 0x00001018, 0xff836100, 0x00001020, 0xff838100, 0x00001029, 0xff83a100, 0x00001031, 0xff83c200, 0x00001039, 0xff83e200, 0x00001041, 0xff8b0000, 0x0000104a, 0xff8b2000, 0x00001052, 0xff8b4000, 0x0000105a, 0xff8b6100, 0x00001062, 0xff8b8100, 0x0000106a, 0xff8ba100, 0x00001073, 0xff8bc200, 0x0000107b, 0xff8be200, 0x00001083, 0xff940000, 0x0000108b, 0xff942000, 0x00001094, 0xff944000, 0x0000109c, 0xff946100, 0x000010a4, 0xff948100, 0x000010ac, 0xff94a100, 0x000010b4, 0xff94c200, 0x000010bd, 0xff94e200, 0x000010c5, 0xff9c0000, 0x000010cd, 0xff9c2000, 0x000010d5, 0xff9c4000, 0x000010de, 0xff9c6100, 0x000010e6, 0xff9c8100, 0x000010ee, 0xff9ca100, 0x000010f6, 0xff9cc200, 0x000010ff, 0xff9ce200, 0x00001400, 0xffa40000, 0x00001408, 0xffa42000, 0x00001410, 0xffa44000, 0x00001418, 0xffa46100, 0x00001420, 0xffa48100, 0x00001429, 0xffa4a100, 0x00001431, 0xffa4c200, 0x00001439, 0xffa4e200, 0x00001441, 0xffac0000, 0x0000144a, 0xffac2000, 0x00001452, 0xffac4000, 0x0000145a, 0xffac6100, 0x00001462, 0xffac8100, 0x0000146a, 0xffaca100, 0x00001473, 0xffacc200, 0x0000147b, 0xfface200, 0x00001483, 0xffb40000, 0x0000148b, 0xffb42000, 0x00001494, 0xffb44000, 0x0000149c, 0xffb46100, 0x000014a4, 0xffb48100, 0x000014ac, 0xffb4a100, 0x000014b4, 0xffb4c200, 0x000014bd, 0xffb4e200, 0x000014c5, 0xffbd0000, 0x000014cd, 0xffbd2000, 0x000014d5, 0xffbd4000, 0x000014de, 0xffbd6100, 0x000014e6, 0xffbd8100, 0x000014ee, 0xffbda100, 0x000014f6, 0xffbdc200, 0x000014ff, 0xffbde200, 0x00001800, 0xffc50000, 0x00001808, 0xffc52000, 0x00001810, 0xffc54000, 0x00001818, 0xffc56100, 0x00001820, 0xffc58100, 0x00001829, 0xffc5a100, 0x00001831, 0xffc5c200, 0x00001839, 0xffc5e200, 0x00001841, 0xffcd0000, 0x0000184a, 0xffcd2000, 0x00001852, 0xffcd4000, 0x0000185a, 0xffcd6100, 0x00001862, 0xffcd8100, 0x0000186a, 0xffcda100, 0x00001873, 0xffcdc200, 0x0000187b, 0xffcde200, 0x00001883, 0xffd50000, 0x0000188b, 0xffd52000, 0x00001894, 0xffd54000, 0x0000189c, 0xffd56100, 0x000018a4, 0xffd58100, 0x000018ac, 0xffd5a100, 0x000018b4, 0xffd5c200, 0x000018bd, 0xffd5e200, 0x000018c5, 0xffde0000, 0x000018cd, 0xffde2000, 0x000018d5, 0xffde4000, 0x000018de, 0xffde6100, 0x000018e6, 0xffde8100, 0x000018ee, 0xffdea100, 0x000018f6, 0xffdec200, 0x000018ff, 0xffdee200, 0x00001c00, 0xffe60000, 0x00001c08, 0xffe62000, 0x00001c10, 0xffe64000, 0x00001c18, 0xffe66100, 0x00001c20, 0xffe68100, 0x00001c29, 0xffe6a100, 0x00001c31, 0xffe6c200, 0x00001c39, 0xffe6e200, 0x00001c41, 0xffee0000, 0x00001c4a, 0xffee2000, 0x00001c52, 0xffee4000, 0x00001c5a, 0xffee6100, 0x00001c62, 0xffee8100, 0x00001c6a, 0xffeea100, 0x00001c73, 0xffeec200, 0x00001c7b, 0xffeee200, 0x00001c83, 0xfff60000, 0x00001c8b, 0xfff62000, 0x00001c94, 0xfff64000, 0x00001c9c, 0xfff66100, 0x00001ca4, 0xfff68100, 0x00001cac, 0xfff6a100, 0x00001cb4, 0xfff6c200, 0x00001cbd, 0xfff6e200, 0x00001cc5, 0xffff0000, 0x00001ccd, 0xffff2000, 0x00001cd5, 0xffff4000, 0x00001cde, 0xffff6100, 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100, 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200 }; static void Blit_RGB565_ARGB8888(SDL_BlitInfo * info) { Blit_RGB565_32(info, RGB565_ARGB8888_LUT); } /* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */ static const Uint32 RGB565_ABGR8888_LUT[512] = { 0xff000000, 0x00000000, 0xff080000, 0x00002000, 0xff100000, 0x00004000, 0xff180000, 0x00006100, 0xff200000, 0x00008100, 0xff290000, 0x0000a100, 0xff310000, 0x0000c200, 0xff390000, 0x0000e200, 0xff410000, 0x00000008, 0xff4a0000, 0x00002008, 0xff520000, 0x00004008, 0xff5a0000, 0x00006108, 0xff620000, 0x00008108, 0xff6a0000, 0x0000a108, 0xff730000, 0x0000c208, 0xff7b0000, 0x0000e208, 0xff830000, 0x00000010, 0xff8b0000, 0x00002010, 0xff940000, 0x00004010, 0xff9c0000, 0x00006110, 0xffa40000, 0x00008110, 0xffac0000, 0x0000a110, 0xffb40000, 0x0000c210, 0xffbd0000, 0x0000e210, 0xffc50000, 0x00000018, 0xffcd0000, 0x00002018, 0xffd50000, 0x00004018, 0xffde0000, 0x00006118, 0xffe60000, 0x00008118, 0xffee0000, 0x0000a118, 0xfff60000, 0x0000c218, 0xffff0000, 0x0000e218, 0xff000400, 0x00000020, 0xff080400, 0x00002020, 0xff100400, 0x00004020, 0xff180400, 0x00006120, 0xff200400, 0x00008120, 0xff290400, 0x0000a120, 0xff310400, 0x0000c220, 0xff390400, 0x0000e220, 0xff410400, 0x00000029, 0xff4a0400, 0x00002029, 0xff520400, 0x00004029, 0xff5a0400, 0x00006129, 0xff620400, 0x00008129, 0xff6a0400, 0x0000a129, 0xff730400, 0x0000c229, 0xff7b0400, 0x0000e229, 0xff830400, 0x00000031, 0xff8b0400, 0x00002031, 0xff940400, 0x00004031, 0xff9c0400, 0x00006131, 0xffa40400, 0x00008131, 0xffac0400, 0x0000a131, 0xffb40400, 0x0000c231, 0xffbd0400, 0x0000e231, 0xffc50400, 0x00000039, 0xffcd0400, 0x00002039, 0xffd50400, 0x00004039, 0xffde0400, 0x00006139, 0xffe60400, 0x00008139, 0xffee0400, 0x0000a139, 0xfff60400, 0x0000c239, 0xffff0400, 0x0000e239, 0xff000800, 0x00000041, 0xff080800, 0x00002041, 0xff100800, 0x00004041, 0xff180800, 0x00006141, 0xff200800, 0x00008141, 0xff290800, 0x0000a141, 0xff310800, 0x0000c241, 0xff390800, 0x0000e241, 0xff410800, 0x0000004a, 0xff4a0800, 0x0000204a, 0xff520800, 0x0000404a, 0xff5a0800, 0x0000614a, 0xff620800, 0x0000814a, 0xff6a0800, 0x0000a14a, 0xff730800, 0x0000c24a, 0xff7b0800, 0x0000e24a, 0xff830800, 0x00000052, 0xff8b0800, 0x00002052, 0xff940800, 0x00004052, 0xff9c0800, 0x00006152, 0xffa40800, 0x00008152, 0xffac0800, 0x0000a152, 0xffb40800, 0x0000c252, 0xffbd0800, 0x0000e252, 0xffc50800, 0x0000005a, 0xffcd0800, 0x0000205a, 0xffd50800, 0x0000405a, 0xffde0800, 0x0000615a, 0xffe60800, 0x0000815a, 0xffee0800, 0x0000a15a, 0xfff60800, 0x0000c25a, 0xffff0800, 0x0000e25a, 0xff000c00, 0x00000062, 0xff080c00, 0x00002062, 0xff100c00, 0x00004062, 0xff180c00, 0x00006162, 0xff200c00, 0x00008162, 0xff290c00, 0x0000a162, 0xff310c00, 0x0000c262, 0xff390c00, 0x0000e262, 0xff410c00, 0x0000006a, 0xff4a0c00, 0x0000206a, 0xff520c00, 0x0000406a, 0xff5a0c00, 0x0000616a, 0xff620c00, 0x0000816a, 0xff6a0c00, 0x0000a16a, 0xff730c00, 0x0000c26a, 0xff7b0c00, 0x0000e26a, 0xff830c00, 0x00000073, 0xff8b0c00, 0x00002073, 0xff940c00, 0x00004073, 0xff9c0c00, 0x00006173, 0xffa40c00, 0x00008173, 0xffac0c00, 0x0000a173, 0xffb40c00, 0x0000c273, 0xffbd0c00, 0x0000e273, 0xffc50c00, 0x0000007b, 0xffcd0c00, 0x0000207b, 0xffd50c00, 0x0000407b, 0xffde0c00, 0x0000617b, 0xffe60c00, 0x0000817b, 0xffee0c00, 0x0000a17b, 0xfff60c00, 0x0000c27b, 0xffff0c00, 0x0000e27b, 0xff001000, 0x00000083, 0xff081000, 0x00002083, 0xff101000, 0x00004083, 0xff181000, 0x00006183, 0xff201000, 0x00008183, 0xff291000, 0x0000a183, 0xff311000, 0x0000c283, 0xff391000, 0x0000e283, 0xff411000, 0x0000008b, 0xff4a1000, 0x0000208b, 0xff521000, 0x0000408b, 0xff5a1000, 0x0000618b, 0xff621000, 0x0000818b, 0xff6a1000, 0x0000a18b, 0xff731000, 0x0000c28b, 0xff7b1000, 0x0000e28b, 0xff831000, 0x00000094, 0xff8b1000, 0x00002094, 0xff941000, 0x00004094, 0xff9c1000, 0x00006194, 0xffa41000, 0x00008194, 0xffac1000, 0x0000a194, 0xffb41000, 0x0000c294, 0xffbd1000, 0x0000e294, 0xffc51000, 0x0000009c, 0xffcd1000, 0x0000209c, 0xffd51000, 0x0000409c, 0xffde1000, 0x0000619c, 0xffe61000, 0x0000819c, 0xffee1000, 0x0000a19c, 0xfff61000, 0x0000c29c, 0xffff1000, 0x0000e29c, 0xff001400, 0x000000a4, 0xff081400, 0x000020a4, 0xff101400, 0x000040a4, 0xff181400, 0x000061a4, 0xff201400, 0x000081a4, 0xff291400, 0x0000a1a4, 0xff311400, 0x0000c2a4, 0xff391400, 0x0000e2a4, 0xff411400, 0x000000ac, 0xff4a1400, 0x000020ac, 0xff521400, 0x000040ac, 0xff5a1400, 0x000061ac, 0xff621400, 0x000081ac, 0xff6a1400, 0x0000a1ac, 0xff731400, 0x0000c2ac, 0xff7b1400, 0x0000e2ac, 0xff831400, 0x000000b4, 0xff8b1400, 0x000020b4, 0xff941400, 0x000040b4, 0xff9c1400, 0x000061b4, 0xffa41400, 0x000081b4, 0xffac1400, 0x0000a1b4, 0xffb41400, 0x0000c2b4, 0xffbd1400, 0x0000e2b4, 0xffc51400, 0x000000bd, 0xffcd1400, 0x000020bd, 0xffd51400, 0x000040bd, 0xffde1400, 0x000061bd, 0xffe61400, 0x000081bd, 0xffee1400, 0x0000a1bd, 0xfff61400, 0x0000c2bd, 0xffff1400, 0x0000e2bd, 0xff001800, 0x000000c5, 0xff081800, 0x000020c5, 0xff101800, 0x000040c5, 0xff181800, 0x000061c5, 0xff201800, 0x000081c5, 0xff291800, 0x0000a1c5, 0xff311800, 0x0000c2c5, 0xff391800, 0x0000e2c5, 0xff411800, 0x000000cd, 0xff4a1800, 0x000020cd, 0xff521800, 0x000040cd, 0xff5a1800, 0x000061cd, 0xff621800, 0x000081cd, 0xff6a1800, 0x0000a1cd, 0xff731800, 0x0000c2cd, 0xff7b1800, 0x0000e2cd, 0xff831800, 0x000000d5, 0xff8b1800, 0x000020d5, 0xff941800, 0x000040d5, 0xff9c1800, 0x000061d5, 0xffa41800, 0x000081d5, 0xffac1800, 0x0000a1d5, 0xffb41800, 0x0000c2d5, 0xffbd1800, 0x0000e2d5, 0xffc51800, 0x000000de, 0xffcd1800, 0x000020de, 0xffd51800, 0x000040de, 0xffde1800, 0x000061de, 0xffe61800, 0x000081de, 0xffee1800, 0x0000a1de, 0xfff61800, 0x0000c2de, 0xffff1800, 0x0000e2de, 0xff001c00, 0x000000e6, 0xff081c00, 0x000020e6, 0xff101c00, 0x000040e6, 0xff181c00, 0x000061e6, 0xff201c00, 0x000081e6, 0xff291c00, 0x0000a1e6, 0xff311c00, 0x0000c2e6, 0xff391c00, 0x0000e2e6, 0xff411c00, 0x000000ee, 0xff4a1c00, 0x000020ee, 0xff521c00, 0x000040ee, 0xff5a1c00, 0x000061ee, 0xff621c00, 0x000081ee, 0xff6a1c00, 0x0000a1ee, 0xff731c00, 0x0000c2ee, 0xff7b1c00, 0x0000e2ee, 0xff831c00, 0x000000f6, 0xff8b1c00, 0x000020f6, 0xff941c00, 0x000040f6, 0xff9c1c00, 0x000061f6, 0xffa41c00, 0x000081f6, 0xffac1c00, 0x0000a1f6, 0xffb41c00, 0x0000c2f6, 0xffbd1c00, 0x0000e2f6, 0xffc51c00, 0x000000ff, 0xffcd1c00, 0x000020ff, 0xffd51c00, 0x000040ff, 0xffde1c00, 0x000061ff, 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff, 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff }; static void Blit_RGB565_ABGR8888(SDL_BlitInfo * info) { Blit_RGB565_32(info, RGB565_ABGR8888_LUT); } /* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */ static const Uint32 RGB565_RGBA8888_LUT[512] = { 0x000000ff, 0x00000000, 0x000008ff, 0x00200000, 0x000010ff, 0x00400000, 0x000018ff, 0x00610000, 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000, 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000, 0x000041ff, 0x08000000, 0x00004aff, 0x08200000, 0x000052ff, 0x08400000, 0x00005aff, 0x08610000, 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000, 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000, 0x000083ff, 0x10000000, 0x00008bff, 0x10200000, 0x000094ff, 0x10400000, 0x00009cff, 0x10610000, 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000, 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000, 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000, 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000, 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000, 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000, 0x000400ff, 0x20000000, 0x000408ff, 0x20200000, 0x000410ff, 0x20400000, 0x000418ff, 0x20610000, 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000, 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000, 0x000441ff, 0x29000000, 0x00044aff, 0x29200000, 0x000452ff, 0x29400000, 0x00045aff, 0x29610000, 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000, 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000, 0x000483ff, 0x31000000, 0x00048bff, 0x31200000, 0x000494ff, 0x31400000, 0x00049cff, 0x31610000, 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000, 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000, 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000, 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000, 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000, 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000, 0x000800ff, 0x41000000, 0x000808ff, 0x41200000, 0x000810ff, 0x41400000, 0x000818ff, 0x41610000, 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000, 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000, 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000, 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000, 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000, 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000, 0x000883ff, 0x52000000, 0x00088bff, 0x52200000, 0x000894ff, 0x52400000, 0x00089cff, 0x52610000, 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000, 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000, 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000, 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000, 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000, 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000, 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000, 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000, 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000, 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000, 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000, 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000, 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000, 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000, 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000, 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000, 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000, 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000, 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000, 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000, 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000, 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000, 0x001000ff, 0x83000000, 0x001008ff, 0x83200000, 0x001010ff, 0x83400000, 0x001018ff, 0x83610000, 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000, 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000, 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000, 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000, 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000, 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000, 0x001083ff, 0x94000000, 0x00108bff, 0x94200000, 0x001094ff, 0x94400000, 0x00109cff, 0x94610000, 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000, 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000, 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000, 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000, 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000, 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000, 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000, 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000, 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000, 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000, 0x001441ff, 0xac000000, 0x00144aff, 0xac200000, 0x001452ff, 0xac400000, 0x00145aff, 0xac610000, 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000, 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000, 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000, 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000, 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000, 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000, 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000, 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000, 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000, 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000, 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000, 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000, 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000, 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000, 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000, 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000, 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000, 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000, 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000, 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000, 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000, 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000, 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000, 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000, 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000, 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000, 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000, 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000, 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000, 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000, 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000, 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000, 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000, 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000, 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000, 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000, 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000, 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000, 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000, 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000, 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000, 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000, }; static void Blit_RGB565_RGBA8888(SDL_BlitInfo * info) { Blit_RGB565_32(info, RGB565_RGBA8888_LUT); } /* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */ static const Uint32 RGB565_BGRA8888_LUT[512] = { 0x00000000, 0x000000ff, 0x08000000, 0x002000ff, 0x10000000, 0x004000ff, 0x18000000, 0x006100ff, 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff, 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff, 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff, 0x52000000, 0x004008ff, 0x5a000000, 0x006108ff, 0x62000000, 0x008108ff, 0x6a000000, 0x00a108ff, 0x73000000, 0x00c208ff, 0x7b000000, 0x00e208ff, 0x83000000, 0x000010ff, 0x8b000000, 0x002010ff, 0x94000000, 0x004010ff, 0x9c000000, 0x006110ff, 0xa4000000, 0x008110ff, 0xac000000, 0x00a110ff, 0xb4000000, 0x00c210ff, 0xbd000000, 0x00e210ff, 0xc5000000, 0x000018ff, 0xcd000000, 0x002018ff, 0xd5000000, 0x004018ff, 0xde000000, 0x006118ff, 0xe6000000, 0x008118ff, 0xee000000, 0x00a118ff, 0xf6000000, 0x00c218ff, 0xff000000, 0x00e218ff, 0x00040000, 0x000020ff, 0x08040000, 0x002020ff, 0x10040000, 0x004020ff, 0x18040000, 0x006120ff, 0x20040000, 0x008120ff, 0x29040000, 0x00a120ff, 0x31040000, 0x00c220ff, 0x39040000, 0x00e220ff, 0x41040000, 0x000029ff, 0x4a040000, 0x002029ff, 0x52040000, 0x004029ff, 0x5a040000, 0x006129ff, 0x62040000, 0x008129ff, 0x6a040000, 0x00a129ff, 0x73040000, 0x00c229ff, 0x7b040000, 0x00e229ff, 0x83040000, 0x000031ff, 0x8b040000, 0x002031ff, 0x94040000, 0x004031ff, 0x9c040000, 0x006131ff, 0xa4040000, 0x008131ff, 0xac040000, 0x00a131ff, 0xb4040000, 0x00c231ff, 0xbd040000, 0x00e231ff, 0xc5040000, 0x000039ff, 0xcd040000, 0x002039ff, 0xd5040000, 0x004039ff, 0xde040000, 0x006139ff, 0xe6040000, 0x008139ff, 0xee040000, 0x00a139ff, 0xf6040000, 0x00c239ff, 0xff040000, 0x00e239ff, 0x00080000, 0x000041ff, 0x08080000, 0x002041ff, 0x10080000, 0x004041ff, 0x18080000, 0x006141ff, 0x20080000, 0x008141ff, 0x29080000, 0x00a141ff, 0x31080000, 0x00c241ff, 0x39080000, 0x00e241ff, 0x41080000, 0x00004aff, 0x4a080000, 0x00204aff, 0x52080000, 0x00404aff, 0x5a080000, 0x00614aff, 0x62080000, 0x00814aff, 0x6a080000, 0x00a14aff, 0x73080000, 0x00c24aff, 0x7b080000, 0x00e24aff, 0x83080000, 0x000052ff, 0x8b080000, 0x002052ff, 0x94080000, 0x004052ff, 0x9c080000, 0x006152ff, 0xa4080000, 0x008152ff, 0xac080000, 0x00a152ff, 0xb4080000, 0x00c252ff, 0xbd080000, 0x00e252ff, 0xc5080000, 0x00005aff, 0xcd080000, 0x00205aff, 0xd5080000, 0x00405aff, 0xde080000, 0x00615aff, 0xe6080000, 0x00815aff, 0xee080000, 0x00a15aff, 0xf6080000, 0x00c25aff, 0xff080000, 0x00e25aff, 0x000c0000, 0x000062ff, 0x080c0000, 0x002062ff, 0x100c0000, 0x004062ff, 0x180c0000, 0x006162ff, 0x200c0000, 0x008162ff, 0x290c0000, 0x00a162ff, 0x310c0000, 0x00c262ff, 0x390c0000, 0x00e262ff, 0x410c0000, 0x00006aff, 0x4a0c0000, 0x00206aff, 0x520c0000, 0x00406aff, 0x5a0c0000, 0x00616aff, 0x620c0000, 0x00816aff, 0x6a0c0000, 0x00a16aff, 0x730c0000, 0x00c26aff, 0x7b0c0000, 0x00e26aff, 0x830c0000, 0x000073ff, 0x8b0c0000, 0x002073ff, 0x940c0000, 0x004073ff, 0x9c0c0000, 0x006173ff, 0xa40c0000, 0x008173ff, 0xac0c0000, 0x00a173ff, 0xb40c0000, 0x00c273ff, 0xbd0c0000, 0x00e273ff, 0xc50c0000, 0x00007bff, 0xcd0c0000, 0x00207bff, 0xd50c0000, 0x00407bff, 0xde0c0000, 0x00617bff, 0xe60c0000, 0x00817bff, 0xee0c0000, 0x00a17bff, 0xf60c0000, 0x00c27bff, 0xff0c0000, 0x00e27bff, 0x00100000, 0x000083ff, 0x08100000, 0x002083ff, 0x10100000, 0x004083ff, 0x18100000, 0x006183ff, 0x20100000, 0x008183ff, 0x29100000, 0x00a183ff, 0x31100000, 0x00c283ff, 0x39100000, 0x00e283ff, 0x41100000, 0x00008bff, 0x4a100000, 0x00208bff, 0x52100000, 0x00408bff, 0x5a100000, 0x00618bff, 0x62100000, 0x00818bff, 0x6a100000, 0x00a18bff, 0x73100000, 0x00c28bff, 0x7b100000, 0x00e28bff, 0x83100000, 0x000094ff, 0x8b100000, 0x002094ff, 0x94100000, 0x004094ff, 0x9c100000, 0x006194ff, 0xa4100000, 0x008194ff, 0xac100000, 0x00a194ff, 0xb4100000, 0x00c294ff, 0xbd100000, 0x00e294ff, 0xc5100000, 0x00009cff, 0xcd100000, 0x00209cff, 0xd5100000, 0x00409cff, 0xde100000, 0x00619cff, 0xe6100000, 0x00819cff, 0xee100000, 0x00a19cff, 0xf6100000, 0x00c29cff, 0xff100000, 0x00e29cff, 0x00140000, 0x0000a4ff, 0x08140000, 0x0020a4ff, 0x10140000, 0x0040a4ff, 0x18140000, 0x0061a4ff, 0x20140000, 0x0081a4ff, 0x29140000, 0x00a1a4ff, 0x31140000, 0x00c2a4ff, 0x39140000, 0x00e2a4ff, 0x41140000, 0x0000acff, 0x4a140000, 0x0020acff, 0x52140000, 0x0040acff, 0x5a140000, 0x0061acff, 0x62140000, 0x0081acff, 0x6a140000, 0x00a1acff, 0x73140000, 0x00c2acff, 0x7b140000, 0x00e2acff, 0x83140000, 0x0000b4ff, 0x8b140000, 0x0020b4ff, 0x94140000, 0x0040b4ff, 0x9c140000, 0x0061b4ff, 0xa4140000, 0x0081b4ff, 0xac140000, 0x00a1b4ff, 0xb4140000, 0x00c2b4ff, 0xbd140000, 0x00e2b4ff, 0xc5140000, 0x0000bdff, 0xcd140000, 0x0020bdff, 0xd5140000, 0x0040bdff, 0xde140000, 0x0061bdff, 0xe6140000, 0x0081bdff, 0xee140000, 0x00a1bdff, 0xf6140000, 0x00c2bdff, 0xff140000, 0x00e2bdff, 0x00180000, 0x0000c5ff, 0x08180000, 0x0020c5ff, 0x10180000, 0x0040c5ff, 0x18180000, 0x0061c5ff, 0x20180000, 0x0081c5ff, 0x29180000, 0x00a1c5ff, 0x31180000, 0x00c2c5ff, 0x39180000, 0x00e2c5ff, 0x41180000, 0x0000cdff, 0x4a180000, 0x0020cdff, 0x52180000, 0x0040cdff, 0x5a180000, 0x0061cdff, 0x62180000, 0x0081cdff, 0x6a180000, 0x00a1cdff, 0x73180000, 0x00c2cdff, 0x7b180000, 0x00e2cdff, 0x83180000, 0x0000d5ff, 0x8b180000, 0x0020d5ff, 0x94180000, 0x0040d5ff, 0x9c180000, 0x0061d5ff, 0xa4180000, 0x0081d5ff, 0xac180000, 0x00a1d5ff, 0xb4180000, 0x00c2d5ff, 0xbd180000, 0x00e2d5ff, 0xc5180000, 0x0000deff, 0xcd180000, 0x0020deff, 0xd5180000, 0x0040deff, 0xde180000, 0x0061deff, 0xe6180000, 0x0081deff, 0xee180000, 0x00a1deff, 0xf6180000, 0x00c2deff, 0xff180000, 0x00e2deff, 0x001c0000, 0x0000e6ff, 0x081c0000, 0x0020e6ff, 0x101c0000, 0x0040e6ff, 0x181c0000, 0x0061e6ff, 0x201c0000, 0x0081e6ff, 0x291c0000, 0x00a1e6ff, 0x311c0000, 0x00c2e6ff, 0x391c0000, 0x00e2e6ff, 0x411c0000, 0x0000eeff, 0x4a1c0000, 0x0020eeff, 0x521c0000, 0x0040eeff, 0x5a1c0000, 0x0061eeff, 0x621c0000, 0x0081eeff, 0x6a1c0000, 0x00a1eeff, 0x731c0000, 0x00c2eeff, 0x7b1c0000, 0x00e2eeff, 0x831c0000, 0x0000f6ff, 0x8b1c0000, 0x0020f6ff, 0x941c0000, 0x0040f6ff, 0x9c1c0000, 0x0061f6ff, 0xa41c0000, 0x0081f6ff, 0xac1c0000, 0x00a1f6ff, 0xb41c0000, 0x00c2f6ff, 0xbd1c0000, 0x00e2f6ff, 0xc51c0000, 0x0000ffff, 0xcd1c0000, 0x0020ffff, 0xd51c0000, 0x0040ffff, 0xde1c0000, 0x0061ffff, 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff, 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff }; static void Blit_RGB565_BGRA8888(SDL_BlitInfo * info) { Blit_RGB565_32(info, RGB565_BGRA8888_LUT); } #endif /* SDL_HAVE_BLIT_N_RGB565 */ static void BlitNto1(SDL_BlitInfo * info) { #ifndef USE_DUFFS_LOOP int c; #endif int width, height; Uint8 *src; const Uint8 *map; Uint8 *dst; int srcskip, dstskip; int srcbpp; Uint32 Pixel; int sR, sG, sB; SDL_PixelFormat *srcfmt; /* Set up some basic variables */ width = info->dst_w; height = info->dst_h; src = info->src; srcskip = info->src_skip; dst = info->dst; dstskip = info->dst_skip; map = info->table; srcfmt = info->src_fmt; srcbpp = srcfmt->BytesPerPixel; if (map == NULL) { while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); if ( 1 ) { /* Pack RGB into 8bit pixel */ *dst = ((sR>>5)<<(3+2))| ((sG>>5)<<(2)) | ((sB>>6)<<(0)) ; } dst++; src += srcbpp; , width); /* *INDENT-ON* */ #else for (c = width; c; --c) { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); if (1) { /* Pack RGB into 8bit pixel */ *dst = ((sR >> 5) << (3 + 2)) | ((sG >> 5) << (2)) | ((sB >> 6) << (0)); } dst++; src += srcbpp; } #endif src += srcskip; dst += dstskip; } } else { while (height--) { #ifdef USE_DUFFS_LOOP /* *INDENT-OFF* */ DUFFS_LOOP( DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); if ( 1 ) { /* Pack RGB into 8bit pixel */ *dst = map[((sR>>5)<<(3+2))| ((sG>>5)<<(2)) | ((sB>>6)<<(0)) ]; } dst++; src += srcbpp; , width); /* *INDENT-ON* */ #else for (c = width; c; --c) { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); if (1) { /* Pack RGB into 8bit pixel */ *dst = map[((sR >> 5) << (3 + 2)) | ((sG >> 5) << (2)) | ((sB >> 6) << (0))]; } dst++; src += srcbpp; } #endif /* USE_DUFFS_LOOP */ src += srcskip; dst += dstskip; } } } /* blits 32 bit RGB<->RGBA with both surfaces having the same R,G,B fields */ static void Blit4to4MaskAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *src = (Uint32 *) info->src; int srcskip = info->src_skip; Uint32 *dst = (Uint32 *) info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; if (dstfmt->Amask) { /* RGB->RGBA, SET_ALPHA */ Uint32 mask = ((Uint32)info->a >> dstfmt->Aloss) << dstfmt->Ashift; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { *dst = *src | mask; ++dst; ++src; }, width); /* *INDENT-ON* */ src = (Uint32 *) ((Uint8 *) src + srcskip); dst = (Uint32 *) ((Uint8 *) dst + dstskip); } } else { /* RGBA->RGB, NO_ALPHA */ Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { *dst = *src & mask; ++dst; ++src; }, width); /* *INDENT-ON* */ src = (Uint32 *) ((Uint8 *) src + srcskip); dst = (Uint32 *) ((Uint8 *) dst + dstskip); } } } /* blits 32 bit RGBA<->RGBA with both surfaces having the same R,G,B,A fields */ static void Blit4to4CopyAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint32 *src = (Uint32 *) info->src; int srcskip = info->src_skip; Uint32 *dst = (Uint32 *) info->dst; int dstskip = info->dst_skip; /* RGBA->RGBA, COPY_ALPHA */ while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { *dst = *src; ++dst; ++src; }, width); /* *INDENT-ON* */ src = (Uint32 *) ((Uint8 *) src + srcskip); dst = (Uint32 *) ((Uint8 *) dst + dstskip); } } /* permutation for mapping srcfmt to dstfmt, overloading or not the alpha channel */ static void get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt, int *_p0 , int *_p1, int *_p2, int *_p3, int *_alpha_channel) { int alpha_channel = 0, p0, p1, p2, p3; #if SDL_BYTEORDER == SDL_LIL_ENDIAN int Pixel = 0x04030201; /* identity permutation */ #else int Pixel = 0x01020304; /* identity permutation */ int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; #endif if (srcfmt->Amask) { RGBA_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2, p3); } else { RGB_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2); p3 = 0; } if (dstfmt->Amask) { if (srcfmt->Amask) { PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, p3); } else { PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, 0); } } else { PIXEL_FROM_RGB(Pixel, dstfmt, p0, p1, p2); } #if SDL_BYTEORDER == SDL_LIL_ENDIAN p0 = Pixel & 0xFF; p1 = (Pixel >> 8) & 0xFF; p2 = (Pixel >> 16) & 0xFF; p3 = (Pixel >> 24) & 0xFF; #else p3 = Pixel & 0xFF; p2 = (Pixel >> 8) & 0xFF; p1 = (Pixel >> 16) & 0xFF; p0 = (Pixel >> 24) & 0xFF; #endif if (p0 == 0) { p0 = 1; alpha_channel = 0; } else if (p1 == 0) { p1 = 1; alpha_channel = 1; } else if (p2 == 0) { p2 = 1; alpha_channel = 2; } else if (p3 == 0) { p3 = 1; alpha_channel = 3; } #if SDL_BYTEORDER == SDL_LIL_ENDIAN #else if (srcbpp == 3 && dstbpp == 4) { if (p0 != 1) p0--; if (p1 != 1) p1--; if (p2 != 1) p2--; if (p3 != 1) p3--; } else if (srcbpp == 4 && dstbpp == 3) { p0 = p1; p1 = p2; p2 = p3; } #endif *_p0 = p0 - 1; *_p1 = p1 - 1; *_p2 = p2 - 1; *_p3 = p3 - 1; if (_alpha_channel) { *_alpha_channel = alpha_channel; } } static void BlitNtoN(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; unsigned alpha = dstfmt->Amask ? info->a : 0; #if HAVE_FAST_WRITE_INT8 /* Blit with permutation: 4->4 */ if (srcbpp == 4 && dstbpp == 4 && srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 && dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) { /* Find the appropriate permutation */ int alpha_channel, p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; dst[3] = src[p3]; dst[alpha_channel] = alpha; src += 4; dst += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #endif /* Blit with permutation: 4->3 */ if (srcbpp == 4 && dstbpp == 3 && srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) { /* Find the appropriate permutation */ int p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; src += 4; dst += 3; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #if HAVE_FAST_WRITE_INT8 /* Blit with permutation: 3->4 */ if (srcbpp == 3 && dstbpp == 4 && dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) { /* Find the appropriate permutation */ int alpha_channel, p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; dst[3] = src[p3]; dst[alpha_channel] = alpha; src += 3; dst += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 Pixel; unsigned sR; unsigned sG; unsigned sB; DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha); dst += dstbpp; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } static void BlitNtoNCopyAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; int c; #if HAVE_FAST_WRITE_INT8 /* Blit with permutation: 4->4 */ if (srcbpp == 4 && dstbpp == 4 && srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 && dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) { /* Find the appropriate permutation */ int p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; dst[3] = src[p3]; src += 4; dst += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #endif while (height--) { for (c = width; c; --c) { Uint32 Pixel; unsigned sR, sG, sB, sA; DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA); dst += dstbpp; src += srcbpp; } src += srcskip; dst += dstskip; } } static void BlitNto1Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; const Uint8 *palmap = info->table; Uint32 ckey = info->colorkey; Uint32 rgbmask = ~srcfmt->Amask; int srcbpp; Uint32 Pixel; unsigned sR, sG, sB; /* Set up some basic variables */ srcbpp = srcfmt->BytesPerPixel; ckey &= rgbmask; if (palmap == NULL) { while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); if ( (Pixel & rgbmask) != ckey ) { /* Pack RGB into 8bit pixel */ *dst = (Uint8)(((sR>>5)<<(3+2))| ((sG>>5)<<(2)) | ((sB>>6)<<(0))); } dst++; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } else { while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB); if ( (Pixel & rgbmask) != ckey ) { /* Pack RGB into 8bit pixel */ *dst = (Uint8)palmap[((sR>>5)<<(3+2))| ((sG>>5)<<(2)) | ((sB>>6)<<(0)) ]; } dst++; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } } static void Blit2to2Key(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint16 *srcp = (Uint16 *) info->src; int srcskip = info->src_skip; Uint16 *dstp = (Uint16 *) info->dst; int dstskip = info->dst_skip; Uint32 ckey = info->colorkey; Uint32 rgbmask = ~info->src_fmt->Amask; /* Set up some basic variables */ srcskip /= 2; dstskip /= 2; ckey &= rgbmask; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ( (*srcp & rgbmask) != ckey ) { *dstp = *srcp; } dstp++; srcp++; }, width); /* *INDENT-ON* */ srcp += srcskip; dstp += dstskip; } } static void BlitNtoNKey(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint32 ckey = info->colorkey; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; unsigned alpha = dstfmt->Amask ? info->a : 0; Uint32 rgbmask = ~srcfmt->Amask; int sfmt = srcfmt->format; int dfmt = dstfmt->format; /* Set up some basic variables */ ckey &= rgbmask; /* BPP 4, same rgb */ if (srcbpp == 4 && dstbpp == 4 && srcfmt->Rmask == dstfmt->Rmask && srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask) { Uint32 *src32 = (Uint32*)src; Uint32 *dst32 = (Uint32*)dst; if (dstfmt->Amask) { /* RGB->RGBA, SET_ALPHA */ Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ((*src32 & rgbmask) != ckey) { *dst32 = *src32 | mask; } ++dst32; ++src32; }, width); /* *INDENT-ON* */ src32 = (Uint32 *) ((Uint8 *) src32 + srcskip); dst32 = (Uint32 *) ((Uint8 *) dst32 + dstskip); } return; } else { /* RGBA->RGB, NO_ALPHA */ Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ((*src32 & rgbmask) != ckey) { *dst32 = *src32 & mask; } ++dst32; ++src32; }, width); /* *INDENT-ON* */ src32 = (Uint32 *) ((Uint8 *) src32 + srcskip); dst32 = (Uint32 *) ((Uint8 *) dst32 + dstskip); } return; } } #if HAVE_FAST_WRITE_INT8 /* Blit with permutation: 4->4 */ if (srcbpp == 4 && dstbpp == 4 && srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 && dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) { /* Find the appropriate permutation */ int alpha_channel, p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 *src32 = (Uint32*)src; if ((*src32 & rgbmask) != ckey) { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; dst[3] = src[p3]; dst[alpha_channel] = alpha; } src += 4; dst += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #endif /* BPP 3, same rgb triplet */ if ((sfmt == SDL_PIXELFORMAT_RGB24 && dfmt == SDL_PIXELFORMAT_RGB24) || (sfmt == SDL_PIXELFORMAT_BGR24 && dfmt == SDL_PIXELFORMAT_BGR24)) { #if SDL_BYTEORDER == SDL_LIL_ENDIAN Uint8 k0 = ckey & 0xFF; Uint8 k1 = (ckey >> 8) & 0xFF; Uint8 k2 = (ckey >> 16) & 0xFF; #else Uint8 k0 = (ckey >> 16) & 0xFF; Uint8 k1 = (ckey >> 8) & 0xFF; Uint8 k2 = ckey & 0xFF; #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint8 s0 = src[0]; Uint8 s1 = src[1]; Uint8 s2 = src[2]; if (k0 != s0 || k1 != s1 || k2 != s2) { dst[0] = s0; dst[1] = s1; dst[2] = s2; } src += 3; dst += 3; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } /* BPP 3, inversed rgb triplet */ if ((sfmt == SDL_PIXELFORMAT_RGB24 && dfmt == SDL_PIXELFORMAT_BGR24) || (sfmt == SDL_PIXELFORMAT_BGR24 && dfmt == SDL_PIXELFORMAT_RGB24)) { #if SDL_BYTEORDER == SDL_LIL_ENDIAN Uint8 k0 = ckey & 0xFF; Uint8 k1 = (ckey >> 8) & 0xFF; Uint8 k2 = (ckey >> 16) & 0xFF; #else Uint8 k0 = (ckey >> 16) & 0xFF; Uint8 k1 = (ckey >> 8) & 0xFF; Uint8 k2 = ckey & 0xFF; #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint8 s0 = src[0]; Uint8 s1 = src[1]; Uint8 s2 = src[2]; if (k0 != s0 || k1 != s1 || k2 != s2) { /* Inversed RGB */ dst[0] = s2; dst[1] = s1; dst[2] = s0; } src += 3; dst += 3; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } /* Blit with permutation: 4->3 */ if (srcbpp == 4 && dstbpp == 3 && srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) { /* Find the appropriate permutation */ int p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 *src32 = (Uint32*)src; if ((*src32 & rgbmask) != ckey) { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; } src += 4; dst += 3; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #if HAVE_FAST_WRITE_INT8 /* Blit with permutation: 3->4 */ if (srcbpp == 3 && dstbpp == 4 && dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) { #if SDL_BYTEORDER == SDL_LIL_ENDIAN Uint8 k0 = ckey & 0xFF; Uint8 k1 = (ckey >> 8) & 0xFF; Uint8 k2 = (ckey >> 16) & 0xFF; #else Uint8 k0 = (ckey >> 16) & 0xFF; Uint8 k1 = (ckey >> 8) & 0xFF; Uint8 k2 = ckey & 0xFF; #endif /* Find the appropriate permutation */ int alpha_channel, p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint8 s0 = src[0]; Uint8 s1 = src[1]; Uint8 s2 = src[2]; if (k0 != s0 || k1 != s1 || k2 != s2) { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; dst[3] = src[p3]; dst[alpha_channel] = alpha; } src += 3; dst += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 Pixel; unsigned sR; unsigned sG; unsigned sB; RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel); if ( (Pixel & rgbmask) != ckey ) { RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha); } dst += dstbpp; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; Uint32 ckey = info->colorkey; SDL_PixelFormat *srcfmt = info->src_fmt; SDL_PixelFormat *dstfmt = info->dst_fmt; Uint32 rgbmask = ~srcfmt->Amask; Uint8 srcbpp; Uint8 dstbpp; Uint32 Pixel; unsigned sR, sG, sB, sA; /* Set up some basic variables */ srcbpp = srcfmt->BytesPerPixel; dstbpp = dstfmt->BytesPerPixel; ckey &= rgbmask; /* Fastpath: same source/destination format, with Amask, bpp 32, loop is vectorized. ~10x faster */ if (srcfmt->format == dstfmt->format) { if (srcfmt->format == SDL_PIXELFORMAT_ARGB8888 || srcfmt->format == SDL_PIXELFORMAT_ABGR8888 || srcfmt->format == SDL_PIXELFORMAT_BGRA8888 || srcfmt->format == SDL_PIXELFORMAT_RGBA8888) { Uint32 *src32 = (Uint32*)src; Uint32 *dst32 = (Uint32*)dst; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { if ((*src32 & rgbmask) != ckey) { *dst32 = *src32; } ++src32; ++dst32; }, width); /* *INDENT-ON* */ src32 = (Uint32 *)((Uint8 *)src32 + srcskip); dst32 = (Uint32 *)((Uint8 *)dst32 + dstskip); } } return; } #if HAVE_FAST_WRITE_INT8 /* Blit with permutation: 4->4 */ if (srcbpp == 4 && dstbpp == 4 && srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 && dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) { /* Find the appropriate permutation */ int p0, p1, p2, p3; get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL); while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 *src32 = (Uint32*)src; if ((*src32 & rgbmask) != ckey) { dst[0] = src[p0]; dst[1] = src[p1]; dst[2] = src[p2]; dst[3] = src[p3]; } src += 4; dst += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } return; } #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); if ( (Pixel & rgbmask) != ckey ) { ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA); } dst += dstbpp; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } /* Special optimized blit for ARGB 2-10-10-10 --> RGBA */ static void Blit2101010toN(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; Uint32 Pixel; unsigned sR, sG, sB, sA; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Pixel = *(Uint32 *)src; RGBA_FROM_ARGB2101010(Pixel, sR, sG, sB, sA); ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA); dst += dstbpp; src += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } /* Special optimized blit for RGBA --> ARGB 2-10-10-10 */ static void BlitNto2101010(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; Uint32 Pixel; unsigned sR, sG, sB, sA; while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA); ARGB2101010_FROM_RGBA(Pixel, sR, sG, sB, sA); *(Uint32 *)dst = Pixel; dst += 4; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } /* Blit_3or4_to_3or4__same_rgb: 3 or 4 bpp, same RGB triplet */ static void Blit_3or4_to_3or4__same_rgb(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; if (dstfmt->Amask) { /* SET_ALPHA */ Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift; #if SDL_BYTEORDER == SDL_LIL_ENDIAN int i0 = 0, i1 = 1, i2 = 2; #else int i0 = srcbpp - 1 - 0; int i1 = srcbpp - 1 - 1; int i2 = srcbpp - 1 - 2; #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 *dst32 = (Uint32*)dst; Uint8 s0 = src[i0]; Uint8 s1 = src[i1]; Uint8 s2 = src[i2]; *dst32 = (s0) | (s1 << 8) | (s2 << 16) | mask; dst += 4; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } else { /* NO_ALPHA */ #if SDL_BYTEORDER == SDL_LIL_ENDIAN int i0 = 0, i1 = 1, i2 = 2; int j0 = 0, j1 = 1, j2 = 2; #else int i0 = srcbpp - 1 - 0; int i1 = srcbpp - 1 - 1; int i2 = srcbpp - 1 - 2; int j0 = dstbpp - 1 - 0; int j1 = dstbpp - 1 - 1; int j2 = dstbpp - 1 - 2; #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint8 s0 = src[i0]; Uint8 s1 = src[i1]; Uint8 s2 = src[i2]; dst[j0] = s0; dst[j1] = s1; dst[j2] = s2; dst += dstbpp; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } } /* Blit_3or4_to_3or4__inversed_rgb: 3 or 4 bpp, inversed RGB triplet */ static void Blit_3or4_to_3or4__inversed_rgb(SDL_BlitInfo * info) { int width = info->dst_w; int height = info->dst_h; Uint8 *src = info->src; int srcskip = info->src_skip; Uint8 *dst = info->dst; int dstskip = info->dst_skip; SDL_PixelFormat *srcfmt = info->src_fmt; int srcbpp = srcfmt->BytesPerPixel; SDL_PixelFormat *dstfmt = info->dst_fmt; int dstbpp = dstfmt->BytesPerPixel; if (dstfmt->Amask) { if (srcfmt->Amask) { /* COPY_ALPHA */ /* Only to switch ABGR8888 <-> ARGB8888 */ while (height--) { #if SDL_BYTEORDER == SDL_LIL_ENDIAN int i0 = 0, i1 = 1, i2 = 2, i3 = 3; #else int i0 = 3, i1 = 2, i2 = 1, i3 = 0; #endif /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 *dst32 = (Uint32*)dst; Uint8 s0 = src[i0]; Uint8 s1 = src[i1]; Uint8 s2 = src[i2]; Uint32 alphashift = ((Uint32)src[i3]) << dstfmt->Ashift; /* inversed, compared to Blit_3or4_to_3or4__same_rgb */ *dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift; dst += 4; src += 4; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } else { /* SET_ALPHA */ Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift; #if SDL_BYTEORDER == SDL_LIL_ENDIAN int i0 = 0, i1 = 1, i2 = 2; #else int i0 = srcbpp - 1 - 0; int i1 = srcbpp - 1 - 1; int i2 = srcbpp - 1 - 2; #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint32 *dst32 = (Uint32*)dst; Uint8 s0 = src[i0]; Uint8 s1 = src[i1]; Uint8 s2 = src[i2]; /* inversed, compared to Blit_3or4_to_3or4__same_rgb */ *dst32 = (s0 << 16) | (s1 << 8) | (s2) | mask; dst += 4; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } } else { /* NO_ALPHA */ #if SDL_BYTEORDER == SDL_LIL_ENDIAN int i0 = 0, i1 = 1, i2 = 2; int j0 = 2, j1 = 1, j2 = 0; #else int i0 = srcbpp - 1 - 0; int i1 = srcbpp - 1 - 1; int i2 = srcbpp - 1 - 2; int j0 = dstbpp - 1 - 2; int j1 = dstbpp - 1 - 1; int j2 = dstbpp - 1 - 0; #endif while (height--) { /* *INDENT-OFF* */ DUFFS_LOOP( { Uint8 s0 = src[i0]; Uint8 s1 = src[i1]; Uint8 s2 = src[i2]; /* inversed, compared to Blit_3or4_to_3or4__same_rgb */ dst[j0] = s0; dst[j1] = s1; dst[j2] = s2; dst += dstbpp; src += srcbpp; }, width); /* *INDENT-ON* */ src += srcskip; dst += dstskip; } } } /* Normal N to N optimized blitters */ #define NO_ALPHA 1 #define SET_ALPHA 2 #define COPY_ALPHA 4 struct blit_table { Uint32 srcR, srcG, srcB; int dstbpp; Uint32 dstR, dstG, dstB; enum blit_features blit_features; SDL_BlitFunc blitfunc; Uint32 alpha; /* bitwise NO_ALPHA, SET_ALPHA, COPY_ALPHA */ }; static const struct blit_table normal_blit_1[] = { /* Default for 8-bit RGB source, never optimized */ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} }; static const struct blit_table normal_blit_2[] = { #if SDL_ALTIVEC_BLITTERS /* has-altivec */ {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000, BLIT_FEATURE_HAS_ALTIVEC, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000, BLIT_FEATURE_HAS_ALTIVEC, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, #endif #if SDL_ARM_SIMD_BLITTERS {0x00000F00, 0x000000F0, 0x0000000F, 4, 0x00FF0000, 0x0000FF00, 0x000000FF, BLIT_FEATURE_HAS_ARM_SIMD, Blit_RGB444_RGB888ARMSIMD, NO_ALPHA | COPY_ALPHA}, #endif #if SDL_HAVE_BLIT_N_RGB565 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0, Blit_RGB565_ARGB8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00, 0x00FF0000, 0, Blit_RGB565_ABGR8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0, Blit_RGB565_RGBA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000, 0xFF000000, 0, Blit_RGB565_BGRA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, #endif /* Default for 16-bit RGB source, used if no other blitter matches */ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} }; static const struct blit_table normal_blit_3[] = { /* 3->4 with same rgb triplet */ {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x000000FF, 0x0000FF00, 0x00FF0000, 0, Blit_3or4_to_3or4__same_rgb, #if HAVE_FAST_WRITE_INT8 NO_ALPHA | #endif SET_ALPHA}, {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0, Blit_3or4_to_3or4__same_rgb, #if HAVE_FAST_WRITE_INT8 NO_ALPHA | #endif SET_ALPHA}, /* 3->4 with inversed rgb triplet */ {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0, Blit_3or4_to_3or4__inversed_rgb, #if HAVE_FAST_WRITE_INT8 NO_ALPHA | #endif SET_ALPHA}, {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000, 0, Blit_3or4_to_3or4__inversed_rgb, #if HAVE_FAST_WRITE_INT8 NO_ALPHA | #endif SET_ALPHA}, /* 3->3 to switch RGB 24 <-> BGR 24 */ {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF, 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA }, {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000, 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA }, /* Default for 24-bit RGB source, never optimized */ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} }; static const struct blit_table normal_blit_4[] = { #if SDL_ALTIVEC_BLITTERS /* has-altivec | dont-use-prefetch */ {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000, BLIT_FEATURE_HAS_ALTIVEC | BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH, ConvertAltivec32to32_noprefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, /* has-altivec */ {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000, BLIT_FEATURE_HAS_ALTIVEC, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, /* has-altivec */ {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F, BLIT_FEATURE_HAS_ALTIVEC, Blit_RGB888_RGB565Altivec, NO_ALPHA}, #endif #if SDL_ARM_SIMD_BLITTERS {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF, BLIT_FEATURE_HAS_ARM_SIMD, Blit_BGR888_RGB888ARMSIMD, NO_ALPHA | COPY_ALPHA }, #endif /* 4->3 with same rgb triplet */ {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x000000FF, 0x0000FF00, 0x00FF0000, 0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA}, {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x00FF0000, 0x0000FF00, 0x000000FF, 0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA}, /* 4->3 with inversed rgb triplet */ {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF, 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA}, {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000, 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA}, /* 4->4 with inversed rgb triplet, and COPY_ALPHA to switch ABGR8888 <-> ARGB8888 */ {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0, Blit_3or4_to_3or4__inversed_rgb, #if HAVE_FAST_WRITE_INT8 NO_ALPHA | #endif SET_ALPHA | COPY_ALPHA}, {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000, 0, Blit_3or4_to_3or4__inversed_rgb, #if HAVE_FAST_WRITE_INT8 NO_ALPHA | #endif SET_ALPHA | COPY_ALPHA}, /* RGB 888 and RGB 565 */ {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F, 0, Blit_RGB888_RGB565, NO_ALPHA}, {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F, 0, Blit_RGB888_RGB555, NO_ALPHA}, /* Default for 32-bit RGB source, used if no other blitter matches */ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} }; static const struct blit_table *const normal_blit[] = { normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4 }; /* Mask matches table, or table entry is zero */ #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000)) SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface * surface) { SDL_PixelFormat *srcfmt; SDL_PixelFormat *dstfmt; const struct blit_table *table; int which; SDL_BlitFunc blitfun; /* Set up data for choosing the blit */ srcfmt = surface->format; dstfmt = surface->map->dst->format; /* We don't support destinations less than 8-bits */ if (dstfmt->BitsPerPixel < 8) { return (NULL); } switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) { case 0: blitfun = NULL; if (dstfmt->BitsPerPixel == 8) { if ((srcfmt->BytesPerPixel == 4) && (srcfmt->Rmask == 0x00FF0000) && (srcfmt->Gmask == 0x0000FF00) && (srcfmt->Bmask == 0x000000FF)) { blitfun = Blit_RGB888_index8; } else if ((srcfmt->BytesPerPixel == 4) && (srcfmt->Rmask == 0x3FF00000) && (srcfmt->Gmask == 0x000FFC00) && (srcfmt->Bmask == 0x000003FF)) { blitfun = Blit_RGB101010_index8; } else { blitfun = BlitNto1; } } else { /* Now the meat, choose the blitter we want */ Uint32 a_need = NO_ALPHA; if (dstfmt->Amask) a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA; table = normal_blit[srcfmt->BytesPerPixel - 1]; for (which = 0; table[which].dstbpp; ++which) { if (MASKOK(srcfmt->Rmask, table[which].srcR) && MASKOK(srcfmt->Gmask, table[which].srcG) && MASKOK(srcfmt->Bmask, table[which].srcB) && MASKOK(dstfmt->Rmask, table[which].dstR) && MASKOK(dstfmt->Gmask, table[which].dstG) && MASKOK(dstfmt->Bmask, table[which].dstB) && dstfmt->BytesPerPixel == table[which].dstbpp && (a_need & table[which].alpha) == a_need && ((table[which].blit_features & GetBlitFeatures()) == table[which].blit_features)) break; } blitfun = table[which].blitfunc; if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ if (srcfmt->format == SDL_PIXELFORMAT_ARGB2101010) { blitfun = Blit2101010toN; } else if (dstfmt->format == SDL_PIXELFORMAT_ARGB2101010) { blitfun = BlitNto2101010; } else if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 && srcfmt->Rmask == dstfmt->Rmask && srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask) { if (a_need == COPY_ALPHA) { if (srcfmt->Amask == dstfmt->Amask) { /* Fastpath C fallback: 32bit RGBA<->RGBA blit with matching RGBA */ blitfun = Blit4to4CopyAlpha; } else { blitfun = BlitNtoNCopyAlpha; } } else { /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ blitfun = Blit4to4MaskAlpha; } } else if (a_need == COPY_ALPHA) { blitfun = BlitNtoNCopyAlpha; } } } return (blitfun); case SDL_COPY_COLORKEY: /* colorkey blit: Here we don't have too many options, mostly because RLE is the preferred fast way to deal with this. If a particular case turns out to be useful we'll add it. */ if (srcfmt->BytesPerPixel == 2 && surface->map->identity) return Blit2to2Key; else if (dstfmt->BytesPerPixel == 1) return BlitNto1Key; else { #if SDL_ALTIVEC_BLITTERS if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4) && SDL_HasAltiVec()) { return Blit32to32KeyAltivec; } else #endif if (srcfmt->Amask && dstfmt->Amask) { return BlitNtoNKeyCopyAlpha; } else { return BlitNtoNKey; } } } return NULL; } #endif /* SDL_HAVE_BLIT_N */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit_N.c
C
apache-2.0
119,446
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../SDL_internal.h" #include "SDL_video.h" #include "SDL_blit.h" #include "SDL_blit_copy.h" #ifdef __SSE__ /* This assumes 16-byte aligned src and dst */ static SDL_INLINE void SDL_memcpySSE(Uint8 * dst, const Uint8 * src, int len) { int i; __m128 values[4]; for (i = len / 64; i--;) { _mm_prefetch(src, _MM_HINT_NTA); values[0] = *(__m128 *) (src + 0); values[1] = *(__m128 *) (src + 16); values[2] = *(__m128 *) (src + 32); values[3] = *(__m128 *) (src + 48); _mm_stream_ps((float *) (dst + 0), values[0]); _mm_stream_ps((float *) (dst + 16), values[1]); _mm_stream_ps((float *) (dst + 32), values[2]); _mm_stream_ps((float *) (dst + 48), values[3]); src += 64; dst += 64; } if (len & 63) SDL_memcpy(dst, src, len & 63); } #endif /* __SSE__ */ #ifdef __MMX__ #ifdef _MSC_VER #pragma warning(disable:4799) #endif static SDL_INLINE void SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len) { const int remain = (len & 63); int i; __m64* d64 = (__m64*)dst; __m64* s64 = (__m64*)src; for(i= len / 64; i--;) { d64[0] = s64[0]; d64[1] = s64[1]; d64[2] = s64[2]; d64[3] = s64[3]; d64[4] = s64[4]; d64[5] = s64[5]; d64[6] = s64[6]; d64[7] = s64[7]; d64 += 8; s64 += 8; } if (remain) { const int skip = len - remain; SDL_memcpy(dst + skip, src + skip, remain); } } #endif /* __MMX__ */ void SDL_BlitCopy(SDL_BlitInfo * info) { SDL_bool overlap; Uint8 *src, *dst; int w, h; int srcskip, dstskip; w = info->dst_w * info->dst_fmt->BytesPerPixel; h = info->dst_h; src = info->src; dst = info->dst; srcskip = info->src_pitch; dstskip = info->dst_pitch; /* Properly handle overlapping blits */ if (src < dst) { overlap = (dst < (src + h*srcskip)); } else { overlap = (src < (dst + h*dstskip)); } if (overlap) { if ( dst < src ) { while ( h-- ) { SDL_memmove(dst, src, w); src += srcskip; dst += dstskip; } } else { src += ((h-1) * srcskip); dst += ((h-1) * dstskip); while ( h-- ) { SDL_memmove(dst, src, w); src -= srcskip; dst -= dstskip; } } return; } #ifdef __SSE__ if (SDL_HasSSE() && !((uintptr_t) src & 15) && !(srcskip & 15) && !((uintptr_t) dst & 15) && !(dstskip & 15)) { while (h--) { SDL_memcpySSE(dst, src, w); src += srcskip; dst += dstskip; } return; } #endif #ifdef __MMX__ if (SDL_HasMMX() && !(srcskip & 7) && !(dstskip & 7)) { while (h--) { SDL_memcpyMMX(dst, src, w); src += srcskip; dst += dstskip; } _mm_empty(); return; } #endif while (h--) { SDL_memcpy(dst, src, w); src += srcskip; dst += dstskip; } } /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit_copy.c
C
apache-2.0
4,208
/* Simple DirectMedia Layer Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_blit_copy_h_ #define SDL_blit_copy_h_ void SDL_BlitCopy(SDL_BlitInfo * info); #endif /* SDL_blit_copy_h_ */ /* vi: set ts=4 sw=4 expandtab: */
YifuLiu/AliOS-Things
components/SDL2/src/video/SDL_blit_copy.h
C
apache-2.0
1,098