Commit 24343b60 authored by IOhannes m zmölnig's avatar IOhannes m zmölnig
Browse files

reduce variable scopes

parent 387d1939
......@@ -129,7 +129,6 @@ pixBlock* filmMPEG3 :: getFrame(void) {
}
m_readNext = false;
int i;
int wantedFormat=m_wantedFormat;
char*u=NULL,*y=NULL,*v=NULL;
......@@ -142,7 +141,7 @@ pixBlock* filmMPEG3 :: getFrame(void) {
// the mpeg3-YUV2RGB decoder works better than ours
unsigned char **rows = new unsigned char* [m_image.image.ysize];
unsigned char **dummy=rows;
i=m_image.image.ysize;
int i=m_image.image.ysize;
while(i--)*dummy++=m_image.image.data+(i*m_image.image.xsize*m_image.image.csize);
if (mpeg3_read_frame(mpeg_file, rows,
0, 0,
......@@ -225,10 +224,9 @@ void filmMPEG3::setProperties(gem::Properties&props) {
void filmMPEG3::getProperties(gem::Properties&props) {
std::vector<std::string> keys=props.keys();
gem::any value;
double d;
unsigned int i=0;
for(i=0; i<keys.size(); i++) {
for(unsigned i=0; i<keys.size(); i++) {
gem::any value;
double d;
std::string key=keys[i];
props.erase(key);
if("fps"==key) {
......
......@@ -526,11 +526,10 @@ static void setalpha(unsigned char *lptr, size_t n)
static void expandrow(unsigned char *optr, unsigned char *iptr, int32 z)
{
unsigned char pixel, count;
unsigned char count;
optr += z;
while(1) {
pixel = *iptr++;
unsigned char pixel = *iptr++;
if ( !(count = (pixel & 0x7f)) )
return;
if(pixel & 0x80) {
......@@ -703,24 +702,21 @@ static void lumrow(unsigned char *rgbptr, unsigned char *lumptr, size_t n)
static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int32 z, int32 cnt)
{
unsigned char *iptr, *ibufend, *sptr, *optr;
short todo, cc;
int32 count;
unsigned char *iptr, *ibufend, *optr;
lbuf += z;
iptr = lbuf;
ibufend = iptr+cnt*4;
optr = rlebuf;
while(iptr<ibufend) {
sptr = iptr;
unsigned char *sptr = iptr;
iptr += 8;
while((iptr<ibufend)&& ((iptr[-8]!=iptr[-4])||(iptr[-4]!=iptr[0])))
iptr+=4;
iptr -= 8;
count = (iptr-sptr)/4;
int32 count = (iptr-sptr)/4;
while(count) {
todo = static_cast<short>((count > 126) ? 126 : count);
short todo = static_cast<short>((count > 126) ? 126 : count);
count -= todo;
*optr++ = 0x80|todo;
while(todo>8) {
......@@ -742,13 +738,13 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int32 z, int3
}
}
sptr = iptr;
cc = *iptr;
short cc = *iptr;
iptr += 4;
while( (iptr<ibufend) && (*iptr == cc) )
iptr += 4;
count = (iptr-sptr)/4;
while(count) {
todo = static_cast<short>(count>126 ? 126:count);
short todo = static_cast<short>(count>126 ? 126:count);
count -= todo;
*optr++ = static_cast<unsigned char>(todo);
*optr++ = static_cast<unsigned char>(cc);
......
......@@ -502,7 +502,6 @@ static GLboolean
_glmWriteMTL(const GLMmodel* model, const char* modelpath, const std::string&mtllibname)
{
FILE* file=0;
GLMmaterial* material=0;
GLuint i;
std::string filename = _glmDirName(model->pathname);
......@@ -526,7 +525,7 @@ _glmWriteMTL(const GLMmodel* model, const char* modelpath, const std::string&mtl
fprintf(file, "# \n\n");
for (i = 0; i < model->nummaterials; i++) {
material = &model->materials[i];
GLMmaterial* material = &model->materials[i];
fprintf(file, "newmtl %s\n", material->name.c_str());
fprintf(file, "Ka %f %f %f\n",
material->ambient[0], material->ambient[1], material->ambient[2]);
......@@ -1589,7 +1588,6 @@ glmGetNumGroups(GLMmodel *model){return (model && model->groups)?model->numgroup
GLvoid
glmDelete(GLMmodel* model)
{
GLMgroup* group=0;
GLuint i;
if (!(model))return;
......@@ -1611,7 +1609,7 @@ glmDelete(GLMmodel* model)
}
delete[]model->materials;
while(model->groups) {
group = model->groups;
GLMgroup* group = model->groups;
model->groups = model->groups->next;
//free(group->name);
group->name.clear();
......@@ -2150,7 +2148,6 @@ glmDrawGroup(const GLMmodel* model, GLuint mode, int groupNumber, std::vector<s
group = model->groups;
int count = 1;
int numgroup;
numgroup = model->numgroups-1;
......@@ -2158,6 +2155,7 @@ glmDrawGroup(const GLMmodel* model, GLuint mode, int groupNumber, std::vector<s
verbose(1, "[GEM:modelOBJ] number of groups: %d",numgroup);
//groupNumber-=1;
if ( (!(groupNumber > numgroup)) && (groupNumber > 0)){
int count = 1;
verbose(1, "[GEM:modelOBJ] model group requested is %d number of groups: %d",groupNumber,numgroup);
......
......@@ -544,7 +544,6 @@ HRESULT CSampleGrabberAllocator::Alloc( )
}
LPBYTE pNext = m_pBuffer;
CMediaSample *pSample;
ASSERT(m_lAllocated == 0);
......@@ -553,8 +552,7 @@ HRESULT CSampleGrabberAllocator::Alloc( )
// the memory after the prefix - so that GetPointer() will return a pointer
// to m_lSize bytes.
for (; m_lAllocated < m_lCount; m_lAllocated++, pNext += lAlignedSize) {
pSample = new CMediaSample(
CMediaSample *pSample = new CMediaSample(
NAME("Sample Grabber memory media sample"),
this,
&hr,
......@@ -588,9 +586,8 @@ void CSampleGrabberAllocator::ReallyFree()
/* Free up all the CMediaSamples */
CMediaSample *pSample;
for (;;) {
pSample = m_lFree.RemoveHead();
CMediaSample *pSample = m_lFree.RemoveHead();
if (pSample != NULL) {
delete pSample;
} else {
......
......@@ -405,11 +405,9 @@ bool videoDV4L::enumProperties(gem::Properties&readable,
}
void videoDV4L::getProperties(gem::Properties&props) {
std::vector<std::string>keys=props.keys();
int i;
#if 0
/* get properties without decoder */
for(i=0; i<keys.size(); i++) {
for(int i=0; i<keys.size(); i++) {
std::string key=keys[i];
if(0) {
}
......@@ -420,7 +418,7 @@ void videoDV4L::getProperties(gem::Properties&props) {
/* get properties that need decoder */
if(m_decoder) {
for(i=0; i<keys.size(); i++) {
for(int i=0; i<keys.size(); i++) {
std::string key=keys[i];
if (0) {
} else if("quality"==key) {
......
......@@ -135,8 +135,8 @@ bool videoHALCON :: grabFrame() {
error("[GEM:videoHALCON] GrabImage exception: '%s'", except.message);
return false;
}
Halcon::HTuple typ, W, H, pR, pG, pB;
long r, g, b, h, w;
Halcon::HTuple pG, pB, typ, W, H;
long r;
try {
r = img.GetImagePointer3(&pG, &pB, &typ, &W, &H);
......@@ -146,6 +146,7 @@ bool videoHALCON :: grabFrame() {
}
try {
long g,b,w,h;
#if 0
#define GETTUPLE(x, y) { try {x=y[0]; } catch (Halcon::HException& except) { error("HTuple exception @ %d: '%s'", __LINE__, except.message); } } while(0)
GETTUPLE(g, pG);
......@@ -570,12 +571,12 @@ void videoHALCON::setProperties(gem::Properties&props) {
for(i=0; i<keys.size(); i++) {
std::string key=keys[i];
std::string s;
double d;
if(m_writeable.find(key) != m_writeable.end()) {
try {
const Halcon::HTuple Param=key.c_str();
Halcon::HTuple Value;
double d=0.;
switch(props.type(key)) {
case gem::Properties::STRING:
if(props.get(key, s)) {
......@@ -609,7 +610,7 @@ void videoHALCON::setProperties(gem::Properties&props) {
}
} else {
if("width" == key) {
double d=0;
double d=0.;
if(props.get(key, d)) {
try {
m_grabber->SetFramegrabberParam("image_width", d);
......
......@@ -231,10 +231,6 @@ void *videoV4L2 :: capturing(void)
fd_set fds;
struct timeval tv;
int r;
unsigned int i;
m_capturing=true;
......@@ -258,7 +254,7 @@ void *videoV4L2 :: capturing(void)
/* Timeout. */
tv.tv_sec = 0;
tv.tv_usec = 100;
r = select(0,0,0,0,&tv);
int r = select(0,0,0,0,&tv);
debugThread("V4L2: waited...");
......@@ -700,7 +696,6 @@ bool videoV4L2 :: stopTransfer()
{
debugPost("v4l2: stoptransfer");
if(!m_capturing)return false;
int i=0;
/* close the v4l2 device and dealloc buffer */
/* terminate thread if there is one */
if(m_continue_thread){
......@@ -716,7 +711,7 @@ bool videoV4L2 :: stopTransfer()
// unmap the mmap
debugPost("v4l2: unmapping %d buffers: %x", m_nbuffers, m_buffers);
if(m_buffers){
for (i = 0; i < m_nbuffers; ++i)
for (int i = 0; i < m_nbuffers; ++i)
if (-1 == v4l2_munmap (m_buffers[i].start, m_buffers[i].length)){
// oops: couldn't unmap the memory
}
......@@ -754,16 +749,15 @@ bool videoV4L2 :: setColor(int format)
std::vector<std::string> videoV4L2::enumerate() {
std::vector<std::string> result;
std::vector<std::string> glob, allglob;
int i=0;
glob=gem::files::getFilenameListing("/dev/video*");
for(i=0; i<glob.size(); i++)
for(int i=0; i<glob.size(); i++)
allglob.push_back(glob[i]);
glob=gem::files::getFilenameListing("/dev/v4l/*");
for(i=0; i<glob.size(); i++)
for(int i=0; i<glob.size(); i++)
allglob.push_back(glob[i]);
for(i=0; i<allglob.size(); i++) {
for(int i=0; i<allglob.size(); i++) {
std::string dev=allglob[i];
verbose(1, "[GEM:videoV4L2] found possible device %s", dev.c_str());
int fd=v4l2_open(dev.c_str(), O_RDWR);
......@@ -894,8 +888,7 @@ void videoV4L2 :: getProperties(gem::Properties&props) {
return;
}
std::vector<std::string>keys=props.keys();
int i=0;
for(i=0; i<keys.size(); i++) {
for(int i=0; i<keys.size(); i++) {
std::string key=keys[i];
std::map<std::string, struct v4l2_queryctrl>::iterator it = m_readprops.find(key);
if(it != m_readprops.end()) {
......@@ -1015,8 +1008,7 @@ void videoV4L2 :: setProperties(gem::Properties&props) {
std::vector<std::string>keys=props.keys();
int i=0;
for(i=0; i<keys.size(); i++) {
for(int i=0; i<keys.size(); i++) {
std::string key=keys[i];
std::map<std::string, struct v4l2_queryctrl>::iterator it = m_writeprops.find(key);
if(it != m_writeprops.end()) {
......
......@@ -106,8 +106,6 @@ GemShape :: ~GemShape()
/////////////////////////////////////////////////////////
void GemShape :: SetVertex(GemState* state,float x, float y, float z, float tx, float ty,int curCoord)
{
int i;
TexCoord*texcoords=NULL;
int numCoords = 0;
int numUnits = 0;
......@@ -122,7 +120,7 @@ void GemShape :: SetVertex(GemState* state,float x, float y, float z, float tx,
}
if (numUnits) {
for( i=0; i<numUnits; i++) {
for(int i=0; i<numUnits; i++) {
glMultiTexCoord2fARB(GL_TEXTURE0+i, tx, ty);
}
} else { // no multitexturing!
......@@ -135,22 +133,19 @@ void GemShape :: SetVertex(GemState* state,float x, float y, float z,
float s, float t, float r, float q,
int curCoord)
{
int i;
int numCoords = 0;
int numUnits = 0;
state->get(GemState::_GL_TEX_NUMCOORDS, numCoords);
state->get(GemState::_GL_TEX_UNITS, numUnits);
if (numCoords) {
s*=state->texCoordX(curCoord);
t*=state->texCoordY(curCoord);
}
if (numUnits) {
for( i=0; i<numUnits; i++)
for(int i=0; i<numUnits; i++)
glMultiTexCoord4fARB(GL_TEXTURE0+i, s, t, r, q);
} else { // no multitexturing!
glTexCoord4f(s, t, r, q);
......
......@@ -137,7 +137,6 @@ int createGemWindow(WindowInfo &info, WindowHints &hints)
XF86VidModeModeInfo **modes;
#endif
int modeNum=4;
int bestMode=0;
int fullscreen=hints.fullscreen;
char svalue[3];
......@@ -262,6 +261,7 @@ int createGemWindow(WindowInfo &info, WindowHints &hints)
int y = hints.y_offset;
#ifdef HAVE_LIBXXF86VM
if (fullscreen){
int bestMode=0;
/* look for mode with requested resolution */
for (int i = 0; i < modeNum; i++) {
if ((modes[i]->hdisplay == hints.width) && (modes[i]->vdisplay == hints.height)) {
......
......@@ -616,9 +616,8 @@ GEM_EXTERN void imageStruct::fromRGBA(const unsigned char *rgbadata) {
break;
case GL_BGRA_EXT:
if(pixels==rgbadata){
unsigned char dummy=0;
while(pixelnum--){
dummy=pixels[2];
unsigned char dummy=pixels[2];
pixels[2]=pixels[0];
pixels[0]=dummy;
pixels+=4;
......@@ -762,9 +761,8 @@ GEM_EXTERN void imageStruct::fromBGRA(const unsigned char *bgradata) {
case GL_RGBA:
if(bgradata==data){
// in place conversion
unsigned char dummy=0;
while(pixelnum--){
dummy =pixels[2];
unsigned char dummy=pixels[2];
pixels[2]=pixels[0];
pixels[0]=dummy;
pixels+=4;
......@@ -857,9 +855,8 @@ GEM_EXTERN void imageStruct::fromABGR(const unsigned char *abgrdata) {
case GL_BGRA_EXT:
if(abgrdata==data){
// in place conversion
unsigned char dummy=0;
while(pixelnum--){
dummy = pixels[0];
unsigned char dummy = pixels[0];
pixels[0] = pixels[1];
pixels[1] = pixels[2];
pixels[2] = pixels[3];
......@@ -879,9 +876,8 @@ GEM_EXTERN void imageStruct::fromABGR(const unsigned char *abgrdata) {
case GL_RGBA:
if(abgrdata==data){
// in place conversion
unsigned char dummy=0;
while(pixelnum--){
unsigned char dummy;
dummy =pixels[3]; pixels[3]=pixels[0]; pixels[0]=dummy;
dummy =pixels[1]; pixels[1]=pixels[2]; pixels[2]=dummy;
pixels+=4;
......@@ -969,8 +965,8 @@ GEM_EXTERN void imageStruct::fromARGB(const unsigned char *argbdata) {
case GL_BGRA_EXT:
if(argbdata==data){
// in place conversion
unsigned char dummy=0;
while(pixelnum--){
unsigned char dummy;
dummy = pixels[0]; pixels[0] = pixels[3]; pixels[3]=dummy;
dummy = pixels[1]; pixels[1] = pixels[2]; pixels[2]=dummy;
pixels+=4;
......@@ -1159,14 +1155,13 @@ GEM_EXTERN void imageStruct::fromYV12(const unsigned char*Y, const unsigned char
const unsigned char*pv=(format==GL_BGR_EXT)?U:V;
const unsigned char*pu=(format==GL_RGB)?U:V;
int y, u, v, yy;
int uv_r, uv_g, uv_b;
int row=ysize>>1;
int cols=xsize>>1;
yy=128;
while(row--){
int col=cols;
while(col--){
int uv_r, uv_g, uv_b;
int y, u, v;
u=*pu++ -UV_OFFSET;
v=*pv++ -UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1213,14 +1208,13 @@ GEM_EXTERN void imageStruct::fromYV12(const unsigned char*Y, const unsigned char
const unsigned char*pv=(format==GL_BGRA_EXT)?V:U;
const unsigned char*pu=(format==GL_RGBA)?V:U;
int y, u, v, yy;
int uv_r, uv_g, uv_b;
int row=ysize>>1;
int cols=xsize>>1;
yy=128;
while(row--){
int col=cols;
while(col--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=*pu++-UV_OFFSET;
v=*pv++-UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1322,14 +1316,13 @@ GEM_EXTERN void imageStruct::fromYV12(const short*Y, const short*U, const short*
const short*pv=V;//(format==GL_BGR_EXT)?V:U;
const short*pu=U;//(format==GL_RGB)?V:U;
int y, u, v, yy;
int uv_r, uv_g, uv_b;
int row=ysize>>1;
int cols=xsize>>1;
yy=128;
while(row--){
int col=cols;
while(col--){
int y, u, v;
int uv_r, uv_g, uv_b;
// these are from http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC30
u=(*pu++)>>8;
v=(*pv++)>>8;
......@@ -1411,14 +1404,13 @@ GEM_EXTERN void imageStruct::fromYV12(const short*Y, const short*U, const short*
const short*pv=V;//(format==GL_BGRA_EXT)?U:V;
const short*pu=U;//(format==GL_RGBA)?U:V;
int y, u, v, yy;
int uv_r, uv_g, uv_b;
int row=ysize>>1;
int cols=xsize>>1;
yy=128;
while(row--){
int col=cols;
while(col--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=(*pu++)>>8;
v=(*pv++)>>8;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1531,8 +1523,6 @@ GEM_EXTERN void imageStruct::fromUYVY(const unsigned char *yuvdata) {
case GL_BGR:
{
unsigned char *pixels=data;
int y, u, v;
int uv_r, uv_g, uv_b;
START_TIMING;
switch(m_simd){
#ifdef __SSE2__
......@@ -1544,6 +1534,8 @@ GEM_EXTERN void imageStruct::fromUYVY(const unsigned char *yuvdata) {
pixelnum>>=1;
while(pixelnum--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=yuvdata[0]-UV_OFFSET;
v=yuvdata[2]-UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1586,10 +1578,10 @@ GEM_EXTERN void imageStruct::fromUYVY(const unsigned char *yuvdata) {
#endif
case GEM_SIMD_NONE: default:
unsigned char *pixels=data;
int y, u, v;
int uv_r, uv_g, uv_b;
pixelnum>>=1;
while(pixelnum--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=yuvdata[0]-UV_OFFSET;
v=yuvdata[2]-UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1651,11 +1643,11 @@ GEM_EXTERN void imageStruct::fromYUY2(const unsigned char *yuvdata) { // YUYV
case GL_BGR:
{
unsigned char *pixels=data;
int y, u, v;
int uv_r, uv_g, uv_b;
pixelnum>>=1;
while(pixelnum--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=yuvdata[1]-UV_OFFSET;
v=yuvdata[3]-UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1683,10 +1675,10 @@ GEM_EXTERN void imageStruct::fromYUY2(const unsigned char *yuvdata) { // YUYV
case GL_BGRA: /* ==GL_BGRA_EXT */
{
unsigned char *pixels=data;
int y, u, v;
int uv_r, uv_g, uv_b;
pixelnum>>=1;
while(pixelnum--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=yuvdata[1]-UV_OFFSET;
v=yuvdata[3]-UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1746,11 +1738,11 @@ GEM_EXTERN void imageStruct::fromYVYU(const unsigned char *yuvdata) {
case GL_RGB: case GL_BGR:
{
unsigned char *pixels=data;
int y, u, v;
int uv_r, uv_g, uv_b;
pixelnum>>=1;
while(pixelnum--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=yuvdata[3]-UV_OFFSET;
v=yuvdata[1]-UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1778,10 +1770,10 @@ GEM_EXTERN void imageStruct::fromYVYU(const unsigned char *yuvdata) {
case GL_BGRA: /* ==GL_BGRA_EXT */
{
unsigned char *pixels=data;
int y, u, v;
int uv_r, uv_g, uv_b;
pixelnum>>=1;
while(pixelnum--){
int y, u, v;
int uv_r, uv_g, uv_b;
u=yuvdata[3]-UV_OFFSET;
v=yuvdata[1]-UV_OFFSET;
uv_r=YUV2RGB_12*u+YUV2RGB_13*v;
......@@ -1827,13 +1819,11 @@ GEM_EXTERN void imageStruct::fixUpDown(void) {
int linewidth = xsize*csize;
unsigned char*line = new unsigned char[linewidth];
unsigned char*line0, *line1;
int y0=0, y1=ysize-1;
for(y0=0; y0<ysize/2; y0++, y1--) {
line0=data+y0*linewidth;
line1=data+y1*linewidth;
int y1=ysize-1;
for(int y0=0; y0<ysize/2; y0++, y1--) {
unsigned char*line0=data+y0*linewidth;
unsigned char*line1=data+y1*linewidth;
memcpy(line , line0, linewidth);
memcpy(line0, line1, linewidth);
memcpy(line1, line , linewidth);
......@@ -1848,12 +1838,11 @@ GEM_EXTERN void imageStruct::fixUpDown(void) {
GEM_EXTERN void imageStruct::swapRedBlue(void) {
size_t pixelnum=xsize*ysize;
unsigned char *pixels=data;
unsigned char dummy=0;
switch (format){
case GL_YUV422_GEM:
pixelnum>>=1;
while(pixelnum--){
dummy=pixels[chU];
unsigned char dummy=pixels[chU];
pixels[chU]=pixels[chV]; // u
pixels[chV]=dummy; // v
pixels+=4;
......@@ -1861,7 +1850,7 @@ GEM_EXTERN void imageStruct::swapRedBlue(void) {
break;
case GL_RGB: case GL_BGR: