X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fcpp%2Fpdutility.cpp;fp=src%2Fcpp%2Fpdutility.cpp;h=4888adf218690ff36284861fb3c9ab721e097bff;hb=c207b2f3957dbf66d5d9b458f765b44ce421fe65;hp=4791f714957829f5f4ed86c06454ab1674ab336e;hpb=07d656f78d8067db9f89a832f838423c8db1985e;p=paldema%2Fpaldema.git diff --git a/src/cpp/pdutility.cpp b/src/cpp/pdutility.cpp index 4791f71..4888adf 100644 --- a/src/cpp/pdutility.cpp +++ b/src/cpp/pdutility.cpp @@ -18,15 +18,21 @@ #include #include -IplImage* pd::loadTGAImage(const char* filename) { - unsigned char format; - unsigned short width, height; - unsigned char depth_color; - char* imageData; - IplImage* img; +namespace pd { + +IplImage* loadTGAImage(const char* filename) { + unsigned char format; // TGA‰æ‘œ‚̃tƒH[ƒ}ƒbƒg + unsigned short width, height; // •A‚‚³ + unsigned char depth_color; // F[“x + char* imageData; // ¶‚̃f[ƒ^ + bool direction_x; // Ši”[•ûŒü(x•ûŒü,false=¶‚©‚ç‰E,true=‰E‚©‚獶) + bool direction_y; // Ši”[•ûŒü(y•ûŒü,false=‰º‚©‚çã,true=ã‚©‚牺) + IplImage* img; // ÅI“I‚ÉŠi”[‚·‚éIplImage FILE* fp = fopen(filename, "rb"); + // ƒwƒbƒ_î•ñ‚Ì“Ç‚ÝŽæ‚è + unsigned char tgaheader[18]; if(fread(tgaheader, 1, 18, fp) != 18){ fclose(fp); @@ -39,9 +45,19 @@ IplImage* pd::loadTGAImage(const char* filename) { depth_color = tgaheader[16]; unsigned char channel = depth_color/8; + unsigned char direction_byte = tgaheader[17]; + direction_x = ((0x01 << 4) & direction_byte) >> 4; + direction_y = ((0x01 << 5) & direction_byte) >> 5; + if(direction_x == true){ //‰E‚©‚獶‚ÉŠi”[‚µ‚Ä‚ ‚éƒf[ƒ^‚͓ǂݍž‚Ü‚È‚¢ + fclose(fp); + return NULL; + } + unsigned int imgsize = channel*width*height; imageData = new char[imgsize]; + // ‚»‚ꂼ‚ê‚Ì•ûŽ®‚ɑΉž‚µ‚½“Ç‚ÝŽæ‚è + if(format == TGA_TYPE_FULLCOLOR) { // ƒtƒ‹ƒJƒ‰[‰æ‘œ(RLEˆ³k‚È‚µ)‚̏ꍇ if(fread(imageData, 1, imgsize, fp) != imgsize){ @@ -113,6 +129,11 @@ IplImage* pd::loadTGAImage(const char* filename) { img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 4); img->imageData = imageData; + // ƒwƒbƒ_‚̐ݒè + if(direction_y == true) img->origin = 0; + else img->origin = 1; + img->widthStep = width*channel; + } else { fclose(fp); return NULL; @@ -121,3 +142,5 @@ IplImage* pd::loadTGAImage(const char* filename) { return img; } + +}