OSDN Git Service

add pdutility.h,cpp
authorrezoo <rezoolab@gmail.com>
Sat, 17 Oct 2009 13:35:20 +0000 (22:35 +0900)
committerrezoo <rezoolab@gmail.com>
Sat, 17 Oct 2009 13:35:20 +0000 (22:35 +0900)
src/cpp/OMakefile
src/cpp/pdutility.cpp [new file with mode: 0644]
src/cpp/pdutility.h [new file with mode: 0644]

index bb8ecf8..b79657d 100644 (file)
@@ -1,4 +1,4 @@
-SRCS = pdcamera pdvideo pdtracker
+SRCS = pdcamera pdvideo pdtracker pdutility
 TARGET = libpaldema
 
 CXXFLAGS += -shared
diff --git a/src/cpp/pdutility.cpp b/src/cpp/pdutility.cpp
new file mode 100644 (file)
index 0000000..a197087
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2009 Masaki Saito <rezoolab@gmail.com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+#include "pdutility.h"
+#include <stdio.h>
+
+using namespace pd;
+
+IplImage* loadTGAImage(const char* filename) {
+  unsigned char format;
+  unsigned short width, height;
+  unsigned char depth_color;
+  char* imageData;
+  IplImage* img;
+
+  FILE* fp = fopen(filename, "rb");
+  
+  unsigned char tgaheader[18];
+  int size = fread(tgaheader, 1, 18, fp);
+  if(size != 18) return NULL;
+  format = tgaheader[2];
+  width = *(short*)(tgaheader + 12);
+  height = *(short*)(tgaheader + 14);
+  depth_color = tgaheader[14];
+  
+  int imgsize = depth_color/8*width*height;
+  imageData = new char[imgsize];
+  
+  if(format == TGA_TYPE_FULLCOLOR) {
+    size = fread(imageData, 1, imgsize, fp);
+    if(size != imgsize) return NULL;
+    
+    if(depth_color == TGA_DEPTH_24BIT){
+      img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
+    }else if(depth_color == TGA_DEPTH_32BIT){
+      img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 4);
+    }else return NULL;
+    
+    img->imageData = imageData;
+    
+  } else if(format == TGA_TYPE_FULLCOLOR_RLE) {
+    return NULL; // »ÃÄêŪ¡£
+  } else {
+    fclose(fp);
+    return NULL;
+  }
+  fclose(fp);
+  
+  return img;
+}
+
diff --git a/src/cpp/pdutility.h b/src/cpp/pdutility.h
new file mode 100644 (file)
index 0000000..c971258
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2009 Masaki Saito <rezoolab@gmail.com>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+#include <cv.h>
+
+namespace pd {
+
+const int TGA_TYPE_NOIMAGE        = 0;
+const int TGA_TYPE_INDEXCOLOR     = 1;
+const int TGA_TYPE_FULLCOLOR      = 2;
+const int TGA_TYPE_MONOCHROME     = 3;
+const int TGA_TYPE_INDEXCOLOR_RLE = 9;
+const int TGA_TYPE_FULLCOLOR_RLE  = 10;
+const int TGA_TYPE_MONOCHROME_RLE = 11;
+const int TGA_DEPTH_24BIT = 24;
+const int TGA_DEPTH_32BIT = 32;
+
+IplImage* loadTGAImage(const char* filename);
+
+}