Exemple #1
0
        public ImageRenderData RenderEffect(Bitmap rawPhoto, ComicEffectType effectType, Dictionary <string, object> parameterValues)
        {
            // Resize
            rawPhoto = this.ResizeToMax(rawPhoto);

            // Convert bitmap to color
            if (rawPhoto.PixelFormat != PixelFormat.Format24bppRgb)
            {
                rawPhoto = rawPhoto.ConvertFormat(PixelFormat.Format24bppRgb);
            }

            // Convert
            IComicRender renderEffect = this.GetRenderEffect(effectType);

            renderEffect.SetRenderParameterValues(parameterValues);
            Bitmap renderPhoto = renderEffect.Render(rawPhoto);

            // Read rendered photo into memory
            MemoryStream renderStream = new MemoryStream();

            renderPhoto.Save(renderStream, ImageFormat.Jpeg);
            renderStream.Seek(0, SeekOrigin.Begin);
            byte[] renderBuffer = new byte[renderStream.Length];
            renderStream.Read(renderBuffer, 0, renderBuffer.Length);

            // Read raw photo into memory
            MemoryStream rawStream = new MemoryStream();

            rawPhoto.Save(rawStream, ImageFormat.Jpeg);
            rawStream.Seek(0, SeekOrigin.Begin);
            byte[] rawBuffer = new byte[rawStream.Length];
            rawStream.Read(rawBuffer, 0, rawBuffer.Length);

            return(new ImageRenderData(rawStream, renderStream));
        }
Exemple #2
0
        public JsonResult QueuePhotoRender(ComicEffectType effect, string photoSource, int intensity)
        {
            // Generate render task
            PhotoTask task = new PhotoTask();

            task.TaskId        = Guid.NewGuid();
            task.Status        = TaskStatus.Queued;
            task.Effect        = effect;
            task.Intensity     = intensity;
            task.FacebookToken = this.Facebook.AccessToken;
            task.SourceUrl     = photoSource;
            task.OwnerUid      = this.ActiveUser.Uid;

            // Queue the task up using Azure Queue services.  Store full task information using Blob storage.  Only the task id is queued.
            // This is done because we need public visibility on render tasks before, during and after the task completes.

            // Save task to storage
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoTaskDirectory);
            CloudBlob          blob      = directory.GetBlobReference(task.TaskId.ToString());

            blob.UploadText(task.ToXml());

            // Queue up task
            CloudQueue        queue   = this.QueueClient.GetQueueReference(ComicConfigSectionGroup.Queue.PhotoTaskQueue);
            CloudQueueMessage message = new CloudQueueMessage(task.TaskId.ToString());

            queue.AddMessage(message, TimeSpan.FromMinutes(5));

            return(this.Json(new ClientPhotoTask(task, null), JsonRequestBehavior.DenyGet));
        }
Exemple #3
0
        public ImageRenderData RenderEffect(string rawUrl, ComicEffectType effectType, Dictionary <string, object> parameterValues)
        {
            HttpWebRequest photoRequest = (HttpWebRequest)HttpWebRequest.Create(rawUrl);

            photoRequest.Timeout = 5000;             // 5 seconds
            HttpWebResponse photoResponse = photoRequest.GetResponse() as HttpWebResponse;
            Bitmap          rawPhoto      = new Bitmap(photoResponse.GetResponseStream());

            return(this.RenderEffect(rawPhoto, effectType, parameterValues));
        }
Exemple #4
0
        public JsonResult QueueRenderWizard(ComicEffectType effect, string photoSource, long templateId, List <RenderFrame> frames)
        {
            // Generate wizard render task
            RenderTask task = new RenderTask();

            task.TaskId = Guid.NewGuid();
            task.Status = TaskStatus.Queued;
            task.CompletedOperations = 1;
            task.TotalOperations     = frames.Count + 2;         // Operations = 1 per frame + save + queue
            task.Effect        = effect;
            task.PhotoSource   = photoSource;
            task.TemplateId    = templateId;
            task.Frames        = frames;
            task.OwnerUid      = this.ActiveUser.Uid;
            task.FacebookToken = this.Facebook.AccessToken;

            return(this.QueueRender(task));
        }
Exemple #5
0
        protected IComicRender GetRenderEffect(ComicEffectType effect)
        {
            IComicRender renderEffect;

            switch (effect)
            {
            case ComicEffectType.ColorSketch:
            default:
                renderEffect = new ColorSketch();
                break;

            case ComicEffectType.PencilSketch:
                renderEffect = new PencilSketch();
                break;

            case ComicEffectType.Comic:
                renderEffect = new Comic();
                break;
            }
            return(renderEffect);
        }
        public ActionResult QueueRender(ComicEffectType effect, int intensity)
        {
            // Generate render task
            ProfileTask task = new ProfileTask();

            task.TaskId        = Guid.NewGuid();
            task.Status        = TaskStatus.Queued;
            task.Effect        = effect;
            task.Intensity     = intensity;
            task.OwnerUid      = this.ActiveUser.Uid;
            task.FacebookToken = this.Facebook.AccessToken;
            task.StorageKey    = this.ActiveUser.Uid.ToString();

            // Queue the task up using Azure Queue services.  Store full task information using Blob storage.  Only the task id is queued.
            // This is done because we need public visibility on render tasks before, during and after the task completes.

            // Save task to storage
            CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer);
            CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.ProfileTaskDirectory);
            CloudBlob          blob      = directory.GetBlobReference(task.TaskId.ToString());

            blob.UploadText(task.ToXml());

            // Queue up task
            CloudQueue        queue   = this.QueueClient.GetQueueReference(ComicConfigSectionGroup.Queue.ProfileTaskQueue);
            CloudQueueMessage message = new CloudQueueMessage(task.TaskId.ToString());

            queue.AddMessage(message, TimeSpan.FromMinutes(5));

            //Session autoshare
            bool autoShareFeed = false;

            if (this.Session[SESSION_AUTO_SHARE] == null)
            {
                autoShareFeed = true;
                this.Session[SESSION_AUTO_SHARE] = true;
            }

            return(this.View("Render", new ViewFacebookRender(new ClientProfileTask(task), autoShareFeed)));
        }
Exemple #7
0
        public List <RenderParameter> GetRenderParameters(ComicEffectType effect)
        {
            IComicRender renderEffect = this.GetRenderEffect(effect);

            return(renderEffect.GetRenderParameters());
        }
Exemple #8
0
 public ClientEffect(string title, string thumbUrl, ComicEffectType effectId)
 {
     this.Title    = title;
     this.ThumbUrl = thumbUrl;
     this.EffectId = effectId;
 }