Lines Matching +full:arr +full:- +full:diff
3 // SPDX-License-Identifier: MIT
6 /* stb_image_write - v1.06 - public domain - http://nothings.org/stb/stb_image_write.h
7 writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
16 Will probably not work correctly with strict-aliasing optimizations.
23 The PNG output is not optimal; it is 20-50% larger than the file
26 or run-time performance.
46 expected to open/close your file-equivalent before and after calling these:
61 Each function returns 0 on failure and non-0 on success.
64 is a rectangle of pixels stored from left-to-right, top-to-bottom.
65 Each pixel contains 'comp' channels of data stored interleaved with 8-bits
68 The *data pointer points to the first byte of the top-left-most pixel.
77 data are not consecutive in memory (e.g. sub-rectangles of a larger image),
79 formats do not. (Thus you cannot write a native-format BMP through the BMP
83 HDR expects linear float data. Since the format is always 32-bit rgb(e)
87 TGA supports RLE or non-RLE compressed data. To use non-RLE-compressed
101 Jean-Sebastien Guay
222 // initialize a callback-based context
225 s->func = c; in stbi__start_write_callbacks()
226 s->context = context; in stbi__start_write_callbacks()
245 fclose((FILE *)s->context); in stbi__end_write_file()
251 typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1];
265 s->func(s->context,&x,1); in stbiw__writefv()
271 s->func(s->context,b,2); in stbiw__writefv()
279 s->func(s->context,b,4); in stbiw__writefv()
298 s->func(s->context, &c, 1); in stbiw__putc()
303 unsigned char arr[3]; in stbiw__write3() local
304 arr[0] = a, arr[1] = b, arr[2] = c; in stbiw__write3()
305 s->func(s->context, arr, 3); in stbiw__write3()
314 s->func(s->context, &d[comp - 1], 1); in stbiw__write_pixel()
317 case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case in stbiw__write_pixel()
322 s->func(s->context, d, 1); // monochrome TGA in stbiw__write_pixel()
328 px[k] = bg[k] + ((d[k] - bg[k]) * d[3]) / 255; in stbiw__write_pixel()
329 stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]); in stbiw__write_pixel()
334 stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]); in stbiw__write_pixel()
338 s->func(s->context, &d[comp - 1], 1); in stbiw__write_pixel()
350 j_end = -1, j = y-1; in stbiw__write_pixels()
359 s->func(s->context, &zero, scanline_pad); in stbiw__write_pixels()
379 int pad = (-x*3) & 3; in stbi_write_bmp_core()
380 return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad, in stbi_write_bmp_core()
409 int colorbytes = has_alpha ? comp-1 : comp; in stbi_write_tga_core()
416 return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0, in stbi_write_tga_core()
423 for (j = y - 1; j >= 0; --j) { in stbi_write_tga_core()
429 int diff = 1; in stbi_write_tga_core() local
432 if (i < x - 1) { in stbi_write_tga_core()
434 diff = memcmp(begin, row + (i + 1) * comp, comp); in stbi_write_tga_core()
435 if (diff) { in stbi_write_tga_core()
442 --len; in stbi_write_tga_core()
457 if (diff) { in stbi_write_tga_core()
458 unsigned char header = STBIW_UCHAR(len - 1); in stbi_write_tga_core()
459 s->func(s->context, &header, 1); in stbi_write_tga_core()
461 stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp); in stbi_write_tga_core()
464 unsigned char header = STBIW_UCHAR(len - 129); in stbi_write_tga_core()
465 s->func(s->context, &header, 1); in stbi_write_tga_core()
466 stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin); in stbi_write_tga_core()
505 if (maxcomp < 1e-32f) { in stbiw__linear_to_rgbe()
521 s->func(s->context, &lengthbyte, 1); in stbiw__write_run_data()
522 s->func(s->context, &databyte, 1); in stbiw__write_run_data()
529 s->func(s->context, &lengthbyte, 1); in stbiw__write_dump_data()
530 s->func(s->context, data, length); in stbiw__write_dump_data()
557 s->func(s->context, rgbe, 4); in stbiw__write_hdr_scanline()
580 s->func(s->context, scanlineheader, 4); in stbiw__write_hdr_scanline()
599 int len = r-x; in stbiw__write_hdr_scanline()
611 int len = r-x; in stbiw__write_hdr_scanline()
631 char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; in stbi_write_hdr_core()
632 s->func(s->context, header, sizeof(header)-1); in stbi_write_hdr_core()
634 len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); in stbi_write_hdr_core()
635 s->func(s->context, buffer, len); in stbi_write_hdr_core()
670 // stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size()
671 #define stbiw__sbraw(a) ((int *) (a) - 2)
683 static void *stbiw__sbgrowf(void **arr, int increment, int itemsize) in stbiw__sbgrowf() argument
685 int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1; in stbiw__sbgrowf()
686 …void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + s… in stbiw__sbgrowf()
689 if (!*arr) ((int *) p)[1] = 0; in stbiw__sbgrowf()
690 *arr = (void *) ((int *) p + 2); in stbiw__sbgrowf()
691 stbiw__sbm(*arr) = m; in stbiw__sbgrowf()
693 return *arr; in stbiw__sbgrowf()
701 *bitcount -= 8; in stbiw__zlib_flushf()
709 while (codebits--) { in stbiw__zlib_bitrev()
742 #define stbiw__zlib_huff2(n) stbiw__zlib_huffa(0x190 + (n)-144, 9)
743 #define stbiw__zlib_huff3(n) stbiw__zlib_huffa(0 + (n)-256,7)
744 #define stbiw__zlib_huff4(n) stbiw__zlib_huffa(0xc0 + (n)-280,8)
765 stbiw__zlib_add(1,2); // BTYPE = 1 -- fixed huffman in stbi_zlib_compress()
771 while (i < data_len-3) { in stbi_zlib_compress()
773 int h = stbiw__zhash(data+i)&(stbiw__ZHASH-1), best=3; in stbi_zlib_compress()
778 if (hlist[j]-data > i-32768) { // if entry lies within window in stbi_zlib_compress()
779 int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i); in stbi_zlib_compress()
791 // "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal in stbi_zlib_compress()
792 h = stbiw__zhash(data+i+1)&(stbiw__ZHASH-1); in stbi_zlib_compress()
796 if (hlist[j]-data > i-32767) { in stbi_zlib_compress()
797 int e = stbiw__zlib_countm(hlist[j], data+i+1, data_len-i-1); in stbi_zlib_compress()
807 int d = (int) (data+i - bestloc); // distance back in stbi_zlib_compress()
809 for (j=0; best > lengthc[j+1]-1; ++j); in stbi_zlib_compress()
811 if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]); in stbi_zlib_compress()
812 for (j=0; d > distc[j+1]-1; ++j); in stbi_zlib_compress()
814 if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]); in stbi_zlib_compress()
906 unsigned int crc = stbiw__crc32(*data - len - 4, len+4); in stbiw__wpcrc()
912 int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c); in stbiw__paeth()
918 // @OPTIMIZE: provide an option that always forces left-predict or paeth predict
921 int ctype[5] = { -1, 0, 4, 2, 6 }; in stbi_write_png_to_mem()
945 case 2: line_buffer[i] = z[i] - z[i-stride_bytes]; break; in stbi_write_png_to_mem()
946 case 3: line_buffer[i] = z[i] - (z[i-stride_bytes]>>1); break; in stbi_write_png_to_mem()
947 … case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-stride_bytes],0)); break; in stbi_write_png_to_mem()
954 case 1: line_buffer[i] = z[i] - z[i-n]; break; in stbi_write_png_to_mem()
955 case 2: line_buffer[i] = z[i] - z[i-stride_bytes]; break; in stbi_write_png_to_mem()
956 case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-stride_bytes])>>1); break; in stbi_write_png_to_mem()
957 …case 4: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-stride_bytes], z[i-stride_bytes-n]); brea… in stbi_write_png_to_mem()
958 case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break; in stbi_write_png_to_mem()
959 case 6: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break; in stbi_write_png_to_mem()
1043 * public domain Simple, Minimalistic JPEG writer - http://www.jonolick.com/code.html
1052 bitBuf |= bs[0] << (24 - bitCnt); in stbiw__jpg_writeBits()
1060 bitCnt -= 8; in stbiw__jpg_writeBits()
1071 float tmp7 = d0 - d7; in stbiw__jpg_DCT()
1073 float tmp6 = d1 - d6; in stbiw__jpg_DCT()
1075 float tmp5 = d2 - d5; in stbiw__jpg_DCT()
1077 float tmp4 = d3 - d4; in stbiw__jpg_DCT()
1081 float tmp13 = tmp0 - tmp3; in stbiw__jpg_DCT()
1083 float tmp12 = tmp1 - tmp2; in stbiw__jpg_DCT()
1086 d4 = tmp10 - tmp11; in stbiw__jpg_DCT()
1090 d6 = tmp13 - z1; in stbiw__jpg_DCT()
1097 // The rotator is modified from fig 4-8 to avoid extra negations. in stbiw__jpg_DCT()
1098 z5 = (tmp10 - tmp12) * 0.382683433f; // c6 in stbiw__jpg_DCT()
1099 z2 = tmp10 * 0.541196100f + z5; // c2-c6 in stbiw__jpg_DCT()
1104 z13 = tmp7 - z3; in stbiw__jpg_DCT()
1107 *d3p = z13 - z2; in stbiw__jpg_DCT()
1109 *d7p = z11 - z4; in stbiw__jpg_DCT()
1115 int tmp1 = val < 0 ? -val : val; in stbiw__jpg_calcBits()
1116 val = val < 0 ? val-1 : val; in stbiw__jpg_calcBits()
1121 bits[0] = val & ((1<<bits[1])-1); in stbiw__jpg_calcBits()
1127 int dataOff, i, diff, end0pos; in stbiw__jpg_processDU() local
1141 // DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f)); in stbiw__jpg_processDU()
1143 DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? v - 0.5f : v + 0.5f); in stbiw__jpg_processDU()
1147 diff = DU[0] - DC; in stbiw__jpg_processDU()
1148 if (diff == 0) { in stbiw__jpg_processDU()
1152 stbiw__jpg_calcBits(diff, bits); in stbiw__jpg_processDU()
1158 for(; (end0pos>0)&&(DU[end0pos]==0); --end0pos) { in stbiw__jpg_processDU()
1171 nrzeroes = i-startpos; in stbiw__jpg_processDU()
1271 quality = quality < 50 ? 5000 / quality : 200 - quality * 2; in stbi_write_jpg_core()
1293 s->func(s->context, (void*)head0, sizeof(head0)); in stbi_write_jpg_core()
1294 s->func(s->context, (void*)YTable, sizeof(YTable)); in stbi_write_jpg_core()
1296 s->func(s->context, UVTable, sizeof(UVTable)); in stbi_write_jpg_core()
1297 s->func(s->context, (void*)head1, sizeof(head1)); in stbi_write_jpg_core()
1298 s->func(s->context, (void*)(std_dc_luminance_nrcodes+1), sizeof(std_dc_luminance_nrcodes)-1); in stbi_write_jpg_core()
1299 s->func(s->context, (void*)std_dc_luminance_values, sizeof(std_dc_luminance_values)); in stbi_write_jpg_core()
1301 s->func(s->context, (void*)(std_ac_luminance_nrcodes+1), sizeof(std_ac_luminance_nrcodes)-1); in stbi_write_jpg_core()
1302 s->func(s->context, (void*)std_ac_luminance_values, sizeof(std_ac_luminance_values)); in stbi_write_jpg_core()
1304 … s->func(s->context, (void*)(std_dc_chrominance_nrcodes+1), sizeof(std_dc_chrominance_nrcodes)-1); in stbi_write_jpg_core()
1305 s->func(s->context, (void*)std_dc_chrominance_values, sizeof(std_dc_chrominance_values)); in stbi_write_jpg_core()
1307 … s->func(s->context, (void*)(std_ac_chrominance_nrcodes+1), sizeof(std_ac_chrominance_nrcodes)-1); in stbi_write_jpg_core()
1308 s->func(s->context, (void*)std_ac_chrominance_values, sizeof(std_ac_chrominance_values)); in stbi_write_jpg_core()
1309 s->func(s->context, (void*)head2, sizeof(head2)); in stbi_write_jpg_core()
1329 p -= width*comp*(row+1 - height); in stbi_write_jpg_core()
1332 p -= comp*(col+1 - width); in stbi_write_jpg_core()
1338 YDU[pos]=+0.29900f*r+0.58700f*g+0.11400f*b-128; in stbi_write_jpg_core()
1339 UDU[pos]=-0.16874f*r-0.33126f*g+0.50000f*b; in stbi_write_jpg_core()
1340 VDU[pos]=+0.50000f*r-0.41869f*g-0.08131f*b; in stbi_write_jpg_core()
1385 1.06 (2017-07-23)
1388 1.04 (2017-03-03)
1391 1.02 (2016-04-02)
1393 1.01 (2016-01-16)
1395 avoid race-condition in crc initialization
1397 1.00 (2015-09-14)
1399 0.99 (2015-09-13)
1401 0.98 (2015-04-08)
1403 0.97 (2015-01-18)
1405 0.96 (2015-01-17)
1408 0.95 (2014-08-17)
1410 0.94 (2014-05-31)
1412 0.93 (2014-05-27)
1414 0.92 (2010-08-01)
1416 0.91 (2010-07-17)
1422 ------------------------------------------------------------------------------
1440 ------------------------------------------------------------------------------