Lines Matching refs:cube_info
439 const CubeInfo *cube_info,const Quantum *pixel,DoublePixelPacket *alpha_pixel) in AssociateAlphaPixel() argument
444 if ((cube_info->associate_alpha == MagickFalse) || in AssociateAlphaPixel()
460 static inline void AssociateAlphaPixelInfo(const CubeInfo *cube_info, in AssociateAlphaPixelInfo() argument
466 if ((cube_info->associate_alpha == MagickFalse) || in AssociateAlphaPixelInfo()
482 static inline size_t ColorToNodeId(const CubeInfo *cube_info, in ColorToNodeId() argument
491 if (cube_info->associate_alpha != MagickFalse) in ColorToNodeId()
496 static MagickBooleanType AssignImageColors(Image *image,CubeInfo *cube_info, in AssignImageColors() argument
511 if (cube_info->quantize_info->colorspace != UndefinedColorspace) in AssignImageColors()
512 (void) TransformImageColorspace(image,cube_info->quantize_info->colorspace, in AssignImageColors()
514 if (AcquireImageColormap(image,cube_info->colors,exception) == MagickFalse) in AssignImageColors()
518 cube_info->transparent_pixels=0; in AssignImageColors()
519 cube_info->transparent_index=(-1); in AssignImageColors()
520 (void) DefineImageColormap(image,cube_info,cube_info->root); in AssignImageColors()
524 if (cube_info->quantize_info->dither_method != NoDitherMethod) in AssignImageColors()
525 (void) DitherImage(image,cube_info,exception); in AssignImageColors()
563 cube=(*cube_info); in AssignImageColors()
642 if (cube_info->quantize_info->measure_error != MagickFalse) in AssignImageColors()
644 if ((cube_info->quantize_info->number_colors == 2) && in AssignImageColors()
645 ((cube_info->quantize_info->colorspace == LinearGRAYColorspace) || in AssignImageColors()
646 (cube_info->quantize_info->colorspace == GRAYColorspace))) in AssignImageColors()
670 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in AssignImageColors()
737 static inline void SetAssociatedAlpha(const Image *image,CubeInfo *cube_info) in SetAssociatedAlpha() argument
744 if ((cube_info->quantize_info->number_colors == 2) && in SetAssociatedAlpha()
745 ((cube_info->quantize_info->colorspace == LinearGRAYColorspace) || in SetAssociatedAlpha()
746 (cube_info->quantize_info->colorspace == GRAYColorspace))) in SetAssociatedAlpha()
748 cube_info->associate_alpha=associate_alpha; in SetAssociatedAlpha()
751 static MagickBooleanType ClassifyImageColors(CubeInfo *cube_info, in ClassifyImageColors() argument
786 SetAssociatedAlpha(image,cube_info); in ClassifyImageColors()
787 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in ClassifyImageColors()
788 (cube_info->quantize_info->colorspace != CMYKColorspace)) in ClassifyImageColors()
790 cube_info->quantize_info->colorspace,exception); in ClassifyImageColors()
811 if (cube_info->nodes > MaxNodes) in ClassifyImageColors()
816 PruneLevel(cube_info,cube_info->root); in ClassifyImageColors()
817 cube_info->depth--; in ClassifyImageColors()
833 AssociateAlphaPixel(image,cube_info,p,&pixel); in ClassifyImageColors()
837 node_info=cube_info->root; in ClassifyImageColors()
844 id=ColorToNodeId(cube_info,&pixel,index); in ClassifyImageColors()
854 node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info); in ClassifyImageColors()
863 cube_info->colors++; in ClassifyImageColors()
872 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
879 cube_info->root->quantize_error+=node_info->quantize_error; in ClassifyImageColors()
889 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
897 if (cube_info->colors > cube_info->maximum_colors) in ClassifyImageColors()
899 PruneToCubeDepth(cube_info,cube_info->root); in ClassifyImageColors()
918 if (cube_info->nodes > MaxNodes) in ClassifyImageColors()
923 PruneLevel(cube_info,cube_info->root); in ClassifyImageColors()
924 cube_info->depth--; in ClassifyImageColors()
940 AssociateAlphaPixel(image,cube_info,p,&pixel); in ClassifyImageColors()
944 node_info=cube_info->root; in ClassifyImageColors()
945 for (level=1; level <= cube_info->depth; level++) in ClassifyImageColors()
951 id=ColorToNodeId(cube_info,&pixel,index); in ClassifyImageColors()
961 node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info); in ClassifyImageColors()
969 if (level == cube_info->depth) in ClassifyImageColors()
970 cube_info->colors++; in ClassifyImageColors()
979 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
986 cube_info->root->quantize_error+=node_info->quantize_error; in ClassifyImageColors()
996 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
1010 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in ClassifyImageColors()
1011 (cube_info->quantize_info->colorspace != CMYKColorspace)) in ClassifyImageColors()
1088 static void ClosestColor(const Image *image,CubeInfo *cube_info, in ClosestColor() argument
1100 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in ClosestColor()
1103 ClosestColor(image,cube_info,node_info->child[i]); in ClosestColor()
1124 q=(&cube_info->target); in ClosestColor()
1127 if (cube_info->associate_alpha != MagickFalse) in ClosestColor()
1134 if (distance <= cube_info->distance) in ClosestColor()
1138 if (distance <= cube_info->distance) in ClosestColor()
1142 if (distance <= cube_info->distance) in ClosestColor()
1144 if (cube_info->associate_alpha != MagickFalse) in ClosestColor()
1149 if (distance <= cube_info->distance) in ClosestColor()
1151 cube_info->distance=distance; in ClosestColor()
1152 cube_info->color_number=node_info->color_number; in ClosestColor()
1235 static size_t DefineImageColormap(Image *image,CubeInfo *cube_info, in DefineImageColormap() argument
1247 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in DefineImageColormap()
1250 (void) DefineImageColormap(image,cube_info,node_info->child[i]); in DefineImageColormap()
1265 if (cube_info->associate_alpha == MagickFalse) in DefineImageColormap()
1304 if (node_info->number_unique > cube_info->transparent_pixels) in DefineImageColormap()
1306 cube_info->transparent_pixels=node_info->number_unique; in DefineImageColormap()
1307 cube_info->transparent_index=(ssize_t) image->colors; in DefineImageColormap()
1338 static void DestroyCubeInfo(CubeInfo *cube_info) in DestroyCubeInfo() argument
1348 nodes=cube_info->node_queue->next; in DestroyCubeInfo()
1349 cube_info->node_queue->nodes=(NodeInfo *) RelinquishMagickMemory( in DestroyCubeInfo()
1350 cube_info->node_queue->nodes); in DestroyCubeInfo()
1351 cube_info->node_queue=(Nodes *) RelinquishMagickMemory( in DestroyCubeInfo()
1352 cube_info->node_queue); in DestroyCubeInfo()
1353 cube_info->node_queue=nodes; in DestroyCubeInfo()
1354 } while (cube_info->node_queue != (Nodes *) NULL); in DestroyCubeInfo()
1355 if (cube_info->memory_info != (MemoryInfo *) NULL) in DestroyCubeInfo()
1356 cube_info->memory_info=RelinquishVirtualMemory(cube_info->memory_info); in DestroyCubeInfo()
1357 cube_info->quantize_info=DestroyQuantizeInfo(cube_info->quantize_info); in DestroyCubeInfo()
1358 cube_info=(CubeInfo *) RelinquishMagickMemory(cube_info); in DestroyCubeInfo()
1465 static inline ssize_t CacheOffset(CubeInfo *cube_info, in CacheOffset() argument
1479 if (cube_info->associate_alpha != MagickFalse) in CacheOffset()
1484 static MagickBooleanType FloydSteinbergDither(Image *image,CubeInfo *cube_info, in FloydSteinbergDither() argument
1551 cube=(*cube_info); in FloydSteinbergDither()
1685 static void Riemersma(Image *image,CacheView *image_view,CubeInfo *cube_info, in Riemersma() argument
1693 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1695 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1697 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1703 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1705 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1707 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1713 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1715 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1717 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1723 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1725 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1727 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1739 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1741 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1743 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1745 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1747 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1749 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1751 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1757 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1759 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1761 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1763 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1765 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1767 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1769 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1775 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1777 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1779 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1781 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1783 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1785 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1787 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1793 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1795 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1797 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1799 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1801 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1803 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1805 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1815 CubeInfo *cube_info,const unsigned int direction,ExceptionInfo *exception) in RiemersmaDither() argument
1832 p=cube_info; in RiemersmaDither()
1848 AssociateAlphaPixel(image,cube_info,q,&pixel); in RiemersmaDither()
1854 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1860 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1862 i=CacheOffset(cube_info,&pixel); in RiemersmaDither()
1877 id=ColorToNodeId(cube_info,&pixel,index); in RiemersmaDither()
1897 if (cube_info->quantize_info->measure_error == MagickFalse) in RiemersmaDither()
1902 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1912 AssociateAlphaPixelInfo(cube_info,image->colormap+index,&color); in RiemersmaDither()
1916 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1933 static MagickBooleanType DitherImage(Image *image,CubeInfo *cube_info, in DitherImage() argument
1948 if (cube_info->quantize_info->dither_method != RiemersmaDitherMethod) in DitherImage()
1949 return(FloydSteinbergDither(image,cube_info,exception)); in DitherImage()
1953 (void) memset(cube_info->error,0,ErrorQueueLength* in DitherImage()
1954 sizeof(*cube_info->error)); in DitherImage()
1955 cube_info->x=0; in DitherImage()
1956 cube_info->y=0; in DitherImage()
1962 cube_info->offset=0; in DitherImage()
1963 cube_info->span=(MagickSizeType) image->columns*image->rows; in DitherImage()
1966 Riemersma(image,image_view,cube_info,depth-1,NorthGravity,exception); in DitherImage()
1967 status=RiemersmaDither(image,image_view,cube_info,ForgetGravity,exception); in DitherImage()
2010 *cube_info; in GetCubeInfo() local
2025 cube_info=(CubeInfo *) AcquireMagickMemory(sizeof(*cube_info)); in GetCubeInfo()
2026 if (cube_info == (CubeInfo *) NULL) in GetCubeInfo()
2028 (void) memset(cube_info,0,sizeof(*cube_info)); in GetCubeInfo()
2029 cube_info->depth=depth; in GetCubeInfo()
2030 if (cube_info->depth > MaxTreeDepth) in GetCubeInfo()
2031 cube_info->depth=MaxTreeDepth; in GetCubeInfo()
2032 if (cube_info->depth < 2) in GetCubeInfo()
2033 cube_info->depth=2; in GetCubeInfo()
2034 cube_info->maximum_colors=maximum_colors; in GetCubeInfo()
2038 cube_info->root=GetNodeInfo(cube_info,0,0,(NodeInfo *) NULL); in GetCubeInfo()
2039 if (cube_info->root == (NodeInfo *) NULL) in GetCubeInfo()
2041 cube_info->root->parent=cube_info->root; in GetCubeInfo()
2042 cube_info->quantize_info=CloneQuantizeInfo(quantize_info); in GetCubeInfo()
2043 if (cube_info->quantize_info->dither_method == NoDitherMethod) in GetCubeInfo()
2044 return(cube_info); in GetCubeInfo()
2049 cube_info->memory_info=AcquireVirtualMemory(length,sizeof(*cube_info->cache)); in GetCubeInfo()
2050 if (cube_info->memory_info == (MemoryInfo *) NULL) in GetCubeInfo()
2052 cube_info->cache=(ssize_t *) GetVirtualMemoryBlob(cube_info->memory_info); in GetCubeInfo()
2056 (void) memset(cube_info->cache,(-1),sizeof(*cube_info->cache)* in GetCubeInfo()
2064 cube_info->weights[ErrorQueueLength-i-1]=PerceptibleReciprocal(weight); in GetCubeInfo()
2072 weight+=cube_info->weights[i]; in GetCubeInfo()
2076 cube_info->weights[i]/=weight; in GetCubeInfo()
2077 sum+=cube_info->weights[i]; in GetCubeInfo()
2079 cube_info->weights[0]+=1.0-sum; in GetCubeInfo()
2080 return(cube_info); in GetCubeInfo()
2111 static NodeInfo *GetNodeInfo(CubeInfo *cube_info,const size_t id, in GetNodeInfo() argument
2117 if (cube_info->free_nodes == 0) in GetNodeInfo()
2132 nodes->next=cube_info->node_queue; in GetNodeInfo()
2133 cube_info->node_queue=nodes; in GetNodeInfo()
2134 cube_info->next_node=nodes->nodes; in GetNodeInfo()
2135 cube_info->free_nodes=NodesInAList; in GetNodeInfo()
2137 cube_info->nodes++; in GetNodeInfo()
2138 cube_info->free_nodes--; in GetNodeInfo()
2139 node_info=cube_info->next_node++; in GetNodeInfo()
2498 static void PruneChild(CubeInfo *cube_info,const NodeInfo *node_info) in PruneChild() argument
2512 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneChild()
2515 PruneChild(cube_info,node_info->child[i]); in PruneChild()
2526 cube_info->nodes--; in PruneChild()
2554 static void PruneLevel(CubeInfo *cube_info,const NodeInfo *node_info) in PruneLevel() argument
2565 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneLevel()
2568 PruneLevel(cube_info,node_info->child[i]); in PruneLevel()
2569 if (node_info->level == cube_info->depth) in PruneLevel()
2570 PruneChild(cube_info,node_info); in PruneLevel()
2599 static void PruneToCubeDepth(CubeInfo *cube_info,const NodeInfo *node_info) in PruneToCubeDepth() argument
2610 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneToCubeDepth()
2613 PruneToCubeDepth(cube_info,node_info->child[i]); in PruneToCubeDepth()
2614 if (node_info->level > cube_info->depth) in PruneToCubeDepth()
2615 PruneChild(cube_info,node_info); in PruneToCubeDepth()
2652 *cube_info; in QuantizeImage() local
2710 cube_info=GetCubeInfo(quantize_info,depth,maximum_colors); in QuantizeImage()
2711 if (cube_info == (CubeInfo *) NULL) in QuantizeImage()
2714 status=ClassifyImageColors(cube_info,image,exception); in QuantizeImage()
2721 if (cube_info->colors > cube_info->maximum_colors) in QuantizeImage()
2722 ReduceImageColors(image,cube_info); in QuantizeImage()
2724 cube_info->quantize_info->dither_method=NoDitherMethod; in QuantizeImage()
2725 status=AssignImageColors(image,cube_info,exception); in QuantizeImage()
2727 DestroyCubeInfo(cube_info); in QuantizeImage()
2765 *cube_info; in QuantizeImages() local
2825 cube_info=GetCubeInfo(quantize_info,depth,maximum_colors); in QuantizeImages()
2826 if (cube_info == (CubeInfo *) NULL) in QuantizeImages()
2838 status=ClassifyImageColors(cube_info,image,exception); in QuantizeImages()
2853 ReduceImageColors(images,cube_info); in QuantizeImages()
2859 status=AssignImageColors(image,cube_info,exception); in QuantizeImages()
2871 DestroyCubeInfo(cube_info); in QuantizeImages()
2908 static size_t QuantizeErrorFlatten(const CubeInfo *cube_info, in QuantizeErrorFlatten() argument
2918 if (offset >= (ssize_t) cube_info->nodes) in QuantizeErrorFlatten()
2922 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in QuantizeErrorFlatten()
2925 n+=QuantizeErrorFlatten(cube_info,node_info->child[i],offset+n, in QuantizeErrorFlatten()
2955 static void Reduce(CubeInfo *cube_info,const NodeInfo *node_info) in Reduce() argument
2966 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in Reduce()
2969 Reduce(cube_info,node_info->child[i]); in Reduce()
2970 if (node_info->quantize_error <= cube_info->pruning_threshold) in Reduce()
2971 PruneChild(cube_info,node_info); in Reduce()
2978 cube_info->colors++; in Reduce()
2979 if (node_info->quantize_error < cube_info->next_threshold) in Reduce()
2980 cube_info->next_threshold=node_info->quantize_error; in Reduce()
3054 static void ReduceImageColors(const Image *image,CubeInfo *cube_info) in ReduceImageColors() argument
3067 cube_info->next_threshold=0.0; in ReduceImageColors()
3068 if (cube_info->colors > cube_info->maximum_colors) in ReduceImageColors()
3076 quantize_error=(double *) AcquireQuantumMemory(cube_info->nodes, in ReduceImageColors()
3080 (void) QuantizeErrorFlatten(cube_info,cube_info->root,0, in ReduceImageColors()
3082 qsort(quantize_error,cube_info->nodes,sizeof(double), in ReduceImageColors()
3084 if (cube_info->nodes > (110*(cube_info->maximum_colors+1)/100)) in ReduceImageColors()
3085 cube_info->next_threshold=quantize_error[cube_info->nodes-110* in ReduceImageColors()
3086 (cube_info->maximum_colors+1)/100]; in ReduceImageColors()
3090 for (span=cube_info->colors; cube_info->colors > cube_info->maximum_colors; ) in ReduceImageColors()
3092 cube_info->pruning_threshold=cube_info->next_threshold; in ReduceImageColors()
3093 cube_info->next_threshold=cube_info->root->quantize_error-1; in ReduceImageColors()
3094 cube_info->colors=0; in ReduceImageColors()
3095 Reduce(cube_info,cube_info->root); in ReduceImageColors()
3096 offset=(MagickOffsetType) span-cube_info->colors; in ReduceImageColors()
3098 cube_info->maximum_colors+1); in ReduceImageColors()
3138 *cube_info; in RemapImage() local
3154 cube_info=GetCubeInfo(quantize_info,MaxTreeDepth, in RemapImage()
3156 if (cube_info == (CubeInfo *) NULL) in RemapImage()
3159 status=ClassifyImageColors(cube_info,remap_image,exception); in RemapImage()
3165 cube_info->quantize_info->number_colors=cube_info->colors; in RemapImage()
3166 status=AssignImageColors(image,cube_info,exception); in RemapImage()
3168 DestroyCubeInfo(cube_info); in RemapImage()
3206 *cube_info; in RemapImages() local
3232 cube_info=GetCubeInfo(quantize_info,MaxTreeDepth, in RemapImages()
3234 if (cube_info == (CubeInfo *) NULL) in RemapImages()
3237 status=ClassifyImageColors(cube_info,remap_image,exception); in RemapImages()
3243 cube_info->quantize_info->number_colors=cube_info->colors; in RemapImages()
3247 status=AssignImageColors(image,cube_info,exception); in RemapImages()
3252 DestroyCubeInfo(cube_info); in RemapImages()