Applied C++: Practical Techniques for Building Better Software [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Applied C++: Practical Techniques for Building Better Software [Electronic resources] - نسخه متنی

Addison Wesley

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


2.2 Thumbnail Class


In our design, the image class is a container for image pixels and nothing else. Since the purpose of this application is to create thumbnail images, a thumbnail class is needed to handle file I/O and the thumbnail algorithm. The thumbnail class has the following properties:

Reads the input image from a file.

Computes the thumbnail image given the input file and the reduction factor to use (i.e., how small a thumbnail image to create).

Throws a C++ exception, invalid, if any errors are encountered. If the image class throws a rangeError error, this exception is caught and the invalid exception is thrown instead.

Writes the thumbnail image to a file.

The complete definition of the thumbnail class is shown in Section 2.3.2 on page 16.


2.2.1 Thumbnail Algorithm


Each pixel in the thumbnail image is found by averaging a number of pixels in the input image. The pixel value in the thumbnail image, T(x0,y0), is computed as shown in Figure 2.1, where factor is the desired reduction value.

Figure 2.1. Computing the Thumbnail Pixel Value

A picture helps clarify this equation. Each pixel in the original image P is reduced, by averaging pixel values in image P, to a corresponding point in the thumbnail image T using the equation from Figure 2.1. In Figure 2.2, we show how a group of pixels in the original image is reduced to the group of pixels shown in the thumbnail image.

Figure 2.2. Pictorial Representation of Thumbnail Computation

To further simplify our application, we ignore the condition created by integer arithmetic where the division by the reduction factor results in a fraction. For example, if the original image is 640x480 pixels in size, and the desired reduction factor is 6, the thumbnail image will be (640/6)x(480/6) pixels in size or 106.67x80. To avoid the fractional result, we ignore the last 4 pixels in each line, effectively making the thumbnail image (636/6)x(480/6) pixels in size or 106x80.


/ 59