⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 photoshopreader.h

📁 网络泡泡被.net管理
💻 H
字号:
#ifndef	_PHOTOSHOP_READER_H_2002_11_28_15_57_
#define _PHOTOSHOP_READER_H_2002_11_28_15_57_
/***********************************************************************************\

\***********************************************************************************/

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "share.h"
#include "GSLib_Internal.h"
#include "streambuf_operators.h"

class CDxFileProgress
{
public:
	CDxFileProgress( int max_value )
	{
		m_max_value = max_value;
		m_current_value = 0;
	}
	virtual ~CDxFileProgress()
	{
	}

	int          get_max_value() const;
	virtual void set_max_value( int arg )
	{
		m_max_value = arg;
	}
	virtual void increment( int arg ) = 0;
protected:
	int m_max_value;
	int m_current_value;
};


////////////////////////////////////////////////////////////////////////////////////////////////
//photoshop file reader

enum t_photoshop_color_mode
{
	k_color_mode_bitmap,
	k_color_mode_grayscale,
	k_color_mode_indexed,
	k_color_mode_RGB,
	k_color_mode_CMYK,
	k_color_mode_multichannel = 7,
	k_color_mode_duotone,
	k_color_mode_lab
};

// ------------------------------------------------------------------------
// photoshop channel
// ------------------------------------------------------------------------
class t_photoshop_channel
{
public:
	t_photoshop_channel( int id, int width, int height );

	void           clear();
	BYTE*		   get();
	const BYTE*    get() const;
	BYTE           get( int x, int y ) const;
	int            get_id() const;
	void           set( int x, int y, BYTE value );
protected:
	friend class t_photoshop_layer;

	bool read( std::streambuf& infile, CDxFileProgress* progress_bar );
	bool read_background( std::streambuf& infile, bool compressed, int* scan_lengths,
		                  CDxFileProgress* progress_bar );
	bool read_compressed( std::streambuf& infile, bool padded, int* scan_lengths,
		                  CDxFileProgress* progress_bar );
	bool write( std::streambuf& outfile, CDxFileProgress* progress_bar );
	bool write_background( std::streambuf& outfile, int* scan_lengths,
		                   CDxFileProgress* progress_bar );
	bool write_compressed( std::streambuf& outfile, int* scan_lengths,
		                   CDxFileProgress* progress_bar );

	int                  m_width;
	int                  m_height;
	int                  m_id;
	std::vector<BYTE> m_data;
};

// ------------------------------------------------------------------------
// inlines for channel
// ------------------------------------------------------------------------
inline t_photoshop_channel::t_photoshop_channel( int id, int width, int height )
{
	m_id = id;
	m_width = width;
	m_height = height;
	m_data.resize( width * height );
	memset( m_data.begin(), 0, width * height );
}

inline BYTE* t_photoshop_channel::get() 
{
	return m_data.begin();
}

inline const BYTE* t_photoshop_channel::get() const
{
	return m_data.begin();
}

inline BYTE t_photoshop_channel::get( int x, int y ) const
{
	return m_data[ x + y * m_width ];
}

inline int t_photoshop_channel::get_id() const
{
	return m_id;
}

inline void t_photoshop_channel::set( int x, int y, BYTE value )
{
	m_data[x + y * m_width ] = value;
}

// ------------------------------------------------------------------------
// photoshop layer
// ------------------------------------------------------------------------
enum t_photoshop_blend
{
	k_blend_normal,
	k_blend_darken,
	k_blend_lighten,
	k_blend_hue,
	k_blend_saturation,
	k_blend_color,
	k_blend_luminosity,
	k_blend_multiply,
	k_blend_screen,
	k_blend_dissolve,
	k_blend_overlay,
	k_blend_hard_light,
	k_blend_soft_light,
	k_blend_difference,
	k_blend_exclusion,
	k_blend_color_dodge,
	k_blend_color_burn
};

class t_photoshop_layer
{
public:
	t_photoshop_layer();
	t_photoshop_layer( const char* name, int top, int left, int bottom, int right,
		               int bits = 32 );
	~t_photoshop_layer();

	void                 clear();
	t_photoshop_channel* get_alpha_channel();
	t_photoshop_channel* get_blue_channel();
	int                  get_bottom() const;
	t_photoshop_channel* get_channel( int id );
	int                  get_channel_count() const;
	t_photoshop_channel* get_green_channel();
	int                  get_height() const;
	int                  get_left() const;
	std::string			 get_name() const;
	PIX32				 get_pixel( int x, int y ) const;
	PIX32				 get_pixel( int x, int y, const PIX24* palette ) const;
	void                 set_pixel( int x, int y, PIX32 pixel );
	GRECT		         get_rect() const;
	t_photoshop_channel* get_red_channel();
	int                  get_right() const;
	int                  get_top() const;
	int                  get_width() const;
protected:
	friend class t_photoshop_image;

	bool				 read( std::streambuf& infile );
	bool				 read_channels( std::streambuf& infile, CDxFileProgress* progress_bar );
	bool				 read_background( std::streambuf& infile, int width, int height, 
		                                  int channels, int bits_per_channel,
										  t_photoshop_color_mode mode, CDxFileProgress* 
										  progress_bar );
	void                 set_id( int id );
	bool				 write( std::streambuf& outfile, int* channel_block_start, int index );
	bool                 write_channels( std::streambuf& outfile, int channel_block_start,
		                                 CDxFileProgress* progress_bar );
	bool                 write_background( std::streambuf& outfile, CDxFileProgress* progress_bar );

	int                  m_top;
	int                  m_left;
	int                  m_bottom;
	int                  m_right;
	t_photoshop_channel* m_red_channel;
	t_photoshop_channel* m_green_channel;
	t_photoshop_channel* m_blue_channel;
	t_photoshop_channel* m_alpha_channel;
	t_photoshop_blend    m_blend;
	BYTE              m_opacity;
	BYTE              m_flags;
	std::vector<int>     m_channel_lengths;
	std::string          m_name;

	std::vector<t_photoshop_channel*> m_channels;
};

// ------------------------------------------------------------------------
// inlines for layer
// ------------------------------------------------------------------------
inline t_photoshop_channel* t_photoshop_layer::get_alpha_channel()
{
	return m_alpha_channel;
}

inline t_photoshop_channel* t_photoshop_layer::get_blue_channel()
{
	return m_blue_channel;
}

inline int t_photoshop_layer::get_bottom() const
{
	return m_bottom;
}

inline t_photoshop_channel* t_photoshop_layer::get_channel( int id )
{
	return m_channels[id];
}

inline int t_photoshop_layer::get_channel_count() const
{
	return m_channels.size();
}

inline t_photoshop_channel* t_photoshop_layer::get_green_channel() 
{
	return m_green_channel;
}

inline int t_photoshop_layer::get_left() const
{
	return m_left;
}

inline std::string t_photoshop_layer::get_name() const
{
	return m_name;
}

inline t_photoshop_channel* t_photoshop_layer::get_red_channel()
{
	return m_red_channel;
}

inline GRECT t_photoshop_layer::get_rect() const
{
	return GRECT( m_left, m_top, m_right, m_bottom );
}

inline int t_photoshop_layer::get_right() const
{
	return m_right;
}

inline int t_photoshop_layer::get_top() const
{
	return m_top;
}

inline int t_photoshop_layer::get_width() const
{
	return m_right - m_left;
}

inline int t_photoshop_layer::get_height() const
{
	return m_bottom - m_top;
}

typedef CSharePtr<t_photoshop_layer> t_photoshop_layer_ptr;

// ------------------------------------------------------------------------
// photoshop image
// ------------------------------------------------------------------------

struct t_additional_data
{
	int type;
	std::vector<BYTE> data;
};

class t_photoshop_image
{
public:
	t_photoshop_image();
	t_photoshop_image( int width, int height, t_photoshop_color_mode mode = k_color_mode_RGB);
	~t_photoshop_image();

	void                   add_layer( const t_photoshop_layer_ptr& layer );
	t_photoshop_layer&     get_background();
	int                    get_height() const;
	t_photoshop_layer_ptr  get_layer( int id );
	t_photoshop_layer_ptr  get_layer( const char* name );
	int                    get_layer_count() const;
	t_photoshop_color_mode get_color_mode() const;
	PIX24*				   get_palette();
	PIX32				   get_pixel( int x, int y ) const;
	GRECT          get_rect() const;
	int                    get_width() const;
	bool                   read( std::streambuf& infile, CDxFileProgress* progress_bar = 0 );
	bool                   write( std::streambuf& outfile, CDxFileProgress* progress_bar = 0 );
protected:
	void create_background();
	bool read_alpha_channel_names( std::streambuf& infile, long length );
	bool read_layers( std::streambuf& infile, CDxFileProgress* progress_bar, int channel_count );
	bool read_resources( std::streambuf& infile, long length );

	bool write_layers( std::streambuf& outfile, CDxFileProgress* progress_bar );
	bool write_resources( std::streambuf& outfile );

	int                      m_height;
	int                      m_width;
	PIX24					 m_palette[256];
	t_photoshop_color_mode   m_color_mode;
	CDxFileProgress*          m_progress_bar;
//	std::vector<std::string> m_alpha_channel_names;

	std::vector<t_photoshop_layer_ptr> m_layers;
	std::vector<t_additional_data>     m_additional_data;

	t_photoshop_layer m_background;
};

// ------------------------------------------------------------------------
// inlines for photoshop image
// ------------------------------------------------------------------------
inline t_photoshop_image::t_photoshop_image()
{
}

inline t_photoshop_image::t_photoshop_image( int width, int height, t_photoshop_color_mode mode )
                        : m_background( "", 0, 0, height, width, 32 )
{
	m_width = width;
	m_height = height;
	m_color_mode = mode;
}


inline void t_photoshop_image::add_layer( const t_photoshop_layer_ptr& layer )
{
	m_layers.push_back( layer );
}

inline t_photoshop_layer& t_photoshop_image::get_background()
{
	return m_background;
}

inline t_photoshop_color_mode t_photoshop_image::get_color_mode() const
{
	return m_color_mode;
}

inline int t_photoshop_image::get_height() const
{
	return m_height;
}

inline GRECT t_photoshop_image::get_rect() const
{
	return GRECT( 0, 0, m_width, m_height );
}

inline int t_photoshop_image::get_width() const
{
	return m_width;
}

inline t_photoshop_layer_ptr t_photoshop_image::get_layer( int id )
{
	return m_layers[id];
}

inline int t_photoshop_image::get_layer_count() const
{
	return m_layers.size();
}

inline PIX24* t_photoshop_image::get_palette()
{
	return m_palette;
}

inline PIX32 t_photoshop_image::get_pixel( int x, int y ) const
{
	if (m_color_mode == k_color_mode_indexed)
		return m_background.get_pixel(x,y, m_palette );
	return m_background.get_pixel( x, y );
}











#endif //_PHOTOSHOP_READER_H_2002_11_28_15_57_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -