static void DeringBlockWeak(unsigned char *SrcPtr, unsigned char *DstPtr, ogg_int32_t Pitch, ogg_uint32_t FragQIndex, const ogg_uint32_t *QuantScale){ ogg_int16_t UDMod[72]; ogg_int16_t LRMod[72]; unsigned int j,k; const unsigned char * Src; unsigned int QValue = QuantScale[FragQIndex]; unsigned char p; unsigned char pl; unsigned char pr; unsigned char pu; unsigned char pd; int al; int ar; int au; int ad; int atot; int B; int newVal; const unsigned char *curRow = SrcPtr-1; unsigned char *dstRow = DstPtr; const unsigned char *lastRow = SrcPtr-Pitch; const unsigned char *nextRow = SrcPtr+Pitch; unsigned int rowOffset = 0; unsigned int round = (1<<6); int High; int Low; int TmpMod; int Sharpen = SharpenModifier[FragQIndex]; High = 3 * QValue; if(High>24) High=24; Low = 0 ; /* Initialize the Mod Data */ Src=SrcPtr-Pitch; for(k=0;k<9;k++) { for(j=0;j<8;j++) { TmpMod = 32 + QValue - 2*(abs(Src[j+Pitch]-Src[j])); if(TmpMod< -64) TmpMod = Sharpen; else if(TmpMod<Low) TmpMod = Low; else if(TmpMod>High) TmpMod = High; UDMod[k*8+j] = (ogg_int16_t)TmpMod; } Src +=Pitch; } Src = SrcPtr-1; for(k=0;k<8;k++){ for(j=0;j<9;j++){ TmpMod = 32 + QValue - 2*(abs(Src[j+1]-Src[j])); if(TmpMod< -64 ) TmpMod = Sharpen; else if(TmpMod<Low) TmpMod = Low; else if(TmpMod>High) TmpMod = High; LRMod[k*9+j] = (ogg_int16_t)TmpMod; } Src+=Pitch; } for(k=0;k<8;k++) { for(j=0;j<8;j++){ atot = 128; B = round; p = curRow[ rowOffset +j+1]; pl = curRow[ rowOffset +j]; al = LRMod[k*9+j]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +j]; au = UDMod[k*8+j]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +j]; ad = UDMod[(k+1)*8+j]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +j+2]; ar = LRMod[k*9+j+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; dstRow[ rowOffset +j] = clamp255( newVal ); } rowOffset += Pitch; } }
static void DeringBlockStrong(unsigned char *SrcPtr, unsigned char *DstPtr, ogg_int32_t Pitch, ogg_uint32_t FragQIndex, const ogg_uint32_t *QuantScale){ ogg_int16_t UDMod[72]; ogg_int16_t LRMod[72]; unsigned int j,k,l; const unsigned char * Src; unsigned int QValue = QuantScale[FragQIndex]; unsigned char p; unsigned char pl; unsigned char pr; unsigned char pu; unsigned char pd; int al; int ar; int au; int ad; int atot; int B; int newVal; const unsigned char *curRow = SrcPtr - 1; /* avoid negative array indexes */ unsigned char *dstRow = DstPtr; const unsigned char *lastRow = SrcPtr-Pitch; const unsigned char *nextRow = SrcPtr+Pitch; unsigned int rowOffset = 0; unsigned int round = (1<<6); int High; int Low; int TmpMod; int Sharpen = SharpenModifier[FragQIndex]; High = 3 * QValue; if(High>32)High=32; Low = 0; /* Initialize the Mod Data */ Src = SrcPtr-Pitch; for(k=0;k<9;k++){ for(j=0;j<8;j++){ TmpMod = 32 + QValue - (abs(Src[j+Pitch]-Src[j])); if(TmpMod< -64) TmpMod = Sharpen; else if(TmpMod<Low) TmpMod = Low; else if(TmpMod>High) TmpMod = High; UDMod[k*8+j] = (ogg_int16_t)TmpMod; } Src +=Pitch; } Src = SrcPtr-1; for(k=0;k<8;k++){ for(j=0;j<9;j++){ TmpMod = 32 + QValue - (abs(Src[j+1]-Src[j])); if(TmpMod< -64 ) TmpMod = Sharpen; else if(TmpMod<0) TmpMod = Low; else if(TmpMod>High) TmpMod = High; LRMod[k*9+j] = (ogg_int16_t)TmpMod; } Src+=Pitch; } for(k=0;k<8;k++){ /* In the case that this function called with same buffer for source and destination, To keep the c and the mmx version to have consistant results, intermediate buffer is used to store the eight pixel value before writing them to destination (i.e. Overwriting souce for the speical case) */ for(l=0;l<8;l++){ atot = 128; B = round; p = curRow[ rowOffset +l +1]; pl = curRow[ rowOffset +l]; al = LRMod[k*9+l]; atot -= al; B += al * pl; pu = lastRow[ rowOffset +l]; au = UDMod[k*8+l]; atot -= au; B += au * pu; pd = nextRow[ rowOffset +l]; ad = UDMod[(k+1)*8+l]; atot -= ad; B += ad * pd; pr = curRow[ rowOffset +l+2]; ar = LRMod[k*9+l+1]; atot -= ar; B += ar * pr; newVal = ( atot * p + B) >> 7; dstRow[ rowOffset +l]= clamp255( newVal ); } rowOffset += Pitch; } }
int main(int argc, char *argv[]) { byte *ibuf, *yibuf, *obuf, *blks, *yibuf2; byte *tbuf, *tbuf1, *ct1, *ibuf2; BTIC1H_Context *ctx; FILE *tfd; double f, g, h, e; int xs, ys, xs1, ys1; int cr, cg, cb, cy, cu, cv, cu1, cv1; int t0, t1, t2, t3; int n, n1, nf, ncf, qf, nwe, nwd; int i, j, k, l; nwe=4; nwd=4; for(i=1; i<argc; i++) { if(!strncmp(argv[i], "--th=", 5)) { nwe=atoi(argv[i]+5); nwd=nwe; btic1h_workqueue_defaultworkers=nwe; // btic1h_workqueue_defaultworkers=atoi(argv[i]+5); continue; } if(!strncmp(argv[i], "--thd=", 6)) { nwd=atoi(argv[i]+6); continue; } if(!strncmp(argv[i], "--the=", 6)) { nwe=atoi(argv[i]+6); continue; } } // BTIC1H_InitCamera(); ibuf=BTIC1H_Img_LoadTGA("StreetHollandSD.tga", &xs, &ys); ibuf2=BTIC1H_Img_LoadTGA("StreetHollandSD_q45.tga", &xs1, &ys1); // ibuf=BTIC1H_Img_LoadTGA("3917969_f260.tga", &xs, &ys); ibuf=BTIC1H_Img_LoadTGA("screencap0.tga", &xs, &ys); ibuf2=BTIC1H_Img_LoadTGA("screencap0.tga", &xs1, &ys1); // ibuf=BTIC1H_Img_LoadTGA("MLP_FIM1.tga", &xs, &ys); // ibuf2=BTIC1H_Img_LoadTGA("MLP_FIM1_q95.tga", &xs1, &ys1); ibuf=BTIC1H_Img_LoadTGA("MLP_FIM3.tga", &xs, &ys); // ibuf2=BTIC1H_Img_LoadTGA("MLP_FIM3.tga", &xs1, &ys1); ibuf2=BTIC1H_Img_LoadTGA("MLP_FIM3_q75.tga", &xs1, &ys1); yibuf=malloc(xs*ys*2); if(!ibuf || !ibuf2) { printf("failed load test images\n"); return(-1); } obuf=malloc(xs*ys*4); // blks=malloc(xs*ys*2); tbuf=malloc(1<<24); tbuf1=malloc(1<<24); #if 0 for(i=0; i<ys; i++) for(j=0; j<xs; j++) { cr=ibuf[(i*xs+j)*4+0]; cg=ibuf[(i*xs+j)*4+1]; cb=ibuf[(i*xs+j)*4+2]; cy=(( 19595*cr + 38470*cg + 7471*cb + 32768)>>16)+0; cu=((-11056*cr - 21712*cg +32768*cb + 32768)>>16)+128; cv=(( 32768*cr - 27440*cg - 5328*cb + 32768)>>16)+128; // cu=128; cv=128; cy=clamp255(cy); cu=clamp255(cu); cv=clamp255(cv); // k=j&(~1); yibuf[(i*xs+j)*2+0]=cy; // yibuf[(i*xs+k)*2+1]=cu; // yibuf[(i*xs+k)*2+3]=cv; // yibuf[(i*xs+j)*2+1]=(j&1)?cv:cu; // yibuf[(i*xs+j)*2+1]=(yibuf[(i*xs+j)*2+1]+((j&1)?cv:cu))>>1; // yibuf[(i*xs+j)*2+3]=(j&1)?cu:cv; if(j&1) { k=j&(~1); yibuf[(i*xs+k)*2+1]=(yibuf[(i*xs+k)*2+1]+cu)>>1; yibuf[(i*xs+k)*2+3]=(yibuf[(i*xs+k)*2+3]+cv)>>1; }else {
static void updatereflectmap(int slot) { float rf, r, g, b, t, dfact, kfact, rdir[3]; float rcol[3], ppos[3], norm[3], ldir[3], h[3], vdir[3], planepos[3]; int x, y; glBindTexture(GL_TEXTURE_2D, reflectid); for (y = slot * TEX_REFLECT_SLOT_SIZE; y < (slot + 1) * TEX_REFLECT_SLOT_SIZE; y++) for (x = 0; x < TEX_REFLECT_WIDTH; x++) { ppos[0] = sphere_pos[y][x][0] + objpos[0]; ppos[1] = sphere_pos[y][x][1] + objpos[1]; ppos[2] = sphere_pos[y][x][2] + objpos[2]; vsub(norm, ppos, objpos); vnormalize(norm, norm); vsub(ldir, lightpos, ppos); vnormalize(ldir, ldir); vsub(vdir, obs, ppos); vnormalize(vdir, vdir); rf = 2.0f * dprod(norm, vdir); if (rf > EPSILON) { rdir[0] = rf * norm[0] - vdir[0]; rdir[1] = rf * norm[1] - vdir[1]; rdir[2] = rf * norm[2] - vdir[2]; t = -objpos[2] / rdir[2]; if (t > EPSILON) { planepos[0] = objpos[0] + t * rdir[0]; planepos[1] = objpos[1] + t * rdir[1]; planepos[2] = 0.0f; if (!colorcheckmap(planepos, rcol)) rcol[0] = rcol[1] = rcol[2] = 0.0f; } else rcol[0] = rcol[1] = rcol[2] = 0.0f; } else rcol[0] = rcol[1] = rcol[2] = 0.0f; dfact = 0.1f * dprod(ldir, norm); if (dfact < 0.0f) { dfact = 0.0f; kfact = 0.0f; } else { h[0] = 0.5f * (vdir[0] + ldir[0]); h[1] = 0.5f * (vdir[1] + ldir[1]); h[2] = 0.5f * (vdir[2] + ldir[2]); kfact = dprod(h, norm); kfact = pow(kfact, 4.0); if (kfact < 1.0e-10) kfact = 0.0; } r = dfact + kfact; g = dfact + kfact; b = dfact + kfact; r *= 255.0f; g *= 255.0f; b *= 255.0f; r += rcol[0]; g += rcol[1]; b += rcol[2]; r = clamp255(r); g = clamp255(g); b = clamp255(b); reflectmap[y][x][0] = (GLubyte) r; reflectmap[y][x][1] = (GLubyte) g; reflectmap[y][x][2] = (GLubyte) b; } glTexSubImage2D(GL_TEXTURE_2D, 0, 0, slot * TEX_REFLECT_SLOT_SIZE, TEX_REFLECT_WIDTH, TEX_REFLECT_SLOT_SIZE, GL_RGB, GL_UNSIGNED_BYTE, &reflectmap[slot * TEX_REFLECT_SLOT_SIZE][0][0]); }
static int colorcheckmap(float ppos[3], float c[3]) { static float norm[3] = { 0.0f, 0.0f, 1.0f }; float ldir[3], vdir[3], h[3], dfact, kfact, r, g, b; int x, y; x = (int) ((ppos[0] + BASESIZE / 2) * (10.0f / BASESIZE)); if ((x < 0) || (x > 10)) return GL_FALSE; y = (int) ((ppos[1] + BASESIZE / 2) * (10.0f / BASESIZE)); if ((y < 0) || (y > 10)) return GL_FALSE; r = 255.0f; if (y & 1) { if (x & 1) g = 255.0f; else g = 0.0f; } else { if (x & 1) g = 0.0f; else g = 255.0f; } b = 0.0f; vsub(ldir, lightpos, ppos); vnormalize(ldir, ldir); if (seelight(ppos, ldir)) { c[0] = r * 0.05f; c[1] = g * 0.05f; c[2] = b * 0.05f; return GL_TRUE; } dfact = dprod(ldir, norm); if (dfact < 0.0f) dfact = 0.0f; vsub(vdir, obs, ppos); vnormalize(vdir, vdir); h[0] = 0.5f * (vdir[0] + ldir[0]); h[1] = 0.5f * (vdir[1] + ldir[1]); h[2] = 0.5f * (vdir[2] + ldir[2]); kfact = dprod(h, norm); kfact = pow(kfact, 6.0) * 7.0 * 255.0; r = r * dfact + kfact; g = g * dfact + kfact; b = b * dfact + kfact; c[0] = clamp255(r); c[1] = clamp255(g); c[2] = clamp255(b); return GL_TRUE; }
void render_col(BITMAP* buffer, MAP* map, short idx, VEC2F vp, float cam_h, VEC2F ray_dir, int col) { if(idx & SHORT_SIGN_FLAG) { //printf("ASDF = %d %d\n", (short)(idx & ~SHORT_SIGN_FLAG), idx); SSECTOR* ssector = &map->ssectors[(short)(idx & ~SHORT_SIGN_FLAG)]; int i; for(i = 0; i < ssector->seg_num; ++i) { SEG* seg = &map->segs[ssector->first_seg_idx + i]; VEC2F v1 = get_vertex(map, seg->v1_idx); VEC2F v2 = get_vertex(map, seg->v2_idx); RAY_VS_SEGMENT_RESULT res = ray_vs_segment(v1, v2, vp, ray_dir); VEC2F n = vec2f(v1.y - v2.y, v2.x - v1.x); LINEDEF* linedef = &map->linedefs[seg->linedef_idx]; SIDEDEF *sidedef1, *sidedef2; SECTOR *sector1, *sector2; if(seg->dir) { sidedef1 = &map->sidedefs[linedef->neg_sidedef_idx]; sector1 = &map->sectors[sidedef1->sector_idx]; sidedef2 = linedef->pos_sidedef_idx == -1 ? NULL : &map->sidedefs[linedef->pos_sidedef_idx]; sector2 = linedef->pos_sidedef_idx == -1 ? NULL : &map->sectors[sidedef2->sector_idx]; } else { sidedef1 = &map->sidedefs[linedef->pos_sidedef_idx]; sector1 = &map->sectors[sidedef1->sector_idx]; sidedef2 = linedef->neg_sidedef_idx == -1 ? NULL : &map->sidedefs[linedef->neg_sidedef_idx]; sector2 = linedef->neg_sidedef_idx == -1 ? NULL : &map->sectors[sidedef2->sector_idx]; } //printf("%c%c%c%c%c%c%c%c\n", sidedef->mid_tex_name[0], sidedef->mid_tex_name[1], //sidedef->mid_tex_name[2], sidedef->mid_tex_name[3], sidedef->mid_tex_name[4], sidedef->mid_tex_name[5], //sidedef->mid_tex_name[6], sidedef->mid_tex_name[7]); if(res.t > 10 && res.k >= 0 && res.k <= 1.0 && vec2f_dot(n, vec2f_diff(vp, v1)) < 0) { VEC2F d = vec2f_diff(v2, v1); VEC2F wall_normal = vec2f(-d.y, d.x); float wall_len = sqrt(d.x * d.x + d.y * d.y); wall_normal.x /= wall_len; wall_normal.y /= wall_len; int r = clamp255((int)(fabs(wall_normal.x) * 4000 / sqrt(res.t))); int g = clamp255((int)(fabs(wall_normal.y) * 4000 / sqrt(res.t))); int color = makecol(r, g, 0); if(sidedef1 && !sidedef2) render_col_helper(col, sector1->ceil_height + cam_h, sector1->floor_height + cam_h, res.t, color); else { render_col_helper(col, sector2->ceil_height + cam_h, sector1->ceil_height + cam_h, res.t, color); render_col_helper(col, sector2->floor_height + cam_h, sector1->floor_height + cam_h, res.t, color); if(sidedef1->mid_tex_name[0] != '-') render_col_helper(col, sector1->floor_height + cam_h, sector1->ceil_height + cam_h, res.t, color); } } } // render subsector... } else { NODE* node = &map->nodes[idx]; VEC2F n = vec2f(-node->y2, node->x2); if(vec2f_dot(n, vec2f(vp.x - node->x1, vp.y - node->y1)) >= 0) { render_col(buffer, map, node->left_child_idx, vp, cam_h, ray_dir, col); render_col(buffer, map, node->right_child_idx, vp, cam_h, ray_dir, col); } else { render_col(buffer, map, node->right_child_idx, vp, cam_h, ray_dir, col); render_col(buffer, map, node->left_child_idx, vp, cam_h, ray_dir, col); } } }