Image *get_grayscale_image(Image *img) { QuantizeInfo info; GetQuantizeInfo(&info); info.colorspace = GRAYColorspace; info.number_colors = 256; QuantizeImage(&info, img); return (img); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d X C F I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadXCFImage() reads a GIMP (GNU Image Manipulation Program) image % file and returns it. It allocates the memory necessary for the new Image % structure and returns a pointer to the new image. % % The format of the ReadXCFImage method is: % % image=ReadXCFImage(image_info) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadXCFImage(const ImageInfo *image_info,ExceptionInfo *exception) { char magick[14]; Image *image; int foundPropEnd = 0; MagickBooleanType status; MagickOffsetType offset; register ssize_t i; size_t length; ssize_t count; size_t image_type; XCFDocInfo doc_info; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } count=ReadBlob(image,14,(unsigned char *) magick); if ((count == 0) || (LocaleNCompare((char *) magick,"gimp xcf",8) != 0)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); (void) ResetMagickMemory(&doc_info,0,sizeof(XCFDocInfo)); doc_info.exception=exception; doc_info.width=ReadBlobMSBLong(image); doc_info.height=ReadBlobMSBLong(image); if ((doc_info.width > 262144) || (doc_info.height > 262144)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); doc_info.image_type=ReadBlobMSBLong(image); /* Initialize image attributes. */ image->columns=doc_info.width; image->rows=doc_info.height; image_type=doc_info.image_type; doc_info.file_size=GetBlobSize(image); image->compression=NoCompression; image->depth=8; if (image_type == GIMP_RGB) image->colorspace=RGBColorspace; else if (image_type == GIMP_GRAY) image->colorspace=GRAYColorspace; else if (image_type == GIMP_INDEXED) ThrowReaderException(CoderError,"ColormapTypeNotSupported"); (void) SetImageBackgroundColor(image); image->matte=MagickTrue; /* Read properties. */ while ((foundPropEnd == MagickFalse) && (EOFBlob(image) == MagickFalse)) { PropType prop_type = (PropType) ReadBlobMSBLong(image); size_t prop_size = ReadBlobMSBLong(image); switch (prop_type) { case PROP_END: foundPropEnd=1; break; case PROP_COLORMAP: { /* Cannot rely on prop_size here--the value is set incorrectly by some Gimp versions. */ size_t num_colours = ReadBlobMSBLong(image); for (i=0; i < (ssize_t) (3L*num_colours); i++ ) (void) ReadBlobByte(image); /* if (info->file_version == 0) { gint i; g_message (_("XCF warning: version 0 of XCF file format\n" "did not save indexed colormaps correctly.\n" "Substituting grayscale map.")); info->cp += xcf_read_int32 (info->fp, (guint32*) &gimage->num_cols, 1); gimage->cmap = g_new (guchar, gimage->num_cols*3); xcf_seek_pos (info, info->cp + gimage->num_cols); for (i = 0; i<gimage->num_cols; i++) { gimage->cmap[i*3+0] = i; gimage->cmap[i*3+1] = i; gimage->cmap[i*3+2] = i; } } else { info->cp += xcf_read_int32 (info->fp, (guint32*) &gimage->num_cols, 1); gimage->cmap = g_new (guchar, gimage->num_cols*3); info->cp += xcf_read_int8 (info->fp, (guint8*) gimage->cmap, gimage->num_cols*3); } */ break; } case PROP_COMPRESSION: { doc_info.compression = ReadBlobByte(image); if ((doc_info.compression != COMPRESS_NONE) && (doc_info.compression != COMPRESS_RLE) && (doc_info.compression != COMPRESS_ZLIB) && (doc_info.compression != COMPRESS_FRACTAL)) ThrowReaderException(CorruptImageError,"UnrecognizedImageCompression"); } break; case PROP_GUIDES: { /* just skip it - we don't care about guides */ for (i=0; i < (ssize_t) prop_size; i++ ) if (ReadBlobByte(image) == EOF) ThrowFileException(exception,CorruptImageError, "UnexpectedEndOfFile",image->filename); } break; case PROP_RESOLUTION: { /* float xres = (float) */ (void) ReadBlobMSBLong(image); /* float yres = (float) */ (void) ReadBlobMSBLong(image); /* if (xres < GIMP_MIN_RESOLUTION || xres > GIMP_MAX_RESOLUTION || yres < GIMP_MIN_RESOLUTION || yres > GIMP_MAX_RESOLUTION) { g_message ("Warning, resolution out of range in XCF file"); xres = gimage->gimp->config->default_xresolution; yres = gimage->gimp->config->default_yresolution; } */ /* BOGUS: we don't write these yet because we aren't reading them properly yet :( image->x_resolution = xres; image->y_resolution = yres; */ } break; case PROP_TATTOO: { /* we need to read it, even if we ignore it */ /*size_t tattoo_state = */ (void) ReadBlobMSBLong(image); } break; case PROP_PARASITES: { /* BOGUS: we may need these for IPTC stuff */ for (i=0; i < (ssize_t) prop_size; i++ ) if (ReadBlobByte(image) == EOF) ThrowFileException(exception,CorruptImageError, "UnexpectedEndOfFile",image->filename); /* gssize_t base = info->cp; GimpParasite *p; while (info->cp - base < prop_size) { p = xcf_load_parasite (info); gimp_image_parasite_attach (gimage, p); gimp_parasite_free (p); } if (info->cp - base != prop_size) g_message ("Error detected while loading an image's parasites"); */ } break; case PROP_UNIT: { /* BOGUS: ignore for now... */ /*size_t unit = */ (void) ReadBlobMSBLong(image); } break; case PROP_PATHS: { /* BOGUS: just skip it for now */ for (i=0; i< (ssize_t) prop_size; i++ ) if (ReadBlobByte(image) == EOF) ThrowFileException(exception,CorruptImageError, "UnexpectedEndOfFile",image->filename); /* PathList *paths = xcf_load_bzpaths (gimage, info); gimp_image_set_paths (gimage, paths); */ } break; case PROP_USER_UNIT: { char unit_string[1000]; /*BOGUS: ignored for now */ /*float factor = (float) */ (void) ReadBlobMSBLong(image); /* size_t digits = */ (void) ReadBlobMSBLong(image); for (i=0; i<5; i++) (void) ReadBlobStringWithLongSize(image, unit_string, sizeof(unit_string)); } break; default: { int buf[16]; ssize_t amount; /* read over it... */ while ((prop_size > 0) && (EOFBlob(image) == MagickFalse)) { amount=(ssize_t) MagickMin(16, prop_size); amount=(ssize_t) ReadBlob(image,(size_t) amount,(unsigned char *) &buf); if (!amount) ThrowReaderException(CorruptImageError,"CorruptImage"); prop_size -= (size_t) MagickMin(16,(size_t) amount); } } break; } } if (foundPropEnd == MagickFalse) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) { ; /* do nothing, were just pinging! */ } else { int current_layer = 0, foundAllLayers = MagickFalse, number_layers = 0; MagickOffsetType oldPos=TellBlob(image); XCFLayerInfo *layer_info; /* the read pointer */ do { ssize_t offset = (ssize_t) ReadBlobMSBLong(image); if (offset == 0) foundAllLayers=MagickTrue; else number_layers++; if (EOFBlob(image) != MagickFalse) { ThrowFileException(exception,CorruptImageError, "UnexpectedEndOfFile",image->filename); break; } } while (foundAllLayers == MagickFalse); offset=SeekBlob(image,oldPos,SEEK_SET); /* restore the position! */ if (offset < 0) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); /* allocate our array of layer info blocks */ length=(size_t) number_layers; layer_info=(XCFLayerInfo *) AcquireQuantumMemory(length, sizeof(*layer_info)); if (layer_info == (XCFLayerInfo *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); (void) ResetMagickMemory(layer_info,0,number_layers*sizeof(XCFLayerInfo)); for ( ; ; ) { MagickBooleanType layer_ok; MagickOffsetType offset, saved_pos; /* read in the offset of the next layer */ offset=(MagickOffsetType) ReadBlobMSBLong(image); /* if the offset is 0 then we are at the end * of the layer list. */ if (offset == 0) break; /* save the current position as it is where the * next layer offset is stored. */ saved_pos=TellBlob(image); /* seek to the layer offset */ offset=SeekBlob(image,offset,SEEK_SET); /* read in the layer */ layer_ok=ReadOneLayer(image,&doc_info,&layer_info[current_layer]); if (layer_ok == MagickFalse) { int j; for (j=0; j < current_layer; j++) layer_info[j].image=DestroyImage(layer_info[j].image); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } /* restore the saved position so we'll be ready to * read the next offset. */ offset=SeekBlob(image, saved_pos, SEEK_SET); current_layer++; } if (number_layers == 1) { /* Composite the layer data onto the main image, dispose the layer. */ (void) CompositeImage(image,OverCompositeOp,layer_info[0].image, layer_info[0].offset_x,layer_info[0].offset_y); layer_info[0].image =DestroyImage( layer_info[0].image); } else { #if 0 { /* NOTE: XCF layers are REVERSED from composite order! */ signed int j; for (j=number_layers-1; j>=0; j--) { /* BOGUS: need to consider layer blending modes!! */ if ( layer_info[j].visible ) { /* only visible ones, please! */ CompositeImage(image, OverCompositeOp, layer_info[j].image, layer_info[j].offset_x, layer_info[j].offset_y ); layer_info[j].image =DestroyImage( layer_info[j].image ); /* Bob says that if we do this, we'll get REAL gray images! */ if ( image_type == GIMP_GRAY ) { QuantizeInfo qi; GetQuantizeInfo(&qi); qi.colorspace = GRAYColorspace; QuantizeImage( &qi, layer_info[j].image ); } } } } #else { /* NOTE: XCF layers are REVERSED from composite order! */ signed int j; /* first we copy the last layer on top of the main image */ (void) CompositeImage(image,CopyCompositeOp, layer_info[number_layers-1].image, layer_info[number_layers-1].offset_x, layer_info[number_layers-1].offset_y); layer_info[number_layers-1].image=DestroyImage( layer_info[number_layers-1].image); /* now reverse the order of the layers as they are put into subimages */ j=number_layers-2; image->next=layer_info[j].image; layer_info[j].image->previous=image; layer_info[j].image->page.x=layer_info[j].offset_x; layer_info[j].image->page.y=layer_info[j].offset_y; layer_info[j].image->page.width=layer_info[j].width; layer_info[j].image->page.height=layer_info[j].height; for (j=number_layers-3; j>=0; j--) { if (j > 0) layer_info[j].image->next=layer_info[j-1].image; if (j < (number_layers-1)) layer_info[j].image->previous=layer_info[j+1].image; layer_info[j].image->page.x=layer_info[j].offset_x; layer_info[j].image->page.y=layer_info[j].offset_y; layer_info[j].image->page.width=layer_info[j].width; layer_info[j].image->page.height=layer_info[j].height; } } #endif } layer_info=(XCFLayerInfo *) RelinquishMagickMemory(layer_info); #if 0 /* BOGUS: do we need the channels?? */ while (MagickTrue) { /* read in the offset of the next channel */ info->cp += xcf_read_int32 (info->fp, &offset, 1); /* if the offset is 0 then we are at the end * of the channel list. */ if (offset == 0) break; /* save the current position as it is where the * next channel offset is stored. */ saved_pos = info->cp; /* seek to the channel offset */ xcf_seek_pos (info, offset); /* read in the layer */ channel = xcf_load_channel (info, gimage); if (channel == 0) goto error; num_successful_elements++; /* add the channel to the image if its not the selection */ if (channel != gimage->selection_mask) gimp_image_add_channel (gimage, channel, -1); /* restore the saved position so we'll be ready to * read the next offset. */ xcf_seek_pos (info, saved_pos); } #endif } (void) CloseBlob(image); if (image_type == GIMP_GRAY) image->type=GrayscaleType; return(GetFirstImageInList(image)); }
bool Image::quantize() { return QuantizeImage( &m_quantizeInfo, m_image ); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W r i t e E P T I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % WriteEPTImage() writes an image in the Encapsulated Postscript format % with a TIFF preview. % % The format of the WriteEPTImage method is: % % MagickBooleanType WriteEPTImage(const ImageInfo *image_info, % Image *image,ExceptionInfo *exception) % % A description of each parameter follows. % % o image_info: the image info. % % o image: The image. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image, ExceptionInfo *exception) { char filename[MagickPathExtent]; EPTInfo ept_info; Image *write_image; ImageInfo *write_info; MagickBooleanType status; /* Write EPT image. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickCoreSignature); assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); if (status == MagickFalse) return(status); write_image=CloneImage(image,0,0,MagickTrue,exception); if (write_image == (Image *) NULL) return(MagickFalse); write_info=CloneImageInfo(image_info); (void) CopyMagickString(write_info->magick,"EPS",MagickPathExtent); if (LocaleCompare(image_info->magick,"EPT2") == 0) (void) CopyMagickString(write_info->magick,"EPS2",MagickPathExtent); if (LocaleCompare(image_info->magick,"EPT3") == 0) (void) CopyMagickString(write_info->magick,"EPS3",MagickPathExtent); (void) ResetMagickMemory(&ept_info,0,sizeof(ept_info)); ept_info.magick=0xc6d3d0c5ul; ept_info.postscript=(unsigned char *) ImageToBlob(write_info,write_image, &ept_info.postscript_length,exception); write_image=DestroyImage(write_image); write_info=DestroyImageInfo(write_info); if (ept_info.postscript == (void *) NULL) return(MagickFalse); write_image=CloneImage(image,0,0,MagickTrue,exception); if (write_image == (Image *) NULL) return(MagickFalse); write_info=CloneImageInfo(image_info); *write_info->magick='\0'; (void) CopyMagickString(write_info->magick,"TIFF",MagickPathExtent); (void) FormatLocaleString(filename,MagickPathExtent,"tiff:%s", write_info->filename); (void) CopyMagickString(write_info->filename,filename,MagickPathExtent); (void) TransformImage(&write_image,(char *) NULL,"512x512>",exception); if ((write_image->storage_class == DirectClass) || (write_image->colors > 256)) { QuantizeInfo quantize_info; /* EPT preview requires that the image is colormapped. */ GetQuantizeInfo(&quantize_info); quantize_info.dither_method=IdentifyPaletteImage(write_image, exception) == MagickFalse ? RiemersmaDitherMethod : NoDitherMethod; (void) QuantizeImage(&quantize_info,write_image,exception); } write_info->compression=NoCompression; ept_info.tiff=(unsigned char *) ImageToBlob(write_info,write_image, &ept_info.tiff_length,exception); write_image=DestroyImage(write_image); write_info=DestroyImageInfo(write_info); if (ept_info.tiff == (void *) NULL) { ept_info.postscript=(unsigned char *) RelinquishMagickMemory( ept_info.postscript); return(MagickFalse); } /* Write EPT image. */ (void) WriteBlobLSBLong(image,(unsigned int) ept_info.magick); (void) WriteBlobLSBLong(image,30); (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length); (void) WriteBlobLSBLong(image,0); (void) WriteBlobLSBLong(image,0); (void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length+30); (void) WriteBlobLSBLong(image,(unsigned int) ept_info.tiff_length); (void) WriteBlobLSBShort(image,0xffff); (void) WriteBlob(image,ept_info.postscript_length,ept_info.postscript); (void) WriteBlob(image,ept_info.tiff_length,ept_info.tiff); /* Relinquish resources. */ ept_info.postscript=(unsigned char *) RelinquishMagickMemory( ept_info.postscript); ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff); (void) CloseBlob(image); return(MagickTrue); }
void * gif_encode(Image *image, int single, int *size) { int width = image->columns; int height = image->rows; int total = width * height; GifByteType red[total]; GifByteType green[total]; GifByteType blue[total]; // Quantize the images using IM/GM first, to reduce // their number of colors to 256. int count = GetImageListLength(image); QuantizeInfo info; GetQuantizeInfo(&info); info.dither = 0; info.number_colors = NCOLORS; QuantizeImage(&info, image); if (count > 1) { #ifdef _MAGICK_USES_IM RemapImages(&info, image->next, image); #else MapImages(image->next, image, 0); #endif } if (!acquire_image_pixels(image, red, green, blue)) { return NULL; } size_t frame_size = sizeof(Frame) + total; Frame *frames = malloc(frame_size * count); ColorMapObject *palette = GifMakeMapObject(NCOLORS, NULL); int palette_size = NCOLORS; // Quantize again using giflib, since it yields a palette which produces // better compression, reducing the file size by 20%. Note that this second // quantization is very fast, because the image already has 256 colors, so // its effect on performance is negligible. if (GifQuantizeBuffer(width, height, &palette_size, red, green, blue, frames->data, palette->Colors) == GIF_ERROR) { GifFreeMapObject(palette); free(frames); return NULL; } frames->width = width; frames->height = height; frames->duration = image->delay; GifColorType *colors = palette->Colors; Image *cur = image->next; PixelCache *cache = pixel_cache_new(); unsigned char *p = (unsigned char*)frames; int ii; for (ii = 1; ii < count; ii++, cur = cur->next) { p += frame_size; Frame *frame = (Frame*)p; frame->width = width; frame->height = height; frame->duration = cur->delay; GifPixelType *data = frame->data; if (!aprox_image_pixels(cur, colors, palette_size, cache, data)) { GifFreeMapObject(palette); free(frames); pixel_cache_free(cache); return NULL; } } pixel_cache_free(cache); void *ret = gif_save(image, palette, frames, count, frame_size, size); GifFreeMapObject(palette); free(frames); return ret; }
// Function to detect and draw any faces that is present in an image void detect_and_draw( IplImage* img ) { potrace_state_t** states; potrace_state_t** fstates; int tmp, num_ccs, face_ccs, *compcolor, *pixeldistribution; int *segmentsize, *facesize, *facecolor, *facelist, *complist, scale = 1; universe *u, *fu; //fu is the face universe, get your mind out of the gutter potrace_bitmap_t** VGbmps, **Facebmps; static int framenumber = 0; CvPoint pt1, pt2; // Create a new image based on the input image IplImage* quantized; IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 ); if(framenumber==0)page_svg_open(OutFile, img->width, img->height); if(framenumber==37)system("pause"); cvShowImage( "original", img ); //find all faces FindFaces(img, &pt1, &pt2); // Quantize our input quantized = QuantizeImage(img); /* system("pause"); if(!cvSaveImage("output.bmp",quantized)){ printf("Could not save: %s\n","output.bmp"); system("pause");} return;*/ // do segmentation u = SegmentImage(quantized, pt1, pt2, &num_ccs, false); fu = SegmentImage(quantized, pt1, pt2, &face_ccs, true); complist = (int*) malloc(sizeof(int)*num_ccs); compcolor = (int*) malloc(sizeof(int)*num_ccs); facelist = (int*) malloc(sizeof(int)*face_ccs); facecolor = (int*) malloc(sizeof(int)*face_ccs); /*************************************************************************/ // this is the workforce code, it does all the cool stuff //allocate bitmaps and associated data VGbmps = (potrace_bitmap_t**)malloc(sizeof(potrace_bitmap_t*)*num_ccs); //figure out distributions for background sutraction segmentsize = (int*) malloc(sizeof(int)*num_ccs); facesize = (int*) malloc(sizeof(int)*face_ccs); pixeldistribution = (int*) malloc(sizeof(int)*num_ccs); VGbmps = bmpalloc(num_ccs, img->width, img->height); for(int k=0; k<num_ccs; k++)compcolor[k] = complist[k] = segmentsize[k] = pixeldistribution[k] = 0; Facebmps = bmpalloc(face_ccs, img->width, img->height); for(int k=0; k<face_ccs; k++)facecolor[k] = facelist[k] = facesize[k] = 0; // find the background cvUpdatePixelBackgroundGMM(pGMM,(unsigned char*)quantized->imageData, (unsigned char*)temp->imageData); int comp; //Find number of pixels in each segment which are foreground for(int j = 0; j<img->height; j++){ for(int i = 0; i<img->width; i++){ int k = j*img->width+i; if(!(((i>pt1.x)&&(i<pt2.x))&&((j>pt1.y)&&(j<pt2.y)))){ comp = u->find(k); comp = FindonList(comp,complist,num_ccs); //incrament its segment segmentsize[comp]++; //increase its distribution if its forground pixeldistribution[comp] += (temp->imageData[k*3]==0)?0:1; //note temp is grayscale so it doesn't matter which color we take // just take one for every 3 }else{ comp = fu->find(k); comp = FindonList(comp,facelist,face_ccs); facesize[comp]++; }//don't bother with the face pixels they're getting 1's anyway }} double *R = (double*)malloc(sizeof(double)*num_ccs); double *G = (double*)malloc(sizeof(double)*num_ccs); double *B = (double*)malloc(sizeof(double)*num_ccs); for(int k = 0; k<num_ccs; k++)R[k] = G[k] = B[k] = 0.0; double *fR = (double*)malloc(sizeof(double)*face_ccs); double *fG = (double*)malloc(sizeof(double)*face_ccs); double *fB = (double*)malloc(sizeof(double)*face_ccs); for(int k = 0; k<face_ccs; k++)fR[k] = fG[k] = fB[k] = 0.0; for(int j = 0; j<img->height; j++){ for(int i = 0; i<img->width; i++){ int r,g,b; int k = j*img->width+i; if(!(((i>pt1.x)&&(i<pt2.x))&&((j>pt1.y)&&(j<pt2.y)))){ comp = u->find(k); comp = FindonList(comp,complist,num_ccs); r = (quantized->imageData[k*3+2]&0xFF); g = (quantized->imageData[k*3+1]&0xFF); b = (quantized->imageData[k*3+0]&0xFF); R[comp] += r/double(segmentsize[comp]); G[comp] += g/double(segmentsize[comp]); B[comp] += b/double(segmentsize[comp]); compcolor[comp] = (r&0xFF)<<16 | (g&0xFF)<<8 | b&0xFF; PlacePoPixel(VGbmps[comp],i,j); }else{ comp = fu->find(k); comp = FindonList(comp,facelist,face_ccs); r = (quantized->imageData[k*3+2]&0xFF); g = (quantized->imageData[k*3+1]&0xFF); b = (quantized->imageData[k*3+0]&0xFF); fR[comp] += r/double(facesize[comp]); fG[comp] += g/double(facesize[comp]); fB[comp] += b/double(facesize[comp]); facecolor[comp] = (r&0xFF)<<16 | (g&0xFF)<<8 | b&0xFF; PlacePoPixel(Facebmps[comp],i,j); } } } for(int k = 0; k<num_ccs; k++) compcolor[k] =(int(R[k])&0xFF)<<16 | (int(G[k])&0xFF)<<8 | int(B[k])&0xFF; for(int k = 0; k<face_ccs; k++) facecolor[k] =(int(fR[k])&0xFF)<<16 | (int(fG[k])&0xFF)<<8 | int(fB[k])&0xFF; //for(int k = 0; k<num_ccs; k++) compcolor[k] =(int(rand()%255)&0xFF)<<16 | (int(rand()%255)&0xFF)<<8 | int(rand()%255)&0xFF; //for(int k = 0; k<face_ccs; k++) facecolor[k] =(int(rand()%255)&0xFF)<<16 | (int(rand()%255)&0xFF)<<8 | int(rand()%255)&0xFF; /*************************************************************************/ float percentage; //generalize segement color for(int j = 0; j<img->height; j++){ for(int i = 0; i<img->width; i++){ int k = j*img->width+i; if(!(((i>pt1.x)&&(i<pt2.x))&&((j>pt1.y)&&(j<pt2.y)))){ comp = u->find(k); comp = FindonList(comp,complist,num_ccs); percentage = ((float)pixeldistribution[comp])/((float)segmentsize[comp]); if(percentage > -1.f){ quantized->imageData[k*3+2] = (compcolor[comp]>>16)&0xFF; quantized->imageData[k*3+1] = (compcolor[comp]>>8)&0xFF; quantized->imageData[k*3+0] = (compcolor[comp])&0xFF; }else{ quantized->imageData[k*3+2] = (0>>16)&0xFF; quantized->imageData[k*3+1] = (0>>8)&0xFF; quantized->imageData[k*3+0] = (0)&0xFF; } }else{