this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add BPP arg to sprites import (#2452)

* add bpp arg

* try to extract declaration jank?

* bit endian doesn't make sense

authored by

Bulby and committed by
GitHub
5cee27b4 0602c496

+39 -4
+39 -4
src/studio/screens/console.c
··· 29 29 #include "ext/png.h" 30 30 #include "zip.h" 31 31 #include "studio/demos.h" 32 + #include "retro_endianness.h" 32 33 33 34 #if defined(TIC80_PRO) 34 35 #include "studio/project.h" ··· 99 100 macro(y) \ 100 101 macro(w) \ 101 102 macro(h) \ 102 - macro(vbank) 103 + macro(vbank) \ 104 + macro(bpp) 103 105 104 106 #define EXPORT_CMD_LIST(macro) \ 105 107 macro(win) \ ··· 1745 1747 { 1746 1748 png_buffer png = {(u8*)buffer, size}; 1747 1749 bool error = true; 1750 + s32 bpp = params.bpp ? params.bpp : 4; 1751 + switch (bpp) { 1752 + case 1: 1753 + case 2: 1754 + case 4: 1755 + break; 1756 + default: 1757 + // not real! 1758 + goto exit; 1759 + } 1748 1760 1749 1761 png_img img = png_read(png, NULL); 1750 1762 ··· 1752 1764 { 1753 1765 const tic_palette* pal = getPalette(console, params.bank, params.vbank); 1754 1766 1767 + s32 bpp_scale = 5 - bpp; 1768 + u32 color1, color2, color3, color4, color; 1769 + 1755 1770 for(s32 j = 0, y = params.y, h = y + (params.h ? params.h : img.height); y < h; ++y, ++j) 1756 - for(s32 i = 0, x = params.x, w = x + (params.w ? params.w : img.width); x < w; ++x, ++i) 1771 + for(s32 i = 0, x = params.x, w = x + ((params.w ? params.w : img.width) / bpp_scale); x < w; ++x, i += bpp_scale) 1757 1772 if(x >= 0 && x < TIC_SPRITESHEET_SIZE && y >= 0 && y < TIC_SPRITESHEET_SIZE) 1758 - setSpritePixel(base, x, y, tic_nearest_color(pal->colors, 1759 - (tic_rgb*)(img.pixels + i + j * img.width), TIC_PALETTE_SIZE)); 1773 + switch (bpp) { 1774 + case 4: 1775 + setSpritePixel(base, x, y, tic_nearest_color(pal->colors, 1776 + (tic_rgb*)(img.pixels + i + j * img.width), TIC_PALETTE_SIZE)); 1777 + break; 1778 + case 2: 1779 + color1 = tic_nearest_color(pal->colors, (tic_rgb*)(img.pixels + i + j * img.width), 4); 1780 + color2 = tic_nearest_color(pal->colors, (tic_rgb*)(img.pixels + i + 1 + j * img.width), 4); 1781 + // unsure if it's better to do add or or it together. 1782 + color = (color2 << 2) + color1; 1783 + setSpritePixel(base, x, y, color); 1784 + break; 1785 + case 1: 1786 + color1 = tic_nearest_color(pal->colors, (tic_rgb*)(img.pixels + i + j * img.width), 2); 1787 + color2 = tic_nearest_color(pal->colors, (tic_rgb*)(img.pixels + i + 1 + j * img.width), 2); 1788 + color3 = tic_nearest_color(pal->colors, (tic_rgb*)(img.pixels + i + 2 + j * img.width), 2); 1789 + color4 = tic_nearest_color(pal->colors, (tic_rgb*)(img.pixels + i + 3 + j * img.width), 2); 1790 + color = (color4 << 3) + (color3 << 2) + (color2 << 1) + color1; 1791 + setSpritePixel(base, x, y, color); 1792 + break; 1793 + } 1760 1794 1761 1795 error = false; 1762 1796 } 1763 1797 1798 + exit: 1764 1799 onFileImported(console, name, !error); 1765 1800 } 1766 1801