CN106780648B - A kind of dynamic mapping method and device of color of image - Google Patents
A kind of dynamic mapping method and device of color of image Download PDFInfo
- Publication number
- CN106780648B CN106780648B CN201611162252.XA CN201611162252A CN106780648B CN 106780648 B CN106780648 B CN 106780648B CN 201611162252 A CN201611162252 A CN 201611162252A CN 106780648 B CN106780648 B CN 106780648B
- Authority
- CN
- China
- Prior art keywords
- color
- pixel
- initial
- target
- image
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 58
- 238000013507 mapping Methods 0.000 title abstract 2
- 239000003086 colorant Substances 0.000 claims description 49
- 238000006243 chemical reaction Methods 0.000 claims description 48
- 230000009466 transformation Effects 0.000 claims description 21
- 230000008569 process Effects 0.000 claims description 15
- 238000005516 engineering process Methods 0.000 claims description 9
- 230000008859 change Effects 0.000 abstract description 12
- 230000037452 priming Effects 0.000 abstract 3
- 238000004364 calculation method Methods 0.000 description 6
- 238000012545 processing Methods 0.000 description 6
- 230000007704 transition Effects 0.000 description 6
- 238000010586 diagram Methods 0.000 description 4
- 238000011426 transformation method Methods 0.000 description 4
- 230000001131 transforming effect Effects 0.000 description 4
- 230000009471 action Effects 0.000 description 3
- 230000015572 biosynthetic process Effects 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 230000008030 elimination Effects 0.000 description 2
- 238000003379 elimination reaction Methods 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 238000003786 synthesis reaction Methods 0.000 description 2
- 239000011800 void material Substances 0.000 description 2
- 230000002411 adverse Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 230000003247 decreasing effect Effects 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 230000005055 memory storage Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 210000003254 palate Anatomy 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 230000003595 spectral effect Effects 0.000 description 1
- 238000001228 spectrum Methods 0.000 description 1
- 238000001308 synthesis method Methods 0.000 description 1
- 230000016776 visual perception Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T11/00—2D [Two Dimensional] image generation
- G06T11/001—Texturing; Colouring; Generation of texture or colour
Landscapes
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Image Processing (AREA)
Abstract
The invention discloses a kind of dynamic mapping method and device of color of image, the method includes:The priming color of each initial pixel in image to be transformed is preserved in memory;When the colour switching for receiving the image to be transformed instructs, the priming color is compared with color of object, obtains color in the image to be transformed and need the target pixel converted;The image to be transformed, which is carried, in the colour switching instruction carries out the color of object after dynamic change;By the priming color in the target pixel under HLS color modes corresponding HUE values, be uniformly adjusted to the color of object corresponding HUE values under HLS color modes;HUE values after the adjustment of image to be transformed are converted to the rgb value of rgb color pattern, and transformed image to be transformed is shown according to rgb value.
Description
Technical Field
The present invention relates to the field of image processing technologies, and in particular, to a method and an apparatus for dynamically changing image colors.
Background
The dynamic transformation of image color refers to the process of dynamically transforming the color of an image according to logic requirements, and the color dynamic transformation technology is widely applied along with the popularization of computer multimedia application. Taking a game as an example, the dynamic color transformation can enrich the shape of the player, meet the requirements of diversification and individuation of the shape of the player, and be used for reflecting the transformation of the attribute values of the game role so as to meet the requirements of game logic. An image comprises at least one pixel, the pixel is the minimum drawing unit of the image, and the color in each pixel is uniformly changed in the color transformation process.
In the prior art, a method for converting image colors includes dividing each pixel in an image into a plurality of regions according to colors, wherein the colors of the pixels in one region are the same, generating new colors according to a RGB color synthesis principle during color conversion, wherein RGB represents three colors of red (R), green (G), and blue (B), and replacing the original colors in each region with the new colors. When a certain pixel includes a region having a color transition (i.e., a color gradually changes), in order to achieve a smooth transition when the color of the entire pixel changes, a more detailed region needs to be divided in the pixel.
Disclosure of Invention
The inventor finds in the research process that, in the prior art, in order to make the transition color change smoothly, each color of a pixel to be transformed is usually saved into a system as a pixel file, and when the color transformation of the pixel is needed, each pixel file of the corresponding color is directly loaded for the image. However, as a result, one pixel corresponds to multiple pixel files, and for an image including multiple pixels, a large number of pixel files need to be saved in a program, which causes the program to occupy more resources of the system and the color conversion process to be tedious. Therefore, the effect of smooth gradual transition of the transition colors in the pixel color conversion and the fast and simple processing of the color conversion process become a contradiction.
In view of the above, an embodiment of the present invention provides a method and an apparatus for dynamically changing image colors, which can improve the efficiency of pixel color change and ensure smooth gradual change of transition colors of pixels on the basis of not occupying system resources.
In order to achieve the above object, an embodiment of the present invention provides a method for dynamically transforming image colors, including:
storing the initial color of each initial pixel in the image to be converted in an internal memory;
when a color conversion instruction of the image to be converted is received, comparing the initial color with a target color to obtain a target pixel of which the color needs to be converted in the image to be converted; the color conversion instruction carries the target color of the image to be converted after dynamic change;
uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode;
and converting the adjusted HUE value of the image to be converted into an RGB value of an RGB color mode, and displaying the converted image to be converted according to the RGB value.
Optionally, the comparing the initial color with the target color to obtain a target pixel of which the color needs to be transformed in the image to be transformed includes:
traversing initial pixels in the image to be transformed;
performing initial pixel point traversal on the currently traversed initial pixel, and performing pixel value comparison on the currently traversed initial pixel point and a target pixel point corresponding to the target color at the same position;
when the comparison results are different, stopping pixel point traversal on the currently traversed initial pixel and continuously traversing the next initial pixel, and marking the currently traversed initial pixel as a target pixel of which the color needs to be changed;
or,
traversing initial pixel points in the image to be transformed;
comparing the pixel values of the currently traversed initial pixel point with the target pixel point corresponding to the target color at the same position;
when the comparison results are different, marking the initial pixel to which the currently traversed initial pixel belongs as a target pixel of which the color needs to be changed, and skipping over the pixel in the marked target pixel in the subsequent traversal process.
Optionally, the uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode includes:
determining a HUE value corresponding to the initial color corresponding to the target pixel in an HLS color mode;
and according to the HUE value of the target color, carrying out angle adjustment on the HUE value corresponding to each initial color.
Optionally, the method further includes:
storing the RGB value of the initial color of each pixel in the image to be converted in an RGB color mode;
the uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode further includes:
and converting the initial color of each initial pixel in the image to be converted into an HLS value in an HLS color mode from an RGB value in an RGB color mode.
Optionally, the method further includes:
if the memory is not full, storing the target color to which the target pixel needs to be converted in the memory;
and if the memory is full, releasing the memory block which is not used for the longest time, and storing the target color to which the target pixel needs to be converted by using the released memory block.
Optionally, the method further includes:
and storing the HUE value corresponding to the target color to which the target pixel needs to be converted.
Optionally, the uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to be before the HUE value corresponding to the target color in the HLS color mode further includes:
judging whether the HUE value corresponding to the target color into which the target pixel needs to be converted is stored in a memory;
if yes, acquiring a HUE value corresponding to the target color to which the target pixel needs to be converted from a memory, converting the acquired HUE value into an RGB value in an RGB color mode, and then executing the step of displaying the converted image to be converted according to the RGB value;
if not, executing the step of uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode.
Optionally, the saving the target color to which the target pixel needs to be transformed includes:
and allocating the memory by adopting a memory pool allocation technology, and storing the target color to which the target pixel needs to be converted by using the allocated memory.
Optionally, the saving the initial color of each initial pixel in the image to be transformed includes:
storing the initial color of each initial pixel in the image to be converted by adopting a palette format;
correspondingly, the saving the target color to which the target pixel needs to be transformed includes:
and storing the target color into which the target pixel needs to be transformed by adopting a palette format.
The embodiment of the invention also provides a device for dynamically changing the image color, which comprises:
the pixel color storage unit is used for storing the initial color of each initial pixel in the image to be converted in the memory;
the conversion pixel determining unit is used for comparing the initial color with a target color when receiving a color conversion instruction of the image to be converted to obtain a target pixel of which the color needs to be converted in the image to be converted; the color conversion instruction carries the target color of the image to be converted after dynamic change;
the pixel tone adjusting unit is used for uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode;
and the conversion pixel display unit is used for converting the adjusted HUE value of the image to be converted into an RGB value of an RGB color mode and displaying the converted image to be converted according to the RGB value.
The dynamic image color conversion method and device provided by the embodiment of the invention can realize the color change of the pixel through the adjustment of the HUE value in the HLS mode after the pixel needing color conversion is determined, so that the pixel file is not required to be saved in the system in advance, and the color conversion of the pixel is realized only through changing the HUE value in the HLS mode, thereby not only improving the efficiency of the color conversion of the pixel, but also reducing the system load.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a schematic diagram of HLS mode according to one embodiment of the present invention;
FIG. 2 is a flowchart illustrating a method for dynamically changing image colors according to an embodiment of the present invention;
FIG. 3 is a schematic flow chart of a dynamic image color transformation method according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of an apparatus for dynamically changing image colors according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The present invention relates to the RGB color mode and the HLS color mode, which are described below.
The RGB color mode is a color synthesis mode which is commonly used at present, almost all drawing software and image display adopt the RGB color mode, and the RGB color mode has the advantages of convenience in processing and small occupied space. RGB represents three colors of red (R), green (G) and blue (B), respectively, and among spectral colors, the three colors are the most sensitive colors for human eyes, and can be mixed into most colors, and conversely, most colors can also be decomposed into three colors of red, green and blue, i.e., the so-called three primary colors principle. The color synthesis method of mixing red, green and blue to obtain other colors is called RGB color mode. R, G, B, the values of the three parameters are all in the range of 0 to 255, for example, white is displayed (0, 0, 0) and black is displayed (255, 255, 255).
The HLS color mode is a color mode which is closest to the practical habit and is more in line with the color adjustment habit of a general user. HLS consists of three elements, namely HUE or HUE (HUE), brightness (Lightness), Saturation (Saturation). Hue (hue) is the most basic property of a color, i.e. the color range of a color, and each color in the spectrum is a hue, for example, between red and purple, and any number of hues can be defined. Fig. 1 shows a schematic diagram of HLS mode. In the figure, the ordinate represents brightness (L), the abscissa represents Saturation (S), and the circular arc represents Hue (H, Hue), and the color is changed uniformly by rotating at a certain angle along the circular arc.
Based on the above description, for the HLS color mode, the color conversion can be realized by modifying the hue value, that is, referring to fig. 1, the color conversion of the image can be realized by adjusting the arc angle; for the RGB color mode, if color conversion is needed, R, G, B the three parameters are converted in a ratio, which is difficult to obtain, and the three parameter values are all changed, which brings inconvenience in the implementation process. Therefore, one of the key points of the present invention is to perform color transformation in the HLS mode, so that the color transformation can be realized by changing only one parameter value of the hue, and the color transformation efficiency is high.
The following specifically describes embodiments of the present invention.
Referring to fig. 2, a flow chart of a method for dynamically transforming image colors according to an embodiment of the present invention is schematically shown, where the method includes the following steps:
step 201: and storing the initial color of each initial pixel in the image to be transformed in the memory.
For the current image transformation operation, the image to be transformed is an image before transformation, the image to be transformed comprises at least one pixel, and each pixel is composed of at least one pixel point.
In some embodiments, step 201 may include: and storing the initial color of each initial pixel in the image to be converted in a memory by adopting a palette format. In this embodiment, in order to save storage space, a palette format is used to record the initial color of each initial pixel in the image to be transformed, the initial color of each pixel in the initial pixel corresponds to one color in the palette used by the initial pixel, when a pair of initial pixels is color-transformed in step 203, the initial colors of all initial pixels in the initial pixel need to be transformed, actually, all colors in the palette used by the initial pixel are transformed and stored as another palette, and the newly generated palette is used as the palette used by the initial pixel.
Step 202: when a color conversion instruction of the image to be converted is received, comparing the initial color with a target color to obtain a target pixel of which the color needs to be converted in the image to be converted; and the color conversion instruction carries the target color of the image to be converted after dynamic change.
Because the color conversion instruction contains the converted image color information, namely the target color information corresponding to each pixel point in each pixel in the converted image, the image before conversion, namely the image to be converted and the converted image can be subjected to color comparison, namely the initial color in each initial pixel in the image to be converted and the converted target color are compared, and therefore which pixels in the image to be converted are subjected to color conversion can be found. Specifically, the initial pixel points in the image to be transformed may be traversed, the pixel values of the traversed initial pixel points and the target pixel points at the same position in the transformed image are compared, and for the traversed pixel points with different comparison results, the initial pixel to which the traversed pixel point belongs is determined as the target pixel whose color needs to be transformed.
In one embodiment, the step 202 of comparing the initial color with the target color to obtain a target pixel of the image to be transformed whose color needs to be transformed may include: traversing initial pixels in the image to be transformed; performing initial pixel point traversal on the currently traversed initial pixel, and performing pixel value comparison on the currently traversed initial pixel point and a target pixel point corresponding to the target color at the same position; and when the comparison results are different, stopping pixel point traversal on the currently traversed initial pixel and continuously traversing the next initial pixel, and marking the currently traversed initial pixel as a target pixel of which the color needs to be changed.
In this embodiment, each initial pixel in the image to be transformed is traversed in units of initial pixels, each initial pixel may be traversed one by one in a row-by-row or column-by-column order while traversing the initial pixels, and the following operations are performed for each traversed initial pixel: traversing initial pixel points in the currently traversed initial pixels, traversing each initial pixel point one by one in a row-by-row or column-by-column sequence when traversing the initial pixel points, comparing the initial pixel points with target pixel points at the same positions as the initial pixel points in the transformed image, and stopping traversing the initial pixel points in the current initial pixels as long as different initial pixel points of comparison results appear, so as to save traversal time, and further continuing traversing the initial pixel points in the next initial pixels, and simultaneously marking the current initial pixels as target pixels of which the colors need to be transformed.
In another embodiment, the step 202 of comparing the initial color with the target color to obtain a target pixel of which the color needs to be transformed in the image to be transformed may include: traversing initial pixel points in the image to be transformed; comparing the pixel values of the currently traversed initial pixel point with the target pixel point corresponding to the target color at the same position; when the comparison results are different, marking the initial pixel to which the currently traversed initial pixel belongs as a target pixel of which the color needs to be changed, and skipping over the pixel in the marked target pixel in the subsequent traversal process.
In the embodiment, the initial pixel points are taken as units, the initial pixel points in the image to be transformed are traversed in a mode of line-by-line or line-by-line and the like, for the currently traversed initial pixel points, the initial pixel points and target pixel points in the transformed image, which are at the same positions as the initial pixel points, are compared in pixel value, when the comparison results are different, the initial pixel points to which the initial pixel points belong are marked as target pixels of which the colors need to be transformed, and then the next initial pixel points are traversed continuously, and in the subsequent traversal process, in order to save the traversal time and avoid repeatedly marking the pixels, the initial pixel points in the marked initial pixel points are skipped.
Step 203: and uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode.
To implement step 203, the method may further comprise: storing the RGB values of the initial colors of the pixels in the image to be transformed in the RGB color mode in a memory, that is, storing the RGB values corresponding to the initial colors of the initial pixels in the image to be transformed, and before step 203, converting the initial colors of the initial pixels in the image to be transformed from the RGB values in the RGB color mode to HLS values in the HLS color mode, mainly converting the RGB values corresponding to the initial colors of the initial pixels in the image to be transformed into HUE values representing the initial colors of the pixels.
For the target pixel of which the color needs to be transformed in the image to be transformed, the color of the target pixel can be changed by adjusting the HUE value representing the color, so that if the initial color in each initial pixel in the image to be transformed is stored in the memory in an RGB color mode, the value of each initial color in the target pixel in the RGB mode is converted into an HLS value, and the purpose of transforming the color is achieved by modifying the H value in the HLS value at a certain angle. Based on this, step 203 may comprise: determining a HUE value corresponding to the initial color corresponding to the target pixel in an HLS color mode; and according to the HUE value of the target color, carrying out angle adjustment on the HUE value corresponding to each initial color.
Further, the method may further include: if the memory is not full, storing the target color to which the target pixel needs to be converted in the memory; and if the memory is full, releasing the memory block which is not used for the longest time, and storing the target color to which the target pixel needs to be converted by using the released memory block. In order to improve the processing efficiency of the system, the embodiment of the present invention uses a memory pool technique to create an allocation memory for storing the pixel color, that is, when storing the target color to which the target pixel needs to be converted, the memory pool allocation technique is used to allocate the memory, and the allocated memory is used to store the target color to which the target pixel needs to be converted.
Furthermore, in order to save memory storage space, the palette format is used to record the colors of the pixels after conversion, that is, when the target color to which the target pixel needs to be converted is stored in the memory, the target color to which the target pixel needs to be converted may be specifically stored in the palette format.
It can be understood that step 203 adopts HLS mode for color transformation, and color change can be realized by modifying HUE value, i.e. HUE value, in HLS mode without changing saturation value and brightness value, and for RGB mode, based on RGB principle, when the pixel color is transformed, R, G, B three parameters are transformed in a certain proportion, which is not easy to obtain, and all three parameters are transformed, so that the calculation amount is large in dynamic color transformation, therefore, the transformation of pixel color is realized only by changing HUE value in HLS mode, thereby improving the efficiency of pixel color transformation,
in order to further improve the efficiency of pixel color dynamic transformation, in the embodiment of the present invention, the HUE value corresponding to the target color after the target pixel is transformed is also saved while the target color is saved, that is, when the target color to which the target pixel needs to be transformed is saved, the HUE value corresponding to the target color to which the target pixel needs to be transformed is also saved. The used pixel color or the preset pixel color can be stored in the memory, the colors in the pixels can be stored in a HUE value mode, when the target pixel is subjected to color transformation, whether the HUE value corresponding to the target color into which the target pixel needs to be transformed is stored in the memory can be judged according to the HUE value of the stored pixel color, if yes, the pixel color can be directly called for improving the image transformation efficiency, and otherwise, the step 203 is adopted to carry out angle adjustment on the HUE value of the target pixel so as to carry out color transformation on the pixel. It can be seen that before step 203, the method may further include: judging whether the HUE value corresponding to the target color into which the target pixel needs to be converted is stored in a memory; if yes, acquiring a HUE value corresponding to the target color to which the target pixel needs to be converted from the memory, converting the acquired HUE value into an RGB value in an RGB color mode, and then executing the step of displaying the converted image to be converted according to the RGB value in step 204; if not, go to step 203.
Step 204: and converting the adjusted HUE value of the image to be converted into an RGB value of an RGB color mode, and displaying the converted image to be converted according to the RGB value.
In general, since the physical structure of the computer display follows the RGB mode, step 204 converts the adjusted HUE value into an RGB value and displays the converted image to be converted according to the RGB value so as to be compatible with most current display technologies.
See fig. 3 for another flow chart of the dynamic image color transformation method.
Initializing pixel information includes the following steps.
301: the pixel is loaded. The steps can be embodied as follows: judging whether the pixel is stored in the memory, if so, directly executing step 306 after receiving a pixel color conversion request, if not, further judging whether the current memory residual space is enough, if so, going to step 302 to execute the step of creating a buffer area, otherwise, eliminating the least used pixel stored in the memory space to release the memory space, and further executing step 302.
302: and creating a buffer area, wherein the invention recommends adopting the memory pool technology to distribute and create the buffer area in the memory. Besides the memory pool technology, NEW or malloc dynamic application of the memory can be adopted. Generally, when applying for a memory dynamically by using NEW or malloc, a small number of operations will not cause adverse effects, but if the operations for applying for a memory block are frequently performed, the processing efficiency of the system will be lost, and even more, if a memory fragment exists, the efficiency of the system will be further affected. Based on the above consideration, the present invention adopts a memory pool technology, that is, a large memory block is applied once, and a block is allocated for use every time when needed, and a new memory block is applied only when the memory block is insufficient. In general, memory pool techniques are more suitable for applications that apply for fixed-size blocks of memory each time. The preferred embodiment of the present invention employs a memory pool technique, but is not limited to the use of other memory usage techniques.
303: a palette is created, and in order to reduce the amount of operations, pixel colors are recorded using a palette format in the present embodiment. The color palette is in the form of an array, and records 256 colors, that is, at most 256 colors in a pixel, and only 256 colors in one color palette need to be calculated for each color conversion. Every colour in the palette all has a serial number to reach the purpose of unique identification, a serial number in the colour palette is corresponded to the colour serial number of every pixel, when the pixel carries out the color transform, the serial number of the present palette that uses of pixel changes for the palette serial number of new generation, but the serial number in the corresponding palette of every pixel is unchangeable, when carrying out the color transform, carry out the color transform calculation with 256 kinds of colours in the present palette, thereby generate a new palette and be preserved.
The palette and buffer are present with the pixel, i.e. they are created in memory only when the pixel is to be rendered, and are released if the pixel is not to be rendered in the next display frame.
Because the number of the hues which can be obviously distinguished by human eyes is 7, the pixel colors are converted among the 7 hues, and the visual perception can be enriched. Therefore, 7 palettes are provided for each pixel in the present embodiment, and numbers from 0 to 6 are used for identification. The present invention is not intended to limit the number of palettes set. In order to further reduce the amount of operations, 8 buffer areas are created in the memory for each pixel to store palettes, one buffer area is used for storing default palettes, the other 7 buffer areas are used for storing set 7 palettes respectively, and 8 palettes which are used recently are reserved in the buffer areas according to the oldest unused elimination principle. Furthermore, most color transforms only include a calculation process when they are used for the first time, and when the transformed color is requested again to be saved in the buffer, it can be called directly and displayed for output, further reducing the system computation.
304: the default palette is set and stored in the buffer, and since the default palette is used as a reference when performing color conversion calculation in the present embodiment, the default palette is stored in the buffer until the image is no longer displayed. The palette attribute with the number 0 is set, including the deflection angle (i.e., Hue value), the last use time, and the value of the color in the palette corresponding to the color of each pixel point in the image. The following is a palette data structure.
struct Pal
{
int last_ref_time;
int hue;
int palate[256];
}
Wherein int last _ ref _ time is the last time the palette is used, and is used to identify whether the palette is unused; the int HUE is a HUE value deflection angle based on a default palette when the color of the palette is transformed, and when the color is transformed, whether the currently requested color is stored in the buffer area can be judged according to the record of the int HUE, so that whether a new palette needs to be generated by calculation or is directly called from the buffer area is determined; int palette [256] is the palette data, and is referred by each pixel point in the pixel, thereby realizing the drawing of the pixel.
305: the data structure of a pixel object is shown below.
class Image
{
Pal extPal[8];
int width;
int height;
void*pImageData;
int findPal(hue);
int getPal(hue);
}
As can be seen from this example, the attribute of a pixel includes the called palette, and the subscript of the palette array is the palette number; the height and width of the pixel; the hue value of the pixel.
Requesting color conversion of the current image based on the known HUE value, comprising the following steps.
306: traversing the buffer area, judging whether the palette with the HUE value is saved according to the HUE value, if so, performing step 307, otherwise, performing step 308.
307: returning the palette number to realize the calling of the palette, modifying the number of the palette used for drawing the current pixel, and modifying the last use time of the palette to be the current time; proceeding to step 312, the pixel is rendered.
308: and traversing the buffer area, judging whether a free buffer area exists, if so, performing 310, and otherwise, performing 309.
309: according to the palette data structure provided above, according to the attribute of the latest called time, the palette which is not used for the longest time is eliminated, and the memory space is released; since the color transformation performed in this embodiment all uses the default palette as a reference to adjust the HUE value, the oldest unused elimination rule in this step is not applicable to the default palette, and the default palette is stored in the buffer until the pixel is not displayed in the next display cycle.
An example is provided below, which embodies the processing from step 26 to step 29.
int Image::getPal(int hue)
{
int find=findPal(hue)
if(find==0)
{
int def_ref_time=0;
int found=0;
int i=0;
for(i=1;i<8;i++)
{
if(extPal[i].hue==0)
{
break;
}
elseif(extPal[i].last_ref_time>def_ref_time)
{
def_ref_time=extPal[i].last_ref_time;
fount=i;
}
}
find=(i<8)?i:found;
convPal(extPal[0],extPal[find])
}
extPal[find].last_ref_time=time();
return find;
}
310: recalculating 256 color values in the palette based on the default palette; specifically, each color value in the default palette is converted from an RGB mode to an HLS mode, and after the color value in the HLS mode is obtained, a HUE (HUE) value therein is adjusted, that is, increased or decreased by a certain angle, so as to obtain the requested color.
311: and storing the palette generated by new calculation into the current buffer area, wherein the color value stored into the buffer area adopts an RGB mode. The method for interconversion between the palette color value RGB mode and the HLS mode refers to the above description, and is not described again.
312: and displaying the output pixel.
An example of drawing a pixel is shown below.
void Drawimage ("name", HUE)// Pixel name, color corresponding HUE value
{
Image & aImage ═ findImageByName ("name")// judging whether the memory is stored according to the pixel name
int palIdx. aImage. getPal (hue)// calling toning according to hue value
CopyToScreen (aImage.pData, aImage.extParal [ palIdx ])// output display
}
In the above-mentioned embodiments, the default palette is set as the reference for color conversion, so that adjustment of the hue value is more flexible and color conversion is more flexible; however, the default palette may not be set as the change HUE value standard in the present invention, and color conversion may be performed as long as the deflection angle between HUE values of the respective palettes is known. As mentioned above, the above embodiments use the RGB values when saving the pixel color palette, however, the present invention does not exclude the HLS value when saving the pixel color, and the HLS should be converted into the RGB before displaying the output pixel.
The dynamic transformation method of pixel colors is described in detail above, and the method is particularly suitable for image display of game interfaces, however, the application field of the technology is not limited by the present invention.
Further, since the present invention relates to image conversion between the RGB color mode and the HLS color mode, a conversion formula between the RGB color mode and the HLS color mode is given below:
1) the formula for converting HLS color mode to RGB mode is as follows:
MIN=2×L-MAX
S=0
R=G=B=L
S≠0
h=H+120
h=h-360 h≥360
h=H
h=H-120
h=h+360 h<0
2) the conversion formula from the RGB color mode to the HLS color mode is as follows:
MAX=max(R,G,B)
MIN=min(R,G,B)
L=(MAX+MIN)/2
MAX=MIN
S=0
H=0
MAX≠MIN
Cr=(MAX-R)/(MAX-MIN)
Cg=(MAX-G)/(MAX-MIN)
Cb=(MAX-B)/(MAX-MIN)
H=60×H
H=H+360 H<0
the dynamic image color conversion method provided by the embodiment of the invention can realize the color change of the pixel through the HUE value adjustment in the HLS mode after the pixel needing color conversion is determined, so that the pixel file does not need to be saved in the system in advance, and the color conversion of the pixel is realized only through changing the HUE value in the HLS mode, thereby not only improving the efficiency of the color conversion of the pixel, but also reducing the system load.
Referring to fig. 4, a schematic composition diagram of an apparatus for dynamically changing image colors according to an embodiment of the present invention includes:
a pixel color saving unit 401, configured to save, in an internal memory, initial colors of initial pixels in an image to be transformed;
a transform pixel determining unit 402, configured to compare the initial color with a target color when a color transform instruction of the image to be transformed is received, to obtain a target pixel whose color needs to be transformed in the image to be transformed; the color conversion instruction carries the target color of the image to be converted after dynamic change;
a pixel tone adjustment unit 403, configured to uniformly adjust the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode;
and a transform pixel display unit 404, configured to convert the adjusted HUE value of the image to be transformed into an RGB value in an RGB color mode, and display the converted image to be transformed according to the RGB value.
In some embodiments, the transform pixel determination unit 402 includes:
the first traversal module is used for traversing initial pixels in the image to be transformed;
the first comparison module is used for traversing initial pixel points of the currently traversed initial pixels and comparing the pixel values of the currently traversed initial pixel points with target pixel points corresponding to the target colors under the same position;
the first marking module is used for stopping pixel point traversal on the currently traversed initial pixel and continuously traversing the next initial pixel when the comparison results are different, and marking the currently traversed initial pixel as a target pixel of which the color needs to be changed;
alternatively, the transform pixel determination unit 402 includes:
the second traversal module is used for traversing the initial pixel points in the image to be transformed;
the second comparison module is used for comparing the pixel values of the currently traversed initial pixel point with the target pixel point corresponding to the target color at the same position;
and the second marking module is used for marking the initial pixel to which the currently traversed initial pixel belongs as a target pixel of which the color needs to be changed when the comparison results are different, and skipping over the pixels in the marked target pixel in the subsequent traversal process.
In some embodiments, the pixel tone adjustment unit 403 includes:
a HUE value determining module, configured to determine a HUE value corresponding to the initial color of the target pixel in the HLS color mode;
and the pixel tone adjusting module is used for carrying out angle adjustment on the HUE value corresponding to each initial color according to the HUE value of the target color.
In some embodiments, the apparatus further comprises:
the first storage unit is used for storing the RGB values of the initial colors of all pixels in the image to be converted in an RGB color mode;
a mode conversion unit, configured to convert the initial color of each initial pixel in the image to be transformed from the RGB value in the RGB color mode to the HLS value in the HLS color mode before the HUE value corresponding to the initial color in the target pixel in the HLS color mode is uniformly adjusted to the HUE value corresponding to the target color in the HLS color mode by the pixel tone adjustment unit 403.
In some embodiments, the apparatus further comprises:
a conversion color storage unit, configured to store, in the memory, a target color to which the target pixel needs to be converted if the memory is not full; and if the memory is full, releasing the memory block which is not used for the longest time, and storing the target color to which the target pixel needs to be converted by using the released memory block.
In some embodiments, the apparatus further comprises:
and the second storage unit is used for storing the HUE value corresponding to the target color into which the target pixel needs to be converted.
In some embodiments, the apparatus further comprises:
a pixel judgment unit, configured to judge whether the HUE value corresponding to the target color into which the target pixel needs to be transformed is stored in a memory before uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode;
a pixel calling unit, configured to, if the determination result of the pixel determination unit is yes, obtain, from the memory, a HUE value corresponding to a target color to which the target pixel needs to be converted, convert the obtained HUE value into an RGB value in an RGB color mode, and then use the conversion pixel display unit 404 to implement a function of displaying the converted image to be converted according to the RGB value; if the determination result of the pixel determination unit is negative, the pixel tone adjustment unit 403 is utilized to implement a function of uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode.
In some embodiments, the transformed color storage unit is specifically configured to allocate a memory by using a memory pool allocation technique, and store a target color to which the target pixel needs to be transformed by using the allocated memory.
In some embodiments, the pixel color saving unit is specifically configured to save the initial color of each initial pixel in the image to be transformed by using a palette format; the conversion color storage unit is specifically configured to store, in a palette format, a target color to which the target pixel needs to be converted.
As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that all or part of the steps in the above embodiment methods can be implemented by software plus a necessary general hardware platform. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network communication device such as a media gateway, etc.) to execute the method according to the embodiments or some parts of the embodiments of the present invention.
It should be noted that, for the apparatuses disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and for the relevant points, refer to the description of the method.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
1. A method for dynamic transformation of image colors, comprising:
storing the initial color of each initial pixel in the image to be converted in an internal memory;
when a color conversion instruction of the image to be converted is received, traversing initial pixel points in the image to be converted, comparing the pixel values of the traversed initial pixel points with target pixel points at the same position in the converted image, and determining initial pixels to which the traversed pixel points with different comparison results belong as target pixels of which the colors need to be converted; when the target pixel is determined, the pixel points which are not traversed in the target pixel are not traversed any more, and the color conversion instruction carries a target color corresponding to each pixel point in each pixel in the converted image;
uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode;
and converting the adjusted HUE value of the image to be converted into an RGB value of an RGB color mode, and displaying the converted image to be converted according to the RGB value.
2. The method of claim 1, wherein traversing the initial pixel points in the image to be transformed, comparing the pixel values of the traversed initial pixel points with target pixel points at the same position in the transformed image, and determining the initial pixel to which the traversed pixel points with different comparison results belong as a target pixel whose color needs to be transformed, comprises:
traversing initial pixels in the image to be transformed;
performing initial pixel point traversal on the currently traversed initial pixel, and performing pixel value comparison on the currently traversed initial pixel point and a target pixel point corresponding to the target color at the same position;
when the comparison results are different, stopping pixel point traversal on the currently traversed initial pixel and continuously traversing the next initial pixel, and marking the currently traversed initial pixel as a target pixel of which the color needs to be changed;
or,
traversing initial pixel points in the image to be transformed;
comparing the pixel values of the currently traversed initial pixel point with the target pixel point corresponding to the target color at the same position;
when the comparison results are different, marking the initial pixel to which the currently traversed initial pixel belongs as a target pixel of which the color needs to be changed, and skipping over the pixel in the marked target pixel in the subsequent traversal process.
3. The method according to claim 1, wherein the uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode comprises:
determining a HUE value corresponding to the initial color corresponding to the target pixel in an HLS color mode;
and according to the HUE value of the target color, carrying out angle adjustment on the HUE value corresponding to each initial color.
4. The method according to claim 1 or 3, characterized in that the method further comprises:
storing the RGB value of the initial color of each pixel in the image to be converted in an RGB color mode;
the uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode further includes:
and converting the initial color of each initial pixel in the image to be converted into an HLS value in an HLS color mode from an RGB value in an RGB color mode.
5. The method of claim 1, further comprising:
if the memory is not full, storing the target color to which the target pixel needs to be converted in the memory;
and if the memory is full, releasing the memory block which is not used for the longest time, and storing the target color to which the target pixel needs to be converted by using the released memory block.
6. The method of claim 5, further comprising:
and storing the HUE value corresponding to the target color to which the target pixel needs to be converted.
7. The method according to claim 6, wherein the uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to be before the HUE value corresponding to the target color in the HLS color mode further comprises:
judging whether the HUE value corresponding to the target color into which the target pixel needs to be converted is stored in a memory;
if yes, acquiring a HUE value corresponding to the target color to which the target pixel needs to be converted from a memory, converting the acquired HUE value into an RGB value in an RGB color mode, and then executing the step of displaying the converted image to be converted according to the RGB value;
if not, executing the step of uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode.
8. The method of claim 5, wherein saving the target color to which the target pixel needs to be transformed comprises:
and allocating the memory by adopting a memory pool allocation technology, and storing the target color to which the target pixel needs to be converted by using the allocated memory.
9. The method of claim 5,
the storing of the initial color of each initial pixel in the image to be transformed includes:
storing the initial color of each initial pixel in the image to be converted by adopting a palette format;
correspondingly, the saving the target color to which the target pixel needs to be transformed includes:
and storing the target color into which the target pixel needs to be transformed by adopting a palette format.
10. An apparatus for dynamically changing the color of an image, comprising:
the pixel color storage unit is used for storing the initial color of each initial pixel in the image to be converted in the memory;
the conversion pixel determining unit is used for traversing initial pixel points in the image to be converted when a color conversion instruction of the image to be converted is received, comparing the pixel values of the traversed initial pixel points with target pixel points at the same position in the converted image, and determining the initial pixel to which the traversed pixel points with different comparison results belong as a target pixel of which the color needs to be converted; when the target pixel is determined, the pixel points which are not traversed in the target pixel are not traversed any more, and the color conversion instruction carries a target color corresponding to each pixel point in each pixel in the converted image;
the pixel tone adjusting unit is used for uniformly adjusting the HUE value corresponding to the initial color in the target pixel in the HLS color mode to the HUE value corresponding to the target color in the HLS color mode;
and the conversion pixel display unit is used for converting the adjusted HUE value of the image to be converted into an RGB value of an RGB color mode and displaying the converted image to be converted according to the RGB value.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611162252.XA CN106780648B (en) | 2016-12-15 | 2016-12-15 | A kind of dynamic mapping method and device of color of image |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611162252.XA CN106780648B (en) | 2016-12-15 | 2016-12-15 | A kind of dynamic mapping method and device of color of image |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106780648A CN106780648A (en) | 2017-05-31 |
CN106780648B true CN106780648B (en) | 2018-11-13 |
Family
ID=58892690
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201611162252.XA Active CN106780648B (en) | 2016-12-15 | 2016-12-15 | A kind of dynamic mapping method and device of color of image |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106780648B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107450873B (en) * | 2017-07-01 | 2020-09-04 | 广州视源电子科技股份有限公司 | Color wheel, color matching method, readable storage medium and computer device |
CN109166162A (en) * | 2018-10-08 | 2019-01-08 | 苏州仙峰网络科技股份有限公司 | 2D color changing method based on fixed form and aspect |
CN110719382B (en) * | 2019-10-09 | 2021-11-16 | 北京明略软件系统有限公司 | Color replacement method and device |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH02284274A (en) * | 1989-04-25 | 1990-11-21 | Canon Inc | Picture processing method |
CN1787010A (en) * | 2005-11-24 | 2006-06-14 | 北京金山软件有限公司 | Method for dynamic changing picture element colour and method for changing image colour |
CN102292972A (en) * | 2009-01-23 | 2011-12-21 | 日本电气株式会社 | image processing method, image processing device and recording medium |
CN102651136A (en) * | 2011-02-28 | 2012-08-29 | 国际商业机器公司 | Color mapping method and device of image |
-
2016
- 2016-12-15 CN CN201611162252.XA patent/CN106780648B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH02284274A (en) * | 1989-04-25 | 1990-11-21 | Canon Inc | Picture processing method |
CN1787010A (en) * | 2005-11-24 | 2006-06-14 | 北京金山软件有限公司 | Method for dynamic changing picture element colour and method for changing image colour |
CN102292972A (en) * | 2009-01-23 | 2011-12-21 | 日本电气株式会社 | image processing method, image processing device and recording medium |
CN102651136A (en) * | 2011-02-28 | 2012-08-29 | 国际商业机器公司 | Color mapping method and device of image |
Also Published As
Publication number | Publication date |
---|---|
CN106780648A (en) | 2017-05-31 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8493619B2 (en) | Hardware-accelerated color data processing | |
US7457003B1 (en) | Color management for limited gamut devices | |
CN106780648B (en) | A kind of dynamic mapping method and device of color of image | |
JPWO2003043306A1 (en) | Medium on which color conversion program is recorded, medium on which color conversion table data is recorded, color conversion apparatus, color conversion method, color conversion program, color conversion table, medium on which color conversion table creation program is recorded, medium on which interpolation calculation program is recorded , Color conversion table creation program, interpolation computation program, color conversion table creation device, interpolation computation device, color conversion table creation method, interpolation computation method, partial color conversion table, printing device and printing method | |
EP0878090A1 (en) | Appearance-based technique for rendering colors on an output device | |
JP2000134486A (en) | Image processing unit, image processing method and storage medium | |
KR101303874B1 (en) | Apparatus and method for gamut mapping | |
JP6793281B2 (en) | Color gamut mapping method and color gamut mapping device | |
CN111179370A (en) | Picture generation method and device, electronic equipment and storage medium | |
KR101225059B1 (en) | Apparatus and method for enhancing color device-adaptively | |
CN100369065C (en) | Method for dynamic changing picture element colour and method for changing image colour | |
JPH11146219A (en) | Image processing device and method and medium recording image processing program | |
JP4146506B1 (en) | Mosaic image generating apparatus, method and program | |
CN111338627B (en) | Front-end webpage theme color adjustment method and device | |
WO2023241339A1 (en) | Color cast correction method and apparatus, device, storage medium and program product | |
CN104021579A (en) | Method and device for changing colors of image | |
JP2007312313A (en) | Image processor, image processing method and program | |
WO1997028640A1 (en) | Appearance-based technique for rendering colors on an output device | |
US12087249B2 (en) | Perceptual color enhancement based on properties of responses of human vision system to color stimulus | |
CN107492365B (en) | Method and device for obtaining color gamut mapping fitting function | |
US7956868B2 (en) | Gamut map model with improved gradation fidelity at low chroma values | |
CN108876800A (en) | A kind of information processing method and equipment | |
Thomas et al. | Cross-media color reproduction and display characterization | |
JP2003078777A (en) | Medium having color conversion program recorded thereon, medium having color conversion table data recorded thereon, color converter, color conversion method, color conversion program and color conversion table | |
JPH05290133A (en) | Color image processor |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |