// GET /projects/{project-id}/textures/{texture-id}/{texture-size}/raw func (resource *WorkspaceResource) getTextureImageAsRaw(request *restful.Request, response *restful.Response) { projectID := request.PathParameter("project-id") project, err := resource.ws.Project(projectID) if err == nil { textureID, _ := strconv.ParseInt(request.PathParameter("texture-id"), 10, 16) textureSize := request.PathParameter("texture-size") bmp := project.Textures().Image(int(textureID), model.TextureSize(textureSize)) var entity model.RawBitmap entity.Width = int(bmp.ImageWidth()) entity.Height = int(bmp.ImageHeight()) var pixel []byte for row := 0; row < entity.Height; row++ { pixel = append(pixel, bmp.Row(row)...) } entity.Pixels = base64.StdEncoding.EncodeToString(pixel) response.WriteEntity(entity) } else { response.AddHeader("Content-Type", "text/plain") response.WriteErrorString(http.StatusBadRequest, err.Error()) return } }
// GET /projects/{project-id}/textures/{texture-id}/{texture-size} func (resource *WorkspaceResource) getTextureImage(request *restful.Request, response *restful.Response) { projectID := request.PathParameter("project-id") project, err := resource.ws.Project(projectID) if err == nil { textureID, _ := strconv.ParseInt(request.PathParameter("texture-id"), 10, 16) textureSize := request.PathParameter("texture-size") var entity model.Image entity.Href = "/projects/" + projectID + "/textures/" + fmt.Sprintf("%d", textureID) + "/" + textureSize bmp := project.Textures().Image(int(textureID), model.TextureSize(textureSize)) hotspot := bmp.Hotspot() entity.Properties.HotspotLeft = hotspot.Min.X entity.Properties.HotspotTop = hotspot.Min.Y entity.Properties.HotspotRight = hotspot.Max.X entity.Properties.HotspotBottom = hotspot.Max.Y entity.Formats = []model.Link{model.Link{Rel: "png", Href: entity.Href + "/png"}} entity.Formats = []model.Link{model.Link{Rel: "raw", Href: entity.Href + "/raw"}} response.WriteEntity(entity) } else { response.AddHeader("Content-Type", "text/plain") response.WriteErrorString(http.StatusBadRequest, err.Error()) return } }
// GET /projects/{project-id}/textures/{texture-id}/{texture-size}/png func (resource *WorkspaceResource) getTextureImageAsPng(request *restful.Request, response *restful.Response) { projectID := request.PathParameter("project-id") project, err := resource.ws.Project(projectID) if err == nil { textureID, _ := strconv.ParseInt(request.PathParameter("texture-id"), 10, 16) textureSize := request.PathParameter("texture-size") var palette color.Palette bmp := project.Textures().Image(int(textureID), model.TextureSize(textureSize)) palette, err = project.Palettes().GamePalette() image := image.FromBitmap(bmp, palette) response.AddHeader("Content-Type", "image/png") png.Encode(response.ResponseWriter, image) } else { response.AddHeader("Content-Type", "text/plain") response.WriteErrorString(http.StatusBadRequest, err.Error()) return } }