История изменений
Исправление LINUX-ORG-RU, (текущая версия) :
Пол часаполтора я тупил жестоко потратил
gcc main.c -lpng16 && ./a.out pixmap.txt
#include <png.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
void icon_pixmap_to_png(char * raw_data,const char * out_filename)
{
assert(raw_data);
assert(out_filename);
int sx = 0;
int sy = 0;
sscanf(raw_data,"%d, %d, {",&sx,&sy);
assert(sx);
assert(sy);
char * imgdata = malloc((sx*sy*4));
assert(imgdata);
char minibuff[20];
memset(minibuff,0,sizeof(minibuff));
char * data = strstr(raw_data,"{");
assert(data);
int channel_color = 0;
for (int i = 0,mbc=0,imc=0;data[i] !='\0'; ++i)
{
switch(data[i])
{
case ' ': break;
case '{': break;
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': minibuff[mbc++]=data[i]; break;
case '}': goto write_image;
case ',':
{
minibuff[++mbc]='\0';
sscanf(minibuff,"%d",&channel_color);
imgdata[imc++]=channel_color;
memset(minibuff,0,sizeof(minibuff));
mbc=0;
}
}
}
/*http://www.libpng.org/pub/png/libpng-manual.txt*/
write_image:
png_image png_image;
memset(&png_image, 0, sizeof (png_image));
png_image.version = PNG_IMAGE_VERSION;
png_image.format = PNG_FORMAT_ARGB;
png_image.height = sy;
png_image.width = sx;
png_image_write_to_file(&png_image,out_filename,0,imgdata,0, NULL);
free(imgdata);
}
int main(int argc, char *argv[])
{
assert(argc-1);
char * input = argv[argc-1];
FILE * file = fopen(input,"r");
assert(file);
fseek(file,0,SEEK_END);
int flen = ftell(file);
fseek(file,0,SEEK_SET);
char * fdata = malloc(flen+1);
assert(fdata);
fread(fdata,1,flen,file);
icon_pixmap_to_png(fdata,"out.png");
fclose(file);
free(fdata);
return 0;
}
Теперь я умею маненько libpng
использовать. :3
Что там за }], [Argument: (iiay)
даже проверять не стал.
Формат на глаз такой ширина, высота, {A, R, G, B,...}
Исправление LINUX-ORG-RU, :
Пол часаполтора я тупил жестоко потратил
gcc main.c -lpng16 && ./a.out pixmap.txt
#include <png.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
void icon_pixmap_to_png(char * raw_data,const char * out_filename)
{
assert(raw_data);
assert(out_filename);
int sx = 0;
int sy = 0;
sscanf(raw_data,"%d, %d, {",&sx,&sy);
assert(sx);
assert(sy);
char * imgdata = malloc((sx*sy*4));
assert(imgdata);
char minibuff[20];
memset(minibuff,0,sizeof(minibuff));
char * data = strstr(raw_data,"{");
assert(data);
int channel_color = 0;
for (int i = 0,mbc=0,imc=0;data[i] !='\0'; ++i)
{
switch(data[i])
{
case ' ': break;
case '{': break;
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': minibuff[mbc++]=data[i]; break;
case '}': goto write_image;
case ',':
{
minibuff[++mbc]='\0';
sscanf(minibuff,"%d",&channel_color);
imgdata[imc++]=channel_color;
memset(minibuff,0,sizeof(minibuff));
mbc=0;
}
}
}
/*http://www.libpng.org/pub/png/libpng-manual.txt*/
write_image:
png_image png_image;
memset(&png_image, 0, sizeof (png_image));
png_image.version = PNG_IMAGE_VERSION;
png_image.format = PNG_FORMAT_ARGB;
png_image.height = sy;
png_image.width = sx;
png_image_write_to_file(&png_image,out_filename,0,imgdata,0, NULL);
free(imgdata);
}
int main(int argc, char *argv[])
{
assert(argc-1);
char * input = argv[argc-1];
FILE * file = fopen(input,"r");
assert(file);
fseek(file,0,SEEK_END);
int flen = ftell(file);
fseek(file,0,SEEK_SET);
char * fdata = malloc(flen+1);
assert(fdata);
fread(fdata,1,flen,file);
icon_pixmap_to_png(fdata,"out.png");
fclose(file);
free(fdata);
return 0;
}
Теперь я умею маненько libpng
использовать. :3
Что там за }], [Argument: (iiay)
даже проверять не стал.
Формат на глаз такой ширина, высота, {A, R, G, B,...}
Исходная версия LINUX-ORG-RU, :
Пол часаполтора я тупил жестоко потратил gcc main.c -lpng16 && ./a.out pixmap.txt
#include <png.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
void icon_pixmap_to_png(char * raw_data,const char * out_filename)
{
assert(raw_data);
assert(out_filename);
int sx = 0;
int sy = 0;
sscanf(raw_data,"%d, %d, {",&sx,&sy);
assert(sx);
assert(sy);
char * imgdata = malloc((sx*sy*4));
assert(imgdata);
char minibuff[20];
memset(minibuff,0,sizeof(minibuff));
char * data = strstr(raw_data,"{");
assert(data);
int channel_color = 0;
for (int i = 0,mbc=0,imc=0;data[i] !='\0'; ++i)
{
switch(data[i])
{
case ' ': break;
case '{': break;
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': minibuff[mbc++]=data[i]; break;
case '}': goto write_image;
case ',':
{
minibuff[++mbc]='\0';
sscanf(minibuff,"%d",&channel_color);
imgdata[imc++]=channel_color;
memset(minibuff,0,sizeof(minibuff));
mbc=0;
}
}
}
/*http://www.libpng.org/pub/png/libpng-manual.txt*/
write_image:
png_image png_image;
memset(&png_image, 0, sizeof (png_image));
png_image.version = PNG_IMAGE_VERSION;
png_image.format = PNG_FORMAT_ARGB;
png_image.height = sy;
png_image.width = sx;
png_image_write_to_file(&png_image,out_filename,0,imgdata,0, NULL);
free(imgdata);
}
int main(int argc, char *argv[])
{
assert(argc-1);
char * input = argv[argc-1];
FILE * file = fopen(input,"r");
assert(file);
fseek(file,0,SEEK_END);
int flen = ftell(file);
fseek(file,0,SEEK_SET);
char * fdata = malloc(flen+1);
assert(fdata);
fread(fdata,1,flen,file);
icon_pixmap_to_png(fdata,"out.png");
fclose(file);
free(fdata);
return 0;
}
Теперь я умею маненько libpng
использовать. :3
Что там за }], [Argument: (iiay)
даже проверять не стал.
Формат на глаз такой ширина, высота, {A, R, G, B,...}