public uint png_get_sPLT(ref png_sPLT_t[] spalettes) { if((info_ptr_valid&PNG_INFO.sPLT)!=PNG_INFO.sPLT) return 0; spalettes=info_ptr_splt_palettes.ToArray(); return (uint)info_ptr_splt_palettes.Count; }
public void png_set_sPLT(png_sPLT_t entry) { if(info_ptr_splt_palettes==null) info_ptr_splt_palettes=new List<png_sPLT_t>(); info_ptr_splt_palettes.Add(entry); info_ptr_valid|=PNG_INFO.sPLT; }
public void png_set_sPLT(png_sPLT_t[] entries) { if(entries==null||entries.Length==0) { Debug.WriteLine("Ignoring attempt to set empty sPLT"); return; } if(info_ptr_splt_palettes==null) info_ptr_splt_palettes=new List<png_sPLT_t>(); info_ptr_splt_palettes.AddRange(entries); info_ptr_valid|=PNG_INFO.sPLT; }
// write a sPLT chunk void png_write_sPLT(png_sPLT_t spalette) { uint name_len; byte[] new_name=null; byte[] entrybuf=new byte[10]; uint entry_size=(uint)(spalette.depth==8?6:10); uint palette_size=entry_size*spalette.nentries; if((name_len=png_check_keyword(spalette.name, ref new_name))==0) return; // make sure we include the NULL after the name png_write_chunk_start(PNG.sPLT, (uint)(name_len+2+palette_size)); png_write_chunk_data(new_name, name_len+1); entrybuf[0]=spalette.depth; png_write_chunk_data(entrybuf, 1); // loop through each palette entry, writing appropriately for(uint i=0; i<spalette.nentries; i++) { png_sPLT_entry ep=spalette.entries[i]; if(spalette.depth==8) { entrybuf[0]=(byte)ep.red; entrybuf[1]=(byte)ep.green; entrybuf[2]=(byte)ep.blue; entrybuf[3]=(byte)ep.alpha; png_save_uint_16(entrybuf, 4, ep.frequency); } else { png_save_uint_16(entrybuf, ep.red); png_save_uint_16(entrybuf, 2, ep.green); png_save_uint_16(entrybuf, 4, ep.blue); png_save_uint_16(entrybuf, 6, ep.alpha); png_save_uint_16(entrybuf, 8, ep.frequency); } png_write_chunk_data(entrybuf, entry_size); } png_write_chunk_end(); }