/** * Convert given data into normal map * To get height of current pixel the grey scale value will be computed **/ shared_array<byte> nrCTextureLoader::heightmap_to_normalmap (shared_array<byte>& data, int width, int height){ // define putput shared_array<byte> dst (new byte[width*height*4]); shared_array<byte> src = rgba2luminance(data,width,height); // go through all pixels for (int x=1; x < width-1; x++){ for (int y=1; y < height-1; y++){ // wir lesen zunaechst uns interessierte werte aus byte g1 = src[y*width + x+1]; byte g2 = src[y*width + x-1]; vec3 dfdx(2.0f, 0.0f, 4.0*float(g1-g2)/255.0f); // und jetzt das andere g1 = src[(y+1)*width + x]; g2 = src[(y-1)*width + x]; vec3 dfdy(0.f, 2.0f, 4.0*float(g1 - g2)/255.0f); // verrechnen und speichern vec3 n = cross(dfdx, dfdy); n.normalize(); // Ergebnis speichern dst[y*4*width + x*4 + 0] = range_compress(n[0]); dst[y*4*width + x*4 + 1] = range_compress(n[1]); dst[y*4*width + x*4 + 2] = range_compress(n[2]); dst[y*4*width + x*4 + 3] = 255; } } // kopiere den Inhalt von den Rändern zu den letzten Pixeln for(int i = 0; i < width; i++) { dst[0*4*width + i*4 + 0] = dst[1*4*width + i*4 + 0]; dst[0*4*width + i*4 + 1] = dst[1*4*width + i*4 + 1]; dst[0*4*width + i*4 + 2] = dst[1*4*width + i*4 + 2]; dst[0*4*width + i*4 + 3] = dst[1*4*width + i*4 + 3]; dst[(height-1)*4*width + i*4 + 0] = dst[(height-2)*4*width + i*4 + 0]; dst[(height-1)*4*width + i*4 + 1] = dst[(height-2)*4*width + i*4 + 1]; dst[(height-1)*4*width + i*4 + 2] = dst[(height-2)*4*width + i*4 + 2]; dst[(height-1)*4*width + i*4 + 3] = dst[(height-2)*4*width + i*4 + 3]; } for(int j = 0; j < height; j++) { dst[j*4*width + 0*4 + 0] = dst[j*4*width + 1*4 + 0]; dst[j*4*width + 0*4 + 1] = dst[j*4*width + 1*4 + 1]; dst[j*4*width + 0*4 + 2] = dst[j*4*width + 1*4 + 2]; dst[j*4*width + 0*4 + 3] = dst[j*4*width + 1*4 + 3]; dst[j*4*width + (width-1)*4 + 0] = dst[j*4*width + (width-2)*4 + 0]; dst[j*4*width + (width-1)*4 + 1] = dst[j*4*width + (width-2)*4 + 1]; dst[j*4*width + (width-1)*4 + 2] = dst[j*4*width + (width-2)*4 + 2]; dst[j*4*width + (width-1)*4 + 3] = dst[j*4*width + (width-2)*4 + 3]; } return dst; }
char * range_easy_compress(easy_lr* elr, const char ** c_nodes) { apr_pool_clear(elr->querypool); char * retval; // FIXME copy/reference bits from real lr into easy_lr to expose warnings/errors retval = strdup(range_compress(elr->lr, elr->querypool, c_nodes)); apr_pool_clear(elr->querypool); return retval; }