Quellcode durchsuchen

* stock.c: generate images with random noise.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2697 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam vor 16 Jahren
Ursprung
Commit
ee6e43cf81
1 geänderte Dateien mit 35 neuen und 0 gelöschten Zeilen
  1. +35
    -0
      pipi/stock.c

+ 35
- 0
pipi/stock.c Datei anzeigen

@@ -65,6 +65,41 @@ pipi_image_t *pipi_load_stock(char const *name)
return ret;
}

/* Generate a completely random image. */
if(!strncmp(name, "random", 6))
{
unsigned int ctx = 1;
int x, y, w, h;

w = atoi(name + 6);
name = strchr(name + 6, 'x');
if(!name)
return NULL;
h = atoi(name + 1);
if(w <= 0 || h <= 0)
return NULL;

ret = pipi_new(w, h);
pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F);
data = (float *)pix->pixels;

for(y = 0; y < h; y++)
for(x = 0; x < w; x++)
{
long hi, lo;

hi = ctx / 12773L;
lo = ctx % 12773L;
ctx = 16807L * lo - 2836L * hi;
if(ctx <= 0)
ctx += 0x7fffffffL;

data[y * w + x] = (double)((ctx % 65536) / 65535.);
}

return ret;
}

return NULL;
}


Laden…
Abbrechen
Speichern