Set and get data from vx_image - openvx

I have two vx_image's src and dst, I need to get each pixel from the src vx_image and do some operation and set that to dst vx image.
vx_image src;
vx_image dst;
I couldn't find the proper documentation for doing this. May I know how to do this ?.
Thank you.

foo (vx_image & vxSrcImg, vx_image vxDstImg)
{
vx_rectangle_t rect1;
vx_rectangle_t rect2;
vxGetValidRegionImage(vxSrcImg, &rect1);
vxGetValidRegionImage(vxDstImg, &rect2);
vx_imagepatch_addressing_t addr1;
vx_imagepatch_addressing_t addr2;
vx_uint8 *ptr1 = NULL;
vx_uint8 *ptr2 = NULL;
vx_uint32 plane1;
vx_uint32 plane2;
vx_status status1 = vxAccessImagePatch(vxSrcImg, &rect1, plane1, &addr1, &ptr1, VX_READ_AND_WRITE);
vx_status status2 = vxAccessImagePatch(vxDstImg, &rect2, plane2, &addr2, &ptr2, VX_READ_AND_WRITE);
int i=0;
for (i = 0; i < addr1.dim_x * addr1.dim_y; i++)
{
ptr2[i] = myPixelOperation (ptr1[i]);
}
// Rectangle needs to be commit back to the image post operation.
vx_status status3 = vxCommitImagePatch(vxSrcImg, &rect1, plane1, &addr1, &ptr1);
vx_status status4 = vxCommitImagePatch(vxDstImg, &rect2, plane2, &addr2, &ptr2);
}

There is a section "Host Memory Data Object Access Patterns" in the specification : https://www.khronos.org/registry/OpenVX/specs/1.2/html/page_design.html#sec_host_memory
It shows examples of accessing different data objects (includeing images).

Related

How to make URI locations from AST to map on a file read

In ClaiR it is not (yet) possible to write changes made in the AST back to file.
For this reason, I create a list lrel[int, int, str] changes = []; with startposition and endposition of the substring to remove, and a string with which it needs to be replaced.
When I have a full list of changes I want to make to a source file, I sort the changes and open the file with fb = chars(readFile(f));
make the changes
public list[int] changeCharList(list[int] charList, lrel[int, int, str] changesList) {
int offset = 0;
for (t <- [0 .. size(changesList)]) {
tuple[int startIndex, int endIndex, str changeWithString] change = changesList[t];
int startIndexWithOffset = change.startIndex + offset;
int endIndexWithOffset = change.endIndex + offset;
list[int] changeWithChars = chars(change.changeWithString);
for (i <- [startIndexWithOffset .. endIndexWithOffset]) {
charList = delete(charList, startIndexWithOffset);
}
for (i <- [0 .. size(changeWithChars)]) {
charList = insertAt(charList, startIndexWithOffset + i, changeWithChars[i]);
}
offset += size(changeWithChars) - (change.endIndex - change.startIndex);
}
return charList;
}
and write to file writeFileBytes(f, fb);
This approach works for source files without expanded macros, but it does not work for sources files with expanded macros. In the later case the offsets used in the AST do not map the offsets with the file opened using readFile.
As a workaround I can comment macros before running Rascal and uncomment them after running Rascal. I do not like this.
Is there a way to recalculate the offsets in such a way that the AST offsets map the file read offsets?

Game Maker Studio: DoSet :: Invalid comparison type

___________________________________________
############################################################################################
FATAL ERROR in
action number 4
of Create Event
for object eng_Global:
DoSet :: Invalid comparison type
at gml_Script_Data_Load (line 1) - ///Data_Load()
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_Data_Load (line 1)
called from - gml_Object_eng_Global_CreateEvent_4 (line 60) - Data_Load();
I get this error on a comment, not an actual if statement, I can't bypass this without commenting out Data_Load(), which is what loads the users' data.
I recently updated to version 1.4.1567, maybe that is a bug in this version.
I should state that "Connected" and "Guest" variables are both integers (boolean) and do not get set to string at any point in the code.
Here is the Data_Load() script:
///Data_Load()
if (Connected && !Guest) {
ini_open(User_Name+"_NSD_Temp.ini");
// Base Statistics
Level = ini_read_real("Statistics","Level",Level);
Exp_Total = ini_read_real("Statistics","Experience_Total",Exp_Total);
Exp = ini_read_real("Statistics","Experience",Exp);
Exp_Left = ini_read_real("Statistics","Experience_Left",Exp_Left);
Exp_Max = ceil(Level*5);
Gold = ini_read_real("Statistics","Gold",Gold);
Gold_Total = ini_read_real("Statistics","Gold_Total",Gold_Total);
Karma = ini_read_real("Statistics","Karma",Karma);
Karma_Total = ini_read_real("Statistics","Karma_Total",Karma_Total);
Highscore = ini_read_real("Statistics","Highscore",Highscore);
Weapons_Inv_Length = ini_read_real("Statistics","Weapons_Inv_Length",Weapons_Inv_Length);
Stones_Inv_Length = ini_read_real("Statistics","Stones_Inv_Length",Stones_Inv_Length);
Stone_Slots_Owned = ini_read_real("Statistics","Stones_Slots_Owned",Stones_Slots_Owned);
// Game
Ninja_Name = ini_read_string("Game","Ninja_Name",Ninja_Name);
Ninja_Level = ini_read_real("Game","Ninja_Level",Ninja_Level);
Ninja_Health = ini_read_real("Game","Ninja_Health",Ninja_Health);
Ninja_Health_Max = ini_read_real("Game","Ninja_Health_Max",Ninja_Health_Max);
Ninja_Health_Regen_Upgrade = ini_read_real("Game","Ninja_Health_Regen_Upgrade",Ninja_Health_Regen_Upgrade);
Ninja_Health_Regen = Ninja_Health_Base*(Ninja_Health_Regen_Upgrade)/room_speed;
Ninja_Weapon = ini_read_real("Game","Ninja_Weapon",Ninja_Weapon);
Ninja_Colour = ini_read_real("Game","Ninja_Colour",Ninja_Colour);
Ninja_Power = ini_read_real("Game","Ninja_Power",Ninja_Power);
Ninja_Max_Speed = ini_read_real("Game","Ninja_Max_Speed",Ninja_Max_Speed);
Ninja_Attack_Speed = ini_read_real("Game","Ninja_Attack_Speed",Ninja_Attack_Speed);
// Weapons Inventory
for (i=0; i<Weapons_Inv_Length; i++) {
Weapons_Inv[i,0] = i;
Weapons_Inv[i,1] = ini_read_real("Weapons Inventory","Inv_Slot_"+string(i),0);
Weapons[Weapons_Inv[i,1],5] = ini_read_real("Weapons Inventory","Inv_Slot_"+string(i)+"_Owned",Weapons[Weapons_Inv[i,1],5]);
}
// Stones Inventory
for (i=0; i<Stones_Inv_Length; i++) {
Stones_Inv[i,0] = i;
Stones_Inv[i,1] = ini_read_real("Stones Inventory","Inv_Slot_"+string(i),0);
Stones[Stones_Inv[i,1],5] = ini_read_real("Stones Inventory","Inv_Slot_"+string(i)+"_Owned",Stones[Stones_Inv[i,1],5]);
}
// Equipped Stones
for (i=0; i<Stone_Slots_Owned; i++) {
Stone_Slots[i,0] = i;
Stone_Slots[i,1] = ini_read_real("Stones Equipped","Slot_"+string(i),Stone_Slots[i,1]);
}
// Costume Colours
for (i=0; i<array_height_2d(Colours); i++) {
Colours[i,5] = ini_read_real("Costume Colours",Colours[i,1],Colours[i,5]);
}
// Stats
Stat_Clouds_Clicked = ini_read_real("Stats","Clouds_Clicked",Stat_Clouds_Clicked);
Stat_Stars_Clicked = ini_read_real("Stats","Stars_Clicked",Stat_Stars_Clicked);
// Options
SoundFX = ini_read_real("Options","SoundFX",SoundFX);
// Version
Save_Version = ini_read_string("Version","Current",Save_Version);
// Resets
ForceResets = ini_read_string("External","Force_Resets",Force_Resets);
ini_close();
if (ForceResets != Force_Resets) {
Data_Erase();
}
Data_Submit();
} // If Connected & Not Guest
GM's compiler is always weird about those line errors. It often doesn't count blank lines as actual lines.
If you adjust for that issue, the real line of code that is throwing the error is this:
if (ForceResets != Force_Resets) {
Maybe it doesn't like that you're basically asking "If something is not equal to itself", which hardly makes sense. That statement will always evaluate to false, so you should probably remove it.
Seeing as you don't declare var on any of these variables, then you're manipulating the variables on the instance that called this script. If there's somehow a ForceResets script variable, and a ForceResets variable on the calling instance, then this whole thing might be a naming issue. I'm also making this assuming because you called:
ForceResets = ini_read_string("External","Force_Resets",Force_Resets);
Where that third parameter isn't declared anywhere in this script.
All in all, I'd say that you need to clean this script up a little.
Pro Tip: Use for(var i = 0; ... instead of for(i = 0 99% of the time. Otherwise you're leaving this instance with an i variable that it will never use.

easy way of ensuring one element is always in front of everything else?

on a website I want to have an element take up the entire space of the screen (after an event), but I can't seem to manage to get it in front of all the other elements on my website. Do I have to set positions and z-indexes for everything or is there another way of setting the element I want in front of everything else?
Brute force.
function getMaxZ() {
var all = document.querySelectorAll('*');
var len = all.length;
var maxZ = 0;
var dv = document.defaultView;
for (var i = 0; i < len ; i++) {
var el = all[i];
var thisZ = el.currentStyle ? el.currentStyle : dv.getComputedStyle(el, null);
thisZ = thisZ.zIndex.replace(/[^\d]/,'') * 1;
if (thisZ > maxZ) maxZ = thisZ;
}
return maxZ;
}
alert(getMaxZ());
If you want this thing always on top, just set its z-index to 999 (or something higher than you know everything else is).

ASP.NET StreamWriter - new line after x commas

I've got a JS array which is writing to a text file on the server using StreamWriter. This is the line that does it:
sw.WriteLine(Request.Form["seatsArray"]);
At the moment one line is being written out with the entire contents of the array on it. I want a new line to be written after every 5 commas. Example array:
BN,ST,A1,303,601,BN,ST,A2,303,621,BN,WC,A3,303,641,
Should output:
BN,ST,A1,303,601,
BN,ST,A2,303,621,
BN,WC,A3,303,641,
I know I could use a string replace but I only know how to make this output a new line after every comma, and not after a specified amount of commas.
How can I get this to happen?
Thanks!
Well, here's the simplest answer I can think of:
string[] bits = Request.Form["seatsArray"].Split(',');
for (int i = 0; i < bits.Length; i++)
{
sw.Write(bits[i]);
sw.Write(",");
if (i % 5 == 4)
{
sw.WriteLine();
}
}
It's not terribly elegant, but it'll get the job done, I believe.
You may want this afterwards to finish off the current line, if necessary:
if (bits[i].Length % 5 != 0)
{
sw.WriteLine();
}
I'm sure there are cleverer ways... but this is simple.
One question: are the values always three characters long? Because if so, you're basically just breaking the string up every 20 characters...
Something like:
var input = "BN,ST,A1,303,601,BN,ST,A2,303,621,BN,WC,A3,303,641,";
var splitted = input.Split(',');
var cols = 5;
var rows = splitted.Length / cols;
var arr = new string[rows, cols];
for (int row = 0; row < rows; row++)
for (int col = 0; col < cols; col++)
arr[row, col] = splitted[row * cols + col];
I will try find a more elegant solution. Properly with some functional-style over it.
Update: Just find out it is not actually what you needs. With this you get a 2D array with 3 rows and 5 columns.
This however will give you 3 lines. They do not have a ending ','. Do you want that? Do you always want to print it out? Or do you want to have access to the different lines?:
var splitted = input.Split(new [] { ','}, StringSplitOptions.RemoveEmptyEntries);
var lines = from item in splitted.Select((part, i) => new { part, i })
group item by item.i / 5 into g
select string.Join(",", g.Select(a => a.part));
Or by this rather large code. But I have often needed a "Chunk" method so it may be reusable. I do not know whether there is a build-in "Chunk" method - couldn't find it.
public static class LinqExtensions
{
public static IEnumerable<IList<T>> Chunks<T>(this IEnumerable<T> xs, int size)
{
int i = 0;
var curr = new List<T>();
foreach (var x in xs)
{
curr.Add(x);
if (++i % size == 0)
{
yield return curr;
curr = new List<T>();
}
}
}
}
Usage:
var lines = input.Split(',').Chunks(5).Select(list => string.Join(",", list));

Use Take() to get a limited number of results but also get the potential total

Given the following...
int maxResults = 25;
string code = "Thailand";
var q = from i in images where i.component_code == code select i;
var images = q.OrderByDescending(x => x.image_rating).Take(maxResults);
if (images.Count() > 0)
{
...
lblResult = string.Format("Viewing {0} Images Of A Possible {1}", images.Count(), ?);
}
How do I get the potential total number of images that would have been returned if Take() had not been used
Can't you use q.Count() for this?

Resources