photoshop-v.1.0.1源码分析第一篇–AcquireInterface.p

photoshop-v.1.0.1源码分析第一篇–AcquireInterface.p

总体预览

声明:
photoshop-v.1.0.1源码已经公开,地址:http://www.computerhistory.org/atchm/adobe-photoshop-source-code/
由于本人第一次接触大型源码,也是第一次接触Delphi,依靠强大的度娘,慢慢分析,错误之处,请诸君指正。
一.源码预览
二.语法解释
三.结构预览
四:语句分析
五:思维导图
六:疑留问题

一.源码预览

{Photoshop version 1.0.1, file: AcquireInterface.p
  Computer History Museum, www.computerhistory.org
  This material is (C)Copyright 1990 Adobe Systems Inc.
  It may not be distributed to third parties.
  It is licensed for non-commercial use according to 
  www.computerhistory.org/softwarelicense/photoshop/ }

{
	File: AcquireInterface.p

	Copyright 1990 by Thomas Knoll.

	This file describes version 3 of Photoshop's Acquisition module interface.
}

UNIT AcquireInterface;

INTERFACE

USES
	MemTypes, QuickDraw, OSIntf;

CONST

	{ Operation selectors }

	acquireSelectorAbout	= 0;
	acquireSelectorStart	= 1;
	acquireSelectorContinue = 2;
	acquireSelectorFinish	= 3;
	acquireSelectorPrepare	= 4;

	{ Image modes }

	acquireModeBitmap		= 0;
	acquireModeGrayScale	= 1;
	acquireModeIndexedColor = 2;
	acquireModeRGBColor 	= 3;
	acquireModeCMYKColor	= 4;
	acquireModeHSLColor 	= 5;
	acquireModeHSBColor 	= 6;
	acquireModeMultichannel = 7;

	{ Error return values. The plug-in module may also return standard Macintosh
	  operating system error codes, or report its own errors, in which case it
	  can return any positive integer. }

	acquireBadParameters  = -30000; 	{ "a problem with the acquisition module interface" }
	acquireNoScanner	  = -30001; 	{ "there is no scanner installed" }
	acquireScannerProblem = -30002; 	{ "a problem with the scanner" }

TYPE

	AcquireLUT = PACKED ARRAY [0..255] OF CHAR;

	AcquireRecord = RECORD

		serialNumber:	LONGINT;	{ Photoshop's serial number, to allow
									  copy protected plug-in modules. }
		abortProc:		ProcPtr;	{ The plug-in module may call this no-argument
									  BOOLEAN function (using Pascal calling
									  conventions) several times a second during long
									  operations to allow the user to abort the operation.
									  If it returns TRUE, the operation should be aborted
									  (and a positive error code returned). }
		progressProc:	ProcPtr;	{ The plug-in module may call this two-argument
									  procedure (using Pascal calling conventions)
									  periodically to update a progress indicator.
									  The first parameter (type LONGINT) is the number
									  of operations completed; the second (type LONGINT)
									  is the total number of operations. }

		maxData:		LONGINT;	{ Maximum number of bytes that should be
									  passed back at once, plus the size of any
									  interal buffers.	The plug-in may reduce this
									  value in the acquireSelectorPrepare routine. }

		imageMode:		INTEGER;	{ Image mode }
		imageSize:		Point;		{ Size of image }
		depth:			INTEGER;	{ Bits per sample, currently must be 1 or 8 }
		planes: 		INTEGER;	{ Samples per pixel }
		imageHRes:		Fixed;		{ Pixels per inch }
		imageVRes:		Fixed;		{ Pixels per inch }
		redLUT: 		AcquireLUT; { Red LUT, only used for Indexed Color images }
		greenLUT:		AcquireLUT; { Green LUT, only used for Indexed Color images }
		blueLUT:		AcquireLUT; { Blue LUT, only used for Indexed Color images }

		data:			Ptr;		{ A pointer to the returned image data. The
									  plug-in module is now responsible for freeing
									  this buffer (this is a change from previous
									  versions). Should be set to NIL when
									  all the image data has been returned. }
		theRect:		Rect;		{ Rectangle being returned }
		loPlane:		INTEGER;	{ First plane being returned }
		hiPlane:		INTEGER;	{ Last plane being returned }
		colBytes:		INTEGER;	{ Spacing between columns }
		rowBytes:		LONGINT;	{ Spacing between rows }
		planeBytes: 	LONGINT;	{ Spacing between planes (ignored if only one
									  plane is returned at a time) }

		filename:		Str255; 	{ Document file name }
		vRefNum:		INTEGER;	{ Volume reference number, or zero if none }
		dirty:			BOOLEAN;	{ Changes since last saved flag. The plug-in may clear
									  this field to prevent prompting the user when
									  closing the document. }

		END;

	AcquireRecordPtr = ^AcquireRecord;

END.

二.语法解释

  1. {}:Delphi 注释;
  2. UNIT:一个Delphi程序由多个称为单元的源代码模块组成。使用单元可以把一个大型程序分成多个逻辑相关的模块,并用来创建在不同程序中使用的程序库。UNIT单元相当于C语言的子程序。基本上Delphi每个窗体都一个对应的单元。当你为应用程序创建窗体时,你就创建了一个与该窗体相联系的新单元。然而,单元也可以独立于窗体而存在。例如,一个单元可以只包含数学运算程序,而不需要有窗体。一个单元可以由多个程序共享。单元的磁盘文件名后缀为.pas
    单元结构:不管单元是否与窗体相关,单元的基本结构都是一样的 。UNIT单元由单元首部、接口部分(interface part)、实现部分(implementation part)、可选择的初始化部分(initialization part)、结束部分(finalization part)、end.组成。
    (1)单元首部:单元的首部用保留字Unit开始,后跟单元名。单元名必须遵循标识符的所有一般原则(不能以数字开头等)。
    (2)接口部分(Interface):在单元名之后是接口部分。接口部分用于声明变量、类型、过程和函数等。在接口部分声明的变量、类型以及过程、函数等是其它使用该单元的程序或单元等都可见的。接口部分用保留字Interface标明开始,用implemention标明结束。
    接口部分只能含有声明部分。一个单元的接口部分还作为该单元说明文件的起点。虽然接口部分没有告诉你子程序做什么或变量如何使用,但它正确告诉了你的变量、类型、过程、函数等的名字及其调用方法。接口部分本身又可以由几个可选的部分组成,分别是单元的USES语句、常量声明部分、类型声明部分、变量声明部分、过程和函数声明部分。其中常量声明、类型声明、变量声明、过程和函数声明部分用于声明其它使用该单元的单元可以访问的变量、类型、过程和函数等。而USES语句列出该单元要用到的标准单元
    和其它单元,用于把外部的已定义的常量、类型、变量、过程或函数引入到本单元中使用。USES语句紧跟在Interface之后。
    (3)实现部分(Implementation):主要用于定义接口部分声明过的过程、函数等的代码。实现部分用保留字implementation标明,总是紧随接口部分之后。实现部分也可以用USES语句列出该单元要用到的标准单元和其它单元等。如上面的uses MDIEdit;语句。实际上,实现部分也可以声明变量、数据类型、过程及函数等。但是,在实现部分定义的变量、类型、过程、函数等只能由本单元自己使用(private declarations),使用该单元的其它单元或程序不可见的。私有定义可以隐藏单元的细节
  3. CONST:对于在 程序运 行期间保持不变的值,Pascal 允许通过常量来声明。声明常量不必特定数 据类型,但需要赋一个初值。编译器 会根据所赋 初值自动选 用合适的数据类型
  4. TYPE:说点delphi的设计思路吧。我们都知道delphi需要把文本转换成汇编语言,所以,type其实是一个定义的起始标志.因为需要进行语言转换,所以,你所编写的每一个变量或者是窗体都需要有明确的定义,所以,你会再PAS文件中看到很多的type.
  5. PACKED:不带packed关键字的结构体表明编译器编译时要求进行字对齐.带packed关键字的结构体表明编译器编译该结构体时不需要进行字对齐,这种方式对结构体中的字段访问会比第一种方式慢!但是更节约空间。有Packed 的占用内存小,但是速度慢一点。没Packed 的占用内存大,但是速度快一点.delphi写明没有packed的数据会根据cpu的规则来分配内存。
  6. RECORD:在Delphi中的Record类型中,与之C语言对应的即是结构体类型(struct)。
  7. LONGINT:有符号32位整数
  8. ProcPtr:没有查到,欢迎诸君指正
  9. Point: 是数据类型 比如表示一个点,有两个属性xy坐标
  10. Fixed: 没有查到,欢迎诸君指正
  11. LUT:LUT指显示查找表(Look-Up-Table),本质上就是一个RAM。它把数据事先写入RAM后,每当输入一个信号就等于输入一个地址进行查表,找出地址对应的内容,然后输出
  12. Pascal:Pascal语言是沃斯教授设计的编程语言,类比C语言。Object Pascal是面向对象的Pascal语言,是一个编程语言,类比为C++语言。Delphi是开发工具,支持Object Pascal语言的程序开发,类比为Visual Studio。一个编程语言,可以有多个开发平台的,
    比如Object Pascal的开发平台工具,有Turbo Pascal, Free Pascal,Delphi,RAD Studio
  13. Indexed Color:索引颜色是位图图片的一种编码方法,需要基于RGB、CMYK等更基本的颜色编码方法。可以通过限制图片中的颜色总数的方法实现有损压缩。挑选一副图片中最有代表性的若干种颜色(通常不超过256种),编制成颜色表。在表示图片中每一个点
    的颜色信息时,不直接使用这个点的颜色信息,而使用颜色表的索引。这样,要表示一幅32位真彩色的图片,使用索引颜色的图片只需要用不超过8位的颜色索引就可以表达同样的信息。使用索引颜色的位图广泛用于网络图形、游戏制作等场合,常见的格式有GIF、PNG等。将RGB,CMYK等模式图片转换为索引颜色模式:利用Photoshop中图像->模式->索引颜色命令即可
  14. Ptr: 没有查到,欢迎诸君指正
  15. Rect:Delphi为用户提供了一个方便的绘图环境,即某些控件的CANVAS属性(画布)。用户可以把某些控件的表面作为一张画布,在上面绘制各种图形或显示图像,但在CANVAS的使用过程中少不了一个特殊对象,那就是矩形RECT,灵活使用它会完成很多特殊的功能,为Delphi编制的Windows程序增加活力。RECT既是一个特殊的数据结构,又是一个函数,它的作用就是定义一个矩形区域对象,而作为函数使用时它可以用两个属性(Tpiont型)指明区域范围,同时也可分解成四个单一的变量类型(Integer型)
  16. ^:符号 ^ 有两种用途,当它出现在类型标识符之前,如 ^typeName 表示一个类型,该类型表示指向typeName类型变量的指针。当它出现在指针变量之后,如pointer^该符号对指针解除参照,也就是说,返回存储在内存地址(该地址保存在指针中)的值指针,指向的数据.

三.结构预览

{代码注释}
{代码注释}
UNIT-------------------------------------------单元首部
  INTERFACE-------------------------------------接口部分
    USES-----------------------------------------USES子句部分
    CONST-------------------------------------常量声明部分
        {代码注释}-------------------------------------代码注释
        /--------------------------------------------------常量声明
        /--------------------------------------------------常量声明
        /--------------------------------------------------常量声明
        /--------------------------------------------------常量声明
     TYPE-------------------------------------------- 用户自定义类型
     、、、、、、、、、、、、、、、、、、、、、、、、、、
     END;;----------------------------------------------    TYPE结束
END;--------------------------------------------------------单元结束

四:语句分析

{Photoshop version 1.0.1, file: AcquireInterface.p
  Computer History Museum, www.computerhistory.org
  This material is (C)Copyright 1990 Adobe Systems Inc.
  It may not be distributed to third parties.
  It is licensed for non-commercial use according to 
  www.computerhistory.org/softwarelicense/photoshop/ }

语句分析1:没啥好说的,版权声明,不得用于商用,研究可以。

{
	File: AcquireInterface.p

	Copyright 1990 by Thomas Knoll.

	This file describes version 3 of Photoshop's Acquisition module interface.
}

语句分析2:没啥好说的,作者。。。

UNIT AcquireInterface;--------------------------定义了一个名为AcquireInterface的单元
INTERFACE---------------------------------------------------------------开始接口部分

USES--------------------------------------------下面是USES语句,定义程序用到的所有单元
	MemTypes, QuickDraw, OSIntf;-----------这三个是啥单元,也没有查到
	CONST--------------------------------------------------------------下面是常量声明部分

	{ Operation selectors }--------------------------------------------注释:操作选择

	acquireSelectorAbout	= 0;------------------------------------------------关于
	acquireSelectorStart	= 1;------------------------------------------------开始
	acquireSelectorContinue = 2;------------------------------------------------继续
	acquireSelectorFinish	= 3;------------------------------------------------结束
	acquireSelectorPrepare	= 4;------------------------------------------------准备

	{ Image modes }----------------------------------------------------注释:图像模式

	acquireModeBitmap		= 0;----------------------------------------------Bitmap
	acquireModeGrayScale	= 1;-------------------------------------------GrayScale
	acquireModeIndexedColor = 2;----------------------------------------IndexedColor
	acquireModeRGBColor 	= 3;--------------------------------------------RGBColor
	acquireModeCMYKColor	= 4;-------------------------------------------CMYKColor	
	acquireModeHSLColor 	= 5;--------------------------------------------HSLColor
	acquireModeHSBColor 	= 6;--------------------------------------------HSBColor
	acquireModeMultichannel = 7;----------------------------------------Multichannel

	{ Error return values. The plug-in module may also return standard Macintosh
	  operating system error codes, or report its own errors, in which case it
	  can return any positive integer. }
	  --- plug-in module会返回标准的Macintosh operating system 错误代码,或者报告本身的错误,总是会返回任何正整数。

	acquireBadParameters  = -30000; 	{ "a problem with the acquisition module interface" }--------参数错误
	acquireNoScanner	  = -30001; 	{ "there is no scanner installed" }-----没有安装Scanner
	acquireScannerProblem = -30002; 	{ "a problem with the scanner" }--------Scanner出现错误

TYPE-------------------------------------------- 用户自定义类型

	AcquireLUT = PACKED ARRAY [0..255] OF CHAR;-----定义一个名为AcquireLUT 的字符数组

	AcquireRecord = RECORD--------------------------------------定义一个名为AcquireRecord 记录类型

		serialNumber:	LONGINT;	{ Photoshop's serial number, to allow------------------版本序列号
									  copy protected plug-in modules. }
		abortProc:		ProcPtr;	{ The plug-in module may call this no-argument
									  BOOLEAN function (using Pascal calling
									  conventions) several times a second during long
									  operations to allow the user to abort the operation.
									  If it returns TRUE, the operation should be aborted
									  (and a positive error code returned). }
为了在长时间内允许用户取消操作,plug-in module会每秒调用几次一个无参数,返回值为BOOLEAN的Pascal回调函数,如果返回值为TRUE,操作将会被取消,并且会返回一个	positive error code		  
		progressProc:	ProcPtr;	{ The plug-in module may call this two-argument
									  procedure (using Pascal calling conventions)
									  periodically to update a progress indicator.
									  The first parameter (type LONGINT) is the number
									  of operations completed; the second (type LONGINT)
									  is the total number of operations. }
plug-in module会调用带有2个参数的Pascal回调函数,周期性的更新一个程序的标志,第一个参数为LONGINT,代表完成操作的类型,第二个参数为LONGINT,代表操作的总类型
		maxData:		LONGINT;	{ Maximum number of bytes that should be
									  passed back at once, plus the size of any
									  interal buffers.	The plug-in may reduce this
									  value in the acquireSelectorPrepare routine. }
----诸君指正
		imageMode:		INTEGER;	{ Image mode }---------------------------图像模式
		imageSize:		Point;		{ Size of image }----------------------------图像大小
		depth:			INTEGER;	{ Bits per sample, currently must be 1 or 8 }----------------位图深度
		planes: 		INTEGER;	{ Samples per pixel }---------可能图层吧 。
		imageHRes:		Fixed;		{ Pixels per inch }-------------像素每英寸
		imageVRes:		Fixed;		{ Pixels per inch }-------------像素每英寸
		redLUT: 		AcquireLUT; { Red LUT, only used for Indexed Color images }--------------图像红色通道
		greenLUT:		AcquireLUT; { Green LUT, only used for Indexed Color images }--------------图像绿色通道
		blueLUT:		AcquireLUT; { Blue LUT, only used for Indexed Color images }--------------图像蓝色通道

		data:			Ptr;		{ A pointer to the returned image data. The
									  plug-in module is now responsible for freeing
									  this buffer (this is a change from previous
									  versions). Should be set to NIL when
									  all the image data has been returned. }
一个返回图像数据的指针,	plug-in module现在负责释放缓存,当数据缓存返回后,指针要设为NIL。								  
		theRect:		Rect;		{ Rectangle being returned }-----------矩形
		loPlane:		INTEGER;	{ First plane being returned }-----------------诸君指正
		hiPlane:		INTEGER;	{ Last plane being returned }-----------------诸君指正
		colBytes:		INTEGER;	{ Spacing between columns }---------------列间距
		rowBytes:		LONGINT;	{ Spacing between rows }-------------------行间距
		planeBytes: 	LONGINT;	{ Spacing between planes (ignored if only one
									  plane is returned at a time) }--------------------诸君指正

		filename:		Str255; 	{ Document file name }--------------------------文件名
		vRefNum:		INTEGER;	{ Volume reference number, or zero if none }----------------卷标
		dirty:			BOOLEAN;	{ Changes since last saved flag. The plug-in may clear
									  this field to prevent prompting the user when
									  closing the document. }
-------最后一次保存的标记,当用户关闭文档的时候,plug-in会清除这些空间
		END;

	AcquireRecordPtr = ^AcquireRecord;---------------- ^AcquireRecord表示一个类型,该类型表示指向AcquireRecord类型变量的指针

END.

五:思维导图

思维导图----文件调用

六:疑留问题

  1. MemTypes,QuickDraw,OSIntf三个单元没有找到,不知道干嘛用的。
  2. Bitmap,GrayScale,IndexedColor,RGBColor,CMYKColor,HSLColor,HSBColor,Multichannel的区别
  3. ProcPtr,Fixed是什么类型?
  4. maxData,planes,imageHRes,imageVRes干嘛用的
  5. loPlane,hiPlane,planeBytes干嘛用的
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值