Fri Nov 22 00:24:30 2024
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2016-12-01

LEARN

2024-11-22 | 2024-10-22 | 2024-09-22 | 2024-08-22 | 2024-07-22 | 2024-06-22 | 2024-05-22 | 2024-04-22 | 2024-03-22 | 2024-02-22 | 2024-01-22 | 2023-12-22 | 2023-11-22 | 2023-10-22 | 2023-09-22 | 2023-08-22 | 2023-07-22 | 2023-06-22 | 2023-05-22 | 2023-04-22 | 2023-03-22 | 2023-02-22 | 2023-01-22 | 2022-12-22 | 2022-11-22 | 2022-10-22 | 2022-09-22 | 2022-08-22 | 2022-07-22 | 2022-06-22 | 2022-05-22 | 2022-04-22 | 2022-03-22 | 2022-02-22 | 2022-01-22 | 2021-12-22 | 2021-11-22 | 2021-10-22 | 2021-09-22 | 2021-08-22 | 2021-07-22 | 2021-06-22 | 2021-05-22 | 2021-04-22 | 2021-03-22 | 2021-02-22 | 2021-01-22 | 2020-12-22 | 2020-11-22 | 2020-10-22 | 2020-09-22 | 2020-08-22 | 2020-07-22 | 2020-06-22 | 2020-05-22 | 2020-04-22 | 2020-03-22 | 2020-02-22 | 2020-01-22 | 2019-12-22 | 2019-11-22 | 2019-10-22 | 2019-09-22 | 2019-08-22 | 2019-07-22 | 2019-06-22 | 2019-05-22 | 2019-04-22 | 2019-03-22 | 2019-02-22 | 2019-01-22 | 2018-12-22 | 2018-11-22 | 2018-10-22 | 2018-09-22 | 2018-08-22 | 2018-07-22 | 2018-06-22 | 2018-05-22 | 2018-04-22 | 2018-03-22 | 2018-02-22 | 2018-01-22 | 2017-12-22 | 2017-11-22 | 2017-10-22 | 2017-09-22 | 2017-08-22 | 2017-07-22 | 2017-06-22 | 2017-05-22 | 2017-04-22 | 2017-03-22 | 2017-02-22 | 2017-01-22 | 2016-12-22 | 2016-11-22 | 2016-10-22 | 2016-09-22 | 2016-08-22 | 2016-07-22 | 2016-06-22 | 2016-05-22 | 2016-04-22 | 2016-03-22 | 2016-02-22 | 2016-01-22 | 2015-12-22 | 2015-11-22 | 2015-10-22 | 2015-09-22 | 2015-08-22 | 2015-07-22 | 2015-06-22 | 2015-05-22 | 2015-04-22 | 2015-03-22 | 2015-02-22 | 2015-01-22 | 2014-12-22 | 2014-11-22 | 2014-10-22

Key: Value:

Key: Value:

MESSAGE
DATE 2016-12-21
FROM Ruben Safir
SUBJECT Re: [Learn] thread concurancy
From learn-bounces-at-nylxs.com Wed Dec 21 23:37:35 2016
Return-Path:
X-Original-To: archive-at-mrbrklyn.com
Delivered-To: archive-at-mrbrklyn.com
Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82])
by mrbrklyn.com (Postfix) with ESMTP id 1D32B161312;
Wed, 21 Dec 2016 23:37:35 -0500 (EST)
X-Original-To: learn-at-nylxs.com
Delivered-To: learn-at-nylxs.com
Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89])
by mrbrklyn.com (Postfix) with ESMTP id DEED1160E77
for ; Wed, 21 Dec 2016 23:37:31 -0500 (EST)
Received: from [10.0.0.62] (www.mrbrklyn.com [96.57.23.82])
by mailbackend.panix.com (Postfix) with ESMTPSA id 3BFF31336F
for ; Wed, 21 Dec 2016 23:37:31 -0500 (EST)
To: learn-at-nylxs.com
References: <2a2adad8-9115-46f3-f74f-82ea0d132614-at-mrbrklyn.com>
<1482374939422.53063-at-liu.edu>
From: Ruben Safir
Message-ID: <5d40f92d-f67f-4723-3fbc-d715f3786a2f-at-panix.com>
Date: Wed, 21 Dec 2016 23:37:30 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.5.1
MIME-Version: 1.0
In-Reply-To: <1482374939422.53063-at-liu.edu>
Content-Type: multipart/mixed; boundary="------------F9AE8DB7B02EBA172C533C7F"
Subject: Re: [Learn] thread concurancy
X-BeenThere: learn-at-nylxs.com
X-Mailman-Version: 2.1.17
Precedence: list
List-Id:
List-Unsubscribe: ,

List-Archive:
List-Post:
List-Help:
List-Subscribe: ,

Errors-To: learn-bounces-at-nylxs.com
Sender: "Learn"

This is a multi-part message in MIME format.
--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit



Blackboard is crap



On 12/21/2016 09:49 PM, Samir Iabbassen wrote:
> Hi Ruben,
>
> if you didn't send the project report, please send it to me along with whatever source code you have so far. the semester is at its end and I need to finalize grading. I know you have spent a lots of time on the project and I will be based on it for your total grading.
> Send me your resume and I will forward it to the my friend for the dba position, meanwhile follow the instructions for formal application.
> I also got following this morning from another friend if you are interested.
> >>Hi guys
>
> >>Do you know any jr. App Dev looking for a gig in city?
>
> >>There is job at DOT although not in IT dept. Computer Associate 2
>
> >>Let me know. I will send job link when active.
>
> >>Regards,
>
> Happy Holidays and see you in spring...
> ________________________________________
> From: Ruben Safir
> Sent: Wednesday, December 21, 2016 3:49 PM
> To: learn-at-nylxs.com
> Subject: thread concurancy
>
> [This mail was also posted to comp.lang.c++.]
>
> :(
>
> I don't know. I'm very confused about the behavior of this test program
> I've been right.
> I'm trying to move date by worker threads from one blob of memory to
> another and the debugger is saying that the pointers beg and
> canvas_index is jumping 10 bytes between this two lines
>
> for(int i = 0; i < 10;i++)
> {
> t[i] = std::thread([this]{ readin(beg, canvas_index); });
>
> and I'm not sure why. I lost the concurrency somewhere, but can't seem
> to figure out what I did wrong
>
>
> #include
> #include
> #include
> std::mutex medco;
> std::mutex master;
>
> namespace testing{
> std::thread t[10];
> class PIC
> {
> public:
> PIC():beg{&source[0]} {
> canvas_index = canvas;
> std::cout << "Testing Source" << std::endl;
> for(int i = 0; i<100; i++)
> {
> std::cout << i << " " << source[i] << std::endl ;
> }
> for(int i = 0; i < 10;i++)
> {
> t[i] = std::thread([this]{ readin(beg, canvas_index); });
> std::cerr << i << ": Making a thread" << std::endl;
> sync_canvas_and_input();
> }
> };
>
> void sync_canvas_and_input()
> {
> std::cout << "**LOCKING**" << std::endl;
> std::lock_guard turn(medco);
> beg += 10;
> canvas_index += 10;
> }
>
> ~PIC()
> {
> std::cerr << "In the destructor" << std::endl;
> for(int i=0; i<10; i++)
> {
> t[i].join();
> std::cerr << i << ": Joining a thread" << std::endl; }
>
> };
> void readin(char * start, char * loc_canvas_index)
> {
> for( int i = 9; i>=0; i-- )
> {
> *loc_canvas_index = start[i];
> std::cerr << i << ": Copy " << start[i] << std::endl;
> std::cerr << i << ": Copied to loc_canvas_index " <<
> reinterpret_cast(*loc_canvas_index) << std::endl;
> loc_canvas_index++;
> }
>
>
> --
> So many immigrant groups have swept through our town
> that Brooklyn, like Atlantis, reaches mythological
> proportions in the mind of the world - RI Safir 1998
> http://www.mrbrklyn.com
>
> DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
> http://www.nylxs.com - Leadership Development in Free Software
> http://www2.mrbrklyn.com/resources - Unpublished Archive
> http://www.coinhangout.com - coins!
> http://www.brooklyn-living.com
>
> Being so tracked is for FARM ANIMALS and and extermination camps,
> but incompatible with living as a free human being. -RI Safir 2013
>
> _______________________________________________
> Learn mailing list
> Learn-at-nylxs.com
> http://lists.mrbrklyn.com/mailman/listinfo/learn
>


--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/plain; charset=UTF-8;
name="makefile"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="makefile"

tesitng :
g++ -Wall -pthread -ggdb ./test.cpp


--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/x-c++src;
name="test.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="test.cpp"

/*
* =====================================================================================
*
* Filename: test.cpp
*
* Description: Threading Experiment
*
* Version: 1.0
* Created: 12/18/2016 12:46:51 PM
* Revision: none
* Compiler: gcc
*
* Author: Ruben Safir (mn), ruben-at-mrbrklyn.com
* Company: NYLXS Inc
*
* =====================================================================================
*/

#include
#include
#include
std::mutex medco;
std::mutex master;

namespace testing{
std::thread t[10];
class PIC
{
public:
PIC():source_index{&source[0]}
{
canvas_index = canvas;
std::cout << "Testing Source" << std::endl;
for(int i = 0; i<100; i++)
{
std::cout << i << " " << source[i] << std::endl ;
}

for(int i = 0; i < 10;i++)
{
t[i] = std::thread([this]{ readin(); });
std::cerr << i << ": Making a thread" << std::endl;
}
};


~PIC()
{
std::cerr << "In the destructor" << std::endl;
for(int i=0; i<10; i++)
{
t[i].join();
std::cerr << i << ": Joining a thread" << std::endl;
}

};

void readin()
{
char * loc_canvas_index;
char * loc_source_index;
sync_canvas_and_input(loc_canvas_index, loc_source_index);

for( int i = 9; i>=0; i-- )
{
*loc_canvas_index = loc_source_index[i];
std::cerr << i << ": Copy " << loc_source_index[i] << std::endl;
std::cerr << i << ": Copied to loc_canvas_index " << reinterpret_cast(*loc_canvas_index) << std::endl;
loc_canvas_index++;
}

};
void sync_canvas_and_input(char * &loc_canvas_index, char * &loc_source_index )
{
std::cout << "**LOCKING**" << std::endl;
std::lock_guard turn(medco);
loc_canvas_index = canvas_index;
loc_source_index = source_index;
source_index += 10;
canvas_index += 10;
};

char * get_canvas()
{
return canvas;
}
char * get_canvas_index()
{
return canvas_index;
}
char * get_source_index()
{
return source_index;
}

private:
char * canvas = new char[100]{
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z',
'z', 'z','z','z','z','z','z','z','z','z'
};
char * canvas_index;
char source[100] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'
};
char * source_index;
};
}//end namespace

int main(int argc, char** argv)
{
testing::PIC fido;
for(int i = 0; i<100;i++)
{
std::cout << i << " Canvas Position " << fido.get_canvas()[i] << std::endl;
}

return 0;
}


--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/x-c++src;
name="main_png.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="main_png.cpp"

/*
* =====================================================================================
*
* Filename: main_png.cpp
*
* Description: PNG Project - main
*
* Version: 1.0
* Created: 11/30/2016 02:57:46 PM
* Revision: 1.0
* Compiler: gcc
*
* Author: Ruben Safir (mn), ruben-at-mrbrklyn.com
* Company: NYLXS Inc
*
* =====================================================================================
*/
#include
#include "png_proj.h"

int main(int argc, char **argv)
{
// const char * image_file_path = nullptr;
const char * image_file_path = "/home/ruben/images/tzfat/tzfat_dawn_blended_fused.png";
//const char * image_file_path = "/home/ruben/photo_album/images/135-red_sea_1.png";
png_proj::Image pngtestfile{image_file_path};
// pngtestfile.read_png();
std::cout << "MAIN: line:" << __LINE__ << " char * image size==>" << sizeof(image_file_path) << std::endl;
pngtestfile.read_signature();
pngtestfile.read_chunk();
// while(pngtestfile.getNext() < pngtestfile.get_end() ){
// std::cout << "Hey I am not Kosher Bird, yoy can't eat me!!" << std::endl;
// }

return EXIT_SUCCESS;
}

--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/plain; charset=UTF-8;
name="makefile"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="makefile"

CXX:=g++
CXXFLAGS:=-Wall -ggdb -pg -pthread

LDFLAGS:=-L/usr/local/lib/mysql -lmysqlpp -lmysqlclient -lz


mypng : png_proj.o main.o
${CXX} ${CXXFLAGS} -o mypng png_proj.o main.o

main.o : main_png.cpp
${CXX} ${CXXFLAGS} -o main.o -c main_png.cpp

png_proj.o : png_proj.cpp
${CXX} ${CXXFLAGS} -o png_proj.o -c png_proj.cpp

clean :
rm png_proj *.o make.deps
touch *.cpp *.h

include make.deps
make.deps: *.cpp ; gcc -M *.cpp >$-at-

--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/x-c++src;
name="png_proj.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="png_proj.cpp"

/*
* =====================================================================================
*
* Filename: png_proj.cpp
*
* Description: PNG Project
*
* Version: 1.0
* Created: 11/15/2016 12:08:44 PM
* Revision: none
* Compiler: gcc
*
* Author: Ruben Safir (mn), ruben-at-mrbrklyn.com
* Company: NYLXS Inc
*
* =====================================================================================
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "png_proj.h"

namespace png_proj{


CHUNKY::CHUNKY(unsigned char * slice ):index_{slice}, type_{4,0},
length_{ ntohl(*( reinterpret_cast(slice) ) ) }
{
index(slice + 4 ); //peel off length
t( index() );
index(index() + 4 );//peel off type
type().assign(reinterpret_cast( t() ) , 4);
data( index() );
std::cout << __FILE__ << " LINE: " << __LINE__ << " CHUNKY constructor" << std::endl;
index(index() + length() );//peel off data!
std::cout << __FILE__ << " LINE: " << __LINE__ << " CHUNKY constructor: Length " << length() << std::endl;
cr(ntohl( *(reinterpret_cast( index() ) ) ) );
}

/* -- CHUNKY brush_stroke - paints CHUNKY data into IMAGE canvas --
* This is the intended location for any filtering or work on the pixil
* prior to compression. Originally the idea was to put the compression chucky size
* here but it is not how PNG works. They expect the IDAT payloads to be stiched
* together and then inflated with libz */
void CHUNKY::brush_stroke ( )
{
std::cout << __FILE__ << " LINE: " << __func__ << " " << __LINE__ << std::endl;
std::cout << std::endl;
std::cout << std::endl << "PAINTING" << std::endl;
unsigned char * input_paint = data();
for(unsigned char *i = begin(); i < end(); i++, input_paint++ )
{
std::cout << __LINE__ << " i: " << reinterpret_cast(i) << " input_paint: " << reinterpret_cast(input_paint) << std::endl;
*i = *input_paint;
std::cout << __LINE__ << std::endl;
std::cout << '*';
}
std::cout << std::endl;
return ;
} /* ----- end of method CHUNKY::brush_stroke ----- */


Image::Image(const char * in):chunk_dispatch{0}
{
if(in != nullptr)
{
this->read_png(reinterpret_cast(in) );
}
}

void Image::read_png( const unsigned char * in)
{
std::streampos size;
std::ifstream file;
unsigned char * image;
if(in == nullptr)
{
file.open("/home/ruben/png_project/airplane2.PNG", std::ios::in|std::ios::binary|std::ios::ate);

}else
{
file.open(reinterpret_cast(in), std::ios::in|std::ios::binary|std::ios::ate);
}

if (file.is_open())
{
size = file.tellg();
image = new unsigned char [size];
file.seekg (0, std::ios::beg);
file.read (reinterpret_cast(image), size);
file.close();

std::cout << std::endl << "the entire file content is in memory";
std::cout << std::endl << "File Size: " << size << std::endl ;
set_length(size);
set_index(image);//set the pic buffer index
set_pic(image); //store the pic buffer
set_end( get_index() + get_length() );
set_signature(); //set the internal copy of the signature
}
else{
std::cout << std::endl << "Unable to open file";
}
}

void Image::read_signature()
{
std::cout << "OK lets read the signature!!" << std::endl;
if(get_signature() == nullptr)
{
std::cerr << "The signature hasn't been initialized yet" << std::endl;
//this shouldn't be possible because it is defined as 8 char int in the const
//and then it is filled user set_signature
return;
}
for(int i = 0;i<8;i++)
{
std::cout << "index: " << i << " value: " << *( get_signature() + i ) << std::endl;
}
std::cout << std::endl << "done reading signature" << std::endl << std::endl << std::endl;
}


void Image::read_chunk ( )
{
CHUNKY * new_chunk = set_chunk();//the chunk construction call is within
std::cout << "Type " << new_chunk->type() << std::endl;
std::cout << "Length " << new_chunk->length() << std::endl;
std::cout << "CRC " << new_chunk->cr() << std::endl;

if(new_chunk->type() == "IHDR")
{
std::cout << "we have a header chunk " << std::endl;
IHDR * head = new IHDR;
unsigned char * cur = new_chunk->data(); //NOTE:: cur is now point at the new heap for in CHNUNK and not the index for the file
head->width = ntohl( *(reinterpret_cast(cur ) ) );
cur += 4;
head->height = ntohl( *(reinterpret_cast( cur ) ) );
cur += 4;
head->depth = *( reinterpret_cast( cur ) );
cur++;
head->color_type = *( reinterpret_cast( cur ) );
cur++;
head->compress = *( reinterpret_cast( cur ) );
cur++;
head->filter = *( reinterpret_cast( cur ) );
cur++;
head->interlace = *( reinterpret_cast( cur ) );
cur++;

canvas_size = static_cast(head->height) * static_cast(head->width) * blank_canvas_psize(*head);
canvas = new unsigned char[ canvas_size ];
canvas_index(canvas);
std::cout << "Canvas made: " << static_cast(head->height) * static_cast(head->width) * blank_canvas_psize(*head) << " bytes" << std::endl;
//char tmp;
//std::cin >> tmp;
}

if(new_chunk->type() == "IDAT")
{
//confusion here. Do we want to create a new data array on the heap to
//pass through to the images for placement on canvas?
//No. Not needed. use the CHUNKY object instead. have the chunky obj schedule itself for copy to the canvas

set_canvas(*new_chunk); //SET LOCK and assign canvas index to a CHUNKY object
new_chunk->brush_stroke();
}
if(new_chunk->type() == "IEND"){
std::cout << "we have a IEND chunk " << std::endl;
//set_index(get_index() + 12 + new_chunk->length() ) ;
return;
}
std::thread ctch = getNext();
ctch.detach();
//read_chunk();
return ;
} /* ----- end of method Image::read_chunk ----- */

/*
*--------------------------------------------------------------------------------------
* Class: Image
* Method: getNext
* Description: gets the next chunk and reads the data
*--------------------------------------------------------------------------------------
*/

std::thread Image::getNext ()
{
std::cout << std::endl << "getNext" << std::endl;
// next_index();
std::thread paint( [this]{ read_chunk(); } );
std::cout << std::endl << "**created thread**" << paint.get_id() << std::endl;
return paint;
} /* ----- end of method Image::getNext ----- */


}


--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/x-chdr;
name="png_proj.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="png_proj.h"

/*
* =====================================================================================
*
* Filename: png_proj.h
*
* Description: png_proj.h
*
* Version: 1.0
* Created: 11/30/2016 03:50:13 PM
* Revision: none
* Compiler: gcc
*
* Author: Ruben Safir (mn), ruben-at-mrbrklyn.com
* Company: NYLXS Inc
*
* =====================================================================================
*/

#ifndef PNGPRJ
#define PNGPRJ
#include
#include
#include

namespace png_proj{
std::mutex medco;
std::mutex master;

class thread_guard
{
public:
explicit thread_guard(std::thread& mythread):
thd{mythread}
{};
~thread_guard()
{
if(thd.joinable())
thd.join();
};
thread_guard(thread_guard const & )=delete; //prevent copy const
thread_guard& operator=(thread_guard const &)=delete;
std::thread& thd;
};

typedef uint32_t CHUNK;
struct IHDR {
int32_t width;
int32_t height;
int8_t depth;
int8_t color_type; //0 greyscale, 2 RGB, 3 Palette, 4 greyscale with alpha, 6 RGB with alpha
int8_t compress; //must be 0
int8_t filter; // must be zero
int8_t interlace;
};

/*
* =====================================================================================
* Class: CHUNKY
* Description: threaded chunk reader
* =====================================================================================
*/
class CHUNKY
{
public:

/* ==================== LIFECYCLE ======================================= */
CHUNKY (unsigned char *); /* constructor */
CHUNKY ( const CHUNKY &other ); /* copy constructor */
~CHUNKY (); /* destructor */

/* ==================== ACCESSORS ======================================= */
unsigned char *& index(){
return index_;
};
unsigned char * &index(unsigned char * pic_position){
index_ = pic_position;
return index_;
};
std::string &type(){
return type_;
};
uint32_t &length()
{
return length_;
};
uint32_t &length(uint32_t value){
return length_ = value;
};
unsigned char * & data(){
return data_;
};

unsigned char * &data(unsigned char * value){
// std::lock_guard turn(master);
// std::cout << "Master Lock Set" << std::endl;

if(value == nullptr){
std::cerr << "assigning empty chunk" << std::endl;
exit(1);
}
std::cout << std::endl << "LINE: " << __FILE__ << " " << __func__ << " " << __LINE__ << std::endl;
std::cout << length() << " length" << std::endl;
if(length() == 0) //cant seem to create an array with zero elements
return data_ = new unsigned char[1]{0};

data_ = new unsigned char[length()]{0};
std::cout << std::endl << "LINE: " << __FILE__ << " " << __func__ << " " << __LINE__ << std::endl;
std::cout << "Loading Payload of a Data Slice from Original Image Data" < for(unsigned int i = 0; i < length(); i++ ){
data_[i] = value[i];
}
std::cout << std::endl << "LINE: " << __FILE__ << " " << __func__ << " " << __LINE__ ;
std::cout << std::endl << "DATA's Address: " << reinterpret_cast(data_) << std::endl;
return data_;
};

uint32_t &cr()
{
return crc_;
};

uint32_t &cr(uint32_t value)
{
return crc_ = value;
};

unsigned char *begin()
{
return chunk_canvas_index;
};

void begin(unsigned char * value )
{
chunk_canvas_index = value;
};

unsigned char *end()
{
return next_canvas_index;
};

void end(unsigned char * value )
{
next_canvas_index = value;
};

/* ==================== MUTATORS ======================================= */
void brush_stroke();

/* ==================== OPERATORS ======================================= */

const CHUNKY& operator = ( const CHUNKY &other ); /* assignment operator */

unsigned char & operator[](unsigned int value){
if(value >= length()){
std::cerr << "out of range" << std::endl;
return data_[0];
}
return data_[value];
};

protected:

private:
/*=================== Private Accessory =====================================*/
std::string &type(std::string value){
type_ = value;
return type_;
};
std::string &type(char * type_name){
type_.resize(4);
type_.assign(type_name, 4);
return type_;
};

/* ==================== DATA MEMBERS ======================================= */

unsigned char * index_;
std::string type_ ;
unsigned char t_[5];
uint32_t length_;
unsigned char * data_; //payload
uint32_t crc_;
unsigned char * t(){
return t_; //4 byte type
};
unsigned char * t(unsigned char * value){ //this is TYPE rawdata
t_[1] = value[1];
t_[2] = value[2];
t_[3] = value[3];
t_[4] = '\0';
t_[0] = value[0];

return t_;
};

unsigned char * chunk_canvas_index;
unsigned char * next_canvas_index;

}; /* ----- end of class CHUNKY ----- */


/*
* =====================================================================================
* Class: Image
* Description: Basic Image Library for PNG and Parrallel Programming Class
* =====================================================================================
*/
class Image
{
public:
/* ==================== LIFECYCLE ======================================= */
Image (); /* constructor */
Image(const char *);


/* ==================== ACCESSORS ======================================= */

unsigned char * get_index ( )
{
return index;
}; /* ----- end of method Image::get_index ----- */

inline void set_index ( unsigned char * value )
{
index = value;
return ;
}; /* ----- end of method Image::set_index ----- */

unsigned char * get_pic ( )
{
return pic;
}; /* ----- end of method Image::get_pic ----- */

unsigned char* get_signature()
{
return loc_signature_cpy;
}; /* ----- end of method Image::get_signature ----- */

void set_signature ()
{
unsigned char * start = loc_signature_cpy;
//loc_signature_cpy is an array int he constructor of 8 chars
// unsigned char * value = get_pic();
std::cout << "setting the signature array**" << std::endl;
std::cout << "**************************" << std::endl;
for(int i = 0; i<8; i++){
std::cout << "setting the signature" << *get_index() << std::endl;
*start = *get_index(); //this is a copy
std::cout << "signature set to =>>" << *start<< std::endl;
next_index();
start++;
}
return ;
}; /* ----- end of method Image::set_signature ----- */


void set_pic ( unsigned char * value )
{
pic = value;
return ;
}; /* ----- end of method Image::set_pic ----- */

long unsigned int get_length ( )
{
return length;
}; /* ----- end of method Image::get_length ----- */

long unsigned set_length ( long unsigned int value )
{
length = value;
return value ;
}; /* ----- end of method Image::set_length ----- */

unsigned char * get_end()
{
return end;
}; /* --- end of method Image::get_end --- */

void set_end(unsigned char * value)
{
end = value;
}; /* --- end of method Image::set_end --- */

unsigned char * canvas_index()
{
return canvas_index_;
}; /* -- end of method Image::canvas_index --- */

void canvas_index(unsigned char * value)
{
canvas_index_ = value;

};/* -- end of method Image::canvas_index -- */


/* ==================== MUTATORS in CLASS Image:: ======================================= */
void read_png( const unsigned char * in = nullptr );
void read_signature();
void read_chunk();
std::thread getNext( );
CHUNKY * set_chunk()
{
std::cout << std::endl << "ENTER IMAGE::SET_CHUNK:: LINE: " << __func__ << " " << __LINE__ << std::endl;
std::lock_guard turn(master);
std::cout << "Master Lock Set" << std::endl;
unsigned char *cur = reinterpret_cast( get_index() );
CHUNKY * new_chunk = new CHUNKY(cur);
std::cout << std::endl << __FILE__ << " LINE: " << __func__ << " " << __LINE__ << std::endl;
set_index(get_index() + 12 + new_chunk->length() ) ;
std::cout << "Length after reading new chunk " << new_chunk->length() << std::endl;
std::cout << "Leaving set_chunk:: Master Lock Unset" << std::endl;
return new_chunk;

};

CHUNKY & set_canvas(CHUNKY &yourit)
{
std::cout << std::endl << "LINE: " << __FILE__ << " " << __func__ << " " << __LINE__ << std::endl;
std::lock_guard turn(medco);
std::cout << "Medco Lock Set" << std::endl;
yourit.begin( canvas_index() );
yourit.end( canvas_index() + yourit.length() );
canvas_index( yourit.end() );
std::cout << "Lock " << std::dec << std::showbase << reinterpret_cast(yourit.begin() ) << " : " << std::dec << std::showbase << reinterpret_cast( yourit.end() )<< std::endl;
return yourit;
};

void next_index()
{
unsigned char * tmp = get_index();
set_index(++tmp);
};

void signature()
{
read_signature();
};


/* ==================== OPERATORS ======================================= */

/* ==================== DATA MEMBERS ======================================= */
protected:

private:
unsigned char * pic;
unsigned char loc_signature_cpy[8];
unsigned char * index;
unsigned char * end;
long unsigned int length; //This is the length of the entire image
// uint8_t * data = nullptr;
// int32_t type;
// int32_t crc;

unsigned char * canvas; //this is the outgoign image data
unsigned char * canvas_index_;
long int canvas_size;
long int chunk_dispatch;

int blank_canvas_psize(const IHDR &look )
{
int pixil_size;
switch (look.color_type)
{
case 0:
if(look.depth == 1)
pixil_size = 1;
if(look.depth == 2)
pixil_size = 1;
if(look.depth == 4)
pixil_size = 1;
if(look.depth == 8)
pixil_size = 1;
if(look.depth == 16)
pixil_size = 2;
break;
case 2:
if(look.depth == 8)
pixil_size = 3;
if(look.depth == 16)
pixil_size = 6;
break;
case 3:
if(look.depth == 1)
pixil_size = 3;
if(look.depth == 2)
pixil_size = 3;
if(look.depth == 4)
pixil_size = 3;
if(look.depth == 8)
pixil_size = 3;
break;
case 4:
if(look.depth == 8)
pixil_size = 4;
if(look.depth == 16)
pixil_size = 8;
break;
case 6:
if(look.depth == 8)
pixil_size = 4;
if(look.depth == 16)
pixil_size = 8;
break;
default:
std::cerr << "incorrect color type" << std::endl;
exit(EXIT_FAILURE);
}
return pixil_size;
};
}; /* ----- end of class Image ----- */


}
#endif

--------------F9AE8DB7B02EBA172C533C7F
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Learn mailing list
Learn-at-nylxs.com
http://lists.mrbrklyn.com/mailman/listinfo/learn

--------------F9AE8DB7B02EBA172C533C7F--

  1. 2016-12-01 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Learn] Fwd: Patrolling the Dark Net,
  2. 2016-12-02 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Tutorial on threaded binary tree part 1: simple
  3. 2016-12-03 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Witner Labs
  4. 2016-12-04 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Nice lecture on Quantum Mechanics
  5. 2016-12-05 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] information access, copyright wars and DRM
  6. 2016-12-06 Christopher League <league-at-contrapunctus.net> Re: [Learn] png data format
  7. 2016-12-06 Christopher League <league-at-contrapunctus.net> Re: [Learn] png data format
  8. 2016-12-06 Christopher League <league-at-contrapunctus.net> Re: [Learn] png data format
  9. 2016-12-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] png data format
  10. 2016-12-06 Christopher League <league-at-contrapunctus.net> Re: [Learn] png data format
  11. 2016-12-06 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Learn] png data format
  12. 2016-12-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] png data format
  13. 2016-12-06 Christopher League <league-at-contrapunctus.net> Re: [Learn] png data format
  14. 2016-12-06 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] png data format
  15. 2016-12-06 Christopher League <league-at-contrapunctus.net> Re: [Learn] png data format
  16. 2016-12-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] [Hangout-NYLXS] png data format
  17. 2016-12-06 John Bowler <john.cunningham.bowler-at-gmail.com> Re: [Learn] [png-mng-implement] 4 byte length storage
  18. 2016-12-06 John Bowler <john.cunningham.bowler-at-gmail.com> Re: [Learn] [png-mng-implement] 4 byte length storage
  19. 2016-12-06 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] [png-mng-implement] 4 byte length storage
  20. 2016-12-06 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Ocaml
  21. 2016-12-06 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: [luny-talk] Humble Bundle O'Reilly UNIX books
  22. 2016-12-06 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] JT's words
  23. 2016-12-06 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] png data format
  24. 2016-12-07 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: png data format
  25. 2016-12-08 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: png data format
  26. 2016-12-08 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: png data format
  27. 2016-12-08 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: png data format
  28. 2016-12-10 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] references to pointers
  29. 2016-12-10 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] C++ returning lvalue references and pointers and refs
  30. 2016-12-10 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] const puzzle and literal type arguments
  31. 2016-12-11 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: png data format
  32. 2016-12-12 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Fwd: Re: png data format
  33. 2016-12-12 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] gene phylogienics of homonids
  34. 2016-12-13 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Bit Depth
  35. 2016-12-13 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] C++ Threads Workshop
  36. 2016-12-13 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Summer Jobs
  37. 2016-12-14 From: "Mancini, Sabin (DFS)" <Sabin.Mancini-at-dfs.ny.gov> Subject: [Learn] For Ruben ( + those in NYC Metro ) : Holiday Social Event
  38. 2016-12-14 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: [dinosaur] Ceratopsid (Centrosaurinae:
  39. 2016-12-15 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [Learn] Happy Holidays
  40. 2016-12-15 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] zlib demo with vector::resize
  41. 2016-12-15 John Bowler <john.cunningham.bowler-at-gmail.com> Re: [Learn] [png-mng-implement] 4 byte length storage
  42. 2016-12-15 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: [dinosaur] Elephant bird nuclear genome fragments
  43. 2016-12-15 Christopher League <league-at-contrapunctus.net> Subject: [Learn] zlib demo with vector::resize
  44. 2016-12-16 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] zlib demo with vector::resize
  45. 2016-12-16 Christopher League <league-at-contrapunctus.net> Re: [Learn] zlib demo with vector::resize
  46. 2016-12-16 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] PNG Parallel Programming problem
  47. 2016-12-17 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] [Hangout-NYLXS] I'm sure it's a coincidence, part n+1
  48. 2016-12-17 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] irc thread on the use of object methods in threads
  49. 2016-12-17 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] PNG threaded program
  50. 2016-12-18 ruben safir <ruben-at-mrbrklyn.com> Re: [Learn] Threads and Object Methods
  51. 2016-12-18 ruben safir <ruben-at-mrbrklyn.com> Re: [Learn] Threads and Object Methods
  52. 2016-12-18 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Look C++ is a functional programming language
  53. 2016-12-19 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] C++ Threading
  54. 2016-12-19 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] C++ Threading
  55. 2016-12-19 ISOC-NY announcements <announce-at-lists.isoc-ny.org> Subject: [Learn] [isoc-ny] JOB: Telecommunications Policy Specialist -at- NTIA
  56. 2016-12-20 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] F'ing Mouse Pad
  57. 2016-12-20 mrbrklyn <mrbrklyn-at-panix.com> Subject: [Learn] Phylogenetic study worth noting
  58. 2016-12-21 Samir Iabbassen <Samir.Iabbassen-at-liu.edu> Re: [Learn] Noobdy is home
  59. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] Noobdy is home
  60. 2016-12-21 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Noobdy is home
  61. 2016-12-21 Samir Iabbassen <Samir.Iabbassen-at-liu.edu> Re: [Learn] thread concurancy
  62. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] thread concurancy
  63. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: lamda's in classes
  64. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: lamda's in classes
  65. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: thread concurancy
  66. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  67. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  68. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  69. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  70. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  71. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  72. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  73. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  74. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Re: Threads and Object Methods
  75. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) thread concurancy
  76. 2016-12-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [Learn] (fwd) Threads and Object Methods
  77. 2016-12-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] I need help
  78. 2016-12-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Noobdy is home
  79. 2016-12-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] thread concurancy
  80. 2016-12-21 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] [Hangout-NYLXS] Marnchester by the Sea
  81. 2016-12-22 Ruben Safir <mrbrklyn-at-panix.com> Re: [Learn] [Hangout-NYLXS] And be aware you were an unexcused
  82. 2016-12-22 ruben safir <ruben-at-mrbrklyn.com> Subject: [Learn] Fwd: Re: thread concurancy
  83. 2016-12-23 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] HOPL (History of Programming Languages)
  84. 2016-12-23 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Noobdy is home
  85. 2016-12-23 Ruben Safir <ruben-at-mrbrklyn.com> Re: [Learn] Tiny Compiler in many languages at Rosettacode.org
  86. 2016-12-25 Ruben Safir <ruben-at-mrbrklyn.com> Subject: [Learn] Google and C++
  87. 2016-12-25 Ruben Safir <ruben.safir-at-my.liu.edu> Subject: [Learn] phylogentics
  88. 2016-12-27 Samir Iabbassen <Samir.Iabbassen-at-liu.edu> Re: [Learn] thread concurancy

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!