public static int stbi__psd_decode_rle(stbi__context s, byte *p, int pixelCount) { var count = 0; var nleft = 0; var len = 0; count = 0; while ((nleft = pixelCount - count) > 0) { len = stbi__get8(s); if (len == 128) { } else if (len < 128) { len++; if (len > nleft) { return(0); } count += len; while (len != 0) { *p = stbi__get8(s); p += 4; len--; } } else if (len > 128) { byte val = 0; len = 257 - len; if (len > nleft) { return(0); } val = stbi__get8(s); count += len; while (len != 0) { *p = val; p += 4; len--; } } } return(1); }
public static int stbi__hdr_test_core(stbi__context s, string signature) { var i = 0; for (i = 0; i < signature.Length; ++i) { if (stbi__get8(s) != signature[i]) { return(0); } } stbi__rewind(s); return(1); }
private static void *stbi__load_main(stbi__context s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) { // make sure it's initialized if we add new fields ri->num_channels = 0; ri->channel_order = 0; ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order ri->num_channels = 0; //if (stbi__hdr_test(s)) { float *hdr = stbi__hdr_load(s, x, y, comp, req_comp, ri); return(stbi__hdr_to_ldr(hdr, *x, *y, req_comp != 0 ? req_comp : *comp)); //} //return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt"); }
private static void stbi__start_callbacks(stbi__context s, stbi_io_callbacks c, object user) { // s->io = *c; //s->io_user_data = user; //s->buflen = sizeof(s->buffer_start); //s->read_from_callbacks = 1; //s->img_buffer_original = s->buffer_start; //stbi__refill_buffer(s); //s->img_buffer_original_end = s->img_buffer_end; s.io = c; s.io_user_data = user; s.buflen = s.buffer_start.array.Length; s.read_from_callbacks = true; s.img_buffer_original = s.buffer_start; stbi__refill_buffer(s); s.img_buffer_original_end = s.img_buffer_end; }
public static int stbi__png_is16(stbi__context s) { var p = new stbi__png(); p.s = s; if (stbi__png_info_raw(p, null, null, null) == 0) { return(0); } if (p.depth != 16) { stbi__rewind(p.s); return(0); } return(1); }
public static int stbi__gif_header(stbi__context s, stbi__gif g, int *comp, int is_info) { byte version = 0; if (stbi__get8(s) != 71 || stbi__get8(s) != 73 || stbi__get8(s) != 70 || stbi__get8(s) != 56) { return(stbi__err("not GIF")); } version = stbi__get8(s); if (version != 55 && version != 57) { return(stbi__err("not GIF")); } if (stbi__get8(s) != 97) { return(stbi__err("not GIF")); } stbi__g_failure_reason = ""; g.w = stbi__get16le(s); g.h = stbi__get16le(s); g.flags = stbi__get8(s); g.bgindex = stbi__get8(s); g.ratio = stbi__get8(s); g.transparent = -1; if (g.w > 1 << 24) { return(stbi__err("too large")); } if (g.h > 1 << 24) { return(stbi__err("too large")); } if (comp != null) { *comp = 4; } if (is_info != 0) { return(1); } if ((g.flags & 0x80) != 0) { stbi__gif_parse_colortable(s, g.pal, 2 << (g.flags & 7), -1); } return(1); }
static bool stbi__at_eof(stbi__context s) { if (s.io.read != null) { if (s.io.eof(s.io_user_data) != 0) { return(false); } // if feof() is true, check if buffer = end // special case: we've only got the special 0 character at the end if (s.read_from_callbacks == 0) { return(true); } } return(s.img_buffer >= s.img_buffer_end); }
public static int stbi__gif_info_raw(stbi__context s, int *x, int *y, int *comp) { var g = new stbi__gif(); if (stbi__gif_header(s, g, comp, 1) == 0) { stbi__rewind(s); return(0); } if (x != null) { *x = g.w; } if (y != null) { *y = g.h; } return(1); }
public static int stbi__gif_test_raw(stbi__context s) { var sz = 0; if ((stbi__get8(s) != 'G') || (stbi__get8(s) != 'I') || (stbi__get8(s) != 'F') || (stbi__get8(s) != '8')) { return(0); } sz = stbi__get8(s); if ((sz != '9') && (sz != '7')) { return(0); } if (stbi__get8(s) != 'a') { return(0); } return(1); }
private static void stbi__refill_buffer(stbi__context s) { int n = s.io.read(s.io_user_data, s.buffer_start, s.buflen); if (n == 0) { // at end of file, treat same as if from memory, but need to handle case // where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file s.read_from_callbacks = 0; s.img_buffer = s.buffer_start; s.img_buffer_end = s.buffer_start + 1; *s.img_buffer = 0; } else { s.img_buffer = s.buffer_start; s.img_buffer_end = s.buffer_start + n; } }
public static int stbi__gif_test_raw(stbi__context s) { var sz = 0; if (stbi__get8(s) != 71 || stbi__get8(s) != 73 || stbi__get8(s) != 70 || stbi__get8(s) != 56) { return(0); } sz = stbi__get8(s); if (sz != 57 && sz != 55) { return(0); } if (stbi__get8(s) != 97) { return(0); } return(1); }
public static int stbi__bmp_test_raw(stbi__context s) { var r = 0; var sz = 0; if (stbi__get8(s) != 'B') { return(0); } if (stbi__get8(s) != 'M') { return(0); } stbi__get32le(s); stbi__get16le(s); stbi__get16le(s); stbi__get32le(s); sz = (int)stbi__get32le(s); r = sz == 12 || sz == 40 || sz == 56 || sz == 108 || sz == 124 ? 1 : 0; return(r); }
public static ushort *stbi__load_and_postprocess_16bit(stbi__context s, int *x, int *y, int *comp, int req_comp) { var ri = new stbi__result_info(); var result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16); if (result == null) { return(null); } if (ri.bits_per_channel != 16) { result = stbi__convert_8_to_16((byte *)result, *x, *y, (req_comp == 0) ? *comp : req_comp); ri.bits_per_channel = 16; } if (stbi__vertically_flip_on_load != 0) { var channels = (req_comp != 0) ? req_comp : *comp; stbi__vertical_flip(result, *x, *y, channels * sizeof(ushort)); } return((ushort *)result); }
public static float *stbi__loadf_main(stbi__context s, int *x, int *y, int *comp, int req_comp) { byte *data; if (stbi__hdr_test(s) != 0) { var ri = new stbi__result_info(); var hdr_data = stbi__hdr_load(s, x, y, comp, req_comp, &ri); if (hdr_data != null) { stbi__float_postprocess(hdr_data, x, y, comp, req_comp); } return(hdr_data); } data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp); if (data != null) { return(stbi__ldr_to_hdr(data, *x, *y, req_comp != 0 ? req_comp : *comp)); } return((float *)(ulong)(stbi__err("unknown image type") != 0 ? (byte *)null : null)); }
public static sbyte *stbi__hdr_gettoken(stbi__context z, sbyte *buffer) { var len = 0; var c = (sbyte)'\0'; c = (sbyte)stbi__get8(z); while (stbi__at_eof(z) == 0 && (c != '\n')) { buffer[len++] = c; if (len == 1024 - 1) { while (stbi__at_eof(z) == 0 && (stbi__get8(z) != '\n')) { } break; } c = (sbyte)stbi__get8(z); } buffer[len] = 0; return(buffer); }
public static void *stbi__load_main(stbi__context s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc) { CRuntime.memset(ri, 0, (ulong)sizeof(stbi__result_info)); ri->bits_per_channel = 8; ri->channel_order = STBI_ORDER_RGB; ri->num_channels = 0; if (stbi__png_test(s) != 0) { return(stbi__png_load(s, x, y, comp, req_comp, ri)); } if (stbi__bmp_test(s) != 0) { return(stbi__bmp_load(s, x, y, comp, req_comp, ri)); } if (stbi__gif_test(s) != 0) { return(stbi__gif_load(s, x, y, comp, req_comp, ri)); } if (stbi__psd_test(s) != 0) { return(stbi__psd_load(s, x, y, comp, req_comp, ri, bpc)); } if (stbi__jpeg_test(s) != 0) { return(stbi__jpeg_load(s, x, y, comp, req_comp, ri)); } if (stbi__hdr_test(s) != 0) { var hdr = stbi__hdr_load(s, x, y, comp, req_comp, ri); return(stbi__hdr_to_ldr(hdr, *x, *y, req_comp != 0 ? req_comp : *comp)); } if (stbi__tga_test(s) != 0) { return(stbi__tga_load(s, x, y, comp, req_comp, ri)); } return((byte *)(ulong)(stbi__err("unknown image type") != 0 ? 0 : 0)); }
public static int stbi__gif_header(stbi__context s, stbi__gif g, int *comp, int is_info) { byte version = 0; if ((stbi__get8(s) != 'G') || (stbi__get8(s) != 'I') || (stbi__get8(s) != 'F') || (stbi__get8(s) != '8')) { return(stbi__err("not GIF")); } version = stbi__get8(s); if ((version != '7') && (version != '9')) { return(stbi__err("not GIF")); } if (stbi__get8(s) != 'a') { return(stbi__err("not GIF")); } stbi__g_failure_reason = ""; g.w = stbi__get16le(s); g.h = stbi__get16le(s); g.flags = stbi__get8(s); g.bgindex = stbi__get8(s); g.ratio = stbi__get8(s); g.transparent = -1; if (comp != null) { *comp = 4; } if (is_info != 0) { return(1); } if ((g.flags & 0x80) != 0) { stbi__gif_parse_colortable(s, g.pal, 2 << (g.flags & 7), -1); } return(1); }
public static unsafe ImageResult FromStream(Stream stream, ColorComponents requiredComponents = ColorComponents.Default) { byte *result = null; try { int x, y, comp; var context = new stbi__context(stream); result = stbi__load_and_postprocess_8bit(context, &x, &y, &comp, (int)requiredComponents); return(FromResult(result, x, y, (ColorComponents)comp, requiredComponents)); } finally { if (result != null) { CRuntime.free(result); } } }
static float *stbi__loadf_main(stbi__context s, int *x, int *y, int *comp, int req_comp) { char *data; //if (stbi__hdr_test(s)) { stbi__result_info ri; float * hdr_data = stbi__hdr_load(s, x, y, comp, req_comp, &ri); if (hdr_data != null) { stbi__float_postprocess(hdr_data, x, y, comp, req_comp); } return(hdr_data); //} data = stbi__load_and_postprocess_8bit(s, x, y, comp, req_comp); if (data != null) { return(stbi__ldr_to_hdr(data, *x, *y, req_comp != 0 ? req_comp : *comp)); } stbi__errpf("Image not of any known type, or corrupt"); return(null); }
public static int stbi__psd_is16(stbi__context s) { var channelCount = 0; var depth = 0; if (stbi__get32be(s) != 0x38425053) { stbi__rewind(s); return(0); } if (stbi__get16be(s) != 1) { stbi__rewind(s); return(0); } stbi__skip(s, 6); channelCount = stbi__get16be(s); if (channelCount < 0 || channelCount > 16) { stbi__rewind(s); return(0); } stbi__get32be(s); stbi__get32be(s); depth = stbi__get16be(s); if (depth != 16) { stbi__rewind(s); return(0); } return(1); }
public static int stbi__info_main(stbi__context s, int *x, int *y, int *comp) { if (stbi__jpeg_info(s, x, y, comp) != 0) { return(1); } if (stbi__png_info(s, x, y, comp) != 0) { return(1); } if (stbi__gif_info(s, x, y, comp) != 0) { return(1); } if (stbi__bmp_info(s, x, y, comp) != 0) { return(1); } if (stbi__tga_info(s, x, y, comp) != 0) { return(1); } return(stbi__err("unknown image type")); }
static int stbi__getn(stbi__context* s, byte* buffer, int n) { ////if (s->io.read) ////{ //// int blen = (int)(s->img_buffer_end - s->img_buffer); //// if (blen < n) //// { //// int res, count; //// CLib.CString.memcpy(buffer, s->img_buffer, (uint)blen); //// count = s->io._read(s->io_user_data, (sbyte*)buffer + blen, n - blen); //// res = (count == (n - blen)) ? 1 : 0; //// s->img_buffer = s->img_buffer_end; //// return res; //// } ////} if (s->img_buffer + n <= s->img_buffer_end) { CLib.CString.memcpy(buffer, s->img_buffer, (uint)n); s->img_buffer += n; return 1; } else return 0; }
static int stbi__check_png_header(stbi__context* s) { byte[] png_sig = new byte[8] { 137, 80, 78, 71, 13, 10, 26, 10 }; int i; for (i = 0; i < 8; ++i) if (stbi__get8(s) != png_sig[i]) throw new Exception("bad png sig:Not a PNG"); return 1; }
public static byte* stbi_load_from_memory(byte* buffer, int len, int* x, int* y, int* comp, int req_comp) { stbi__context s = new stbi__context(); stbi__start_mem(&s, buffer, len); return stbi__load_flip(&s, x, y, comp, req_comp); }
// initialize a memory-decode context static void stbi__start_mem(stbi__context* s, byte* buffer, int len) { s->io.read = false; s->read_from_callbacks = 0; s->img_buffer = s->img_buffer_original = (byte*)buffer; s->img_buffer_end = (byte*)buffer + len; }
////static int stbi__at_eof(stbi__context* s) ////{ //// if (s->io.read) //// { //// if ((s->io._eof)(s->io_user_data) == 0) //// return 0; //// // if feof() is true, check if buffer = end //// // special case: we've only got the special 0 character at the end //// if (s->read_from_callbacks == 0) return 1; //// } //// return s->img_buffer >= s->img_buffer_end ? 1 : 0; ////} static void stbi__skip(stbi__context* s, int n) { if (n < 0) { s->img_buffer = s->img_buffer_end; return; } ////if (s->io.read) ////{ //// int blen = (int)(s->img_buffer_end - s->img_buffer); //// if (blen < n) //// { //// s->img_buffer = s->img_buffer_end; //// (s->io._skip)(s->io_user_data, n - blen); //// return; //// } ////} s->img_buffer += n; }
static void stbi__rewind(stbi__context* s) { // conceptually rewind SHOULD rewind to the beginning of the stream, // but we just rewind to the beginning of the initial buffer, because // we only use it after doing 'test', which only ever looks at at most 92 bytes s->img_buffer = s->img_buffer_original; }
static uint stbi__get32be(stbi__context* s) { uint z = (uint)stbi__get16be(s); return (z << 16) + (uint)stbi__get16be(s); }
public static void stbi__rewind(stbi__context s) { s.Stream.Seek(0, SeekOrigin.Begin); }
public static int stbi__tga_info(stbi__context s, int *x, int *y, int *comp) { var tga_w = 0; var tga_h = 0; var tga_comp = 0; var tga_image_type = 0; var tga_bits_per_pixel = 0; var tga_colormap_bpp = 0; var sz = 0; var tga_colormap_type = 0; stbi__get8(s); tga_colormap_type = stbi__get8(s); if (tga_colormap_type > 1) { stbi__rewind(s); return(0); } tga_image_type = stbi__get8(s); if (tga_colormap_type == 1) { if ((tga_image_type != 1) && (tga_image_type != 9)) { stbi__rewind(s); return(0); } stbi__skip(s, 4); sz = stbi__get8(s); if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32)) { stbi__rewind(s); return(0); } stbi__skip(s, 4); tga_colormap_bpp = sz; } else { if ((tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) && (tga_image_type != 11)) { stbi__rewind(s); return(0); } stbi__skip(s, 9); tga_colormap_bpp = 0; } tga_w = stbi__get16le(s); if (tga_w < 1) { stbi__rewind(s); return(0); } tga_h = stbi__get16le(s); if (tga_h < 1) { stbi__rewind(s); return(0); } tga_bits_per_pixel = stbi__get8(s); stbi__get8(s); if (tga_colormap_bpp != 0) { if (tga_bits_per_pixel != 8 && tga_bits_per_pixel != 16) { stbi__rewind(s); return(0); } tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, null); } else { tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, ((tga_image_type == 3) || (tga_image_type == 11)) ? 1 : 0, null); } if (tga_comp == 0) { stbi__rewind(s); return(0); } if (x != null) { *x = tga_w; } if (y != null) { *y = tga_h; } if (comp != null) { *comp = tga_comp; } return(1); }
public static uint stbi__get32le(stbi__context s) { var z = (uint)stbi__get16le(s); return((uint)(z + (stbi__get16le(s) << 16))); }
public static uint stbi__get32be(stbi__context s) { var z = (uint)stbi__get16be(s); return((uint)((z << 16) + stbi__get16be(s))); }
static int stbi__get16be(stbi__context* s) { int z = stbi__get8(s); return (z << 8) + stbi__get8(s); }
static byte* stbi__load_flip(stbi__context* s, int* x, int* y, int* comp, int req_comp) { byte* result = stbi__load_main(s, x, y, comp, req_comp); if (stbi__vertically_flip_on_load != 0 && result != null) { int w = *x, h = *y; int depth = req_comp != 0 ? req_comp : *comp; int row, col, z; byte temp; // @OPTIMIZE: use a bigger temp buffer and memcpy multiple pixels at once for (row = 0; row < (h >> 1); row++) { for (col = 0; col < w; col++) { for (z = 0; z < depth; z++) { temp = result[(row * w + col) * depth + z]; result[(row * w + col) * depth + z] = result[((h - row - 1) * w + col) * depth + z]; result[((h - row - 1) * w + col) * depth + z] = temp; } } } } return result; }
static byte* stbi__load_main(stbi__context* s, int* x, int* y, int* comp, int req_comp) { //#if !STBI_NO_JPEG //if (stbi__jpeg_test(s)) return stbi__jpeg_load(s, x, y, comp, req_comp); //#endif //#if !STBI_NO_PNG if (stbi__png_test(s) != 0) return stbi__png_load(s, x, y, comp, req_comp); //#endif //#if !STBI_NO_BMP // if (stbi__bmp_test(s)) return stbi__bmp_load(s, x, y, comp, req_comp); //#endif //#if !STBI_NO_GIF // if (stbi__gif_test(s)) return stbi__gif_load(s, x, y, comp, req_comp); //#endif //#if !STBI_NO_PSD // if (stbi__psd_test(s)) return stbi__psd_load(s, x, y, comp, req_comp); //#endif //#if !STBI_NO_PIC // if (stbi__pic_test(s)) return stbi__pic_load(s, x, y, comp, req_comp); //#endif //#if !STBI_NO_PNM // if (stbi__pnm_test(s)) return stbi__pnm_load(s, x, y, comp, req_comp); //#endif //#if !STBI_NO_HDR // if (stbi__hdr_test(s)) // { // float* hdr = stbi__hdr_load(s, x, y, comp, req_comp); // return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp); // } //#endif //#if !STBI_NO_TGA // // test tga last because it's a crappy test! // if (stbi__tga_test(s)) // return stbi__tga_load(s, x, y, comp, req_comp); //#endif throw new Exception("unknown image type:Image not of any known type, or corrupt"); }
static uint stbi__get32le(stbi__context* s) { uint z = (uint)stbi__get16le(s); return z + ((uint)stbi__get16le(s) << 16); }
static int stbi__get16le(stbi__context* s) { int z = stbi__get8(s); return z + (stbi__get8(s) << 8); }
public static int stbi__get16be(stbi__context s) { var z = (int)stbi__get8(s); return((z << 8) + stbi__get8(s)); }
static stbi__pngchunk stbi__get_chunk_header(stbi__context* s) { stbi__pngchunk c; c.length = stbi__get32be(s); c.type = stbi__get32be(s); return c; }
public static int stbi__get16le(stbi__context s) { var z = (int)stbi__get8(s); return(z + (stbi__get8(s) << 8)); }
////static void stbi__refill_buffer(stbi__context* s) ////{ //// int n = s->io._read(s->io_user_data, (sbyte*)s->buffer_start, s->buflen); //// if (n == 0) //// { //// // at end of file, treat same as if from memory, but need to handle case //// // where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file //// s->read_from_callbacks = 0; //// s->img_buffer = s->buffer_start; //// s->img_buffer_end = s->buffer_start + 1; //// *s->img_buffer = 0; //// } //// else //// { //// s->img_buffer = s->buffer_start; //// s->img_buffer_end = s->buffer_start + n; //// } ////} static byte stbi__get8(stbi__context* s) { if (s->img_buffer < s->img_buffer_end) return *s->img_buffer++; ////if (s->read_from_callbacks != 0) ////{ //// stbi__refill_buffer(s); //// return *s->img_buffer++; ////} return 0; }
public static void *stbi__tga_load(stbi__context s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) { var tga_offset = (int)stbi__get8(s); var tga_indexed = (int)stbi__get8(s); var tga_image_type = (int)stbi__get8(s); var tga_is_RLE = 0; var tga_palette_start = stbi__get16le(s); var tga_palette_len = stbi__get16le(s); var tga_palette_bits = (int)stbi__get8(s); var tga_x_origin = stbi__get16le(s); var tga_y_origin = stbi__get16le(s); var tga_width = stbi__get16le(s); var tga_height = stbi__get16le(s); var tga_bits_per_pixel = (int)stbi__get8(s); var tga_comp = 0; var tga_rgb16 = 0; var tga_inverted = (int)stbi__get8(s); byte *tga_data; byte *tga_palette = null; var i = 0; var j = 0; var raw_data = stackalloc byte[4]; raw_data[0] = 0; var RLE_count = 0; var RLE_repeating = 0; var read_next_pixel = 1; if (tga_image_type >= 8) { tga_image_type -= 8; tga_is_RLE = 1; } tga_inverted = 1 - ((tga_inverted >> 5) & 1); if (tga_indexed != 0) { tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16); } else { tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3) ? 1 : 0, &tga_rgb16); } if (tga_comp == 0) { return((byte *)(ulong)((stbi__err("bad format") != 0) ? (byte *)null : null)); } *x = tga_width; *y = tga_height; if (comp != null) { *comp = tga_comp; } if (stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0) == 0) { return((byte *)(ulong)((stbi__err("too large") != 0) ? (byte *)null : null)); } tga_data = (byte *)stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0); if (tga_data == null) { return((byte *)(ulong)((stbi__err("outofmem") != 0) ? (byte *)null : null)); } stbi__skip(s, tga_offset); if ((tga_indexed == 0) && (tga_is_RLE == 0) && (tga_rgb16 == 0)) { for (i = 0; i < tga_height; ++i) { var row = tga_inverted != 0 ? tga_height - i - 1 : i; var tga_row = tga_data + row * tga_width * tga_comp; stbi__getn(s, tga_row, tga_width * tga_comp); } } else { if (tga_indexed != 0) { stbi__skip(s, tga_palette_start); tga_palette = (byte *)stbi__malloc_mad2(tga_palette_len, tga_comp, 0); if (tga_palette == null) { CRuntime.free(tga_data); return((byte *)(ulong)((stbi__err("outofmem") != 0) ? (byte *)null : null)); } if (tga_rgb16 != 0) { var pal_entry = tga_palette; for (i = 0; i < tga_palette_len; ++i) { stbi__tga_read_rgb16(s, pal_entry); pal_entry += tga_comp; } } else { if (stbi__getn(s, tga_palette, tga_palette_len * tga_comp) == 0) { CRuntime.free(tga_data); CRuntime.free(tga_palette); return((byte *)(ulong)((stbi__err("bad palette") != 0) ? (byte *)null : null)); } } } for (i = 0; i < tga_width * tga_height; ++i) { if (tga_is_RLE != 0) { if (RLE_count == 0) { var RLE_cmd = (int)stbi__get8(s); RLE_count = 1 + (RLE_cmd & 127); RLE_repeating = RLE_cmd >> 7; read_next_pixel = 1; } else { if (RLE_repeating == 0) { read_next_pixel = 1; } } } else { read_next_pixel = 1; } if (read_next_pixel != 0) { if (tga_indexed != 0) { var pal_idx = (tga_bits_per_pixel == 8) ? stbi__get8(s) : stbi__get16le(s); if (pal_idx >= tga_palette_len) { pal_idx = 0; } pal_idx *= tga_comp; for (j = 0; j < tga_comp; ++j) { raw_data[j] = tga_palette[pal_idx + j]; } } else { if (tga_rgb16 != 0) { stbi__tga_read_rgb16(s, raw_data); } else { for (j = 0; j < tga_comp; ++j) { raw_data[j] = stbi__get8(s); } } } read_next_pixel = 0; } for (j = 0; j < tga_comp; ++j) { tga_data[i * tga_comp + j] = raw_data[j]; } --RLE_count; } if (tga_inverted != 0) { for (j = 0; j * 2 < tga_height; ++j) { var index1 = j * tga_width * tga_comp; var index2 = (tga_height - 1 - j) * tga_width * tga_comp; for (i = tga_width * tga_comp; i > 0; --i) { var temp = tga_data[index1]; tga_data[index1] = tga_data[index2]; tga_data[index2] = temp; ++index1; ++index2; } } } if (tga_palette != null) { CRuntime.free(tga_palette); } } if ((tga_comp >= 3) && (tga_rgb16 == 0)) { var tga_pixel = tga_data; for (i = 0; i < tga_width * tga_height; ++i) { var temp = tga_pixel[0]; tga_pixel[0] = tga_pixel[2]; tga_pixel[2] = temp; tga_pixel += tga_comp; } } if (req_comp != 0 && req_comp != tga_comp) { tga_data = stbi__convert_format(tga_data, tga_comp, req_comp, (uint)tga_width, (uint)tga_height); } tga_palette_start = tga_palette_len = tga_palette_bits = tga_x_origin = tga_y_origin = 0; return(tga_data); }
static int stbi__png_info(stbi__context* s, int* x, int* y, int* comp) { stbi__png p; p.s = s; return stbi__png_info_raw(&p, x, y, comp); }
public static void stbi__skip(stbi__context s, int skip) { s.Stream.Seek(skip, SeekOrigin.Current); }
static byte* stbi__png_load(stbi__context* s, int* x, int* y, int* comp, int req_comp) { stbi__png p; p.s = s; return stbi__do_png(&p, x, y, comp, req_comp); }
public static int stbi__at_eof(stbi__context s) { return((s.Stream.Position == s.Stream.Length) ? 1 : 0); }
static int stbi__png_test(stbi__context* s) { int r; r = stbi__check_png_header(s); stbi__rewind(s); return r; }