Skip to main content
Commonmark migration
Source Link

#C++, 979 969 898 859 848 bytes

C++, 979 969 898 859 848 bytes

#C++, 979 969 898 859 848 bytes

C++, 979 969 898 859 848 bytes

formatting tweaks
Source Link
p4plus2
  • 111
  • 4

#C++, 979 969 898 859 859848 bytes

#include<cstdio>
#include<cstdlib>
#define K 400
#define L 400
#define M (i*)malloc(sizeof(i))
#define a(C,X,Y)if(C&&b[Y][X].c){t->n=M;t=t->n;b[Y][X].d=d+1;t->n=0;t->c=X;t->d=Y;}
#define A(n,d)case n:d;break;
#define F fgetc(f)
#define W(A,B) for(A=0;A<B;A++){
struct i{int c;int d;int v;i*n;}b[L][K]={0},*h,*t;float m=0;int main(){FILE*f=fopen("d","r+b");int x,y,d=0;W(y,L)W(x,K)b[y][x].c=F<<16|F<<8|F;}}rewind(f);x=165,y=155;h=M;h->c=x;h->d=y;b[y][x].d=d;t=h;while(h){i*p=&b[hi*p=b[h->d][h>d]+h->c];if>c;if(p->v){h=h->n;continue;}>n;else{p->v=1;x=h->c;y=h->d;d=p->d;m=d>m?d:m;a(x>0,x-1,y)a(x<K-1,x+1,y)a(y>0,x,y-1)a(y<L-1,x,y+1)}}W(y,L)W(x,K)i p=b[y][x];unsigned char n=-1,h=p.d/(m/n),R=h%43*6,Q=n*(n-(n*R>>8))>>8,t=n*(n-(n*(n-R)>>8))>>8,r=0r,g=0g,b=0;switchb;switch(h/43){A(0,r=n;g=tn,t,0)A(1,r=Q;g=nQ,n,0)A(2,g=n;b=t0,n,t)A(3,g=Q;b=n0,Q,n)A(4,r=t;b=nt,0,n)A(5,r=n;b=Qn,0,Q)}d=h?r|g<<8|b<<16:p.c?-1:0;fwrite(&d,1,3,f);}}}

Many concepts remain similar, but there are certainly a myriad of tiny changes. To compile that as C you do need to use C11 (C99 will probably work but I only strictly tested in C11).
I quite enjoyed this challenge, thanks for giving me the idea to try something new :).
Edit: Golf'd a bit better. 
Edit2: Merged two structs so my pixel struct and queue are the same, bit more macro abuse, and reflowed uses of 255 such that it can be defined as -1 when defining a series of unsigned chars, and lastly removed a function call. 
Edit3: Reused a few more variables, operator precedence tweaks, and output converted to RGB saving the alpha channel
Edit4: I think I am done with this now, some pointer arithmetic changes and slight control flow tweaks.

#C++, 979 969 898 859 bytes

#include<cstdio>
#include<cstdlib>
#define K 400
#define L 400
#define M (i*)malloc(sizeof(i))
#define a(C,X,Y)if(C&&b[Y][X].c){t->n=M;t=t->n;b[Y][X].d=d+1;t->n=0;t->c=X;t->d=Y;}
#define A(n,d)case n:d;break;
#define F fgetc(f)
#define W(A,B) for(A=0;A<B;A++){
struct i{int c;int d;int v;i*n;}b[L][K]={0},*h,*t;float m=0;int main(){FILE*f=fopen("d","r+b");int x,y,d=0;W(y,L)W(x,K)b[y][x].c=F<<16|F<<8|F;}}rewind(f);x=165,y=155;h=M;h->c=x;h->d=y;b[y][x].d=d;t=h;while(h){i*p=&b[h->d][h->c];if(p->v){h=h->n;continue;}p->v=1;x=h->c;y=h->d;d=p->d;m=d>m?d:m;a(x>0,x-1,y)a(x<K-1,x+1,y)a(y>0,x,y-1)a(y<L-1,x,y+1)}W(y,L)W(x,K)i p=b[y][x];unsigned char n=-1,h=p.d/(m/n),R=h%43*6,Q=n*(n-(n*R>>8))>>8,t=n*(n-(n*(n-R)>>8))>>8,r=0,g=0,b=0;switch(h/43){A(0,r=n;g=t)A(1,r=Q;g=n)A(2,g=n;b=t)A(3,g=Q;b=n)A(4,r=t;b=n)A(5,r=n;b=Q)}d=h?r|g<<8|b<<16:p.c?-1:0;fwrite(&d,1,3,f);}}}

Many concepts remain similar, but there are certainly a myriad of tiny changes. To compile that as C you do need to use C11 (C99 will probably work but I only strictly tested in C11).
I quite enjoyed this challenge, thanks for giving me the idea to try something new :).
Edit: Golf'd a bit better. Edit2: Merged two structs so my pixel struct and queue are the same, bit more macro abuse, and reflowed uses of 255 such that it can be defined as -1 when defining a series of unsigned chars, and lastly removed a function call. Edit3: Reused a few more variables, operator precedence tweaks, and output converted to RGB saving the alpha channel

#C++, 979 969 898 859 848 bytes

#include<cstdio>
#include<cstdlib>
#define K 400
#define L 400
#define M (i*)malloc(sizeof(i))
#define a(C,X,Y)if(C&&b[Y][X].c){t->n=M;t=t->n;b[Y][X].d=d+1;t->n=0;t->c=X;t->d=Y;}
#define A(n,d)case n:d;break;
#define F fgetc(f)
#define W(A,B) for(A=0;A<B;A++){
struct i{int c;int d;int v;i*n;}b[L][K]={0},*h,*t;float m=0;int main(){FILE*f=fopen("d","r+b");int x,y,d=0;W(y,L)W(x,K)b[y][x].c=F<<16|F<<8|F;}}rewind(f);x=165,y=155;h=M;h->c=x;h->d=y;b[y][x].d=d;t=h;while(h){i*p=b[h->d]+h->c;if(p->v)h=h->n;else{p->v=1;x=h->c;y=h->d;d=p->d;m=d>m?d:m;a(x>0,x-1,y)a(x<K-1,x+1,y)a(y>0,x,y-1)a(y<L-1,x,y+1)}}W(y,L)W(x,K)i p=b[y][x];unsigned char n=-1,h=p.d/(m/n),R=h%43*6,Q=n*(n-(n*R>>8))>>8,t=n*(n-(n*(n-R)>>8))>>8,r,g,b;switch(h/43){A(0,n,t,0)A(1,Q,n,0)A(2,0,n,t)A(3,0,Q,n)A(4,t,0,n)A(5,n,0,Q)}d=h?r|g<<8|b<<16:p.c?-1:0;fwrite(&d,1,3,f);}}}

Many concepts remain similar, but there are certainly a myriad of tiny changes. To compile that as C you do need to use C11 (C99 will probably work but I only strictly tested in C11).
I quite enjoyed this challenge, thanks for giving me the idea to try something new :).
Edit: Golf'd a bit better. 
Edit2: Merged two structs so my pixel struct and queue are the same, bit more macro abuse, and reflowed uses of 255 such that it can be defined as -1 when defining a series of unsigned chars, and lastly removed a function call. 
Edit3: Reused a few more variables, operator precedence tweaks, and output converted to RGB saving the alpha channel
Edit4: I think I am done with this now, some pointer arithmetic changes and slight control flow tweaks.

added 107 characters in body
Source Link
p4plus2
  • 111
  • 4

#C++, 979 969 898 898859 bytes

#include<cstdio>
#include<cstdlib>
#define K 400
#define L 400
#define M (i*)malloc(sizeof(i))
#define a(C,X,Y)if(C&&b[Y][X].c){t->n=M;t=t->n;b[Y][X].d=d+1;t->n=0;t->c=X;t->d=Y;}
#define A(n,d)case n:d;break;
#define F fgetc(f)
#define W(A,B) for(A=0;A<B;A++){
struct i{int c;int d;int v;i*n;}b[L][K]={0},*h,*t;float m=0;int main(){FILE*f=fopen("d","r+b");int x,y;fory,d=0;W(y=0;y<L;y++y,L){forW(x=0;x<K;x++x,K){b[y][x].c=(F<<24)|(F<<16)|(F<<8);c=F<<16|F<<8|F;}}rewind(f);x=165,y=155;h=M;int d=0;hy=155;h=M;h->c=x;h->d=y;b[y][x].d=d;t=h;while(h){i*p=&b[h->d][h->c];if(p->v){h=h->n;continue;}p->v=1;x=h->c;y=h->d;d=p->d;m=d>m?d:m;a(x>0,x-1,y)a(x<K-1,x+1,y)a(y>0,x,y-1)a(y<L-1,x,y+1)}forW(y=0;y<L;y++y,L){forW(x=0;x<K;x++x,K){i p=b[y][x];unsigned char n=-1,h=p.d/(m/n),R=h%43*6,Q=n*(n-(n*R>>8))>>8,t=n*(n-(n*(n-R)>>8))>>8,r=0,g=0,b=0;switch(h/43){A(0,r=n;g=t)A(1,r=Q;g=n)A(2,g=n;b=t)A(3,g=Q;b=n)A(4,r=t;b=n)A(5,r=n;b=Q)}int s=hd=h?r|g<<8|b<<16|n<<24r|g<<8|b<<16:p.c?-1:n<<24;fwrite0;fwrite(&s,4&d,1,3,f);}}}
  • Input: RGB data file (contained in file: d)
  • Output: RGBARGBA RGB data file (outputted in file: d)
  • Example: convert -depth 8 -size "400x400" test.png d.rgb && mv -f d.rgb d && g++ -o test main.c && ./test
  • NOTE: the image size and start are controlled at a source level, if this is an issue add 50 bytes or something -- I just didn't care to change it to be honest.

Many concepts remain similar, but there are certainly a myriad of tiny changes. To compile that as C you do need to use C11 (C99 will probably work but I only strictly tested in C11).
I quite enjoyed this challenge, thanks for giving me the idea to try something new :).
Edit: Golf'd a bit better. Edit2: Merged two structs so my pixel struct and queue are the same, bit more macro abuse, and reflowed uses of 255 such that it can be defined as -1 when defining a series of unsigned chars, and lastly removed a function call. Edit3: Reused a few more variables, operator precedence tweaks, and output converted to RGB saving the alpha channel

#C++, 979 969 898 bytes

#include<cstdio>
#include<cstdlib>
#define K 400
#define L 400
#define M (i*)malloc(sizeof(i))
#define a(C,X,Y)if(C&&b[Y][X].c){t->n=M;t=t->n;b[Y][X].d=d+1;t->n=0;t->c=X;t->d=Y;}
#define A(n,d)case n:d;break;
#define F fgetc(f)
struct i{int c;int d;int v;i*n;}b[L][K]={0},*h,*t;float m=0;int main(){FILE*f=fopen("d","r+b");int x,y;for(y=0;y<L;y++){for(x=0;x<K;x++){b[y][x].c=(F<<24)|(F<<16)|(F<<8);}}rewind(f);x=165,y=155;h=M;int d=0;h->c=x;h->d=y;b[y][x].d=d;t=h;while(h){i*p=&b[h->d][h->c];if(p->v){h=h->n;continue;}p->v=1;x=h->c;y=h->d;d=p->d;m=d>m?d:m;a(x>0,x-1,y)a(x<K-1,x+1,y)a(y>0,x,y-1)a(y<L-1,x,y+1)}for(y=0;y<L;y++){for(x=0;x<K;x++){i p=b[y][x];unsigned char n=-1,h=p.d/(m/n),R=h%43*6,Q=n*(n-(n*R>>8))>>8,t=n*(n-(n*(n-R)>>8))>>8,r=0,g=0,b=0;switch(h/43){A(0,r=n;g=t)A(1,r=Q;g=n)A(2,g=n;b=t)A(3,g=Q;b=n)A(4,r=t;b=n)A(5,r=n;b=Q)}int s=h?r|g<<8|b<<16|n<<24:p.c?-1:n<<24;fwrite(&s,4,1,f);}}}
  • Input: RGB data file (contained in file: d)
  • Output: RGBA data file (outputted in file: d)
  • Example: convert -depth 8 -size "400x400" test.png d.rgb && mv -f d.rgb d && g++ -o test main.c && ./test
  • NOTE: the image size and start are controlled at a source level, if this is an issue add 50 bytes or something -- I just didn't care to change it to be honest.

Many concepts remain similar, but there are certainly a myriad of tiny changes. To compile that as C you do need to use C11 (C99 will probably work but I only strictly tested in C11).
I quite enjoyed this challenge, thanks for giving me the idea to try something new :).
Edit: Golf'd a bit better. Edit2: Merged two structs so my pixel struct and queue are the same, bit more macro abuse, and reflowed uses of 255 such that it can be defined as -1 when defining a series of unsigned chars, and lastly removed a function call.

#C++, 979 969 898 859 bytes

#include<cstdio>
#include<cstdlib>
#define K 400
#define L 400
#define M (i*)malloc(sizeof(i))
#define a(C,X,Y)if(C&&b[Y][X].c){t->n=M;t=t->n;b[Y][X].d=d+1;t->n=0;t->c=X;t->d=Y;}
#define A(n,d)case n:d;break;
#define F fgetc(f)
#define W(A,B) for(A=0;A<B;A++){
struct i{int c;int d;int v;i*n;}b[L][K]={0},*h,*t;float m=0;int main(){FILE*f=fopen("d","r+b");int x,y,d=0;W(y,L)W(x,K)b[y][x].c=F<<16|F<<8|F;}}rewind(f);x=165,y=155;h=M;h->c=x;h->d=y;b[y][x].d=d;t=h;while(h){i*p=&b[h->d][h->c];if(p->v){h=h->n;continue;}p->v=1;x=h->c;y=h->d;d=p->d;m=d>m?d:m;a(x>0,x-1,y)a(x<K-1,x+1,y)a(y>0,x,y-1)a(y<L-1,x,y+1)}W(y,L)W(x,K)i p=b[y][x];unsigned char n=-1,h=p.d/(m/n),R=h%43*6,Q=n*(n-(n*R>>8))>>8,t=n*(n-(n*(n-R)>>8))>>8,r=0,g=0,b=0;switch(h/43){A(0,r=n;g=t)A(1,r=Q;g=n)A(2,g=n;b=t)A(3,g=Q;b=n)A(4,r=t;b=n)A(5,r=n;b=Q)}d=h?r|g<<8|b<<16:p.c?-1:0;fwrite(&d,1,3,f);}}}
  • Input: RGB data file (contained in file: d)
  • Output: RGBA RGB data file (outputted in file: d)
  • Example: convert -depth 8 -size "400x400" test.png d.rgb && mv -f d.rgb d && g++ -o test main.c && ./test
  • NOTE: the image size and start are controlled at a source level, if this is an issue add 50 bytes or something -- I just didn't care to change it to be honest.

Many concepts remain similar, but there are certainly a myriad of tiny changes. To compile that as C you do need to use C11 (C99 will probably work but I only strictly tested in C11).
I quite enjoyed this challenge, thanks for giving me the idea to try something new :).
Edit: Golf'd a bit better. Edit2: Merged two structs so my pixel struct and queue are the same, bit more macro abuse, and reflowed uses of 255 such that it can be defined as -1 when defining a series of unsigned chars, and lastly removed a function call. Edit3: Reused a few more variables, operator precedence tweaks, and output converted to RGB saving the alpha channel

added 169 characters in body
Source Link
p4plus2
  • 111
  • 4
Loading
added 49 characters in body
Source Link
p4plus2
  • 111
  • 4
Loading
Source Link
p4plus2
  • 111
  • 4
Loading