MESSAGE
DATE | 2016-12-06 |
FROM | Ruben Safir
|
SUBJECT | Re: [Learn] [Hangout-NYLXS] png data format
|
From learn-bounces-at-nylxs.com Tue Dec 6 09:19:09 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 95E9B161317; Tue, 6 Dec 2016 09:19:08 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id 4E825161311; Tue, 6 Dec 2016 09:19:02 -0500 (EST) To: hangout-at-nylxs.com, learn-at-nylxs.com References: <66105244-4afa-4330-b0c2-0661bde965fd-at-mrbrklyn.com> From: Ruben Safir Message-ID: <88d707eb-a9af-0c28-b0f0-ba42a14efae5-at-mrbrklyn.com> Date: Tue, 6 Dec 2016 09:19:02 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <66105244-4afa-4330-b0c2-0661bde965fd-at-mrbrklyn.com> Content-Type: multipart/mixed; boundary="------------16735A954701A5CD405EE5A1" Subject: Re: [Learn] [Hangout-NYLXS] png data format 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. --------------16735A954701A5CD405EE5A1 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit
On 12/06/2016 09:10 AM, ruben safir wrote: > Hello > > I'm having trouble with this imput of data from a PNG image. The > specification says that "chunks" have a 4 byte field that is the length > of the attached data segment. I tried to read the length in for a chunk > that has a length of 13, which was confirmed in a hexdump > > 0000000 211 120 116 107 015 012 032 012 -->>000 000 000 015<<-- 111 110 > 104 122 > 0000010 000 000 041 215 000 000 007 165 010 006 000 000 001 206 055 074 > 0000020 336 000 000 000 004 147 101 115 101 000 000 261 217 013 374 141 > > I am storing the data in a uint32_t variable using the following code, > but the value keeps showing up with a huge number 218103808 which > happens to be the number that is evaluated by iostream for the value of > the whole chunk > > > done reading header > > > > Sizeof Chunk 4 > Raw Chunk Number 0: 218103808 > ***LENGTH**** > Length value => 218103808 > Sizeof Byte 1 > Character 0:: > ^-at- > Byte 0:: > 0 > Character 1:: > ^-at- > Byte 1:: > 0 > Character 2:: > ^-at- > Byte 2:: > 0 > Character 3:: > Byte 3:: > 13 > > > As yet, when I break it down by single bytes, it returns 0 0 0 13, which > is correct. ddd seems to say the same thing, and I don't know why. > When evaluated as 4 bytes, you get this large number, but when you > evaluate them seperately, each byte, it comes out right. > > The code snippet I'm using looks like this > > in the .h file #ifndef PNGPRJ > #define PNGPRJ > #include > namespace png_proj{ > typedef uint32_t CHUNK; > > > > In the .cpp file > void Image::read_chunk() > { > char * cur = get_index(); > CHUNK * tmp = reinterpret_cast(cur); > std::cout << std::endl << "Sizeof Chunk " << sizeof(*tmp) << std::endl; > for(int j = 0; j<4; j++){ > std::cout << "Raw Chunk Number " << j << ": " << *tmp << std::endl; > > > switch ( j ) { > case 0: > std::cout << "***LENGTH****" << std::endl; > set_length(static_cast(*tmp)); > std::cout << "Length value => " << static_cast(*tmp) << std::endl; > break; > > case 1: > std::cout << "***TYPE****" << std::endl; > set_type(static_cast(*tmp)); > break; > > case 2: > { > std::cout << "***DATA****" << std::endl; > unsigned long int l = static_cast(get_length()); > std::cout << "buffer size should be " << get_length() << std::endl; > int8_t * buffer = new int8_t[l]; > std::cout << "buffer element size is " << *buffer << std::endl; > std::cout << "buffer size is " << l << std::endl; > for(unsigned int k = 0; k < get_length(); k++){ > buffer[k] = static_cast(tmp[k]); > std::cout << "data " << *buffer << std::endl; > } > set_data(buffer); > } > break; > > case 3: > std::cout << "***CRC****" << std::endl; > set_crc(static_cast(*tmp)); > break; > > default: > std::cout << "***NOMANDSLAND****" << std::endl; > break; > } /* ----- end switch ----- */ > > char * tmp2 = reinterpret_cast(tmp); //reading each byte > std::cout << "Sizeof Byte " << sizeof(*tmp2) << std::endl; > //std::cout << "Mark ==>>" << __LINE__ << std::endl; > for(int i=0; i<4; i++){ > std::cout << "Character " << i << "::" << std::endl << "\t" << *tmp2 > << std::endl; > std::cout << "Byte " << i << "::" << std::endl << "\t" << > static_cast(*tmp2) << std::endl; > tmp2++; > } > std::cout<> std::cout<> tmp++; > cur = ( reinterpret_cast(tmp) ); > } > set_index(cur); > } > > > > I dug through libpng since this seems to not being doing what I > expected. They seem to set it up as 4 byte array > > void /* PRIVATE */ > png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr) > { > png_uint_32 chunk_name; > #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED > int keep; /* unknown handling method */ > #endif > > /* First we make sure we have enough data for the 4-byte chunk name > * and the 4-byte chunk length before proceeding with decoding the > * chunk data. To fully decode each of these chunks, we also make > * sure we have enough data in the buffer for the 4-byte CRC at the > * end of every chunk (except IDAT, which is handled separately). > */ > if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0) > { > png_byte chunk_length[4]; > png_byte chunk_tag[4]; > > PNG_PUSH_SAVE_BUFFER_IF_LT(8) > png_push_fill_buffer(png_ptr, chunk_length, 4); > png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); > png_reset_crc(png_ptr); > png_crc_read(png_ptr, chunk_tag, 4); > png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); > png_check_chunk_name(png_ptr, png_ptr->chunk_name); > png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; > } > > > I'm obviously not understanding something I'm evaluation here. So I'm > wondering if anyone can shed light on this. > http://www.nylxs.com/docs/grad_school/parallel/src/png/png_proj.h > http://www.nylxs.com/docs/grad_school/parallel/src/png/png_proj.cpp > http://www.nylxs.com/docs/grad_school/parallel/src/png/main_png.cpp > http://www.nylxs.com/docs/grad_school/parallel/src/png/makefile > > ruben > > let.me.in > > > Ruben > _______________________________________________ > hangout mailing list > hangout-at-nylxs.com > http://www.nylxs.com/ >
-- 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
--------------16735A954701A5CD405EE5A1 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 namespace png_proj{ 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: Image * Description: Basic Image Library for PNG and Parrallel Programming Class * ===================================================================================== */ class Image { public: /* ==================== LIFECYCLE ======================================= */ Image (); /* constructor */ Image(const char *);
/* ==================== ACCESSORS ======================================= */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_index *-------------------------------------------------------------------------------------- */ char * get_index ( ) { return index; } /* ----- end of method Image::get_index ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_index *-------------------------------------------------------------------------------------- */ inline void set_index ( char * value ) { index = value; return ; } /* ----- end of method Image::set_index ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_pic *-------------------------------------------------------------------------------------- */ char * get_pic ( ) { return pic; } /* ----- end of method Image::get_pic ----- */ /* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_header *-------------------------------------------------------------------------------------- */ char* get_header() { return loc_header_cpy; } /* ----- end of method Image::get_header ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_header *-------------------------------------------------------------------------------------- */ void set_header () { char * start = loc_header_cpy; //loc_header_cpy is an array int he constructor of 8 chars // char * value = get_pic(); std::cout << "setting the header array**" << std::endl; std::cout << "**************************" << std::endl; for(int i = 0; i<8; i++){ std::cout << "setting the header" << *get_index() << std::endl; *start = *get_index(); //this is a copy std::cout << "header set to =>>" << *start<< std::endl; next_index(); start++; } return ; } /* ----- end of method Image::set_header ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_pic *-------------------------------------------------------------------------------------- */ void set_pic ( char * value ) { pic = value; return ; } /* ----- end of method Image::set_pic ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_current_chunk *-------------------------------------------------------------------------------------- */ CHUNK * get_current_chunk ( ) { return current_chunk; } /* ----- end of method Image::get_current_chunk ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_current_chunk *-------------------------------------------------------------------------------------- */ CHUNK * set_current_chunk ( CHUNK * value ) { current_chunk = value; return current_chunk ; } /* ----- end of method Image::set_current_chunk ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_length *-------------------------------------------------------------------------------------- */ long unsigned int get_length ( ) { return length; } /* ----- end of method Image::get_length ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_length *-------------------------------------------------------------------------------------- */ long unsigned set_length ( long unsigned int value ) { length = value; return value ; } /* ----- end of method Image::set_length ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_type *-------------------------------------------------------------------------------------- */ inline int32_t get_type ( ) { return type; } /* ----- end of method Image::get_type ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_type *-------------------------------------------------------------------------------------- */ int32_t set_type ( int32_t value ) { type = value; return value; } /* ----- end of method Image::set_type ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_data *-------------------------------------------------------------------------------------- */ int8_t * get_data ( ) { return data; } /* ----- end of method Image::get_data ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_data *-------------------------------------------------------------------------------------- */ void set_data ( int8_t * value ) { if(data != nullptr){ delete data; } data = value;//the size is determined in get_length() return ; } /* ----- end of method Image::set_data ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: get_crc *-------------------------------------------------------------------------------------- */ int32_t get_crc ( ) { return crc; } /* ----- end of method Image::get_crc ----- */
/* *-------------------------------------------------------------------------------------- * Class: Image * Method: set_crc *-------------------------------------------------------------------------------------- */ void set_crc ( int32_t value ) { crc = value; return ; } /* ----- end of method Image::set_crc ----- */
/* ==================== MUTATORS ======================================= */ void read_png( const char * in = nullptr ); void read_header(); void read_chunk(); void next_index(){ char * tmp = get_index(); set_index(++tmp); }; void header(){ read_header(); }; const CHUNK * getNext( CHUNK* );
/* ==================== OPERATORS ======================================= */
/* ==================== DATA MEMBERS ======================================= */ protected:
private: char * pic; char loc_header_cpy[8]; CHUNK * current_chunk; char * index; long unsigned int length; int8_t * data; int32_t type; int32_t crc; }; /* ----- end of class Image ----- */
} #endif
--------------16735A954701A5CD405EE5A1 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 |
|