1. Field of the Invention
The invention relates to display devices, and particularly to a display device and image resizing method thereof.
2. Description of Related Art
With mobile communication devices, such as mobile phones and portable computers, becoming more popular, demand for their greater functionality and faster completion speed of tasks has increased as well. Generally, sizes of imported images are inconsistent with that of images that a mobile communication device can display, therefore, the mobile communication device needs to process the imported images to resize them for the display. Conventionally, mobile communication devices resize images through a series of calculations involving floating-point type data and multiplication.
However, the calculations are complex, thus mobile communication devices take time to process the images, particularly large images, and are significantly slow to display such images. This is inefficient and unfriendly to users.
A display device for resizing an original image according to a predetermined destination image format includes an image reading module, a first processing module, a second processing module, a third processing module, and a pixel generating module. The image reading module is used for reading pixel data of the original image and the predetermined destination image format. The first processing module is used for calculating a horizontal shift value and a vertical shift value, used for resizing the original image to the predetermined destination image format, according to the pixel data and a size of a register of the display device. The second processing module is used for converting ratios of a length of the original image to a length of the predetermined destination image format and a height of the original image to a height of the predetermined destination image format to integer values, used for resizing the original image to the predetermined destination image format, according to the pixel data, the horizontal shift value and the vertical shift value. The third processing module is used for determining which pixel in the original image to copy to each pixel position in the predetermined destination image format according to the pixel data, the horizontal shift value, the vertical shift value, and the integer values from ratios of the length of the original image to the length of the predetermined destination image format and the height of the original image to the height of the predetermined destination image format. The pixel generating module is used for copying pixels in the original image to corresponding pixel positions in the predetermined destination image format to form a destination image and storing the destination image into a memory.
Other advantages and novel features will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings:
The image reading module 200 is used for reading pixel data of the original image and the destination format, and for sending the pixel data to the first processing module 210. In the exemplary embodiment, the pixel data of the original image and the destination format includes lengths and heights in pixels thereof. To better describe the exemplary embodiment, a length and a height of either of the original image and the destination format corresponds to an X-axis and a Y-axis of a two dimensional coordinate system. Furthermore, x and y represent the length and height of the original image, and x′ and y′ denote the length and height of the destination format.
The first processing module 210 is connected to the image reading module 200, and is used for receiving the pixel data from the image reading module 200, and for calculating a horizontal shift value and a vertical shift value, used for resizing the original image to the destination format, according to the pixel data and a size of the register 250. In the exemplary embodiment, the horizontal shift value and the vertical shift value are used to shift a number stored in the register 250 to convert the number to an integer that represents an X or Y coordinate of a pixel to be copied from the original image. The shift values are calculated using the following formulas:
Horizontal shift value: Nx=A−Bx; and
Vertical shift value: Ny=A−By.
Where A is the size of the register 250 in bits, for example, in this embodiment A=32. Bx is how many bits are needed to represent the length of the original image in pixels, for example, an image of 2 pixels long would be 10 in binary, therefore, Bx=2. By is how many bits are needed to represent the height of the original image in pixels, for example, an image of 4 pixels high would be 100 in binary, therefore, By=3. According to the above examples, Nx=32−2=30, and Ny=32−3=29.
The second processing module 220 is used for converting ratios of x to x′ and y to y′ to integer values, also used for resizing the original image to the destination format, according to the pixel data, the horizontal shift value and the vertical shift value. The integer values from ratios of x to x′ and y to y′ are calculated using the following formulas:
Integer value from ratio of x to x′: dx=int(x/x′×2Nx); and
Integer value from ratio of y to y′: dy=int(y/y′×2Ny).
For example, assuming that the original image is 2×4 pixels, and the destination format is 3×3 pixels, then, x=2, y=4, x′=y′=3, and according to the above example, Nx=30, and Ny=29. Thus, dx=int(2/3×230)=715827882, and dy=int(4/3×229)=715827882.
The third processing module 230 is used for determining which pixel in the original image to copy to each pixel position in the destination format according to the pixel data, the horizontal shift value, the vertical shift value and the integer values from ratios of x to x′ and y to y′. The process begins with the first pixel of the first row of the destination format, then proceeds to each pixel in that row before going to the next row. To determine X, Y coordinates of a pixel of the original image to be copied to a current pixel position of the destination format, dx is first loaded into the register 250 X′ number of times, where X′ equals the X coordinate of the current pixel position. Subsequently, dx multiplies X′, and a resulted value is transformed into a binary value. Then the binary value in the register 250 is shifted right Nx bits. The binary value in the register 250 after the right shift is transformed into a decimal value, and the decimal value gives the X coordinate of the pixel to be copied. Similarly the Y coordinate is found by first loading dy into the register Y′ number of times, where Y′ equals the Y coordinate of the current pixel position. Subsequently, dy multiplies Y′, and a resulted value is transformed into a binary value. Then the binary value in the register 250 is shifted right Ny bits. The binary value in the register 250 after the right shift is transformed into a decimal value, and the decimal value remaining in the register 250 is the Y coordinate of the pixel to be copied.
In the example, the destination format is 3×3 pixels, and the original image is 2×4 pixels, so XY coordinates for pixel positions of the destination format would be (0,0), (1,0), (2,0), (0,1), (1,1), (2,1), (0,2), (1,2), (2,2). Then we use the above formulas and steps beginning with the first pixel (0,0) of the destination format, and assume that we are using a 32 bit register 250, as follows:
N
x
=A−B
x=32−2=30;
N
y
=A−B
y=32−3=29;
d
x=int(x/x′×2Nx)=int(2/3×230)=715827882;
d
y=int(y/y′×2Ny)=int(4/3×229)=715827882.
For example, to determine the X, Y coordinates of the pixel of the original image to be copied to a position of the pixel (2, 0) of the destination image, 715827882 is first loaded into the register 250 two times. Subsequently, 715827882 multiplies 2, which resulted value is 1431655764, and the resulted value 1431655764 is transformed into a binary value 1010101010101010101010101010100. Then the binary value 1010101010101010101010101010100 in the register 250 is shifted right 30 bits, which is 0000000000000000000000000000001, and the binary value after the right shift is transformed into a decimal value 1. The decimal value 1 in the register 250 gives the X coordinate of the pixel to be copied. Similarly the Y coordinate is found by first loading dy into the register 250 0 times. Subsequently, 715827882 multiples 0, which resulted value is 0, and the resulted value 0 is transformed into a binary value 0. Then the binary value 0 in the register 250 is shifted right 29 bits, and the binary value 0 after the right shift is transformed into a decimal value 0. The decimal value 0 remaining in the register 250 is the Y coordinate of the pixel to be copied. That is, the pixel (1, 0) of the original image should be copied to the position of the pixel (2, 0) of the destination format. Similarly, the third processing module 230 can determine which pixels in the original image to copy to other pixel positions in the destination format using the same steps.
The pixel generating module 240 is connected to the third processing module 230 and the image reading module 200, and is used for copying pixels in the original image to corresponding pixel positions in the destination format to form a destination image, and stores the destination image into memory.
In step S200, the image reading module 200 reads pixel data of the original image and the destination format, and sends the pixel data to the first processing module 210. In the exemplary embodiment, the pixel data of the original image and the destination format includes lengths and heights in pixels thereof. To better describe the exemplary embodiment, a length and a height of either of the original image and the destination format corresponds to an X-axis and a Y-axis of a two dimensional coordinate system. Furthermore, x and y represent the length and height of the original image, and x′ and y′ denote the length and height of the destination format.
In step S202, the first processing module 210 receives the pixel data, and calculates a horizontal shift value and a vertical shift value, used for resizing the original image to the destination format, according to the pixel data and a size of the register 250. In the exemplary embodiment, the horizontal shift value and the vertical shift value are used to shift a number stored in the register 250 to convert the number to an integer that represents an X or Y coordinate of a pixel to be copied from the original image. The shift values are calculated using the following formulas:
Horizontal shift value: Nx=A−Bx;
Vertical shift value: Ny=A−By;
Where A is the size of the register 250 in bits, for example, in this embodiment A=32. Bx is how many bits are needed to represent the length of the original image in pixels, for example, an image of 2 pixels long would be 10 in binary, therefore Bx=2. By is how many bits are needed to represent the height of the original image in pixels, for example, an image of 4 pixels high would be 100 in binary, therefore By=3. According to the above examples, Nx=32−2=30, and Ny=32−3=29.
In step S204, the second processing module 220 converts ratios of x to x′ and y to y′ to integer values, used for resizing the original image to the destination format, according to the pixel data, the horizontal shift value and the vertical shift value. The integer values from ratios of x to x′ and y to y′ are calculated using the following formulas:
Integer value from ratio of x to x′: dxint(x/x′×2Nx);
Integer value from ratio of y to y′: dyint(y/y′×2Ny);
For example, assuming that the original image is 2×4 pixels, and the destination format is 3×3 pixels, then, x=2, y=4, x′=y′=3, and according to the above example, Nx=30, Ny=29. Thus, dx=int(2/3×230)=715827882, and dy=int(4/3×229)=715827882.
In step S206, for each pixel position in the destination format, the third processing module 230 determines which pixel in the original image to copy to that pixel position in the following manner according to the pixel data, the horizontal shift value, the vertical shift value and the integer values from ratios of x to x′ and y to y′. The process begins with the first pixel of the first row of the destination format, then proceeds to each pixel in that row before going to the next row. To determine X, Y coordinates of a pixel of the original image to be copied to a current pixel position of the destination format, dx is first loaded into the register 250 X′ number of times, where X′ equals the X coordinate of the current pixel position. Subsequently, dx multiplies X′, and a resulted value is transformed into a binary value. Then the binary value in the register 250 is shifted right Nx bits. The binary value in the register 250 after the right shift is transformed into a decimal value, and the decimal value gives the X coordinate of the pixel to be copied. Similarly the Y coordinate is found by first loading dy into the register Y′ number of times, where Y′ equals the Y coordinate of the current pixel position. Subsequently, dy multiplies Y′, and a resulted value is transformed into a binary value. Then the binary value in the register 250 is shifted right Ny bits. The binary value in the register 250 after the right shift is transformed into a decimal value, and the decimal value remaining in the register 250 is the Y coordinate of the pixel to be copied.
In the example, the destination format is 3×3 pixels, and the original image is 2×4 pixels, so XY coordinates for pixel positions of the destination format would be (0,0), (1,0), (2,0), (0,1), (1,1), (2,1), (0,2), (1,2), (2,2). Then we use the above formulas and steps beginning with the first pixel (0,0) of the destination format, and assume that we are using a 32 bit register 250, as follows:
N
x
=A−B
x=32−2=30;
N
y
=A−B
y=32−3=29;
d
x=int(x/x′×2Nx)=int(2/3×230)=715827882;
d
y=int(y/y′×2Ny)=int(4/3×229)=715827882.
For example, to determine the X, Y coordinates of the pixel of the original image to be copied to a position of the pixel (2, 0) of the destination image, 715827882 is first loaded into the register 250 2 times. Subsequently, 715827882 multiplies 2, which resulted value is 1431655764, and the resulted value 1431655764 is transformed into a binary value 1010101010101010101010101010100. Then the binary value 1010101010101010101010101010100 in the register 250 is shifted right 30 bits, which is 0000000000000000000000000000001, and the binary value after the right shift is transformed into a decimal value 1. The decimal value 1 in the register 250 gives the X coordinate of the pixel to be copied. Similarly the Y coordinate is found by first loading dy into the register 250 0 times. Subsequently, 715827882 multiples 0, which resulted value is 0, and the resulted value 0 is transformed into a binary value 0. Then the binary value 0 in the register 250 is shifted right 29 bits, and the binary value 0 is transformed into a decimal value 0. The decimal value 0 remaining in the register 250 is the Y coordinate of the pixel to be copied. That is, the pixel (1, 0) of the original image should be copied to the position of the pixel (2, 0) of the destination format. Similarly, the third processing module 230 can determine which pixels in the original image to copy to other pixel positions in the destination format using the same steps.
In step S208, the pixel generating module 240 copies pixels in the original image to corresponding pixel positions in the destination format to form a destination image, and stores the destination image into memory.
The display device 10 and the image resizing method thereof use calculations involving integer type data instead of floating-point type data, therefore calculation is simpler than before, thus, time spent on processing images is saved, and speed of processing image is increased.
The foregoing disclosure of various embodiments has been presented for purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many variations and modifications of the embodiments described herein will be apparent to one of ordinary skill in the art in light of the above disclosure. The scope of the invention is to be defined only by the claims appended hereto and their equivalents.