[opengtl-commits] [702] read the position of the alpha channel from the image |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 702
Author: cyrille
Date: 2009-03-26 15:06:15 +0100 (Thu, 26 Mar 2009)
Log Message:
-----------
read the position of the alpha channel from the image
Modified Paths:
--------------
trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h
trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2009-03-26 13:45:12 UTC (rev 701)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2009-03-26 14:06:15 UTC (rev 702)
@@ -175,6 +175,21 @@
new llvm::StoreInst( result, ptr, "", _currentBlock );
}
+void CodeGenerator::setPixelAlphaPos( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _image, const GTLCore::Type* _imageType )
+{
+ // Get the alpha position from the image
+ llvm::Value* alphaPos = callImageAlphaPos(_gc, _currentBlock, _imageType, _image);
+
+ // Create a pointer to the alphaPos index in the pixel structure
+ std::vector<llvm::Value*> indexes;
+ indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
+ indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::POS_ALPHAPOS ));
+ llvm::Value* ptr = llvm::GetElementPtrInst::Create( _pixel, indexes.begin(), indexes.end(), "", _currentBlock );
+
+ // Store the alpha position
+ new llvm::StoreInst( alphaPos, ptr, "", _currentBlock );
+}
+
llvm::Function* CodeGenerator::generateEvaluatePixeles( Kernel* _kernel, int _channels)
{
GTLCore::ModuleData* moduleData = _kernel->d->moduleData();
@@ -282,10 +297,14 @@
func->getBasicBlockList().push_back( firstBlockILoop );
llvm::Value* jVal = incJ->get( generationContext, firstBlockILoop );
llvm::Value* iVal = incI->get( generationContext, firstBlockILoop );
+ llvm::Value* px_var = resultVar->pointer(firstBlockILoop);
// Set the coordinates of the pixel
- setPixelCoordinates( generationContext, firstBlockILoop, resultVar->pointer(firstBlockILoop), iVal, GTLCore::Type::Integer32, jVal, GTLCore::Type::Integer32 );
+ setPixelCoordinates( generationContext, firstBlockILoop, px_var, iVal, GTLCore::Type::Integer32, jVal, GTLCore::Type::Integer32 );
+ // Set the position of the alpha channel
+ setPixelAlphaPos( generationContext, firstBlockILoop, px_var, arg_result, _kernel->d->outputImageType() );
+
// Call evaluatePixel
llvm::Function* llvmEPFunction = ePFunction->d->data->function( countArguments );
SHIVA_ASSERT( llvmEPFunction );
@@ -575,8 +594,21 @@
GTL_COMPARE_FUNCTION_PARAMETERS( func, image_wrap_data_params );
return llvm::CallInst::Create(
- func, image_wrap_data_params.begin(), image_wrap_data_params.end(), "", _currentBlock ); // TODO get the real type of the output image (even if it doesn't matter much currently)
+ func, image_wrap_data_params.begin(), image_wrap_data_params.end(), "", _currentBlock );
+}
+
+llvm::Value* CodeGenerator::callImageAlphaPos( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, const GTLCore::Type* _imageType, llvm::Value* _imageWrap )
+{
+ GTL_DEBUG( "CodeGenerator::callImageAlphaPos " << *_imageType << " " << *_imageWrap );
+ GTL_ASSERT( _imageType );
+ std::vector<llvm::Value*> image_wrap_data_params;
+ image_wrap_data_params.push_back( _imageWrap );
+ llvm::Function* func = Wrapper::image_alpha_posFunction( _gc.llvmModule(), _imageType );
+ GTL_COMPARE_FUNCTION_PARAMETERS( func, image_wrap_data_params );
+
+ return llvm::CallInst::Create(
+ func, image_wrap_data_params.begin(), image_wrap_data_params.end(), "", _currentBlock );
}
int imageSampleNearestId = 0;
@@ -625,6 +657,7 @@
callImageWrapData( generationContext, currentBlock, _imageType, arg_self, x_i, y_i ),
px_var, arg_self );
setPixelCoordinates( generationContext, currentBlock, px_var, x_f, GTLCore::Type::Float, y_f, GTLCore::Type::Float );
+ setPixelAlphaPos( generationContext, currentBlock, px_var, arg_self, _imageType );
llvm::ReturnInst::Create( px_var, currentBlock);
return func;
}
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h 2009-03-26 13:45:12 UTC (rev 701)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h 2009-03-26 14:06:15 UTC (rev 702)
@@ -81,11 +81,13 @@
static llvm::Value* accessPixelDataAsU8Ptr( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel);
static llvm::Value* callMemcpy( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _src, llvm::Value* _n );
static void setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _iVal, const GTLCore::Type* _iValType, llvm::Value* _jVal, const GTLCore::Type* _jValType );
+ static void setPixelAlphaPos( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _image, const GTLCore::Type* _imageType );
/**
* Call a "virtual" member of a structure, aka, a member with a pointer.
*/
static llvm::Value* callVirtualMember( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, int _member_index , std::vector<llvm::Value*> arguments);
static llvm::Value* callImageWrapData( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, const GTLCore::Type* _imageType, llvm::Value* _imageWrap, llvm::Value* _x, llvm::Value* _y );
+ static llvm::Value* callImageAlphaPos( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, const GTLCore::Type* _imageType, llvm::Value* _imageWrap);
private:
static int s_evaluatePixelesId;
};
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp 2009-03-26 13:45:12 UTC (rev 701)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp 2009-03-26 14:06:15 UTC (rev 702)
@@ -229,6 +229,15 @@
return (llvm::Function*)_module->getOrInsertFunction( "image_wrap_data", functionTy);
}
+llvm::Function* Wrapper::image_alpha_posFunction( llvm::Module* _module, const GTLCore::Type* _imageType )
+{
+ GTL_ASSERT( _imageType );
+ std::vector<const llvm::Type*> functionArgs;
+ functionArgs.push_back(llvm::PointerType::get( _imageType->d->type(), 0));
+ llvm::FunctionType* functionTy = llvm::FunctionType::get(llvm::IntegerType::get(32), functionArgs, false);
+ return (llvm::Function*)_module->getOrInsertFunction( "image_alpha_pos", functionTy);
+}
+
llvm::FunctionType* Wrapper::image_wrap_sample_nearest_type( GTLCore::TypesManager* _typesManager, const GTLCore::Type* _imageType, const GTLCore::Type* _pixelType )
{
std::vector<const llvm::Type*> functionArgs;
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h 2009-03-26 13:45:12 UTC (rev 701)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.h 2009-03-26 14:06:15 UTC (rev 702)
@@ -57,6 +57,7 @@
public:
static void fillTypesManager( GTLCore::ModuleData* _module, GTLCore::TypesManager*, GTLCore::ConvertCenter*, int _channels );
static llvm::Function* image_wrap_dataFunction( llvm::Module* _module, const GTLCore::Type* _imageType );
+ static llvm::Function* image_alpha_posFunction( llvm::Module* _module, const GTLCore::Type* _imageType );
static llvm::FunctionType* image_wrap_sample_nearest_type( GTLCore::TypesManager* _typesManager, const GTLCore::Type* _imageType, const GTLCore::Type* _pixelType );
static llvm::FunctionType* image_wrap_mem_to_vec_float_type( GTLCore::TypesManager* _typesManager, int _channels );
static llvm::FunctionType* image_wrap_vec_float_to_mem_type( GTLCore::TypesManager* _typesManager, int _channels );
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp 2009-03-26 13:45:12 UTC (rev 701)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp 2009-03-26 14:06:15 UTC (rev 702)
@@ -20,6 +20,7 @@
#include "ImageWrap_p.h"
#include "GTLCore/AbstractImage.h"
+#include <GTLCore/PixelDescription.h>
#include "../Debug.h"
@@ -33,4 +34,12 @@
return _imageWrap->image->data(_x, _y);
}
+int image_alpha_pos( ImageWrap* _imageWrap )
+{
+ SHIVA_ASSERT( _imageWrap );
+ SHIVA_ASSERT( _imageWrap->image );
+ std::cout << _imageWrap->image->pixelDescription().alphaPos() << std::endl;
+ return _imageWrap->image->pixelDescription().alphaPos();
}
+
+}
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h 2009-03-26 13:45:12 UTC (rev 701)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h 2009-03-26 14:06:15 UTC (rev 702)
@@ -50,7 +50,7 @@
extern "C" {
char* image_wrap_data( ImageWrap* _imageWrap, int _x, int _y );
-
+ int image_alpha_pos( ImageWrap* _imageWrap );
}
#endif