/* A toy program for hiding "secret messages" in SIRDS random-dot stereograms. Overlay the two produced images to reveal the secret message. This program is placed in the public domain by Arthur O'Dwyer, July 2004. SIRDS generator adapted from WWW sources such as http://www.cs.waikato.ac.nz/~singlis/sirds/creation.html */ #include #include #include #include #include "ImageFmtc.h" #define NELEM(a) ((int)(sizeof (a) / sizeof *(a))) #define SQR(x) ((x)*(x)) #define randint0(m) (rand()%(m)) /* The output device is assumed to have |DPI| many pixels per inch. */ #define DPI 96 /* The user's eyes are expected to be |E| inches apart. */ #define E (2.5*DPI) #define ZMAX 1.0 static char *Argv0; /* |random| is an array to be filled with random noise (zeros and ones), to be subsequently XORed with the secret message. */ static int random[97][65]; /* This is our secret message. In this case, it's a picture of a cat's face, but just pretend it's top-secret information. */ static int secret[97][65] = { 1,1,0,1,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1, 0,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1,1,1,0, 1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,1,0,1,1,1,0,1,0,1,1,0,1,1, 0,1,1,0,1,1,0,1,0,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,0, 1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,0,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0,1,0,0,1,1,1,0,0,0,0,0,0,1,0,1,0,0, 1,1,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,1,1,0,0,1,1,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1, 0,0,0,1,0,1,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0,1,1,1,0,0,0,0,1,0,1,0,0,0,1,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,0,0, 0,1,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,1,1,0,0,1,0,0,0,1,0, 0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,0,1,0,0,0,1, 1,0,1,1,0,1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,0,0,0,1,0,1,0,1,0,1,0,0,1,0,0,1,0,0, 0,0,0,0,1,0,1,0,1,1,0,0,1,1,1,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0, }; int makeDepthMapDonut(double *Z, int w, int h); int makeDepthMapStairs(double *Z, int w, int h); int getSIRDS(double *Z, unsigned char *image, int w, int h, int flip); void getHide(unsigned char *small, unsigned char (*big)[3], int w, int h); void do_error(const char *fmt, ...); int main() { int w = 512/2; int h = 384/2; int i, j; double *Z = malloc(w*h * sizeof *Z); unsigned char *sirds = malloc(w*h * sizeof *sirds); unsigned char (*data)[3] = malloc(3*4*w*h * sizeof *data); for (j=0; j < NELEM(random); ++j) for (i=0; i < NELEM(random[j]); ++i) random[j][i] = randint0(2); makeDepthMapDonut(Z, w, h); if (getSIRDS(Z, sirds, w, h,0)) do_error("Failed to get SIRDS!"); getHide(sirds, data, w, h); if (WriteBMP8("sirds2.bmp", data, 2*w, 2*h)) do_error("Can't write!"); makeDepthMapStairs(Z, w, h); if (getSIRDS(Z, sirds, w, h,1)) do_error("Failed to get SIRDS!"); getHide(sirds, data, w, h); if (WriteBMP8("sirds4.bmp", data, 2*w, 2*h)) do_error("Can't write!"); free(Z); free(sirds); free(data); return 0; } int makeDepthMapDonut(double *Z, int w, int h) { /* We are filling |Z| with some "interesting" but fairly simple depth map. In this case, it's a donut. */ double cx = w/2., cy = h/2.; int i, j; for (j=0; j < h; ++j) { for (i=0; i < w; ++i) { double dist = sqrt(SQR(j-cy)+SQR(i-cx)); dist = fabs(dist - w*0.1) / (w*0.05); if (dist > 1.) Z[j*w+i] = 0.0; else Z[j*w+i] = (ZMAX/5)*sqrt(1.0-SQR(dist)); } } return 0; } int makeDepthMapStairs(double *Z, int w, int h) { /* We are filling |Z| with some "interesting" but fairly simple depth map. In this case, it's a "staircase" going "out" toward the user and getting wider as it goes. */ int map[8][12] = { 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,1,1,0,0,0,0,0, 0,0,0,0,2,2,2,2,0,0,0,0, 0,0,0,3,3,3,3,3,3,0,0,0, 0,0,4,4,4,4,4,4,4,4,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, }; int i, j; for (j=0; j < h; ++j) { for (i=0; i < w; ++i) { Z[j*w+i] = map[8*j/h][12*i/w] * ZMAX/10.; } } return 0; } int getSIRDS(double *Z, unsigned char *image, int w, int h, int flip) { #define mu (1/3.0) #define separation(Z) ((int)(0.5+(ZMAX-mu*Z)*E/(2*ZMAX-mu*Z))) int i, j, k; for (j=0; j < h; ++j) { /* The array element |same[i]| holds the index of a pixel in the current row, farther to the right than pixel |i| itself, which is constrained to be the same color as pixel |i|. The array |pix| holds the actual color values of all |w| pixels in the current row. */ int pix[w]; int same[w]; for (i=0; i < w; ++i) same[i] = i; /* calculate the links for this array of Z values */ for (i=0; i < w; ++i) { int sep = separation(Z[j*w+i])/2; int left = i - sep/2; int right = left + sep; if (0 <= left && right < w) { int k; for (k = same[left]; k!=left && k!=right; k=same[left]) { if (k < right) left = k; else { left = right; right = k; } } same[left] = right; } } /* assign the colors */ for (i=0; i < w; ++i) pix[i] = -1; if (j < NELEM(secret)) { for (i = 0; i < NELEM(secret[j]); ++i) { pix[i] = secret[j][i]? random[i][j]^flip: random[i][j]; for (k=i; same[k] != k; k = same[k]) { pix[same[k]] = pix[k]; } } } for (i = w-1; i >= 0; --i) { if (pix[i] == -1) { if (same[i] == i) pix[i] = randint0(2); else pix[i] = pix[same[i]]; } image[j*w+i] = pix[i]; } } return 0; #undef mu #undef separation } void getHide(unsigned char *small, unsigned char (*big)[3], int w, int h) { int i,j; for (j=0; j < h; ++j) { for (i=0; i < w; ++i) { memset(big[(2*j+0)*2*w+(2*i+0)], (255*small[j*w+i]), 3); memset(big[(2*j+0)*2*w+(2*i+1)], ~(255*small[j*w+i]), 3); memset(big[(2*j+1)*2*w+(2*i+0)], ~(255*small[j*w+i]), 3); memset(big[(2*j+1)*2*w+(2*i+1)], (255*small[j*w+i]), 3); } } } void do_error(const char *fmt, ...) { va_list ap; va_start(ap, fmt); printf("%s: ", Argv0); vprintf(fmt, ap); putchar('\n'); va_end(ap); exit(EXIT_FAILURE); }